MessageHandler.c 1004 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338
  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 meterValueBufferQuery(uint8_t gun_index, json_object *MeterValues)
  422. {
  423. int result = PASS;
  424. char sqlCmd[8192];
  425. char zErrMsg[200];
  426. int rows, cols;
  427. char **resultData;
  428. sprintf(sqlCmd, "select * from meterValuesBuffer where gun_index='%d' order by ReadingContext, idx", gun_index);
  429. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  430. {
  431. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  432. result = FAIL;
  433. }
  434. else
  435. {
  436. for(uint32_t idxRow=1;idxRow<=rows;idxRow++)
  437. {
  438. json_object *MeterValue = json_tokener_parse(resultData[(idxRow*cols)+5]);
  439. json_object_array_add(MeterValues, MeterValue);
  440. }
  441. }
  442. return result;
  443. }
  444. //=========================================
  445. // Certificate related routine
  446. //=========================================
  447. int certVerify(char *privateKey, char *cert)
  448. {
  449. int result = PASS;
  450. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  451. // Load certificate file
  452. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  453. {
  454. DEBUG_ERROR("Load certificate error!\n");
  455. result = FAIL;
  456. }
  457. // Load private key file
  458. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  459. {
  460. DEBUG_ERROR("Load private key error!\n");
  461. result = FAIL;
  462. }
  463. if(!SSL_CTX_check_private_key(ctx))
  464. {
  465. result = FAIL;
  466. }
  467. SSL_CTX_free(ctx);
  468. return result;
  469. }
  470. //=========================================
  471. // TTIA routine
  472. //=========================================
  473. int sendTTIAInfo(uint8_t gun_index)
  474. {
  475. static int sn = 0;
  476. int result = FAIL;
  477. struct hostent *server;
  478. int udp_socket_fd;
  479. struct sockaddr_in dest_addr = {0};
  480. uint8_t tx_buf[80] = {0};
  481. uint8_t logBuf[256]= {0};
  482. uint8_t tx_len, tempIndex, socStart, socEnd;
  483. uint16_t PresentChargedEnergy;
  484. struct tm tmStart, tmEnd;
  485. DEBUG_INFO("sendTTIAInfo...\n");
  486. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  487. {
  488. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  489. {
  490. tempIndex = ((gun_index==2) ? 1: 0);
  491. }
  492. else
  493. {
  494. tempIndex = gun_index;
  495. }
  496. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  497. {
  498. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  499. {
  500. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  501. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  502. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  503. }
  504. }
  505. }
  506. else if(gunType[gun_index] == GUN_TYPE_CCS)
  507. {
  508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  509. {
  510. tempIndex = ((gun_index==2) ? 1: 0);
  511. }
  512. else
  513. {
  514. tempIndex = gun_index;
  515. }
  516. for (int index = 0; index < CCS_QUANTITY; index++)
  517. {
  518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  519. {
  520. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  521. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  522. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  523. }
  524. }
  525. }
  526. else if(gunType[gun_index] == GUN_TYPE_GBT)
  527. {
  528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  529. {
  530. tempIndex = ((gun_index==2) ? 1: 0);
  531. }
  532. else
  533. {
  534. tempIndex = gun_index;
  535. }
  536. for (int index = 0; index < GB_QUANTITY; index++)
  537. {
  538. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  539. {
  540. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  541. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  542. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  543. }
  544. }
  545. }
  546. else if(gunType[gun_index] == GUN_TYPE_DO)
  547. {
  548. tempIndex = gun_index;
  549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  550. {
  551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  552. {
  553. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  554. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  555. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  556. }
  557. }
  558. }
  559. else
  560. {
  561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  562. {
  563. tempIndex = 2;
  564. }
  565. else
  566. {
  567. tempIndex = gun_index;
  568. }
  569. for (int index = 0; index < AC_QUANTITY; index++)
  570. {
  571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  572. {
  573. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  574. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  575. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  576. }
  577. }// END
  578. }
  579. // Message assembly
  580. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  581. tx_buf[4] = 0x02; // Protocol Version
  582. tx_buf[5] = 0xb0; // Message ID
  583. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  584. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  585. tx_buf[8] = 0x00; // CarID low byte
  586. tx_buf[9] = 0x00; // CarID high byte
  587. tx_buf[10] = 0x00; // ID Storage
  588. tx_buf[11] = 0x00; // Driver lowest byte
  589. tx_buf[12] = 0x00; // Driver 2nd byte
  590. tx_buf[13] = 0x00; // Driver 3rd byte
  591. tx_buf[14] = 0x00; // Driver highest byte
  592. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  593. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  594. tx_buf[17] = 0x00; // Reserve
  595. tx_buf[18] = 60 & 0xff; // Payload length low byte
  596. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  597. // EVSE provider
  598. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  599. // EVSE provider
  600. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  601. // EVSE id
  602. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  603. // Connector id
  604. tx_buf[37] = gun_index;
  605. // EVSE station
  606. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  607. // Vehicle SN
  608. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  609. // Mileage
  610. tx_buf[61] = 0x00; // lowest byte
  611. tx_buf[62] = 0x00; // 2nd byte
  612. tx_buf[63] = 0x00; // highest byte
  613. // Start date time 6 bytes
  614. 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))
  615. {
  616. struct tm *tmTarget;
  617. struct timeb tbTarget;
  618. tmStart.tm_year -= 1900;
  619. tmStart.tm_mon -= 1;
  620. tmStart.tm_gmtoff = 0;
  621. tbTarget.time = mktime(&tmStart);
  622. tbTarget.timezone = 0;
  623. tbTarget.time += (8*3600);
  624. tmTarget = gmtime(&tbTarget.time);
  625. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  626. tx_buf[65] = (tmTarget->tm_mon+1);
  627. tx_buf[66] = tmTarget->tm_mday;
  628. tx_buf[67] = tmTarget->tm_hour;
  629. tx_buf[68] = tmTarget->tm_min;
  630. tx_buf[69] = tmTarget->tm_sec;
  631. }
  632. // Stop date time 6 bytes
  633. 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))
  634. {
  635. struct tm *tmTarget;
  636. struct timeb tbTarget;
  637. tmEnd.tm_year -= 1900;
  638. tmEnd.tm_mon -= 1;
  639. tmEnd.tm_gmtoff = 0;
  640. tbTarget.time = mktime(&tmEnd);
  641. tbTarget.timezone = 0;
  642. tbTarget.time += (8*3600);
  643. tmTarget = gmtime(&tbTarget.time);
  644. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  645. tx_buf[71] = (tmTarget->tm_mon+1);
  646. tx_buf[72] = tmTarget->tm_mday;
  647. tx_buf[73] = tmTarget->tm_hour;
  648. tx_buf[74] = tmTarget->tm_min;
  649. tx_buf[75] = tmTarget->tm_sec;
  650. }
  651. // Session energy 2 bytes
  652. tx_buf[76] = PresentChargedEnergy & 0xff;
  653. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  654. // Start SOC 1 byte
  655. tx_buf[78] = socStart;
  656. // Stop SOC 1 byte
  657. tx_buf[79] = socEnd;
  658. // Open socket
  659. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  660. if(udp_socket_fd == -1)
  661. {
  662. DEBUG_ERROR("UDP socket create failed!\n");
  663. }
  664. else
  665. {
  666. // Get server DNS entry
  667. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  668. if (server == NULL)
  669. {
  670. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  671. }
  672. else
  673. {
  674. // Build the server's Internet address
  675. bzero((char *) &dest_addr, sizeof(dest_addr));
  676. dest_addr.sin_family = AF_INET;
  677. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  678. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  679. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  680. {
  681. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  682. {
  683. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  684. }
  685. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  686. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  687. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  688. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  689. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  690. DEBUG_TTIA_INFO("---------- Header ----------\n");
  691. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  692. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  693. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  694. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  695. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  696. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  697. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  698. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  699. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  700. DEBUG_TTIA_INFO("Len: 0x3C\n");
  701. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  702. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  703. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  704. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  705. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  706. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  707. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  708. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  709. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  710. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  711. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  712. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  713. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  714. DEBUG_TTIA_INFO("=========================================\n");
  715. sn++;
  716. result = PASS;
  717. }
  718. else
  719. {
  720. DEBUG_ERROR("UDP sent out fail.\n");
  721. }
  722. }
  723. }
  724. return result;
  725. }
  726. //=========================================
  727. // Save configuration
  728. //=========================================
  729. int runShellCmd(const char*cmd)
  730. {
  731. int result = FAIL;
  732. char buf[256];
  733. FILE *fp;
  734. fp = popen(cmd, "r");
  735. if(fp != NULL)
  736. {
  737. while(fgets(buf, sizeof(buf), fp) != NULL)
  738. {
  739. DEBUG_INFO("%s\n", buf);
  740. }
  741. result = PASS;
  742. }
  743. pclose(fp);
  744. return result;
  745. }
  746. int StoreUsrConfigData(struct SysConfigData *UsrData)
  747. {
  748. int result = PASS;
  749. int fd,wrd;
  750. unsigned int i,Chk;
  751. unsigned char *ptr, *BufTmp;
  752. int MtdBlockSize = 0x300000;
  753. Chk=0;
  754. ptr=(unsigned char *)UsrData;
  755. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  756. {
  757. memset(BufTmp,0,MtdBlockSize);
  758. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  759. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  760. Chk+=*(BufTmp+i);
  761. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  762. // Output configuration to file.
  763. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  764. if (fd < 0)
  765. {
  766. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  767. free(BufTmp);
  768. return 0;
  769. }
  770. wrd=write(fd, BufTmp, MtdBlockSize);
  771. close(fd);
  772. if(wrd<MtdBlockSize)
  773. {
  774. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  775. free(BufTmp);
  776. return 0;
  777. }
  778. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  779. DEBUG_INFO("Erase /dev/mtd10.\n");
  780. runShellCmd("flash_erase /dev/mtd10 0 0");
  781. DEBUG_INFO("Write /dev/mtd10.\n");
  782. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  783. DEBUG_INFO("Erase /dev/mtd11.\n");
  784. runShellCmd("flash_erase /dev/mtd11 0 0");
  785. DEBUG_INFO("Write /dev/mtd11.\n");
  786. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  787. system("rm -f /mnt/EvseConfig.bin");
  788. DEBUG_INFO("EvseConfig write to flash OK\n");
  789. }
  790. else
  791. {
  792. DEBUG_ERROR("alloc BlockSize NG\r\n");
  793. result = FAIL;
  794. }
  795. if(BufTmp!=NULL)
  796. free(BufTmp);
  797. return result;
  798. }
  799. //=========================================
  800. // Sqlite3 related function
  801. //=========================================
  802. static int selectSqlCount = 0;
  803. static int callback(void *data, int argc, char **argv, char **azColName){
  804. int i;
  805. //printf("%s: ", (const char*)data);
  806. selectSqlCount = argc;
  807. for(i = 0; i<argc; i++){
  808. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  809. }
  810. //printf("\n");
  811. return 0;
  812. }
  813. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  814. //int i;
  815. //printf("%s:\n", (const char*)data);
  816. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  817. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  818. return 0;
  819. }
  820. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  821. //printf("%s:\n", (const char*)data);
  822. //idTag
  823. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  824. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  825. //parentIdTag
  826. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  827. //expir_date
  828. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  829. //status
  830. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  831. //version
  832. if(columenCount > 5)
  833. idTagQuery.listVersionInt = atoi(columnValue[5]);
  834. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  835. return 0;
  836. }
  837. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  838. {
  839. // localversion = argv[5] ? atoi(argv[5]) : 0;
  840. // printf("localversion=%d\n", localversion);
  841. return 0;
  842. }
  843. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  844. {
  845. for (int i = 0; i < n_columns; i++)
  846. {
  847. DEBUG_INFO("%s\t", col_values[i]);
  848. }
  849. DEBUG_INFO("\n");
  850. return 0;
  851. }
  852. int OCPP_cleanLocalCache()
  853. {
  854. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  855. char *errMsg = 0;
  856. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  857. if (SQLITE_OK != rc)
  858. {
  859. DEBUG_INFO("SQL error: %s\n",errMsg);
  860. return FALSE;
  861. }
  862. return TRUE;
  863. }
  864. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  865. {
  866. int isSuccess = TRUE;
  867. int ret = 0;
  868. //const char* data = "Callback function called";
  869. char sql[300];
  870. char zErrMsg[200];
  871. memset(sql, 0, 300);
  872. memset(zErrMsg, 0, 200);
  873. 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);
  874. //* Execute SQL statement */
  875. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  876. if( ret != SQLITE_OK )
  877. {
  878. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  879. isSuccess = FALSE;
  880. }
  881. return isSuccess;
  882. }
  883. void OCPP_getIdTagFromLocalCache(char idTag[])
  884. {
  885. int rc = 0;
  886. char sql[100];
  887. char zErrMsg[100];
  888. memset(sql, 0, 100);
  889. memset(zErrMsg, 0, 100);
  890. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  891. memset(&idTagQuery, 0, sizeof(idTagQuery));
  892. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  893. /* Execute SQL statement */
  894. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  895. if( rc != SQLITE_OK )
  896. {
  897. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  898. }
  899. }
  900. void OCPP_getListVerion()
  901. {
  902. int rc = 0;
  903. // const char* data = "Callback function called";
  904. char sql[100];
  905. char zErrMsg[100];
  906. memset(sql, 0, 100);
  907. memset(zErrMsg, 0, 100);
  908. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  909. /* Execute SQL statement */
  910. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  911. if( rc != SQLITE_OK )
  912. {
  913. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  914. }
  915. }
  916. void OCPP_get_TableAuthlocalAllData(void)
  917. {
  918. int rc = 0;
  919. char sql[100];
  920. char zErrMsg[100];
  921. memset(sql, 0, 100);
  922. memset(zErrMsg, 0, 100);
  923. sprintf(sql,"select * from ocpp_auth_local ");
  924. /* Execute SQL statement */
  925. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  926. if( rc != SQLITE_OK )
  927. {
  928. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  929. }
  930. //return ver;
  931. }
  932. int OCPP_cleanLocalList()
  933. {
  934. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  935. char *errMsg = 0;
  936. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  937. if (SQLITE_OK != rc)
  938. {
  939. DEBUG_INFO("%s\n",errMsg);
  940. return FALSE;
  941. }
  942. return TRUE;
  943. }
  944. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  945. {
  946. int isSuccess = FALSE;
  947. int ret = 0;
  948. //const char* data = "Callback function called";
  949. char sql[300];
  950. char zErrMsg[200];
  951. memset(sql, 0, 300);
  952. memset(zErrMsg, 0, 200);
  953. 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);
  954. //* Execute SQL statement */
  955. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  956. if( ret != SQLITE_OK )
  957. {
  958. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  959. return isSuccess;
  960. }
  961. memset(sql, 0, 300);
  962. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  963. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  964. if( ret != SQLITE_OK )
  965. {
  966. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  967. return isSuccess;
  968. }
  969. isSuccess = TRUE;
  970. return isSuccess;
  971. }
  972. void OCPP_getIdTagFromLocalList(char idTag[])
  973. {
  974. int rc = 0;
  975. // const char* data = "Callback function called";
  976. char sql[100];
  977. char zErrMsg[100];
  978. memset(sql, 0, 100);
  979. memset(zErrMsg, 0, 100);
  980. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  981. memset(&idTagQuery, 0, sizeof(idTagQuery));
  982. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  983. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  984. /* Execute SQL statement */
  985. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  986. if( rc != SQLITE_OK )
  987. {
  988. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  989. }
  990. //return ver;
  991. }
  992. void OCPP_deleteIdTagFromLocalList(char idTag[])
  993. {
  994. //int ver = 0;
  995. //int isSuccess = FALSE;
  996. int rc = 0;
  997. char sql[100];
  998. char zErrMsg[100];
  999. memset(sql, 0, 100);
  1000. memset(zErrMsg, 0, 100);
  1001. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  1002. //* Execute SQL statement */
  1003. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  1004. if( rc != SQLITE_OK )
  1005. {
  1006. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1007. }
  1008. }
  1009. int getCurrentYear()
  1010. {
  1011. int result = 0;
  1012. time_t CurrentTime;
  1013. struct tm *tm;
  1014. CurrentTime = time(NULL);
  1015. tm=localtime(&CurrentTime);
  1016. result = (tm->tm_year + 1900);
  1017. return result;
  1018. }
  1019. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  1020. {
  1021. int result = PASS;
  1022. char* errMsg = NULL;
  1023. char sqlStr[WEBSOCKET_BUFFER_SIZE];
  1024. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  1025. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1026. {
  1027. result = FAIL;
  1028. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  1029. }
  1030. 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));
  1031. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1032. {
  1033. result = FAIL;
  1034. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  1035. }
  1036. return result;
  1037. }
  1038. int OCPP_updatePeriodEnergy(uint8_t gun_index)
  1039. {
  1040. int isSuccess = TRUE;
  1041. int tempIndex;
  1042. json_object *EnergyDataTransfer = json_object_new_object();
  1043. json_object *periodEnergys = json_object_new_object();
  1044. char sql[1024];
  1045. char zErrMsg[200];
  1046. memset(sql, 0, ARRAY_SIZE(sql));
  1047. memset(zErrMsg, 0, ARRAY_SIZE(zErrMsg));
  1048. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  1049. {
  1050. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1051. {
  1052. tempIndex = ((gun_index==2) ? 1: 0);
  1053. }
  1054. else
  1055. {
  1056. tempIndex = gun_index;
  1057. }
  1058. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1059. {
  1060. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1061. {
  1062. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1063. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1064. {
  1065. uint8_t period[3];
  1066. sprintf((char*)period, "%d", idxPeriod);
  1067. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1068. }
  1069. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1070. } //end of the same index
  1071. }//end of for CHAdeMO_QUANTITY
  1072. }
  1073. else if(gunType[gun_index] == GUN_TYPE_CCS)
  1074. {
  1075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1076. {
  1077. tempIndex = ((gun_index==2) ? 1: 0);
  1078. }
  1079. else
  1080. {
  1081. tempIndex = gun_index;
  1082. }
  1083. for (int index = 0; index < CCS_QUANTITY; index++)
  1084. {
  1085. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1086. {
  1087. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1088. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1089. {
  1090. uint8_t period[3];
  1091. sprintf((char*)period, "%d", idxPeriod);
  1092. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1093. }
  1094. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1095. } //end of the same index
  1096. } // end of for CCS_QUANTITY
  1097. }
  1098. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1099. {
  1100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1101. {
  1102. tempIndex = ((gun_index==2) ? 1: 0);
  1103. }
  1104. else
  1105. {
  1106. tempIndex = gun_index;
  1107. }
  1108. for (int index = 0; index < GB_QUANTITY; index++)
  1109. {
  1110. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1111. {
  1112. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1113. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1114. {
  1115. uint8_t period[3];
  1116. sprintf((char*)period, "%d", idxPeriod);
  1117. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1118. }
  1119. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1120. } //end of the same index
  1121. } // end of for GB_QUANTITY
  1122. }
  1123. else if(gunType[gun_index] == GUN_TYPE_DO)
  1124. {
  1125. tempIndex = gun_index;
  1126. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1127. {
  1128. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1129. {
  1130. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1131. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod);idxPeriod++)
  1132. {
  1133. uint8_t period[3];
  1134. sprintf((char*)period, "%d", idxPeriod);
  1135. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.presentChargedEnergyPeriod[idxPeriod]));
  1136. }
  1137. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1138. } //end of the same index
  1139. }
  1140. }
  1141. else
  1142. {
  1143. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1144. {
  1145. tempIndex = 2;
  1146. }
  1147. else
  1148. {
  1149. tempIndex = gun_index;
  1150. }
  1151. for (int index = 0; index < AC_QUANTITY; index++)
  1152. {
  1153. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1154. {
  1155. json_object_object_add(EnergyDataTransfer, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  1156. for(uint8_t idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod);idxPeriod++)
  1157. {
  1158. uint8_t period[3];
  1159. sprintf((char*)period, "%d", idxPeriod);
  1160. json_object_object_add(periodEnergys, (const char *)period, json_object_new_double(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].presentChargedEnergyPeriod[idxPeriod]));
  1161. }
  1162. json_object_object_add(EnergyDataTransfer, "periodEnergy", periodEnergys);
  1163. }//end of the same index
  1164. }//end of for AC_QUANTITY
  1165. }
  1166. 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));
  1167. json_object_put(EnergyDataTransfer);
  1168. //* Execute SQL statement */
  1169. if( sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg) != SQLITE_OK )
  1170. {
  1171. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1172. isSuccess = FALSE;
  1173. }
  1174. sprintf(sql, "delete from ocpp_period_energy where (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  1175. if (sqlite3_exec(db, sql, 0, 0, (char **)&zErrMsg) != SQLITE_OK)
  1176. {
  1177. DEBUG_WARN( "delete period energy record error message: %s\n", zErrMsg);
  1178. isSuccess = FALSE;
  1179. }
  1180. return isSuccess;
  1181. }
  1182. int OCPP_getPeriodEnergyToDataTransfer(int32_t transactionId)
  1183. {
  1184. int isSuccess = TRUE;
  1185. char sql[512];
  1186. char zErrMsg[200];
  1187. int rows, cols;
  1188. char **resultData;
  1189. sprintf(sql, "select * from ocpp_period_energy where transactionId=%d;", transactionId);
  1190. /* Execute SQL statement */
  1191. if( sqlite3_get_table(db, sql, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  1192. {
  1193. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  1194. isSuccess = FALSE;
  1195. }
  1196. else
  1197. {
  1198. if((rows > 0) && (atoi(resultData[4]) > 0))
  1199. {
  1200. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, "%s", resultData[7]);
  1201. }
  1202. else
  1203. {
  1204. DEBUG_WARN("There is not match transaction data.\n");
  1205. isSuccess = FALSE;
  1206. }
  1207. }
  1208. return isSuccess;
  1209. }
  1210. 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)
  1211. {
  1212. int result = PASS;
  1213. char* errMsg = NULL;
  1214. char sqlStr[8192];
  1215. 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');",
  1216. txId, creditNo, deductResult, isDonateInvoice, amount, vemData, ROC, RRN, approvalNo, storeId);
  1217. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1218. {
  1219. result = FAIL;
  1220. DEBUG_WARN( "Insert local report_deduct_info error message: %s\n", errMsg);
  1221. }
  1222. sprintf(sqlStr, "delete from report_deduct_info where (idx < (select idx from report_deduct_info order by idx desc limit 1)-5000);");
  1223. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1224. {
  1225. result = FAIL;
  1226. DEBUG_WARN( "delete local report_deduct_info error message: %s\n", errMsg);
  1227. }
  1228. return result;
  1229. }
  1230. int OCPP_update_deduct_info(int txId, char *creditNo)
  1231. {
  1232. int result = PASS;
  1233. char* errMsg = NULL;
  1234. char sqlStr[8192];
  1235. sprintf(sqlStr, "update report_deduct_info set isUploaded='1' where txId='%d' and creditNo='%s';", txId, creditNo);
  1236. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1237. {
  1238. result = FAIL;
  1239. DEBUG_WARN( "Update local report_deduct_info error message: %s\n", errMsg);
  1240. }
  1241. return result;
  1242. }
  1243. int queryDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1244. {
  1245. json_object *dataBuf = json_object_new_object();
  1246. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1247. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_CreditDeductResult");
  1248. json_object_object_add(dataBuf, "txId", json_object_new_int(atoi(columnValue[1])));
  1249. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1250. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1251. json_object_object_add(dataBuf, "isDonateInvoice", json_object_new_boolean(atoi(columnValue[4])));
  1252. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[5])));
  1253. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[9]));
  1254. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1255. json_object_put(dataBuf);
  1256. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1257. return 0;
  1258. }
  1259. void OCPP_query_deduct_info()
  1260. {
  1261. int rc = 0;
  1262. char sql[100];
  1263. char zErrMsg[100];
  1264. sprintf(sql,"select * from report_deduct_info where isUploaded='0' order by idx limit 1");
  1265. /* Execute SQL statement */
  1266. rc = sqlite3_exec(db, sql, queryDeductCallBack, 0, (char **)&zErrMsg);
  1267. if( rc != SQLITE_OK )
  1268. {
  1269. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1270. }
  1271. }
  1272. // Occupancy fee deduct queue process
  1273. int OCPP_insert_occupancyDeduct_info(char *occupancySN, char *creditNo, uint8_t deductResult, double amount, char *approvalNo)
  1274. {
  1275. int result = PASS;
  1276. char* errMsg = NULL;
  1277. char sqlStr[8192];
  1278. sprintf(sqlStr, "insert or replace into report_occupancyDeduct_info(occupancySN, creditNo, deductResult, amount, approvalNo, isUploaded) values('%s', '%s', '%d', '%.2f', '%s', '0');",
  1279. occupancySN, creditNo, deductResult, amount, approvalNo);
  1280. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1281. {
  1282. result = FAIL;
  1283. DEBUG_WARN( "Insert local report_occupancyDeduct_info error message: %s\n", errMsg);
  1284. }
  1285. sprintf(sqlStr, "delete from report_occupancyDeduct_info where (idx < (select idx from report_occupancyDeduct_info order by idx desc limit 1)-5000);");
  1286. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1287. {
  1288. result = FAIL;
  1289. DEBUG_WARN( "delete local report_occupancyDeduct_info error message: %s\n", errMsg);
  1290. }
  1291. return result;
  1292. }
  1293. int OCPP_update_occupancyDeduct_info(char *occupancySN)
  1294. {
  1295. int result = PASS;
  1296. char* errMsg = NULL;
  1297. char sqlStr[8192];
  1298. sprintf(sqlStr, "update report_occupancyDeduct_info set isUploaded='1' where occupancySN='%s';", occupancySN);
  1299. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  1300. {
  1301. result = FAIL;
  1302. DEBUG_WARN( "Update local report_occupancyDeduct_info error message: %s\n", errMsg);
  1303. }
  1304. return result;
  1305. }
  1306. int queryOccupancyDeductCallBack(void *data, int columenCount, char **columnValue, char **columnName)
  1307. {
  1308. json_object *dataBuf = json_object_new_object();
  1309. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1310. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"%s","ID_OccupancyDeductResult");
  1311. json_object_object_add(dataBuf, "occupancySN", json_object_new_string(columnValue[1]));
  1312. json_object_object_add(dataBuf, "creditNo", json_object_new_string(columnValue[2]));
  1313. json_object_object_add(dataBuf, "deductResult", json_object_new_boolean(atoi(columnValue[3])));
  1314. json_object_object_add(dataBuf, "amount", json_object_new_double(atof(columnValue[4])));
  1315. json_object_object_add(dataBuf, "approvalNo", json_object_new_string(columnValue[5]));
  1316. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1317. json_object_put(dataBuf);
  1318. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  1319. return 0;
  1320. }
  1321. void OCPP_query_occupancyDeduct_info()
  1322. {
  1323. int rc = 0;
  1324. char sql[100];
  1325. char zErrMsg[100];
  1326. sprintf(sql,"select * from report_occupancyDeduct_info where isUploaded='0' order by idx limit 1");
  1327. /* Execute SQL statement */
  1328. rc = sqlite3_exec(db, sql, queryOccupancyDeductCallBack, 0, (char **)&zErrMsg);
  1329. if( rc != SQLITE_OK )
  1330. {
  1331. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  1332. }
  1333. }
  1334. void reportReaderStatus(int gun_index)
  1335. {
  1336. struct timeval tmnow;
  1337. struct tm *tm;
  1338. char buf[28];//, usec_buf[6];
  1339. gettimeofday(&tmnow, NULL);
  1340. time_t t;
  1341. t = time(NULL);
  1342. /*UTC time and date*/
  1343. tm = gmtime(&t);
  1344. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1345. #if 0 // remove temporally
  1346. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1347. strcat(buf,".");
  1348. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1349. strcat(buf,usec_buf);
  1350. #endif
  1351. json_object *dataBuf = json_object_new_object();
  1352. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1353. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_ReaderStatus");
  1354. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1355. json_object_object_add(dataBuf, "readerStatus", json_object_new_int(ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].readerStatus));
  1356. json_object_object_add(dataBuf, "timestamp", json_object_new_string(buf));
  1357. json_object_object_add(dataBuf, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  1358. json_object_object_add(dataBuf, "creditNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].creditNo));
  1359. json_object_object_add(dataBuf, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  1360. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1361. json_object_put(dataBuf);
  1362. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1363. }
  1364. void occupancyFeeAct(int gun_index)
  1365. {
  1366. struct timeval tmnow;
  1367. struct tm *tm;
  1368. char buf[28];//, usec_buf[6];
  1369. gettimeofday(&tmnow, NULL);
  1370. time_t t;
  1371. t = time(NULL);
  1372. /*UTC time and date*/
  1373. tm = gmtime(&t);
  1374. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1375. #if 0 // remove temporally
  1376. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1377. strcat(buf,".");
  1378. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1379. strcat(buf,usec_buf);
  1380. #endif
  1381. json_object *dataBuf = json_object_new_object();
  1382. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1383. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId,"%s","ID_OccupancyFeeAct");
  1384. json_object_object_add(dataBuf, "ConnectorId", json_object_new_int((gun_index+1)));
  1385. json_object_object_add(dataBuf, "occupancySN", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].occupancySN));
  1386. json_object_object_add(dataBuf, "action", json_object_new_int(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].action));
  1387. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "%s", json_object_to_json_string_ext(dataBuf, JSON_C_TO_STRING_PLAIN));
  1388. json_object_put(dataBuf);
  1389. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  1390. }
  1391. //==========================================
  1392. // Check time passed since today
  1393. //==========================================
  1394. long long DiffTimebWithNow(struct timeb ST)
  1395. {
  1396. //return milli-second
  1397. struct timeb ET;
  1398. long long StartTime,StopTime;
  1399. ftime(&ET);
  1400. StartTime=(long long)ST.time;
  1401. StopTime=(long long)ET.time;
  1402. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  1403. }
  1404. int getTimePassSinceToday(uint8_t gun_index)
  1405. {
  1406. int result = -1;
  1407. static time_t lastTime[4];
  1408. time_t t;
  1409. struct tm *tmStartToday;
  1410. struct timeb tbStartToday;
  1411. t=time(NULL);
  1412. if(difftime(t, lastTime[gun_index])>0)
  1413. {
  1414. tmStartToday=localtime(&t);
  1415. tmStartToday->tm_hour = 0;
  1416. tmStartToday->tm_min = 0;
  1417. tmStartToday->tm_sec = 0;
  1418. tbStartToday.time = mktime(tmStartToday);
  1419. tbStartToday.millitm = 0;
  1420. result = DiffTimebWithNow(tbStartToday)/1000;
  1421. lastTime[gun_index] = t;
  1422. }
  1423. return result;
  1424. }
  1425. void getNowDatetime(uint8_t *data)
  1426. {
  1427. time_t t = time(NULL);
  1428. struct tm tm = *localtime(&t);
  1429. 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);
  1430. }
  1431. int syncDateTimeRTC(uint8_t *data)
  1432. {
  1433. struct ParsingResult
  1434. {
  1435. int result;
  1436. int scanedElement;
  1437. int year;
  1438. int month;
  1439. int mday;
  1440. int hour;
  1441. int min;
  1442. int sec;
  1443. int tz_hour;
  1444. int tz_min;
  1445. float minSec;
  1446. }result;
  1447. struct tm tmOrg;
  1448. struct tm *tmTarget;
  1449. struct timeb tbTarget;
  1450. char buf[128];
  1451. memset(&result, 0x00, sizeof(struct ParsingResult));
  1452. result.result = PASS;
  1453. if(strstr((char*)data, ".") != NULL)
  1454. {
  1455. // Original data with mini second
  1456. if(strstr((char*)data, "Z") != NULL)
  1457. {
  1458. // Original data with Z
  1459. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  1460. &result.year,
  1461. &result.month,
  1462. &result.mday,
  1463. &result.hour,
  1464. &result.min,
  1465. &result.sec,
  1466. &result.minSec);
  1467. }
  1468. else
  1469. {
  1470. // Original data without Z
  1471. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1472. &result.year,
  1473. &result.month,
  1474. &result.mday,
  1475. &result.hour,
  1476. &result.min,
  1477. &result.sec,
  1478. &result.minSec,
  1479. &result.tz_hour,
  1480. &result.tz_min);
  1481. }
  1482. }
  1483. else
  1484. {
  1485. // Original data without mini second
  1486. if(strstr((char*)data, "Z") != NULL)
  1487. {
  1488. // Original data with Z
  1489. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1490. &result.year,
  1491. &result.month,
  1492. &result.mday,
  1493. &result.hour,
  1494. &result.min,
  1495. &result.sec);
  1496. }
  1497. else
  1498. {
  1499. // Original data without Z
  1500. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1501. &result.year,
  1502. &result.month,
  1503. &result.mday,
  1504. &result.hour,
  1505. &result.min,
  1506. &result.sec,
  1507. &result.tz_hour,
  1508. &result.tz_min);
  1509. }
  1510. }
  1511. tmOrg.tm_year = result.year - 1900;
  1512. tmOrg.tm_mon = result.month - 1;
  1513. tmOrg.tm_mday = result.mday;
  1514. tmOrg.tm_hour = result.hour;
  1515. tmOrg.tm_min = result.min;
  1516. tmOrg.tm_sec = result.sec;
  1517. tmOrg.tm_gmtoff = 0;
  1518. tbTarget.time = mktime(&tmOrg);
  1519. tbTarget.timezone = 0;
  1520. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1521. tmTarget = gmtime(&tbTarget.time);
  1522. 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);
  1523. //DEBUG_INFO(" org date time: %s\n", data);
  1524. //DEBUG_INFO("parse date time: %s\n", buf);
  1525. system(buf);
  1526. system("/sbin/hwclock -w --systohc");
  1527. if(result.scanedElement < 6)
  1528. result.result = FAIL;
  1529. return result.result;
  1530. }
  1531. //==========================================
  1532. // Parse certificate content
  1533. //==========================================
  1534. int parseCertInfo(char *certPath, int parseType, char *data)
  1535. {
  1536. int result = FAIL;
  1537. int count = 0;
  1538. int showupLine = 0;
  1539. memset(data, 0, ARRAY_SIZE(data));
  1540. if(access(certPath,F_OK) != -1)
  1541. {
  1542. char temp[512] = {0};
  1543. char capturedData[256] = {0};
  1544. char hashType[10] = "SHA256";
  1545. FILE *fp;
  1546. // Need to get hash type first
  1547. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  1548. fp = popen(temp, "r");
  1549. if(fp)
  1550. {
  1551. while(fgets(temp, sizeof(temp), fp) != NULL)
  1552. {
  1553. if(strstr(temp, "Signature Algorithm:") != NULL)
  1554. {
  1555. result = PASS;
  1556. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  1557. sprintf((char*)hashType, "SHA256");
  1558. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  1559. sprintf((char*)hashType, "SHA384");
  1560. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  1561. sprintf((char*)hashType, "SHA512");
  1562. else
  1563. {
  1564. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  1565. result = FAIL;
  1566. }
  1567. break;
  1568. }
  1569. }
  1570. }
  1571. switch(parseType)
  1572. {
  1573. case CERT_PARSE_HashAlgorithm:
  1574. sprintf((char*)data, hashType);
  1575. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  1576. break;
  1577. case CERT_PARSE_SerialNumber:
  1578. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  1579. fp = popen(temp, "r");
  1580. if(fp)
  1581. {
  1582. while(fgets(temp, sizeof(temp), fp) != NULL)
  1583. {
  1584. if(strstr(temp, "serial=") != NULL)
  1585. {
  1586. sscanf(temp, "%*[^=]=%s", capturedData);
  1587. result = PASS;
  1588. break;
  1589. }
  1590. }
  1591. DEBUG_INFO("serialNumber: %s\n", capturedData);
  1592. sprintf((char*)data, capturedData);
  1593. }
  1594. break;
  1595. case CERT_PARSE_IssuerNameHash:
  1596. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1597. fp = popen(temp, "r");
  1598. if(fp)
  1599. {
  1600. while(fgets(temp, sizeof(temp), fp) != NULL)
  1601. {
  1602. if(strstr(temp, "SEQUENCE") != NULL)
  1603. {
  1604. count++;
  1605. if(count==4)
  1606. {
  1607. sscanf(temp, "%[^:]", capturedData);
  1608. showupLine = atoi(capturedData);
  1609. break;
  1610. }
  1611. }
  1612. }
  1613. }
  1614. if(showupLine > 0)
  1615. {
  1616. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerNameHash", certPath, showupLine);
  1617. system(temp);
  1618. }
  1619. else
  1620. {
  1621. break;
  1622. }
  1623. if(access("/Storage/OCPP/IssuerNameHash",F_OK) != -1)
  1624. {
  1625. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerNameHash", (char*)hashType);
  1626. fp = popen(temp, "r");
  1627. if(fp)
  1628. {
  1629. while(fgets(temp, sizeof(temp), fp) != NULL)
  1630. {
  1631. if(strstr(temp, "(stdin)=") != NULL)
  1632. {
  1633. sscanf(temp, "%*[^=]=%s", capturedData);
  1634. result = PASS;
  1635. break;
  1636. }
  1637. }
  1638. stringtrimspace(capturedData);
  1639. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1640. sprintf((char*)data, capturedData);
  1641. }
  1642. }
  1643. break;
  1644. case CERT_PARSE_IssuerKeyHash:
  1645. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1646. fp = popen(temp, "r");
  1647. if(fp)
  1648. {
  1649. while(fgets(temp, sizeof(temp), fp) != NULL)
  1650. {
  1651. if(strstr(temp, "BIT STRING") != NULL)
  1652. {
  1653. sscanf(temp, "%[^:]", capturedData);
  1654. showupLine = atoi(capturedData);
  1655. break;
  1656. }
  1657. }
  1658. }
  1659. if(showupLine > 0)
  1660. {
  1661. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerKeyHash", certPath, showupLine);
  1662. system(temp);
  1663. }
  1664. else
  1665. {
  1666. break;
  1667. }
  1668. if(access("/Storage/OCPP/IssuerKeyHash",F_OK) != -1)
  1669. {
  1670. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerKeyHash", (char*)hashType);
  1671. fp = popen(temp, "r");
  1672. if(fp)
  1673. {
  1674. while(fgets(temp, sizeof(temp), fp) != NULL)
  1675. {
  1676. if(strstr(temp, "(stdin)=") != NULL)
  1677. {
  1678. sscanf(temp, "%*[^=]=%s", capturedData);
  1679. result = PASS;
  1680. break;
  1681. }
  1682. }
  1683. stringtrimspace(capturedData);
  1684. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1685. sprintf((char*)data, capturedData);
  1686. }
  1687. }
  1688. break;
  1689. case CERT_PARSE_OcspUrl:
  1690. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1691. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1692. fp = popen(temp, "r");
  1693. if(fp)
  1694. {
  1695. while(fgets(temp, sizeof(temp), fp) != NULL)
  1696. {
  1697. if(strstr(temp, "OCSP - URI:") != NULL)
  1698. {
  1699. //strcpy((char*)data, temp);
  1700. sscanf(temp, "%*[^:]:%s", capturedData);
  1701. sprintf((char*)data, capturedData);
  1702. DEBUG_INFO("OCSP_URI: %s\n", data);
  1703. result = PASS;
  1704. break;
  1705. }
  1706. }
  1707. }
  1708. break;
  1709. default:
  1710. DEBUG_INFO("Parse type is invalid.\n");
  1711. break;
  1712. }
  1713. pclose(fp);
  1714. }
  1715. return result;
  1716. }
  1717. //==========================================
  1718. // GetCompositeSchedule logic related function
  1719. //==========================================
  1720. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1721. {
  1722. //return milli-second
  1723. unsigned int StartTime,StopTime;
  1724. StartTime=(unsigned int)ST.time;
  1725. StopTime=(unsigned int)ET.time;
  1726. return (StopTime-StartTime);
  1727. }
  1728. int DiffTimebWithNowSec(struct timeb ST)
  1729. {
  1730. //return milli-second
  1731. struct timeb ET;
  1732. unsigned int StartTime,StopTime;
  1733. ftime(&ET);
  1734. StartTime=(unsigned int)ST.time;
  1735. StopTime=(unsigned int)ET.time;
  1736. return (StopTime-StartTime);
  1737. }
  1738. int getStartStop(uint8_t *start, uint8_t *stop)
  1739. {
  1740. struct ParsingResult
  1741. {
  1742. int result;
  1743. int scanedElement;
  1744. int year;
  1745. int month;
  1746. int mday;
  1747. int hour;
  1748. int min;
  1749. int sec;
  1750. int tz_hour;
  1751. int tz_min;
  1752. float minSec;
  1753. };
  1754. struct ParsingResult parseStart;
  1755. struct ParsingResult parseStop;
  1756. int result = -1;
  1757. struct tm tmStart;
  1758. struct timeb tbStart;
  1759. struct tm tmStop;
  1760. struct timeb tbStop;
  1761. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  1762. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  1763. // Scan start & stop date time
  1764. if(strstr((char*)start, ".") != NULL)
  1765. {
  1766. // Original data with mini second
  1767. if(strstr((char*)start, "Z") != NULL)
  1768. {
  1769. // Original data with Z
  1770. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1771. &parseStart.year,
  1772. &parseStart.month,
  1773. &parseStart.mday,
  1774. &parseStart.hour,
  1775. &parseStart.min,
  1776. &parseStart.sec,
  1777. &parseStart.minSec);
  1778. }
  1779. else
  1780. {
  1781. // Original data without Z
  1782. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1783. &parseStart.year,
  1784. &parseStart.month,
  1785. &parseStart.mday,
  1786. &parseStart.hour,
  1787. &parseStart.min,
  1788. &parseStart.sec,
  1789. &parseStart.minSec,
  1790. &parseStart.tz_hour,
  1791. &parseStart.tz_min);
  1792. }
  1793. }
  1794. else
  1795. {
  1796. // Original data without mini second
  1797. if(strstr((char*)start, "Z") != NULL)
  1798. {
  1799. // Original data with Z
  1800. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1801. &parseStart.year,
  1802. &parseStart.month,
  1803. &parseStart.mday,
  1804. &parseStart.hour,
  1805. &parseStart.min,
  1806. &parseStart.sec);
  1807. }
  1808. else
  1809. {
  1810. // Original data without Z
  1811. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1812. &parseStart.year,
  1813. &parseStart.month,
  1814. &parseStart.mday,
  1815. &parseStart.hour,
  1816. &parseStart.min,
  1817. &parseStart.sec,
  1818. &parseStart.tz_hour,
  1819. &parseStart.tz_min);
  1820. }
  1821. }
  1822. if(strstr((char*)stop, ".") != NULL)
  1823. {
  1824. // Original data with mini second
  1825. if(strstr((char*)stop, "Z") != NULL)
  1826. {
  1827. // Original data with Z
  1828. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  1829. &parseStop.year,
  1830. &parseStop.month,
  1831. &parseStop.mday,
  1832. &parseStop.hour,
  1833. &parseStop.min,
  1834. &parseStop.sec,
  1835. &parseStop.minSec);
  1836. }
  1837. else
  1838. {
  1839. // Original data without Z
  1840. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1841. &parseStop.year,
  1842. &parseStop.month,
  1843. &parseStop.mday,
  1844. &parseStop.hour,
  1845. &parseStop.min,
  1846. &parseStop.sec,
  1847. &parseStop.minSec,
  1848. &parseStop.tz_hour,
  1849. &parseStop.tz_min);
  1850. }
  1851. }
  1852. else
  1853. {
  1854. // Original data without mini second
  1855. if(strstr((char*)stop, "Z") != NULL)
  1856. {
  1857. // Original data with Z
  1858. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  1859. &parseStop.year,
  1860. &parseStop.month,
  1861. &parseStop.mday,
  1862. &parseStop.hour,
  1863. &parseStop.min,
  1864. &parseStop.sec);
  1865. }
  1866. else
  1867. {
  1868. // Original data without Z
  1869. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  1870. &parseStop.year,
  1871. &parseStop.month,
  1872. &parseStop.mday,
  1873. &parseStop.hour,
  1874. &parseStop.min,
  1875. &parseStop.sec,
  1876. &parseStop.tz_hour,
  1877. &parseStop.tz_min);
  1878. }
  1879. }
  1880. // Calculate date time difference
  1881. if((parseStart.scanedElement >=6) &&
  1882. (parseStop.scanedElement >=6))
  1883. {
  1884. //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);
  1885. //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);
  1886. tmStart.tm_year = parseStart.year - 1900;
  1887. tmStart.tm_mon = parseStart.month - 1;
  1888. tmStart.tm_mday = parseStart.mday;
  1889. tmStart.tm_hour = parseStart.hour;
  1890. tmStart.tm_min = parseStart.min;
  1891. tmStart.tm_sec = parseStart.sec;
  1892. tmStart.tm_gmtoff = 0;
  1893. tbStart.time = mktime(&tmStart);
  1894. tbStart.timezone = 0;
  1895. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  1896. tmStop.tm_year = parseStop.year - 1900;
  1897. tmStop.tm_mon = parseStop.month - 1;
  1898. tmStop.tm_mday = parseStop.mday;
  1899. tmStop.tm_hour = parseStop.hour;
  1900. tmStop.tm_min = parseStop.min;
  1901. tmStop.tm_sec = parseStop.sec;
  1902. tmStop.tm_gmtoff = 0;
  1903. tbStop.time = mktime(&tmStop);
  1904. tbStop.timezone = 0;
  1905. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  1906. result = DiffTimebSec(tbStart, tbStop);
  1907. //DEBUG_INFO("getStartStop(): %d\n", result);
  1908. }
  1909. else
  1910. {
  1911. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1912. }
  1913. return result;
  1914. }
  1915. int isOvertNow(uint8_t *start)
  1916. {
  1917. int result = NO;
  1918. struct ParsingResult
  1919. {
  1920. int result;
  1921. int scanedElement;
  1922. int year;
  1923. int month;
  1924. int mday;
  1925. int hour;
  1926. int min;
  1927. int sec;
  1928. int tz_hour;
  1929. int tz_min;
  1930. float minSec;
  1931. }parsingResult;
  1932. struct tm tmStart;
  1933. struct timeb tbStart;
  1934. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1935. if(strstr((char*)start, ".") != NULL)
  1936. {
  1937. // Original data with mini second
  1938. if(strstr((char*)start, "Z") != NULL)
  1939. {
  1940. // Original data with Z
  1941. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1942. &parsingResult.year,
  1943. &parsingResult.month,
  1944. &parsingResult.mday,
  1945. &parsingResult.hour,
  1946. &parsingResult.min,
  1947. &parsingResult.sec,
  1948. &parsingResult.minSec);
  1949. }
  1950. else
  1951. {
  1952. // Original data without Z
  1953. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1954. &parsingResult.year,
  1955. &parsingResult.month,
  1956. &parsingResult.mday,
  1957. &parsingResult.hour,
  1958. &parsingResult.min,
  1959. &parsingResult.sec,
  1960. &parsingResult.minSec,
  1961. &parsingResult.tz_hour,
  1962. &parsingResult.tz_min);
  1963. }
  1964. }
  1965. else
  1966. {
  1967. // Original data without mini second
  1968. if(strstr((char*)start, "Z") != NULL)
  1969. {
  1970. // Original data with Z
  1971. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1972. &parsingResult.year,
  1973. &parsingResult.month,
  1974. &parsingResult.mday,
  1975. &parsingResult.hour,
  1976. &parsingResult.min,
  1977. &parsingResult.sec);
  1978. }
  1979. else
  1980. {
  1981. // Original data without Z
  1982. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1983. &parsingResult.year,
  1984. &parsingResult.month,
  1985. &parsingResult.mday,
  1986. &parsingResult.hour,
  1987. &parsingResult.min,
  1988. &parsingResult.sec,
  1989. &parsingResult.tz_hour,
  1990. &parsingResult.tz_min);
  1991. }
  1992. }
  1993. if(parsingResult.scanedElement >= 6)
  1994. {
  1995. tmStart.tm_year = parsingResult.year - 1900;
  1996. tmStart.tm_mon = parsingResult.month - 1;
  1997. tmStart.tm_mday = parsingResult.mday;
  1998. tmStart.tm_hour = parsingResult.hour;
  1999. tmStart.tm_min = parsingResult.min;
  2000. tmStart.tm_sec = parsingResult.sec;
  2001. tmStart.tm_gmtoff = 0;
  2002. tbStart.time = mktime(&tmStart);
  2003. tbStart.timezone = 0;
  2004. tbStart.millitm = 0;
  2005. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  2006. if(DiffTimebWithNowSec(tbStart) <= 0)
  2007. result = NO;
  2008. else
  2009. result = YES;
  2010. }
  2011. else
  2012. {
  2013. DEBUG_WARN("Start date parsing error.\n");
  2014. }
  2015. return result;
  2016. }
  2017. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  2018. {
  2019. struct ParsingResult
  2020. {
  2021. int result;
  2022. int scanedElement;
  2023. int year;
  2024. int month;
  2025. int mday;
  2026. int hour;
  2027. int min;
  2028. int sec;
  2029. int tz_hour;
  2030. int tz_min;
  2031. float minSec;
  2032. };
  2033. struct ParsingResult parseStart;
  2034. struct ParsingResult parseStop;
  2035. int result = -1;
  2036. struct tm tmStart;
  2037. struct timeb tbStart;
  2038. struct tm tmStop;
  2039. struct timeb tbStop;
  2040. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  2041. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  2042. // Scan start & stop date time
  2043. if(strstr((char*)start, ".") != NULL)
  2044. {
  2045. // Original data with mini second
  2046. if(strstr((char*)start, "Z") != NULL)
  2047. {
  2048. // Original data with Z
  2049. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  2050. &parseStart.year,
  2051. &parseStart.month,
  2052. &parseStart.mday,
  2053. &parseStart.hour,
  2054. &parseStart.min,
  2055. &parseStart.sec,
  2056. &parseStart.minSec);
  2057. }
  2058. else
  2059. {
  2060. // Original data without Z
  2061. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2062. &parseStart.year,
  2063. &parseStart.month,
  2064. &parseStart.mday,
  2065. &parseStart.hour,
  2066. &parseStart.min,
  2067. &parseStart.sec,
  2068. &parseStart.minSec,
  2069. &parseStart.tz_hour,
  2070. &parseStart.tz_min);
  2071. }
  2072. }
  2073. else
  2074. {
  2075. // Original data without mini second
  2076. if(strstr((char*)start, "Z") != NULL)
  2077. {
  2078. // Original data with Z
  2079. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  2080. &parseStart.year,
  2081. &parseStart.month,
  2082. &parseStart.mday,
  2083. &parseStart.hour,
  2084. &parseStart.min,
  2085. &parseStart.sec);
  2086. }
  2087. else
  2088. {
  2089. // Original data without Z
  2090. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  2091. &parseStart.year,
  2092. &parseStart.month,
  2093. &parseStart.mday,
  2094. &parseStart.hour,
  2095. &parseStart.min,
  2096. &parseStart.sec,
  2097. &parseStart.tz_hour,
  2098. &parseStart.tz_min);
  2099. }
  2100. }
  2101. if(strstr((char*)stop, ".") != NULL)
  2102. {
  2103. // Original data with mini second
  2104. if(strstr((char*)stop, "Z") != NULL)
  2105. {
  2106. // Original data with Z
  2107. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  2108. &parseStop.year,
  2109. &parseStop.month,
  2110. &parseStop.mday,
  2111. &parseStop.hour,
  2112. &parseStop.min,
  2113. &parseStop.sec,
  2114. &parseStop.minSec);
  2115. }
  2116. else
  2117. {
  2118. // Original data without Z
  2119. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2120. &parseStop.year,
  2121. &parseStop.month,
  2122. &parseStop.mday,
  2123. &parseStop.hour,
  2124. &parseStop.min,
  2125. &parseStop.sec,
  2126. &parseStop.minSec,
  2127. &parseStop.tz_hour,
  2128. &parseStop.tz_min);
  2129. }
  2130. }
  2131. else
  2132. {
  2133. // Original data without mini second
  2134. if(strstr((char*)stop, "Z") != NULL)
  2135. {
  2136. // Original data with Z
  2137. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  2138. &parseStop.year,
  2139. &parseStop.month,
  2140. &parseStop.mday,
  2141. &parseStop.hour,
  2142. &parseStop.min,
  2143. &parseStop.sec);
  2144. }
  2145. else
  2146. {
  2147. // Original data without Z
  2148. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  2149. &parseStop.year,
  2150. &parseStop.month,
  2151. &parseStop.mday,
  2152. &parseStop.hour,
  2153. &parseStop.min,
  2154. &parseStop.sec,
  2155. &parseStop.tz_hour,
  2156. &parseStop.tz_min);
  2157. }
  2158. }
  2159. // Calculate date time difference
  2160. if((parseStart.scanedElement >=6) &&
  2161. (parseStop.scanedElement >=6))
  2162. {
  2163. //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);
  2164. //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);
  2165. tmStart.tm_year = parseStart.year - 1900;
  2166. tmStart.tm_mon = parseStart.month - 1;
  2167. tmStart.tm_mday = parseStart.mday;
  2168. tmStart.tm_hour = parseStart.hour;
  2169. tmStart.tm_min = parseStart.min;
  2170. tmStart.tm_sec = parseStart.sec;
  2171. tmStart.tm_gmtoff = 0;
  2172. tbStart.time = mktime(&tmStart);
  2173. tbStart.timezone = 0;
  2174. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  2175. tmStop.tm_year = parseStop.year - 1900;
  2176. tmStop.tm_mon = parseStop.month - 1;
  2177. tmStop.tm_mday = parseStop.mday;
  2178. tmStop.tm_hour = parseStop.hour;
  2179. tmStop.tm_min = parseStop.min;
  2180. tmStop.tm_sec = parseStop.sec;
  2181. tmStop.tm_gmtoff = 0;
  2182. tbStop.time = mktime(&tmStop);
  2183. tbStop.timezone = 0;
  2184. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  2185. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2186. //DEBUG_INFO("getStartStop(): %d\n", result);
  2187. }
  2188. else
  2189. {
  2190. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2191. }
  2192. return result;
  2193. }
  2194. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2195. {
  2196. FILE *fp;
  2197. char profileFileName[128];
  2198. char *line = NULL;
  2199. size_t len = 0;
  2200. time_t CurrentTime;
  2201. struct tm *tmComposite;
  2202. struct StructChargingProfile maxProfile;
  2203. struct StructChargingProfile compositeProfile;
  2204. uint8_t limitMax=0;
  2205. int compositePeriodIdx = 0;
  2206. //uint8_t isDurationNull = FALSE;
  2207. CurrentTime = time(NULL);
  2208. tmComposite=localtime(&CurrentTime);
  2209. 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);
  2210. if(isUnitA)
  2211. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2212. else
  2213. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2214. compositeProfile.ChargingSchedule.Duration = durationReq;
  2215. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2216. {
  2217. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2218. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2219. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2220. }
  2221. compositeProfile.ChargingProfileId = 0;
  2222. compositeProfile.StackLevel = 99 ;
  2223. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2224. maxProfile.ChargingProfileId = -1;
  2225. maxProfile.ChargingSchedule.Duration = -1;
  2226. system("rm -f /tmp/*.json");
  2227. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2228. // Search max profile
  2229. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2230. if((access(profileFileName, F_OK))!=-1)
  2231. {
  2232. fp = fopen(profileFileName, "r");
  2233. while(getline(&line, &len, fp) != -1)
  2234. {
  2235. json_object *obj = NULL;
  2236. obj = json_tokener_parse(line);
  2237. if(is_error(obj))
  2238. {
  2239. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2240. }
  2241. else
  2242. {
  2243. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2244. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2245. )
  2246. {
  2247. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2248. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2249. )
  2250. {
  2251. struct tm tmFrom, tmTo;
  2252. struct timeb tbFrom, tbTo;
  2253. 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) &&
  2254. (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))
  2255. {
  2256. tmFrom.tm_year -= 1900;
  2257. tmFrom.tm_mon -= 1;
  2258. tbFrom.time = mktime(&tmFrom);
  2259. tmTo.tm_year -= 1900;
  2260. tmTo.tm_mon -= 1;
  2261. tbTo.time = mktime(&tmTo);
  2262. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2263. {
  2264. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2265. {
  2266. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2267. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2268. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2269. }
  2270. if(maxProfile.ChargingProfileId == -1)
  2271. DEBUG_INFO("MaxProfile found.\n");
  2272. else
  2273. DEBUG_INFO("MaxProfile updated.\n");
  2274. // Required item
  2275. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2276. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2277. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2278. if(isUnitA)
  2279. {
  2280. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2281. 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++)
  2282. {
  2283. 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"));
  2284. 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?
  2285. 3:
  2286. 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")));
  2287. 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")));
  2288. }
  2289. }
  2290. else
  2291. {
  2292. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2293. 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++)
  2294. {
  2295. 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"));
  2296. 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?
  2297. 3:
  2298. 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")));
  2299. 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));
  2300. }
  2301. }
  2302. // Optional item
  2303. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2304. {
  2305. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2306. }
  2307. else
  2308. {
  2309. sprintf((char*)maxProfile.ValidFrom, " ");
  2310. }
  2311. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2312. {
  2313. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2314. }
  2315. else
  2316. {
  2317. sprintf((char*)maxProfile.ValidTo, " ");
  2318. }
  2319. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2320. {
  2321. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2322. }
  2323. else
  2324. {
  2325. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2326. }
  2327. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2328. {
  2329. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2330. }
  2331. else
  2332. {
  2333. maxProfile.TransactionId = -1;
  2334. }
  2335. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2336. {
  2337. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2338. }
  2339. else
  2340. {
  2341. maxProfile.ChargingSchedule.Duration = 86400;
  2342. //isDurationNull = TRUE;
  2343. }
  2344. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2345. {
  2346. 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")));
  2347. }
  2348. else
  2349. {
  2350. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2351. }
  2352. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2353. {
  2354. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2355. }
  2356. else
  2357. {
  2358. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2359. }
  2360. }
  2361. }
  2362. }
  2363. else
  2364. {
  2365. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2366. {
  2367. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2368. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2369. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2370. }
  2371. if(maxProfile.ChargingProfileId == -1)
  2372. DEBUG_INFO("MaxProfile found.\n");
  2373. else
  2374. DEBUG_INFO("MaxProfile updated.\n");
  2375. // Required item
  2376. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2377. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2378. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2379. if(isUnitA)
  2380. {
  2381. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2382. 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++)
  2383. {
  2384. 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"));
  2385. 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?
  2386. 3:
  2387. 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")));
  2388. 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")));
  2389. }
  2390. }
  2391. else
  2392. {
  2393. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2394. 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++)
  2395. {
  2396. 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"));
  2397. 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?
  2398. 3:
  2399. 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")));
  2400. 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));
  2401. }
  2402. }
  2403. // Optional item
  2404. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2405. {
  2406. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2407. }
  2408. else
  2409. {
  2410. sprintf((char*)maxProfile.ValidFrom, " ");
  2411. }
  2412. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2413. {
  2414. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2415. }
  2416. else
  2417. {
  2418. sprintf((char*)maxProfile.ValidTo, " ");
  2419. }
  2420. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2421. {
  2422. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2423. }
  2424. else
  2425. {
  2426. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2427. }
  2428. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2429. {
  2430. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2431. }
  2432. else
  2433. {
  2434. maxProfile.TransactionId = -1;
  2435. }
  2436. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2437. {
  2438. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2439. }
  2440. else
  2441. {
  2442. maxProfile.ChargingSchedule.Duration = 86400;
  2443. //isDurationNull = TRUE;
  2444. }
  2445. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2446. {
  2447. 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")));
  2448. }
  2449. else
  2450. {
  2451. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile.ChargingSchedule.StartSchedule);
  2452. }
  2453. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2454. {
  2455. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2456. }
  2457. else
  2458. {
  2459. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2460. }
  2461. }
  2462. }
  2463. }
  2464. json_object_put(obj);
  2465. }
  2466. fclose(fp);
  2467. /*
  2468. if(maxProfile.ChargingProfileId !=-1)
  2469. {
  2470. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2471. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2472. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2473. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2474. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2475. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2476. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2477. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2478. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2479. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2480. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2481. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2482. {
  2483. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2484. {
  2485. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2486. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2487. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2488. }
  2489. }
  2490. }
  2491. else
  2492. DEBUG_INFO("MaxProfile not found.\n");
  2493. DEBUG_INFO("------------------------------------\n");*/
  2494. }
  2495. if(maxProfile.ChargingProfileId != -1)
  2496. {
  2497. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2498. {
  2499. if((maxProfile.ChargingSchedule.Duration != -1)/* && (isDurationNull)*/)
  2500. {
  2501. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2502. 0:
  2503. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2504. }
  2505. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2506. {
  2507. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2508. {
  2509. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  2510. 0:
  2511. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  2512. if(idxPeriod > 0)
  2513. {
  2514. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2515. {
  2516. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2523. {
  2524. if(maxProfile.ChargingSchedule.Duration != -1)
  2525. {
  2526. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2527. }
  2528. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2529. {
  2530. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2531. {
  2532. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  2533. if(idxPeriod > 0)
  2534. {
  2535. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2536. {
  2537. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2538. }
  2539. }
  2540. }
  2541. }
  2542. }
  2543. else
  2544. {
  2545. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2546. {
  2547. if(maxProfile.ChargingSchedule.Duration != -1)
  2548. {
  2549. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2550. 0:
  2551. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2552. }
  2553. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2554. {
  2555. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2556. {
  2557. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  2558. 0:
  2559. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  2560. if(idxPeriod > 0)
  2561. {
  2562. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2563. {
  2564. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2565. }
  2566. }
  2567. }
  2568. }
  2569. }
  2570. else
  2571. {
  2572. if(maxProfile.ChargingSchedule.Duration != -1)
  2573. {
  2574. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2575. 0:
  2576. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2577. }
  2578. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2579. {
  2580. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2581. {
  2582. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  2583. 0:
  2584. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  2585. if(idxPeriod > 0)
  2586. {
  2587. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2588. {
  2589. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2590. }
  2591. }
  2592. }
  2593. }
  2594. }
  2595. }
  2596. /*
  2597. DEBUG_INFO("MaxProfile after align.\n");
  2598. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2599. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2600. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2601. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2602. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2603. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2604. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2605. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2606. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2607. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2608. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2609. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2610. {
  2611. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2612. {
  2613. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2614. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2615. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2616. }
  2617. }
  2618. DEBUG_INFO("------------------------------------\n");*/
  2619. }
  2620. // Find each profile period quantity
  2621. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2622. {
  2623. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2624. limitMax = idx+1;
  2625. }
  2626. if(maxProfile.ChargingProfileId != -1)
  2627. {
  2628. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2629. {
  2630. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2631. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2632. (maxProfile.ChargingSchedule.Duration > 0))
  2633. {
  2634. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2635. {
  2636. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2637. compositePeriodIdx++;
  2638. }
  2639. else
  2640. {
  2641. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2642. }
  2643. }
  2644. }
  2645. }
  2646. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  2647. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  2648. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  2649. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  2650. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2651. {
  2652. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2653. {
  2654. compositeProfile.ChargingProfileId = 1;
  2655. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2656. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2657. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2658. }
  2659. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2660. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2661. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2662. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2663. }
  2664. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  2665. if(line)
  2666. free(line);
  2667. }
  2668. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *targetCompositeProfile, uint8_t isUnitA)
  2669. {
  2670. FILE *fp;
  2671. char profileFileName[128];
  2672. char *line = NULL;
  2673. size_t len = 0;
  2674. time_t CurrentTime;
  2675. struct tm *tmComposite;
  2676. struct StructChargingProfile maxProfile;
  2677. struct StructChargingProfile defaultTxProfile;
  2678. struct StructChargingProfile txProfile;
  2679. struct StructChargingProfile compositeProfile;
  2680. struct StructChargingSchedulePeriod tmpPeriod;
  2681. uint8_t limitMax=0;
  2682. uint8_t limitDef=0;
  2683. uint8_t limitTx=0;
  2684. int compositePeriodIdx = 0;
  2685. CurrentTime = time(NULL);
  2686. tmComposite=localtime(&CurrentTime);
  2687. 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);
  2688. if(isUnitA)
  2689. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "A");
  2690. else
  2691. sprintf((char*)compositeProfile.ChargingSchedule.ChargingRateUnit, "W");
  2692. compositeProfile.ChargingSchedule.Duration = durationReq;
  2693. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2694. {
  2695. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2696. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2697. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2698. }
  2699. compositeProfile.ChargingProfileId = 0;
  2700. compositeProfile.StackLevel = 99 ;
  2701. sprintf((char*)compositeProfile.ChargingProfileKind ,"Absolute");
  2702. maxProfile.ChargingProfileId = -1;
  2703. defaultTxProfile.ChargingProfileId = -1;
  2704. txProfile.ChargingProfileId = -1;
  2705. maxProfile.ChargingSchedule.Duration = -1;
  2706. defaultTxProfile.ChargingSchedule.Duration = -1;
  2707. txProfile.ChargingSchedule.Duration = -1;
  2708. system("rm -f /tmp/*.json");
  2709. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2710. /*
  2711. * Search valid charging profile
  2712. */
  2713. //DEBUG_INFO("====================================\n");
  2714. // Search tx profile
  2715. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2716. if((access(profileFileName, F_OK))!=-1)
  2717. {
  2718. fp = fopen(profileFileName, "r");
  2719. while(getline(&line, &len, fp) != -1)
  2720. {
  2721. json_object *obj = NULL;
  2722. obj = json_tokener_parse(line);
  2723. if(is_error(obj))
  2724. {
  2725. DEBUG_ERROR("Parse txProfile from file error.\n");
  2726. }
  2727. else
  2728. {
  2729. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  2730. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  2731. )
  2732. {
  2733. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2734. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2735. )
  2736. {
  2737. struct tm tmFrom, tmTo;
  2738. struct timeb tbFrom, tbTo;
  2739. 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) &&
  2740. (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))
  2741. {
  2742. tmFrom.tm_year -= 1900;
  2743. tmFrom.tm_mon -= 1;
  2744. tbFrom.time = mktime(&tmFrom);
  2745. tmTo.tm_year -= 1900;
  2746. tmTo.tm_mon -= 1;
  2747. tbTo.time = mktime(&tmTo);
  2748. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2749. {
  2750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2751. {
  2752. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2755. }
  2756. if(txProfile.ChargingProfileId == -1)
  2757. DEBUG_INFO("TxProfile found.\n");
  2758. else
  2759. DEBUG_INFO("TxProfile updated.\n");
  2760. // Required item
  2761. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2762. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2763. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2764. if(isUnitA)
  2765. {
  2766. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2767. 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++)
  2768. {
  2769. 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"));
  2770. 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?
  2771. 3:
  2772. 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")));
  2773. 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")));
  2774. }
  2775. }
  2776. else
  2777. {
  2778. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2779. 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++)
  2780. {
  2781. 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"));
  2782. 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?
  2783. 3:
  2784. 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")));
  2785. 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));
  2786. }
  2787. }
  2788. // Optional item
  2789. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2790. {
  2791. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2792. }
  2793. else
  2794. {
  2795. sprintf((char*)txProfile.ValidFrom, " ");
  2796. }
  2797. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2798. {
  2799. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2800. }
  2801. else
  2802. {
  2803. sprintf((char*)txProfile.ValidTo, " ");
  2804. }
  2805. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2806. {
  2807. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2808. }
  2809. else
  2810. {
  2811. sprintf((char*)txProfile.RecurrencyKind, " ");
  2812. }
  2813. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2814. {
  2815. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2816. }
  2817. else
  2818. {
  2819. txProfile.TransactionId = -1;
  2820. }
  2821. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2822. {
  2823. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2824. }
  2825. else
  2826. {
  2827. txProfile.ChargingSchedule.Duration = 86400;
  2828. }
  2829. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2830. {
  2831. 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")));
  2832. }
  2833. else
  2834. {
  2835. 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));
  2836. }
  2837. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2838. {
  2839. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2840. }
  2841. else
  2842. {
  2843. txProfile.ChargingSchedule.MinChargingRate = -1;
  2844. }
  2845. }
  2846. }
  2847. }
  2848. else
  2849. {
  2850. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2851. {
  2852. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2853. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2854. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2855. }
  2856. if(txProfile.ChargingProfileId == -1)
  2857. DEBUG_INFO("TxProfile found.\n");
  2858. else
  2859. DEBUG_INFO("TxProfile updated.\n");
  2860. // Required item
  2861. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2862. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2863. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2864. if(isUnitA)
  2865. {
  2866. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  2867. 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++)
  2868. {
  2869. 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"));
  2870. 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?
  2871. 3:
  2872. 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")));
  2873. 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")));
  2874. }
  2875. }
  2876. else
  2877. {
  2878. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  2879. 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++)
  2880. {
  2881. 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"));
  2882. 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?
  2883. 3:
  2884. 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")));
  2885. 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));
  2886. }
  2887. }
  2888. // Optional item
  2889. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2890. {
  2891. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2892. }
  2893. else
  2894. {
  2895. sprintf((char*)txProfile.ValidFrom, " ");
  2896. }
  2897. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2898. {
  2899. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2900. }
  2901. else
  2902. {
  2903. sprintf((char*)txProfile.ValidTo, " ");
  2904. }
  2905. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2906. {
  2907. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2908. }
  2909. else
  2910. {
  2911. sprintf((char*)txProfile.RecurrencyKind, " ");
  2912. }
  2913. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2914. {
  2915. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2916. }
  2917. else
  2918. {
  2919. txProfile.TransactionId = -1;
  2920. }
  2921. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2922. {
  2923. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2924. }
  2925. else
  2926. {
  2927. txProfile.ChargingSchedule.Duration = 86400;
  2928. }
  2929. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2930. {
  2931. 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")));
  2932. }
  2933. else
  2934. {
  2935. 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));
  2936. }
  2937. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2938. {
  2939. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2940. }
  2941. else
  2942. {
  2943. txProfile.ChargingSchedule.MinChargingRate = -1;
  2944. }
  2945. }
  2946. }
  2947. }
  2948. json_object_put(obj);
  2949. }
  2950. fclose(fp);
  2951. /*
  2952. if(txProfile.ChargingProfileId != -1)
  2953. {
  2954. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2955. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2956. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2957. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2958. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2959. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2960. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2961. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2962. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2963. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2964. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2965. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2966. {
  2967. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2968. {
  2969. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2970. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2971. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2972. }
  2973. }
  2974. }
  2975. else
  2976. DEBUG_INFO("TxProfile not found.\n");*/
  2977. }
  2978. // Search default tx profile
  2979. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2980. if((access(profileFileName, F_OK))==-1)
  2981. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2982. if((access(profileFileName, F_OK))!=-1)
  2983. {
  2984. fp = fopen(profileFileName, "r");
  2985. while(getline(&line, &len, fp) != -1)
  2986. {
  2987. json_object *obj = NULL;
  2988. obj = json_tokener_parse(line);
  2989. if(is_error(obj))
  2990. {
  2991. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2992. }
  2993. else
  2994. {
  2995. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2996. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2997. )
  2998. {
  2999. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3000. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3001. )
  3002. {
  3003. struct tm tmFrom, tmTo;
  3004. struct timeb tbFrom, tbTo;
  3005. 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) &&
  3006. (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))
  3007. {
  3008. tmFrom.tm_year -= 1900;
  3009. tmFrom.tm_mon -= 1;
  3010. tbFrom.time = mktime(&tmFrom);
  3011. tmTo.tm_year -= 1900;
  3012. tmTo.tm_mon -= 1;
  3013. tbTo.time = mktime(&tmTo);
  3014. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3015. {
  3016. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3017. {
  3018. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3019. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3020. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3021. }
  3022. if(defaultTxProfile.ChargingProfileId == -1)
  3023. DEBUG_INFO("TxDefaultProfile found.\n");
  3024. else
  3025. DEBUG_INFO("TxDefaultProfile updated.\n");
  3026. // Required item
  3027. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3028. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3029. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3030. if(isUnitA)
  3031. {
  3032. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3033. 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++)
  3034. {
  3035. 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"));
  3036. 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?
  3037. 3:
  3038. 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")));
  3039. 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")));
  3040. }
  3041. }
  3042. else
  3043. {
  3044. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3045. 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++)
  3046. {
  3047. 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"));
  3048. 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?
  3049. 3:
  3050. 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")));
  3051. 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));
  3052. }
  3053. }
  3054. // Optional item
  3055. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3056. {
  3057. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3058. }
  3059. else
  3060. {
  3061. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3062. }
  3063. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3064. {
  3065. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3066. }
  3067. else
  3068. {
  3069. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3070. }
  3071. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3072. {
  3073. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3074. }
  3075. else
  3076. {
  3077. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3078. }
  3079. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3080. {
  3081. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3082. }
  3083. else
  3084. {
  3085. defaultTxProfile.TransactionId = -1;
  3086. }
  3087. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3088. {
  3089. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3090. }
  3091. else
  3092. {
  3093. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3094. }
  3095. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3096. {
  3097. 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")));
  3098. }
  3099. else
  3100. {
  3101. 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));
  3102. }
  3103. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3104. {
  3105. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3106. }
  3107. else
  3108. {
  3109. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3110. }
  3111. }
  3112. }
  3113. }
  3114. else
  3115. {
  3116. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3117. {
  3118. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3119. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3120. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3121. }
  3122. if(defaultTxProfile.ChargingProfileId == -1)
  3123. DEBUG_INFO("TxDefaultProfile found.\n");
  3124. else
  3125. DEBUG_INFO("TxDefaultProfile updated.\n");
  3126. // Required item
  3127. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3128. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3129. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3130. if(isUnitA)
  3131. {
  3132. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3133. 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++)
  3134. {
  3135. 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"));
  3136. 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?
  3137. 3:
  3138. 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")));
  3139. 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")));
  3140. }
  3141. }
  3142. else
  3143. {
  3144. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3145. 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++)
  3146. {
  3147. 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"));
  3148. 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?
  3149. 3:
  3150. 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")));
  3151. 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));
  3152. }
  3153. }
  3154. // Optional item
  3155. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3156. {
  3157. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3158. }
  3159. else
  3160. {
  3161. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  3162. }
  3163. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3164. {
  3165. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3166. }
  3167. else
  3168. {
  3169. sprintf((char*)defaultTxProfile.ValidTo, " ");
  3170. }
  3171. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3172. {
  3173. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3174. }
  3175. else
  3176. {
  3177. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  3178. }
  3179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3180. {
  3181. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3182. }
  3183. else
  3184. {
  3185. defaultTxProfile.TransactionId = -1;
  3186. }
  3187. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3188. {
  3189. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3190. }
  3191. else
  3192. {
  3193. defaultTxProfile.ChargingSchedule.Duration = 86400;
  3194. }
  3195. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3196. {
  3197. 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")));
  3198. }
  3199. else
  3200. {
  3201. 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));
  3202. }
  3203. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3204. {
  3205. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3206. }
  3207. else
  3208. {
  3209. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  3210. }
  3211. }
  3212. }
  3213. }
  3214. json_object_put(obj);
  3215. }
  3216. fclose(fp);
  3217. /*
  3218. if(defaultTxProfile.ChargingProfileId != -1)
  3219. {
  3220. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3221. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3222. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3223. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3224. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3225. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3226. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3227. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  3228. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3229. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3230. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3231. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3232. {
  3233. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3234. {
  3235. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3236. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3237. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3238. }
  3239. }
  3240. }
  3241. else
  3242. DEBUG_INFO("TxDefaultProfile not found.\n");
  3243. DEBUG_INFO("------------------------------------\n");*/
  3244. }
  3245. // Search max profile
  3246. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3247. if((access(profileFileName, F_OK))!=-1)
  3248. {
  3249. fp = fopen(profileFileName, "r");
  3250. while(getline(&line, &len, fp) != -1)
  3251. {
  3252. json_object *obj = NULL;
  3253. obj = json_tokener_parse(line);
  3254. if(is_error(obj))
  3255. {
  3256. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3257. }
  3258. else
  3259. {
  3260. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  3261. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  3262. )
  3263. {
  3264. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3265. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3266. )
  3267. {
  3268. struct tm tmFrom, tmTo;
  3269. struct timeb tbFrom, tbTo;
  3270. 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) &&
  3271. (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))
  3272. {
  3273. tmFrom.tm_year -= 1900;
  3274. tmFrom.tm_mon -= 1;
  3275. tbFrom.time = mktime(&tmFrom);
  3276. tmTo.tm_year -= 1900;
  3277. tmTo.tm_mon -= 1;
  3278. tbTo.time = mktime(&tmTo);
  3279. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3280. {
  3281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3282. {
  3283. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3284. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3285. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3286. }
  3287. if(maxProfile.ChargingProfileId == -1)
  3288. DEBUG_INFO("MaxProfile found.\n");
  3289. else
  3290. DEBUG_INFO("MaxProfile updated.\n");
  3291. // Required item
  3292. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3293. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3294. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3295. if(isUnitA)
  3296. {
  3297. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3298. 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++)
  3299. {
  3300. 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"));
  3301. 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?
  3302. 3:
  3303. 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")));
  3304. 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")));
  3305. }
  3306. }
  3307. else
  3308. {
  3309. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3310. 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++)
  3311. {
  3312. 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"));
  3313. 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?
  3314. 3:
  3315. 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")));
  3316. 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));
  3317. }
  3318. }
  3319. // Optional item
  3320. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3321. {
  3322. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3323. }
  3324. else
  3325. {
  3326. sprintf((char*)maxProfile.ValidFrom, " ");
  3327. }
  3328. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3329. {
  3330. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3331. }
  3332. else
  3333. {
  3334. sprintf((char*)maxProfile.ValidTo, " ");
  3335. }
  3336. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3337. {
  3338. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3339. }
  3340. else
  3341. {
  3342. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3343. }
  3344. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3345. {
  3346. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3347. }
  3348. else
  3349. {
  3350. maxProfile.TransactionId = -1;
  3351. }
  3352. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3353. {
  3354. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3355. }
  3356. else
  3357. {
  3358. maxProfile.ChargingSchedule.Duration = 86400;
  3359. }
  3360. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3361. {
  3362. 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")));
  3363. }
  3364. else
  3365. {
  3366. 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));
  3367. }
  3368. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3369. {
  3370. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3371. }
  3372. else
  3373. {
  3374. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3375. }
  3376. }
  3377. }
  3378. }
  3379. else
  3380. {
  3381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3382. {
  3383. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  3384. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  3385. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  3386. }
  3387. if(maxProfile.ChargingProfileId == -1)
  3388. DEBUG_INFO("MaxProfile found.\n");
  3389. else
  3390. DEBUG_INFO("MaxProfile updated.\n");
  3391. // Required item
  3392. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3393. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3394. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3395. if(isUnitA)
  3396. {
  3397. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  3398. 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++)
  3399. {
  3400. 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"));
  3401. 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?
  3402. 3:
  3403. 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")));
  3404. 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")));
  3405. }
  3406. }
  3407. else
  3408. {
  3409. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  3410. 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++)
  3411. {
  3412. 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"));
  3413. 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?
  3414. 3:
  3415. 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")));
  3416. 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));
  3417. }
  3418. }
  3419. // Optional item
  3420. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3421. {
  3422. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3423. }
  3424. else
  3425. {
  3426. sprintf((char*)maxProfile.ValidFrom, " ");
  3427. }
  3428. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3429. {
  3430. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3431. }
  3432. else
  3433. {
  3434. sprintf((char*)maxProfile.ValidTo, " ");
  3435. }
  3436. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  3437. {
  3438. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  3439. }
  3440. else
  3441. {
  3442. sprintf((char*)maxProfile.RecurrencyKind, " ");
  3443. }
  3444. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3445. {
  3446. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  3447. }
  3448. else
  3449. {
  3450. maxProfile.TransactionId = -1;
  3451. }
  3452. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3453. {
  3454. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3455. }
  3456. else
  3457. {
  3458. maxProfile.ChargingSchedule.Duration = 86400;
  3459. }
  3460. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3461. {
  3462. 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")));
  3463. }
  3464. else
  3465. {
  3466. 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));
  3467. }
  3468. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3469. {
  3470. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3471. }
  3472. else
  3473. {
  3474. maxProfile.ChargingSchedule.MinChargingRate = -1;
  3475. }
  3476. }
  3477. }
  3478. }
  3479. json_object_put(obj);
  3480. }
  3481. fclose(fp);
  3482. /*
  3483. if(maxProfile.ChargingProfileId !=-1)
  3484. {
  3485. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3486. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3487. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3488. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3489. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3490. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3491. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3492. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  3493. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3494. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3495. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3496. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3497. {
  3498. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3499. {
  3500. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3501. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3502. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3503. }
  3504. }
  3505. }
  3506. else
  3507. DEBUG_INFO("MaxProfile not found.\n");
  3508. DEBUG_INFO("------------------------------------\n");*/
  3509. }
  3510. /*
  3511. * Align found profile start schedule & periods
  3512. */
  3513. //DEBUG_INFO("====================================\n");
  3514. /*
  3515. // For local test usage, force modify found profile start schedule info
  3516. 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);
  3517. 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);
  3518. 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);
  3519. */
  3520. if(txProfile.ChargingProfileId != -1)
  3521. {
  3522. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  3523. {
  3524. if(txProfile.ChargingSchedule.Duration != -1)
  3525. {
  3526. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3527. 0:
  3528. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3529. }
  3530. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3531. {
  3532. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3533. {
  3534. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3535. 0:
  3536. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3537. if(idxPeriod > 0)
  3538. {
  3539. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3540. {
  3541. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3542. }
  3543. }
  3544. }
  3545. }
  3546. }
  3547. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  3548. {
  3549. if(txProfile.ChargingSchedule.Duration != -1)
  3550. {
  3551. 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?
  3552. 0:
  3553. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3554. }
  3555. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3556. {
  3557. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3558. {
  3559. 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?
  3560. 0:
  3561. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3562. if(idxPeriod > 0)
  3563. {
  3564. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3565. {
  3566. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3567. }
  3568. }
  3569. }
  3570. }
  3571. }
  3572. else
  3573. {
  3574. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  3575. {
  3576. if(txProfile.ChargingSchedule.Duration != -1)
  3577. {
  3578. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3579. 0:
  3580. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3581. }
  3582. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3583. {
  3584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3585. {
  3586. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3587. 0:
  3588. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3589. if(idxPeriod > 0)
  3590. {
  3591. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3592. {
  3593. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3594. }
  3595. }
  3596. }
  3597. }
  3598. }
  3599. else
  3600. {
  3601. if(txProfile.ChargingSchedule.Duration != -1)
  3602. {
  3603. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3604. 0:
  3605. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3606. }
  3607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3608. {
  3609. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3610. {
  3611. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3612. 0:
  3613. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3614. if(idxPeriod > 0)
  3615. {
  3616. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3617. {
  3618. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3619. }
  3620. }
  3621. }
  3622. }
  3623. }
  3624. }
  3625. /*
  3626. DEBUG_INFO("txProfile after align.\n");
  3627. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3628. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3629. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3630. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3631. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3632. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3633. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  3634. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3635. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  3636. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  3637. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  3638. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3639. {
  3640. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3641. {
  3642. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3643. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3644. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3645. }
  3646. }*/
  3647. }
  3648. if(defaultTxProfile.ChargingProfileId != -1)
  3649. {
  3650. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  3651. {
  3652. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3653. {
  3654. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3655. 0:
  3656. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3657. }
  3658. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3659. {
  3660. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3661. {
  3662. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3663. 0:
  3664. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3665. if(idxPeriod > 0)
  3666. {
  3667. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3668. {
  3669. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3670. }
  3671. }
  3672. }
  3673. }
  3674. }
  3675. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  3676. {
  3677. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3678. {
  3679. 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?
  3680. 0:
  3681. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3682. }
  3683. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3684. {
  3685. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3686. {
  3687. 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?
  3688. 0:
  3689. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3690. if(idxPeriod > 0)
  3691. {
  3692. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3693. {
  3694. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3695. }
  3696. }
  3697. }
  3698. }
  3699. }
  3700. else
  3701. {
  3702. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  3703. {
  3704. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3705. {
  3706. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3707. 0:
  3708. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3709. }
  3710. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3711. {
  3712. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3713. {
  3714. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3715. 0:
  3716. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3717. if(idxPeriod > 0)
  3718. {
  3719. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3720. {
  3721. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3722. }
  3723. }
  3724. }
  3725. }
  3726. }
  3727. else
  3728. {
  3729. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  3730. {
  3731. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3732. 0:
  3733. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3734. }
  3735. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3736. {
  3737. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3738. {
  3739. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3740. 0:
  3741. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3742. if(idxPeriod > 0)
  3743. {
  3744. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3745. {
  3746. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3747. }
  3748. }
  3749. }
  3750. }
  3751. }
  3752. }
  3753. /*
  3754. DEBUG_INFO("defaultTxProfile after align.\n");
  3755. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3756. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3757. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3758. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3759. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3760. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3761. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3762. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3763. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  3764. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  3765. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  3766. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3767. {
  3768. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3769. {
  3770. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3771. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3772. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3773. }
  3774. }
  3775. DEBUG_INFO("------------------------------------\n");*/
  3776. }
  3777. if(maxProfile.ChargingProfileId != -1)
  3778. {
  3779. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  3780. {
  3781. if(maxProfile.ChargingSchedule.Duration != -1)
  3782. {
  3783. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3784. 0:
  3785. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3786. }
  3787. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3788. {
  3789. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3790. {
  3791. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule))<0?
  3792. 0:
  3793. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule)));
  3794. if(idxPeriod > 0)
  3795. {
  3796. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3797. {
  3798. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3799. }
  3800. }
  3801. }
  3802. }
  3803. }
  3804. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  3805. {
  3806. if(maxProfile.ChargingSchedule.Duration != -1)
  3807. {
  3808. 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?
  3809. 0:
  3810. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3811. }
  3812. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3813. {
  3814. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3815. {
  3816. 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?
  3817. 0:
  3818. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile.ChargingSchedule.StartSchedule)));
  3819. if(idxPeriod > 0)
  3820. {
  3821. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3822. {
  3823. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3824. }
  3825. }
  3826. }
  3827. }
  3828. }
  3829. else
  3830. {
  3831. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  3832. {
  3833. if(maxProfile.ChargingSchedule.Duration != -1)
  3834. {
  3835. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3836. 0:
  3837. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3838. }
  3839. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3840. {
  3841. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3842. {
  3843. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE))<0?
  3844. 0:
  3845. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, FALSE)));
  3846. if(idxPeriod > 0)
  3847. {
  3848. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3849. {
  3850. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3851. }
  3852. }
  3853. }
  3854. }
  3855. }
  3856. else
  3857. {
  3858. if(maxProfile.ChargingSchedule.Duration != -1)
  3859. {
  3860. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3861. 0:
  3862. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3863. }
  3864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3865. {
  3866. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  3867. {
  3868. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE))<0?
  3869. 0:
  3870. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile.ChargingSchedule.StartSchedule, TRUE)));
  3871. if(idxPeriod > 0)
  3872. {
  3873. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  3874. {
  3875. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  3876. }
  3877. }
  3878. }
  3879. }
  3880. }
  3881. }
  3882. /*
  3883. DEBUG_INFO("MaxProfile after align.\n");
  3884. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3885. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3886. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3887. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3888. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3889. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3890. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3891. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  3892. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  3893. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  3894. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  3895. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3896. {
  3897. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3898. {
  3899. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3900. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3901. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3902. }
  3903. }
  3904. DEBUG_INFO("------------------------------------\n");*/
  3905. }
  3906. /*
  3907. * Merge to composite schedule
  3908. */
  3909. //DEBUG_INFO("====================================\n");
  3910. // Find each profile period quantity
  3911. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3912. {
  3913. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3914. limitMax = idx+1;
  3915. }
  3916. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3917. {
  3918. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3919. limitDef = idx+1;
  3920. }
  3921. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  3922. {
  3923. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  3924. limitTx = idx+1;
  3925. }
  3926. // TxProfile found, composite schedule based on it
  3927. if(txProfile.ChargingProfileId != -1)
  3928. {
  3929. compositeProfile.ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3930. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3931. {
  3932. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3933. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3934. (txProfile.ChargingSchedule.Duration > 0))
  3935. {
  3936. if(maxProfile.ChargingProfileId != -1)
  3937. {
  3938. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3939. {
  3940. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3941. {
  3942. if((maxProfile.ChargingSchedule.Duration > 0))
  3943. {
  3944. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3945. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3946. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3947. }
  3948. else
  3949. {
  3950. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3951. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3952. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3953. }
  3954. }
  3955. if(idxMaxPeriod == (limitMax-1))
  3956. {
  3957. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3958. {
  3959. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3960. {
  3961. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3962. compositePeriodIdx++;
  3963. }
  3964. else
  3965. {
  3966. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3967. }
  3968. }
  3969. }
  3970. }
  3971. }
  3972. else
  3973. {
  3974. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3975. {
  3976. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3977. compositePeriodIdx++;
  3978. }
  3979. else
  3980. {
  3981. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3982. }
  3983. }
  3984. }
  3985. if(idxTxPeriod == (limitTx-1))
  3986. {
  3987. if(defaultTxProfile.ChargingProfileId != -1)
  3988. {
  3989. compositeProfile.ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile.ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile.ChargingSchedule.Duration;
  3990. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3991. {
  3992. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3993. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3994. (defaultTxProfile.ChargingSchedule.Duration>0))
  3995. {
  3996. if(maxProfile.ChargingProfileId != -1)
  3997. {
  3998. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3999. {
  4000. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4001. {
  4002. if((maxProfile.ChargingSchedule.Duration > 0))
  4003. {
  4004. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4005. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4006. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  4007. }
  4008. else
  4009. {
  4010. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4011. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4012. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4013. }
  4014. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4015. {
  4016. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4017. {
  4018. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4019. compositePeriodIdx++;
  4020. }
  4021. else
  4022. {
  4023. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4024. }
  4025. }
  4026. // Delete duplicate period
  4027. if(compositePeriodIdx > 1)
  4028. {
  4029. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4030. {
  4031. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4032. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4033. compositePeriodIdx -= 1;
  4034. }
  4035. }
  4036. }
  4037. else
  4038. {
  4039. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4040. {
  4041. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4042. compositePeriodIdx++;
  4043. }
  4044. else
  4045. {
  4046. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4047. }
  4048. break;
  4049. }
  4050. }
  4051. }
  4052. else
  4053. {
  4054. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4055. {
  4056. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4057. compositePeriodIdx++;
  4058. }
  4059. else
  4060. {
  4061. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4062. }
  4063. }
  4064. }
  4065. }
  4066. }
  4067. }
  4068. }
  4069. }
  4070. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4071. else if(defaultTxProfile.ChargingProfileId != -1)
  4072. {
  4073. compositeProfile.ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  4074. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4075. {
  4076. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  4077. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  4078. (defaultTxProfile.ChargingSchedule.Duration > 0))
  4079. {
  4080. if(maxProfile.ChargingProfileId != -1)
  4081. {
  4082. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4083. {
  4084. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  4085. {
  4086. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  4087. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  4088. if((maxProfile.ChargingSchedule.Duration > 0))
  4089. {
  4090. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  4091. }
  4092. else
  4093. {
  4094. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  4095. }
  4096. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  4097. {
  4098. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4099. {
  4100. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4101. compositePeriodIdx++;
  4102. }
  4103. else
  4104. {
  4105. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4106. }
  4107. }
  4108. // Delete duplicate period
  4109. if(compositePeriodIdx > 1)
  4110. {
  4111. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4112. {
  4113. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4114. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4115. compositePeriodIdx -= 1;
  4116. }
  4117. }
  4118. }
  4119. else
  4120. {
  4121. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4122. {
  4123. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4124. compositePeriodIdx++;
  4125. }
  4126. else
  4127. {
  4128. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4129. }
  4130. break;
  4131. }
  4132. }
  4133. }
  4134. else
  4135. {
  4136. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4137. {
  4138. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4139. compositePeriodIdx++;
  4140. }
  4141. else
  4142. {
  4143. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  4144. }
  4145. }
  4146. }
  4147. }
  4148. }
  4149. // Fill other period by MaxProfile
  4150. if(maxProfile.ChargingProfileId != -1)
  4151. {
  4152. if(compositePeriodIdx==0)
  4153. {
  4154. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4155. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  4156. {
  4157. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4158. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4159. (maxProfile.ChargingSchedule.Duration > 0))
  4160. {
  4161. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  4162. {
  4163. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4164. compositePeriodIdx++;
  4165. }
  4166. else
  4167. {
  4168. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  4169. }
  4170. }
  4171. }
  4172. }
  4173. else
  4174. {
  4175. int lastCompositePeriodIdx = compositePeriodIdx;
  4176. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4177. {
  4178. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  4179. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  4180. (maxProfile.ChargingSchedule.Duration > 0))
  4181. {
  4182. if((maxProfile.ChargingSchedule.Duration >= compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  4183. {
  4184. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit) &&
  4185. (compositeProfile.ChargingSchedule.Duration >= durationReq))
  4186. {
  4187. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4188. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4189. tmpPeriod.Limit = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  4190. }
  4191. else
  4192. {
  4193. if(maxProfile.ChargingSchedule.Duration > compositeProfile.ChargingSchedule.Duration)
  4194. {
  4195. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod <= compositeProfile.ChargingSchedule.Duration)
  4196. tmpPeriod.StartPeriod = compositeProfile.ChargingSchedule.Duration;
  4197. else
  4198. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  4199. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  4200. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  4201. }
  4202. }
  4203. }
  4204. if(tmpPeriod.Limit != -1)
  4205. {
  4206. if(tmpPeriod.Limit != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  4207. {
  4208. if(tmpPeriod.StartPeriod != compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  4209. {
  4210. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4211. compositePeriodIdx++;
  4212. }
  4213. else
  4214. {
  4215. memcpy(&compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  4216. }
  4217. }
  4218. // Delete duplicate period
  4219. if(compositePeriodIdx > 1)
  4220. {
  4221. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  4222. {
  4223. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  4224. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  4225. compositePeriodIdx -= 1;
  4226. }
  4227. }
  4228. }
  4229. }
  4230. }
  4231. if((maxProfile.ChargingSchedule.Duration > durationReq) && (maxProfile.ChargingSchedule.Duration > compositeProfile.ChargingSchedule.Duration))
  4232. {
  4233. compositeProfile.ChargingSchedule.Duration = durationReq;
  4234. }
  4235. else if(maxProfile.ChargingSchedule.Duration > compositeProfile.ChargingSchedule.Duration)
  4236. {
  4237. compositeProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  4238. }
  4239. }
  4240. }
  4241. if(compositeProfile.ChargingSchedule.Duration < durationReq)
  4242. {
  4243. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4244. {
  4245. if((idxPeriod >= 0) && (compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1))
  4246. {
  4247. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = compositeProfile.ChargingSchedule.Duration;
  4248. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  4249. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].NumberPhases;
  4250. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  4251. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4252. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4253. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4254. DEBUG_INFO("------------------------------------------------\n");
  4255. break;
  4256. }
  4257. }
  4258. }
  4259. compositeProfile.ChargingSchedule.Duration = durationReq;
  4260. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4261. DEBUG_INFO("Schedule start: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4262. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.ChargingSchedule.Duration);
  4263. DEBUG_INFO("Rate unit: %s\n", compositeProfile.ChargingSchedule.ChargingRateUnit);
  4264. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  4265. {
  4266. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4267. {
  4268. compositeProfile.ChargingProfileId = 1;
  4269. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4270. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  4271. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4272. }
  4273. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  4274. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  4275. if(compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  4276. compositeProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  4277. }
  4278. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4279. if(line)
  4280. free(line);
  4281. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  4282. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  4283. }
  4284. //==========================================
  4285. // Init all share memory
  4286. //==========================================
  4287. int InitShareMemory()
  4288. {
  4289. int result = PASS;
  4290. int MeterSMId;
  4291. //creat ShmSysConfigAndInfo
  4292. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4293. {
  4294. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4295. result = FAIL;
  4296. }
  4297. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4298. {
  4299. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4300. result = FAIL;
  4301. }
  4302. else
  4303. {}
  4304. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4305. {
  4306. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4307. result = FAIL;
  4308. }
  4309. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4310. {
  4311. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4312. result = FAIL;
  4313. }
  4314. else
  4315. {}
  4316. //creat ShmPsuData
  4317. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4318. {
  4319. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4320. result = FAIL;
  4321. }
  4322. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4323. {
  4324. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4325. result = FAIL;
  4326. }
  4327. else
  4328. {}
  4329. //creat ShmOCPP16Data
  4330. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  4331. {
  4332. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  4333. result = FAIL;
  4334. }
  4335. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4336. {
  4337. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  4338. result = FAIL;
  4339. }
  4340. else
  4341. {}
  4342. /****************************** For Initial Settings************************************************/
  4343. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  4344. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  4345. // allocate Configuration memory address
  4346. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  4347. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  4348. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  4349. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  4350. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  4351. //offline MeterValue Interval
  4352. TempMeterValueInterval = 0;
  4353. return result;
  4354. }
  4355. int ProcessShareMemory()
  4356. {
  4357. int result = PASS;
  4358. if(InitShareMemory() == FAIL)
  4359. {
  4360. DEBUG_ERROR("InitShareMemory NG\n");
  4361. if(ShmStatusCodeData!=NULL)
  4362. {
  4363. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4364. }
  4365. result = FAIL;
  4366. }
  4367. // Model name parsing
  4368. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  4369. {
  4370. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  4371. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  4372. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  4373. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  4374. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  4375. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  4376. ) // 'D' means DC
  4377. {
  4378. // DO series
  4379. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  4380. {
  4381. gunTotalNumber += 1;
  4382. gunType[gun_index] = GUN_TYPE_DO;
  4383. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4384. {
  4385. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  4386. {
  4387. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4388. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  4389. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  4390. }
  4391. }
  4392. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4393. {
  4394. case Gun_Type_Chademo:
  4395. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  4396. break;
  4397. case Gun_Type_CCS_2:
  4398. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  4399. break;
  4400. case Gun_Type_GB:
  4401. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  4402. break;
  4403. case Gun_Type_AC:
  4404. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  4405. break;
  4406. default:
  4407. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  4408. break;
  4409. }
  4410. }
  4411. }
  4412. else
  4413. {
  4414. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  4415. {
  4416. gunTotalNumber += 1;
  4417. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  4418. {
  4419. case Gun_Type_Chademo:
  4420. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  4421. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  4422. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  4423. {
  4424. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  4425. {
  4426. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4427. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  4428. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  4429. }
  4430. }
  4431. break;
  4432. case Gun_Type_CCS_2:
  4433. gunType[gun_index] = GUN_TYPE_CCS;
  4434. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  4435. for (int index = 0; index < CCS_QUANTITY; index++)
  4436. {
  4437. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  4438. {
  4439. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4440. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  4441. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  4442. }
  4443. }
  4444. break;
  4445. case Gun_Type_GB:
  4446. gunType[gun_index] = GUN_TYPE_GBT;
  4447. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  4448. for (int index = 0; index < GB_QUANTITY; index++)
  4449. {
  4450. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  4451. {
  4452. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4453. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  4454. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  4455. }
  4456. }
  4457. break;
  4458. case Gun_Type_AC:
  4459. gunType[gun_index] = GUN_TYPE_AC;
  4460. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  4461. for (int index = 0; index < AC_QUANTITY; index++)
  4462. {
  4463. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  4464. {
  4465. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4466. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  4467. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  4468. }
  4469. }
  4470. break;
  4471. default:
  4472. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  4473. break;
  4474. }
  4475. }
  4476. }
  4477. }
  4478. else
  4479. {
  4480. DEBUG_ERROR("Model name parsing fail.\n");
  4481. result = FAIL;
  4482. }
  4483. if(result != PASS)sleep(5);
  4484. return result;
  4485. }
  4486. void checkRemoteStart(uint8_t connectorIdInt)
  4487. {
  4488. uint8_t tempIndex;
  4489. int result = PASS;
  4490. char cmdBuf[512];
  4491. //check Transaction active
  4492. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  4493. {
  4494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4495. {
  4496. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4497. }
  4498. else
  4499. {
  4500. tempIndex = connectorIdInt -1;
  4501. }
  4502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4503. {
  4504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4505. {
  4506. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4507. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4508. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4509. {
  4510. //Reserved
  4511. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  4512. }
  4513. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  4514. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  4515. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4516. {
  4517. //Reserved
  4518. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  4519. result = FAIL;
  4520. goto end;
  4521. }
  4522. else
  4523. {
  4524. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4525. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  4526. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  4527. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  4528. {
  4529. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  4530. result = FAIL;
  4531. goto end;
  4532. }
  4533. }//END FOR ELSE
  4534. }
  4535. }// END FOR CHAdeMO_QUANTITY
  4536. }
  4537. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  4538. {
  4539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4540. {
  4541. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4542. }
  4543. else
  4544. {
  4545. tempIndex = connectorIdInt -1;
  4546. }
  4547. for (int index = 0; index < CCS_QUANTITY; index++)
  4548. {
  4549. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4550. {
  4551. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4552. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4553. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4554. {
  4555. //Reserved
  4556. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  4557. }
  4558. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  4559. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  4560. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4561. {
  4562. //Reserved
  4563. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  4564. result = FAIL;
  4565. goto end;
  4566. }
  4567. else
  4568. {
  4569. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4570. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4571. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4572. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4573. {
  4574. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  4575. result = FAIL;
  4576. goto end;
  4577. }
  4578. }// END FOR ELSE
  4579. }
  4580. }// END FOR CCS_QUANTITY
  4581. }
  4582. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  4583. {
  4584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4585. {
  4586. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  4587. }
  4588. else
  4589. {
  4590. tempIndex = connectorIdInt -1;
  4591. }
  4592. for (int index = 0; index < GB_QUANTITY; index++)
  4593. {
  4594. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  4595. {
  4596. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4597. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4598. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4599. {
  4600. //Reserved
  4601. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  4602. }
  4603. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  4604. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  4605. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4606. {
  4607. //Reserved
  4608. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  4609. result = FAIL;
  4610. goto end;
  4611. }
  4612. else
  4613. {
  4614. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4615. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4616. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4617. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4618. {
  4619. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  4620. result = FAIL;
  4621. goto end;
  4622. }
  4623. }// END FOR ELSE
  4624. }
  4625. } // END FOR GB_QUANTITY
  4626. }
  4627. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  4628. {
  4629. tempIndex = connectorIdInt -1;
  4630. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4631. {
  4632. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  4633. {
  4634. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4635. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4636. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4637. {
  4638. //Reserved
  4639. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  4640. }
  4641. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  4642. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  4643. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4644. {
  4645. //Reserved
  4646. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  4647. result = FAIL;
  4648. goto end;
  4649. }
  4650. else
  4651. {
  4652. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4653. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4654. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4655. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4656. {
  4657. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  4658. result = FAIL;
  4659. goto end;
  4660. }
  4661. }// END FOR ELSE
  4662. }
  4663. } // END FOR GB_QUANTITY
  4664. }
  4665. else
  4666. {
  4667. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  4668. {
  4669. tempIndex = 2;
  4670. }
  4671. else
  4672. {
  4673. tempIndex = connectorIdInt -1;
  4674. }
  4675. for (int index = 0; index < AC_QUANTITY; index++)
  4676. {
  4677. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  4678. {
  4679. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4680. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4681. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  4682. {
  4683. //Reserved
  4684. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  4685. }
  4686. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  4687. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  4688. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  4689. {
  4690. //Reserved
  4691. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  4692. result = FAIL;
  4693. goto end;
  4694. }
  4695. else
  4696. {
  4697. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  4698. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  4699. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  4700. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  4701. {
  4702. DEBUG_WARN("AC connector not allow start cause busy.\n");
  4703. result = FAIL;
  4704. goto end;
  4705. }
  4706. }//END FOR ELSE
  4707. }
  4708. }// END FOR AC_QUANTITY
  4709. }
  4710. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  4711. {
  4712. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4713. {
  4714. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  4715. {
  4716. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4717. system(cmdBuf);
  4718. }
  4719. }
  4720. else
  4721. {
  4722. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  4723. result = FAIL;
  4724. }
  4725. }
  4726. end:
  4727. if(result == PASS)
  4728. {
  4729. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  4730. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  4731. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4732. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  4733. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  4734. }
  4735. }
  4736. int isConnector0Unavailable()
  4737. {
  4738. uint8_t result = YES;
  4739. uint8_t tempIndex;
  4740. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4741. {
  4742. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4743. {
  4744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4745. {
  4746. tempIndex = ((gun_index==2) ? 1: 0);
  4747. }
  4748. else
  4749. {
  4750. tempIndex = gun_index;
  4751. }
  4752. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4753. {
  4754. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4755. {
  4756. 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))
  4757. {
  4758. result = NO;
  4759. }
  4760. }
  4761. }
  4762. }
  4763. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4764. {
  4765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4766. {
  4767. tempIndex = ((gun_index==2) ? 1: 0);
  4768. }
  4769. else
  4770. {
  4771. tempIndex = gun_index;
  4772. }
  4773. for (int index = 0; index < CCS_QUANTITY; index++)
  4774. {
  4775. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4776. {
  4777. 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))
  4778. {
  4779. result = NO;
  4780. }
  4781. }
  4782. }
  4783. }
  4784. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4785. {
  4786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4787. {
  4788. tempIndex = ((gun_index==2) ? 1: 0);
  4789. }
  4790. else
  4791. {
  4792. tempIndex = gun_index;
  4793. }
  4794. for (int index = 0; index < GB_QUANTITY; index++)
  4795. {
  4796. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4797. {
  4798. 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))
  4799. {
  4800. result = NO;
  4801. }
  4802. }
  4803. }
  4804. }
  4805. else if(gunType[gun_index] == GUN_TYPE_DO)
  4806. {
  4807. tempIndex = gun_index;
  4808. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4809. {
  4810. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4811. {
  4812. 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))
  4813. {
  4814. result = NO;
  4815. }
  4816. }
  4817. }
  4818. }
  4819. else
  4820. {
  4821. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4822. {
  4823. tempIndex = 2;
  4824. }
  4825. else
  4826. {
  4827. tempIndex = gun_index;
  4828. }
  4829. for (int index = 0; index < AC_QUANTITY; index++)
  4830. {
  4831. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4832. {
  4833. 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))
  4834. {
  4835. result = NO;
  4836. }
  4837. }
  4838. }// END
  4839. }
  4840. }
  4841. return result;
  4842. }
  4843. void CheckSystemValue(void)
  4844. {
  4845. char filenmae[100]={0};
  4846. char str[100]={0};
  4847. int tempIndex = 0;
  4848. //===============================
  4849. // send Heartbeat
  4850. //===============================
  4851. if((server_sign == TRUE) && (HeartBeatWaitTime > 0) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4852. {
  4853. //parameter for test
  4854. if(HeartBeatWithNOResponse < 1)
  4855. sendHeartbeatRequest(0);
  4856. //===========================
  4857. // Reset Waiting Time
  4858. //===========================
  4859. HeartBeatWithNOResponse += 1;
  4860. }
  4861. //===============================
  4862. // Tcci credit deduct report
  4863. //===============================
  4864. if(ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq)
  4865. {
  4866. OCPP_insert_deduct_info(ShmOCPP16Data->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.creditNo,
  4867. ShmOCPP16Data->TcciCustomData.DeductInfo.deductResult, ShmOCPP16Data->TcciCustomData.DeductInfo.isDonateInvoice,
  4868. ShmOCPP16Data->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.vemData,
  4869. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.RRN,
  4870. (char*)ShmOCPP16Data->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16Data->TcciCustomData.DeductInfo.storeId);
  4871. ShmOCPP16Data->TcciCustomData.ReportCreditDeductReq = FALSE;
  4872. }
  4873. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  4874. {
  4875. OCPP_query_deduct_info();
  4876. refreshStartTimer(&clientTime.TcciQueryDeduct);
  4877. }
  4878. if(ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq)
  4879. {
  4880. OCPP_insert_occupancyDeduct_info((char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.occupancySN, (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.creditNo,
  4881. ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.deductResult, ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.amount,
  4882. (char*)ShmOCPP16Data->TcciCustomData.OccupancyDeductResult.approvalNo);
  4883. ShmOCPP16Data->TcciCustomData.ReportOccupancyDeductReq = FALSE;
  4884. }
  4885. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[0].DataTransferReq != TRUE) && getDiffSecNow(clientTime.TcciQueryOccupancyDeduct) > 5)
  4886. {
  4887. OCPP_query_occupancyDeduct_info();
  4888. refreshStartTimer(&clientTime.TcciQueryOccupancyDeduct);
  4889. }
  4890. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  4891. {
  4892. // ClockAlign MeterValue
  4893. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  4894. {
  4895. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4896. {
  4897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4898. {
  4899. tempIndex = ((gun_index==2) ? 1: 0);
  4900. }
  4901. else
  4902. {
  4903. tempIndex = gun_index;
  4904. }
  4905. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4906. {
  4907. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4908. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4909. {
  4910. reqClockAlignMeter[gun_index] = 1;
  4911. }
  4912. }// End for CHAdeMO
  4913. }
  4914. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4915. {
  4916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4917. {
  4918. tempIndex = ((gun_index==2) ? 1: 0);
  4919. }
  4920. else
  4921. {
  4922. tempIndex = gun_index;
  4923. }
  4924. for (int index = 0; index < CCS_QUANTITY; index++)
  4925. {
  4926. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4927. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4928. {
  4929. reqClockAlignMeter[gun_index] = 1;
  4930. }
  4931. } // End for CCS
  4932. }
  4933. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4934. {
  4935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4936. {
  4937. tempIndex = ((gun_index==2) ? 1: 0);
  4938. }
  4939. else
  4940. {
  4941. tempIndex = gun_index;
  4942. }
  4943. for (int index = 0; index < GB_QUANTITY; index++)
  4944. {
  4945. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4946. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4947. {
  4948. reqClockAlignMeter[gun_index] = 1;
  4949. }
  4950. }// End for GB
  4951. }
  4952. else if(gunType[gun_index] == GUN_TYPE_DO)
  4953. {
  4954. tempIndex = gun_index;
  4955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4956. {
  4957. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4958. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4959. {
  4960. reqClockAlignMeter[gun_index] = 1;
  4961. }
  4962. }
  4963. }
  4964. else
  4965. {
  4966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4967. {
  4968. tempIndex = 2;
  4969. }
  4970. else
  4971. {
  4972. tempIndex = gun_index;
  4973. }
  4974. for (int index = 0; index < AC_QUANTITY; index++)
  4975. {
  4976. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4977. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4978. {
  4979. reqClockAlignMeter[gun_index] = 1;
  4980. }
  4981. }//End for AC
  4982. }
  4983. }
  4984. }
  4985. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4986. {
  4987. //==========================================
  4988. // Check remote start without connector id
  4989. //==========================================
  4990. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  4991. {
  4992. int connectorIdInt = -1;
  4993. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  4994. {
  4995. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  4996. {
  4997. connectorIdInt = (gun_index+1);
  4998. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  4999. checkRemoteStart(connectorIdInt);
  5000. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  5001. break;
  5002. }
  5003. }
  5004. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  5005. {
  5006. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5007. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  5008. }
  5009. }
  5010. //==========================================
  5011. // csu trigger DataTransferReq
  5012. //==========================================
  5013. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  5014. {
  5015. sendDataTransferRequest(gun_index);
  5016. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  5017. }
  5018. //==========================================
  5019. // CSU Trigger Authorize Request
  5020. //==========================================
  5021. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  5022. {
  5023. sendAuthorizeRequest(0);
  5024. authorizeRetryTimes = authorizeRetryTimes + 1;
  5025. if(authorizeRetryTimes < 3)
  5026. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5027. }
  5028. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  5029. {
  5030. authorizeRetryTimes = 0;
  5031. SetOcppConnStatus(FALSE);
  5032. server_sign = FALSE;
  5033. }
  5034. 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))
  5035. {
  5036. sendAuthorizeRequest(0);
  5037. }
  5038. //==========================================
  5039. // Charger start transaction
  5040. //==========================================
  5041. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  5042. {
  5043. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  5044. meterValueBufferClear(gun_index);
  5045. sendStartTransactionRequest(gun_index);
  5046. refreshStartTimer(&clientTime.StartTransaction);
  5047. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5048. storeTempStopTransaction(gun_index);
  5049. }
  5050. //==========================================
  5051. // Charger stop transaction
  5052. //==========================================
  5053. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  5054. {
  5055. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5056. sendStopTransactionRequest(gun_index);
  5057. OCPP_updatePeriodEnergy(gun_index);
  5058. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  5059. refreshStartTimer(&clientTime.StopTransaction);
  5060. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  5061. }
  5062. //==========================================
  5063. // Charger OCMF message
  5064. //==========================================
  5065. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq == 1)))
  5066. {
  5067. sendOcmfByDataTransferRequest(gun_index);
  5068. ShmOCPP16Data->OcmfData[gun_index].SendOcmfDataReq = 0;
  5069. }
  5070. //==========================================
  5071. // Charger status report
  5072. //==========================================
  5073. //--- Check Mode Change ---//
  5074. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5075. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5076. {
  5077. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5078. {
  5079. tempIndex = ((gun_index==2) ? 1: 0);
  5080. }
  5081. else
  5082. {
  5083. tempIndex = gun_index;
  5084. }
  5085. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5086. {
  5087. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5088. {
  5089. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5090. {
  5091. // Sent unplug message for California pricing logic
  5092. 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])
  5093. {
  5094. uint8_t ts[36];
  5095. getNowDatetime(ts);
  5096. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5097. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5098. if(strcmp((char*)dmsVersion, "2.0")==0)
  5099. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5100. else
  5101. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5102. sendUnplugByDataTransferRequest(gun_index);
  5103. interLock.isSentUnplug[gun_index] = 1;
  5104. }
  5105. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5106. {
  5107. interLock.isSentUnplug[gun_index] = 0;
  5108. }
  5109. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5110. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5111. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5112. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5113. {
  5114. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5115. if((access(filenmae,F_OK))!=-1)
  5116. {
  5117. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5118. sprintf(str,"rm -f %s",filenmae);
  5119. system(str);
  5120. }
  5121. }
  5122. }
  5123. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5124. #if 1 // for TempStopTransaction
  5125. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5126. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5127. {
  5128. checkTempStopTransaction(gun_index);
  5129. }
  5130. #endif
  5131. }
  5132. }
  5133. }
  5134. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5135. {
  5136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5137. {
  5138. tempIndex = ((gun_index==2) ? 1: 0);
  5139. }
  5140. else
  5141. {
  5142. tempIndex = gun_index;
  5143. }
  5144. for (int index = 0; index < CCS_QUANTITY; index++)
  5145. {
  5146. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5147. {
  5148. 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]*/ )
  5149. {
  5150. // Sent unplug message for California pricing logic
  5151. 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])
  5152. {
  5153. uint8_t ts[36];
  5154. getNowDatetime(ts);
  5155. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5156. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5157. if(strcmp((char*)dmsVersion, "2.0")==0)
  5158. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5159. else
  5160. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5161. sendUnplugByDataTransferRequest(gun_index);
  5162. interLock.isSentUnplug[gun_index] = 1;
  5163. }
  5164. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5165. {
  5166. interLock.isSentUnplug[gun_index] = 0;
  5167. }
  5168. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  5169. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  5170. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5171. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5172. {
  5173. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5174. if((access(filenmae,F_OK))!=-1)
  5175. {
  5176. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5177. sprintf(str,"rm -f %s",filenmae);
  5178. system(str);
  5179. }
  5180. }
  5181. }
  5182. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5183. #if 1 // for TempStopTransaction
  5184. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5185. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5186. {
  5187. checkTempStopTransaction(gun_index);
  5188. }
  5189. #endif
  5190. }
  5191. }
  5192. }
  5193. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5194. {
  5195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5196. {
  5197. tempIndex = ((gun_index==2) ? 1: 0);
  5198. }
  5199. else
  5200. {
  5201. tempIndex = gun_index;
  5202. }
  5203. for (int index = 0; index < GB_QUANTITY; index++)
  5204. {
  5205. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5206. {
  5207. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5208. {
  5209. // Sent unplug message for California pricing logic
  5210. 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])
  5211. {
  5212. uint8_t ts[36];
  5213. getNowDatetime(ts);
  5214. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5215. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5216. if(strcmp((char*)dmsVersion, "2.0")==0)
  5217. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5218. else
  5219. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5220. sendUnplugByDataTransferRequest(gun_index);
  5221. interLock.isSentUnplug[gun_index] = 1;
  5222. }
  5223. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5224. {
  5225. interLock.isSentUnplug[gun_index] = 0;
  5226. }
  5227. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5228. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5229. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5230. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5231. {
  5232. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5233. if((access(filenmae,F_OK))!=-1)
  5234. {
  5235. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5236. sprintf(str,"rm -f %s",filenmae);
  5237. system(str);
  5238. }
  5239. }
  5240. }
  5241. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5242. #if 1 // for TempStopTransaction
  5243. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5244. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5245. {
  5246. checkTempStopTransaction(gun_index);
  5247. }
  5248. #endif
  5249. }
  5250. }
  5251. }
  5252. else if(gunType[gun_index] == GUN_TYPE_DO)
  5253. {
  5254. tempIndex = gun_index;
  5255. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5256. {
  5257. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5258. {
  5259. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5260. {
  5261. // Sent unplug message for California pricing logic
  5262. 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])
  5263. {
  5264. uint8_t ts[36];
  5265. getNowDatetime(ts);
  5266. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5267. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5268. if(strcmp((char*)dmsVersion, "2.0")==0)
  5269. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5270. else
  5271. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5272. sendUnplugByDataTransferRequest(gun_index);
  5273. interLock.isSentUnplug[gun_index] = 1;
  5274. }
  5275. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE))
  5276. {
  5277. interLock.isSentUnplug[gun_index] = 0;
  5278. }
  5279. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5280. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5281. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5282. 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
  5283. {
  5284. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5285. if((access(filenmae,F_OK))!=-1)
  5286. {
  5287. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5288. sprintf(str,"rm -f %s",filenmae);
  5289. system(str);
  5290. }
  5291. }
  5292. }
  5293. 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);
  5294. #if 1 // for TempStopTransaction
  5295. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5296. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5297. {
  5298. checkTempStopTransaction(gun_index);
  5299. }
  5300. #endif
  5301. }
  5302. }
  5303. }
  5304. else
  5305. {
  5306. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5307. {
  5308. tempIndex = 2;
  5309. }
  5310. else
  5311. {
  5312. tempIndex = gun_index;
  5313. }
  5314. for (int index = 0; index < AC_QUANTITY; index++)
  5315. {
  5316. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5317. {
  5318. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5319. {
  5320. // Sent unplug message for California pricing logic
  5321. 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])
  5322. {
  5323. uint8_t ts[36];
  5324. getNowDatetime(ts);
  5325. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  5326. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  5327. if(strcmp((char*)dmsVersion, "2.0")==0)
  5328. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"transactionId\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5329. else
  5330. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  5331. sendUnplugByDataTransferRequest(gun_index);
  5332. interLock.isSentUnplug[gun_index] = 1;
  5333. }
  5334. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE))
  5335. {
  5336. interLock.isSentUnplug[gun_index] = 0;
  5337. }
  5338. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5339. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5340. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5341. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  5342. {
  5343. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5344. if((access(filenmae,F_OK))!=-1)
  5345. {
  5346. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5347. sprintf(str,"rm -f %s",filenmae);
  5348. system(str);
  5349. }
  5350. }
  5351. }
  5352. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5353. #if 1 // for TempStopTransaction
  5354. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5355. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  5356. {
  5357. checkTempStopTransaction(gun_index);
  5358. }
  5359. #endif
  5360. }
  5361. }// END
  5362. }
  5363. if(isWebsocketSendable && (server_sign == TRUE) && (isConnector0Unavailable() != Connector0PreviousSystemStatus))
  5364. {
  5365. sendConnector0StatusNotificationRequest();
  5366. Connector0PreviousSystemStatus = isConnector0Unavailable();
  5367. }
  5368. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf != 1) &&
  5369. (
  5370. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  5371. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  5372. )
  5373. )
  5374. {
  5375. sendStatusNotificationRequest(gun_index);
  5376. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  5377. }
  5378. //==============================================
  5379. // TCCI related DataTransfer messages
  5380. //==============================================
  5381. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1))
  5382. {
  5383. reportReaderStatus(gun_index);
  5384. //ShmOCPP16Data->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  5385. }
  5386. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[gun_index].OccupancyFeeActReq == 1))
  5387. {
  5388. occupancyFeeAct(gun_index);
  5389. }
  5390. //==============================================
  5391. // CSU Trigger or timer timeout refresh Smart Charging Profile
  5392. //==============================================
  5393. if((ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1) ||
  5394. ((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))))
  5395. {
  5396. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  5397. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  5398. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  5399. }
  5400. //==============================================
  5401. // Meter report
  5402. //==============================================
  5403. // Trigger MeterValue
  5404. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  5405. {
  5406. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  5407. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  5408. }
  5409. // Clock-aligned Meter value
  5410. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  5411. {
  5412. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  5413. reqClockAlignMeter[gun_index] = 0;
  5414. }
  5415. // Sample period MeterValue
  5416. 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))))
  5417. {
  5418. //check Transaction active
  5419. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5420. {
  5421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5422. {
  5423. tempIndex = ((gun_index==2) ? 1: 0);
  5424. }
  5425. else
  5426. {
  5427. tempIndex = gun_index;
  5428. }
  5429. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5430. {
  5431. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5432. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5433. {
  5434. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5435. {
  5436. reqSampleMeter[gun_index] = 1;
  5437. }
  5438. }
  5439. }// End for CHAdeMO
  5440. }
  5441. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5442. {
  5443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5444. {
  5445. tempIndex = ((gun_index==2) ? 1: 0);
  5446. }
  5447. else
  5448. {
  5449. tempIndex = gun_index;
  5450. }
  5451. for (int index = 0; index < CCS_QUANTITY; index++)
  5452. {
  5453. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5454. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5455. {
  5456. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5457. {
  5458. reqSampleMeter[gun_index] = 1;
  5459. }
  5460. }
  5461. } // End for CCS
  5462. }
  5463. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5464. {
  5465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5466. {
  5467. tempIndex = ((gun_index==2) ? 1: 0);
  5468. }
  5469. else
  5470. {
  5471. tempIndex = gun_index;
  5472. }
  5473. for (int index = 0; index < GB_QUANTITY; index++)
  5474. {
  5475. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5476. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5477. {
  5478. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5479. {
  5480. reqSampleMeter[gun_index] = 1;
  5481. }
  5482. }
  5483. }// End for GB
  5484. }
  5485. else if(gunType[gun_index] == GUN_TYPE_DO)
  5486. {
  5487. tempIndex = gun_index;
  5488. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5489. {
  5490. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5491. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5492. {
  5493. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5494. {
  5495. reqSampleMeter[gun_index] = 1;
  5496. }
  5497. }
  5498. }
  5499. }
  5500. else
  5501. {
  5502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5503. {
  5504. tempIndex = 2;
  5505. }
  5506. else
  5507. {
  5508. tempIndex = gun_index;
  5509. }
  5510. for (int index = 0; index < AC_QUANTITY; index++)
  5511. {
  5512. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5513. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5514. {
  5515. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  5516. {
  5517. reqSampleMeter[gun_index] = 1;
  5518. }
  5519. }
  5520. }//End for AC
  5521. }
  5522. if(reqSampleMeter[gun_index] == 1)
  5523. {
  5524. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  5525. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  5526. storeTempStopTransaction(gun_index);
  5527. reqSampleMeter[gun_index] = 0;
  5528. }
  5529. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  5530. }
  5531. //==============================================
  5532. // Check Connector reserved
  5533. //==============================================
  5534. //===============================
  5535. // Check if Reserve is expired
  5536. //===============================
  5537. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  5538. {
  5539. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  5540. {
  5541. DEBUG_INFO("reserve expired.\n");
  5542. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  5543. }
  5544. }//END OF Check if Reserve is expired
  5545. //==========================================
  5546. // csu trigger FirmwareStatusNotificationReq
  5547. //==========================================
  5548. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  5549. {
  5550. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  5551. }
  5552. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq == 1))
  5553. {
  5554. sendSignedFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status);
  5555. }
  5556. //==========================================
  5557. // csu trigger DiagnosticsStatusNotificationReq
  5558. //==========================================
  5559. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  5560. {
  5561. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  5562. }
  5563. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq == 1))
  5564. {
  5565. sendLogStatusNotificationRequest((char *)ShmOCPP16Data->LogStatusNotification.status);
  5566. }
  5567. //==========================================
  5568. // csu trigger CancelReservationConf
  5569. //==========================================
  5570. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  5571. {
  5572. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  5573. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  5574. }
  5575. //==========================================
  5576. // csu trigger ChangeAvailabilityConf
  5577. //==========================================
  5578. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  5579. {
  5580. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  5581. }
  5582. //==========================================
  5583. // csu trigger UnlockConnectorConf
  5584. //==========================================
  5585. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  5586. {
  5587. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  5588. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  5589. }
  5590. //==========================================
  5591. // csu trigger ReserveNowConf
  5592. //==========================================
  5593. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  5594. {
  5595. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  5596. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  5597. }
  5598. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access(CSR_CP,F_OK) != -1))
  5599. {
  5600. sendSignCertificateRequest();
  5601. }
  5602. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq == 1))
  5603. {
  5604. sendSecurityEventNotificationRequest();
  5605. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  5606. }
  5607. // Support 15118
  5608. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.SignCertificateReq == 1) && (access(CSR_V2G,F_OK) != -1))
  5609. {
  5610. json_object *data = json_object_new_object();
  5611. // Read csr file content
  5612. memset(ShmOCPP16Data->v2g_extend.SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5613. FILE *fp=fopen(CSR_V2G,"r");
  5614. char *line = NULL;
  5615. size_t len = 0;
  5616. while(getline(&line, &len, fp) != -1)
  5617. {
  5618. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5619. {
  5620. memcpy(&ShmOCPP16Data->v2g_extend.SignCertificate.csr[strlen((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr)], line, (strlen(line)-1));
  5621. }
  5622. }
  5623. fclose(fp);
  5624. json_object_object_add(data, "csr", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.SignCertificate.csr));
  5625. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5626. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"SignCertificate");
  5627. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5628. json_object_put(data);
  5629. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5630. ShmOCPP16Data->v2g_extend.SignCertificateReq = 0;
  5631. }
  5632. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.AuthorizeReq == 1))
  5633. {
  5634. memset(&ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  5635. int parseCertResult = FAIL;
  5636. json_object *data = json_object_new_object();
  5637. json_object *idToken = json_object_new_object();
  5638. json_object *iso15118CertificateHashData = json_object_new_array();
  5639. // Read CERTIFICATE_PnCAuth file content
  5640. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  5641. {
  5642. memset(ShmOCPP16Data->v2g_extend.Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5643. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  5644. char *line = NULL;
  5645. size_t len = 0;
  5646. while(getline(&line, &len, fp) != -1)
  5647. {
  5648. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  5649. strcat((char *)ShmOCPP16Data->v2g_extend.Authorize.certificate, line);
  5650. }
  5651. fclose(fp);
  5652. }
  5653. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate) > 0)
  5654. json_object_object_add(data, "certificate", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate));
  5655. //strcpy((char *)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5656. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.idToken.idToken));
  5657. json_object_object_add(data, "idToken", idToken);
  5658. char parseData[512] = {0};
  5659. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  5660. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  5661. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  5662. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  5663. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  5664. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  5665. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  5666. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  5667. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  5668. strcpy((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  5669. for(int idx=0; idx < 4; idx++)
  5670. {
  5671. if(strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  5672. {
  5673. json_object *OCSPRequestDataType = json_object_new_object();
  5674. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  5675. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  5676. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  5677. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].serialNumber));
  5678. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Authorize.iso15118CertificateHashData[idx].responderURL));
  5679. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  5680. parseCertResult = PASS;
  5681. }
  5682. }
  5683. if(parseCertResult == PASS)
  5684. {
  5685. json_object_object_add(data, "iso15118CertificateHashData", iso15118CertificateHashData);
  5686. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5687. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Authorize");
  5688. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5689. json_object_put(data);
  5690. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5691. ShmOCPP16Data->v2g_extend.AuthorizeReq = 0;
  5692. }
  5693. else
  5694. {
  5695. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "NoCertificateAvailable");
  5696. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_idTokenInfo.status, "Invalid");
  5697. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  5698. }
  5699. }
  5700. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq == 1))
  5701. {
  5702. json_object *data = json_object_new_object();
  5703. json_object_object_add(data, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.iso15118SchemaVersion));
  5704. json_object_object_add(data, "action", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.action));
  5705. json_object_object_add(data, "exiRequest", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.exiRequest));
  5706. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5707. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"Get15118EVCertificate");
  5708. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5709. json_object_put(data);
  5710. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5711. ShmOCPP16Data->v2g_extend.Get15118EVCertificateReq = 0;
  5712. }
  5713. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->v2g_extend.GetCertificateStatusReq == 1))
  5714. {
  5715. json_object *data = json_object_new_object();
  5716. json_object *OCSPRequestDataType = json_object_new_object();
  5717. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5718. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerNameHash));
  5719. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5720. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.serialNumber));
  5721. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.ocspRequestData.responderURL));
  5722. json_object_object_add(data, "ocspRequestData", OCSPRequestDataType);
  5723. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "org.openchargealliance.iso15118pnc");
  5724. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId,"GetInstalledCertificateIds");
  5725. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, "%s", json_object_to_json_string_ext(data, JSON_C_TO_STRING_PLAIN));
  5726. json_object_put(data);
  5727. ShmOCPP16Data->CsMsg.bits[0].DataTransferReq = 1;
  5728. ShmOCPP16Data->v2g_extend.GetCertificateStatusReq = 0;
  5729. }
  5730. }
  5731. }
  5732. //==========================================
  5733. // send request routine
  5734. //==========================================
  5735. int sendAuthorizeRequest(int gun_index)
  5736. {
  5737. mtrace();
  5738. int result = FAIL;
  5739. char message[100]={0};
  5740. char guid[37];
  5741. char tempdata[65]={0};
  5742. DEBUG_INFO("sendAuthorizeRequest...\n");
  5743. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  5744. //Local Authorize
  5745. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  5746. {
  5747. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  5748. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  5749. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  5750. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  5751. result = PASS;
  5752. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5753. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5754. authorizeRetryTimes = 0;
  5755. return result;
  5756. }
  5757. 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))||
  5758. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  5759. {
  5760. // Query from cache
  5761. DEBUG_INFO("Authorize from cache.\n");
  5762. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5763. // Query from list
  5764. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5765. {
  5766. DEBUG_INFO("Authorize from list.\n");
  5767. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5768. }
  5769. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strstr(idTagQuery.idTagstatus,"Accepted") == NULL) )
  5770. {
  5771. if(strcmp(idTagQuery.idTagstr,"") == 0)
  5772. {
  5773. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5774. }
  5775. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  5776. {
  5777. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  5778. }
  5779. if(!GetOcppConnStatus())
  5780. {
  5781. DEBUG_INFO("off-line Local Authorization Fail.\n");
  5782. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5783. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5784. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  5785. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5786. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5787. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5788. authorizeRetryTimes = 0;
  5789. return result;
  5790. }
  5791. }
  5792. else
  5793. {
  5794. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  5795. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  5796. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  5797. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  5798. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  5799. else
  5800. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  5801. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  5802. result = PASS;
  5803. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5804. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5805. authorizeRetryTimes = 0;
  5806. return result;
  5807. }
  5808. }
  5809. //initialize struct Authorize
  5810. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  5811. //get data from shared memory
  5812. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5813. random_uuid(guid);
  5814. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  5815. LWS_Send(message);
  5816. sprintf(tempdata, "Authorize,%d", gun_index);
  5817. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5818. {
  5819. result = PASS;
  5820. DEBUG_INFO("Authorize mapItem pass\n");
  5821. }
  5822. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5823. return result;
  5824. }
  5825. int sendBootNotificationRequest(void)
  5826. {
  5827. mtrace();
  5828. int result = FAIL;
  5829. char message[500]={0}, payload[700]={0};
  5830. char guid[37]={0};
  5831. char tempdata[65]={0};
  5832. // Fill BootNotification fields
  5833. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  5834. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  5835. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5836. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5837. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5838. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5839. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5840. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  5841. ShmOCPP16Data->ChargeBoxId
  5842. ,ShmSysConfigAndInfo->SysConfig.ModelName
  5843. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  5844. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  5845. ,ShmOCPP16Data->BootNotification.CpFwVersion
  5846. ,ShmOCPP16Data->BootNotification.CpIccid
  5847. ,ShmOCPP16Data->BootNotification.CpImsi);
  5848. random_uuid(guid);
  5849. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  5850. LWS_Send(message);
  5851. sprintf(tempdata, "BootNotification,0");
  5852. 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*/)
  5853. {
  5854. result = PASS;
  5855. }
  5856. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5857. strcpy(queuedata,message);
  5858. return result;
  5859. }
  5860. int sendDataTransferRequest(int gun_index)
  5861. {
  5862. mtrace();
  5863. char message[10240]={0};
  5864. char guid[37]={0};
  5865. char tempdata[65]={0};
  5866. int result = FAIL;
  5867. json_object *DataTransfer = json_object_new_object();
  5868. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5869. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5870. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].Data));
  5871. random_uuid(guid);
  5872. sprintf(message,"[%d,\"%s\",\"DataTransfer\",%s]", MESSAGE_TYPE_CALL,
  5873. guid,
  5874. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5875. json_object_put(DataTransfer);
  5876. LWS_Send(message);
  5877. sprintf(tempdata, "DataTransfer,%d", gun_index);
  5878. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5879. {
  5880. result = PASS;
  5881. DEBUG_INFO("DataTransfer mapItem pass\n");
  5882. }
  5883. return result;
  5884. }
  5885. int sendUnplugByDataTransferRequest(int gun_index)
  5886. {
  5887. mtrace();
  5888. char message[10752]={0};
  5889. char guid[37]={0};
  5890. char tempdata[65]={0};
  5891. int result = FAIL;
  5892. random_uuid(guid);
  5893. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5894. (gun_index+1),
  5895. MESSAGE_TYPE_CALL,
  5896. guid,
  5897. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  5898. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  5899. ShmOCPP16Data->DataTransfer[gun_index].Data);
  5900. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5901. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5902. {
  5903. result = PASS;
  5904. DEBUG_INFO("DataTransfer mapItem pass\n");
  5905. }
  5906. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5907. return result;
  5908. }
  5909. int sendOcmfByDataTransferRequest(int gun_index)
  5910. {
  5911. mtrace();
  5912. json_object *DataTransfer = json_object_new_object();
  5913. json_object *data = json_object_new_object();
  5914. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5915. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ID_OCMF");
  5916. json_object_object_add(data, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  5917. json_object_object_add(data, "dataString", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].DataString));
  5918. json_object_object_add(data, "publicKey", json_object_new_string((char*)ShmOCPP16Data->OcmfData[gun_index].PublicKey));
  5919. json_object_object_add(DataTransfer, "data", data);
  5920. json_object_object_add(DataTransfer, "vendorId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId));
  5921. json_object_object_add(DataTransfer, "messageId", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId));
  5922. char message[3000]={0};
  5923. char guid[37]={0};
  5924. char tempdata[65]={0};
  5925. int result = FAIL;
  5926. random_uuid(guid);
  5927. sprintf(message,"%d,[%d,\"%s\",\"DataTransfer\",%s]",
  5928. (gun_index+1),
  5929. MESSAGE_TYPE_CALL,
  5930. guid,
  5931. json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  5932. json_object_put(DataTransfer);
  5933. sprintf(tempdata, "DataTransfer,%d", gun_index );
  5934. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5935. {
  5936. result = PASS;
  5937. DEBUG_INFO("DataTransfer mapItem pass\n");
  5938. }
  5939. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  5940. return result;
  5941. }
  5942. int sendDiagnosticsStatusNotificationRequest(char *status)
  5943. {
  5944. mtrace();
  5945. int result = FAIL;
  5946. char message[110]={0};
  5947. char guid[37]={0};
  5948. char tempdata[65]={0};
  5949. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  5950. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  5951. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  5952. random_uuid(guid);
  5953. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  5954. LWS_SendNow(message);
  5955. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  5956. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5957. {
  5958. result = PASS;
  5959. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  5960. }
  5961. //#ifdef SystemLogMessage
  5962. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  5963. //DEBUG_INFO("Message: %s\n", SendBuffer);
  5964. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  5965. //#endif
  5966. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5967. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  5968. //record status
  5969. if(strcmp(status,"Idle")==0)
  5970. {
  5971. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  5972. }
  5973. else if(strcmp(status,"Uploaded")==0)
  5974. {
  5975. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  5976. }
  5977. else if(strcmp(status,"UploadFailed")==0)
  5978. {
  5979. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  5980. }
  5981. else if(strcmp(status,"Uploading")==0)
  5982. {
  5983. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  5984. }
  5985. return result;
  5986. }
  5987. int sendFirmwareStatusNotificationRequest(char *status)
  5988. {
  5989. mtrace();
  5990. int result = FAIL;
  5991. char message[110]={0};
  5992. char guid[37]={0};
  5993. char tempdata[65]={0};
  5994. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  5995. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  5996. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  5997. random_uuid(guid);
  5998. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  5999. LWS_SendNow(message);
  6000. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6001. 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*/)
  6002. {
  6003. result = PASS;
  6004. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  6005. }
  6006. //#ifdef SystemLogMessage
  6007. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  6008. //DEBUG_INFO("Message: %s\n", SendBuffer);
  6009. //#endif
  6010. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  6011. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  6012. //record status
  6013. if(strcmp(status,"Downloaded")==0)
  6014. {
  6015. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  6016. }
  6017. else if(strcmp(status,"DownloadFailed")==0)
  6018. {
  6019. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  6020. }
  6021. else if(strcmp(status,"Downloading")==0)
  6022. {
  6023. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  6024. }
  6025. else if(strcmp(status,"Idle")==0)
  6026. {
  6027. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  6028. }
  6029. else if(strcmp(status,"InstallationFailed")==0)
  6030. {
  6031. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  6032. }
  6033. else if(strcmp(status,"Installing")==0)
  6034. {
  6035. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  6036. }
  6037. else if(strcmp(status,"Installed")==0)
  6038. {
  6039. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  6040. }
  6041. return result;
  6042. }
  6043. int sendHeartbeatRequest(int gun_index)
  6044. {
  6045. mtrace();
  6046. int result = FAIL;
  6047. char message[80]={0};
  6048. char guid[37]={0};
  6049. char tempdata[65]={0};
  6050. random_uuid(guid);
  6051. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  6052. , MESSAGE_TYPE_CALL
  6053. , guid );
  6054. LWS_Send(message);
  6055. sprintf(tempdata, "Heartbeat,%d", 0);
  6056. 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*/)
  6057. {
  6058. result = PASS;
  6059. }
  6060. return result;
  6061. }
  6062. int sendStartTransactionRequest(int gun_index)
  6063. {
  6064. mtrace();
  6065. int result = FAIL;
  6066. char message[250]={0};
  6067. char guid[37]={0};
  6068. struct timeval tmnow;
  6069. struct tm *tm;
  6070. char buf[28];//, usec_buf[6];
  6071. char tempdata[65]={0};
  6072. int tempIndex = 0;
  6073. DEBUG_INFO("sendStartTransactionRequest...\n");
  6074. gettimeofday(&tmnow, NULL);
  6075. time_t t;
  6076. t = time(NULL);
  6077. /*UTC time and date*/
  6078. tm = gmtime(&t);
  6079. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6080. #if 0 // remove temporally
  6081. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6082. strcat(buf,".");
  6083. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6084. strcat(buf,usec_buf);
  6085. #endif
  6086. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  6087. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  6088. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6089. // clear StartTransaction Response
  6090. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  6091. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  6092. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  6093. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  6094. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6095. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6096. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6097. {
  6098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6099. {
  6100. tempIndex = ((gun_index==2) ? 1: 0);
  6101. }
  6102. else
  6103. {
  6104. tempIndex = gun_index;
  6105. }
  6106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6107. {
  6108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6109. {
  6110. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6111. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  6112. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6113. }
  6114. }
  6115. }
  6116. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6117. {
  6118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6119. {
  6120. tempIndex = ((gun_index==2) ? 1: 0);
  6121. }
  6122. else
  6123. {
  6124. tempIndex = gun_index;
  6125. }
  6126. for (int index = 0; index < CCS_QUANTITY; index++)
  6127. {
  6128. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6129. {
  6130. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6131. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  6132. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6133. }
  6134. }
  6135. }
  6136. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6137. {
  6138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6139. {
  6140. tempIndex = ((gun_index==2) ? 1: 0);
  6141. }
  6142. else
  6143. {
  6144. tempIndex = gun_index;
  6145. }
  6146. for (int index = 0; index < GB_QUANTITY; index++)
  6147. {
  6148. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6149. {
  6150. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6151. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  6152. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6153. }
  6154. }
  6155. }
  6156. else if(gunType[gun_index] == GUN_TYPE_DO)
  6157. {
  6158. tempIndex = gun_index;
  6159. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6160. {
  6161. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6162. {
  6163. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6164. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  6165. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6166. }
  6167. }
  6168. }
  6169. else
  6170. {
  6171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6172. {
  6173. tempIndex = 2;
  6174. }
  6175. else
  6176. {
  6177. tempIndex = gun_index;
  6178. }
  6179. for (int index = 0; index < AC_QUANTITY; index++)
  6180. {
  6181. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6182. {
  6183. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6184. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  6185. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6186. }
  6187. }
  6188. }
  6189. random_uuid(guid);
  6190. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  6191. {
  6192. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  6193. , gun_index +1
  6194. , MESSAGE_TYPE_CALL
  6195. , guid
  6196. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6197. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6198. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6199. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6200. }
  6201. else
  6202. {
  6203. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  6204. , gun_index +1
  6205. , MESSAGE_TYPE_CALL
  6206. , guid
  6207. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  6208. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  6209. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  6210. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  6211. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  6212. }
  6213. #if 1
  6214. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  6215. 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*/)
  6216. {
  6217. result = PASS;
  6218. }
  6219. #endif
  6220. strcpy(queuedata, message);
  6221. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6222. OCPP_insert_transaction_msg(YES, queuedata);
  6223. return result;
  6224. }
  6225. int sendConnector0StatusNotificationRequest()
  6226. {
  6227. mtrace();
  6228. int result = FAIL;
  6229. char message[600]={0};
  6230. char guid[37];
  6231. struct timeval tmnow;
  6232. struct tm *tm;
  6233. char buf[28];//, usec_buf[6];
  6234. char tempdata[65]={0};
  6235. DEBUG_INFO("sendConnector0StatusNotificationRequest...\n");
  6236. gettimeofday(&tmnow, NULL);
  6237. time_t t;
  6238. t = time(NULL);
  6239. /*UTC time and date*/
  6240. tm = gmtime(&t);
  6241. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6242. random_uuid(guid);
  6243. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":0,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6244. , MESSAGE_TYPE_CALL
  6245. , guid
  6246. , "NoError"
  6247. , ""
  6248. , (isConnector0Unavailable()==YES?"Unavailable":"Available")
  6249. , buf
  6250. , ShmSysConfigAndInfo->SysConfig.chargePointVendor
  6251. , "");
  6252. LWS_Send(message);
  6253. sprintf(tempdata, "StatusNotification,%d", 99);
  6254. 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*/)
  6255. {
  6256. //DEBUG_ERROR("statusNotification mapitem pass");
  6257. result = PASS;
  6258. }
  6259. return result;
  6260. }
  6261. int sendStatusNotificationRequest(int gun_index)
  6262. {
  6263. mtrace();
  6264. int result = FAIL;
  6265. char message[600]={0};
  6266. char guid[37];
  6267. int currentStatus = 0;
  6268. struct timeval tmnow;
  6269. struct tm *tm;
  6270. char buf[28];//, usec_buf[6];
  6271. char tempdata[65]={0};
  6272. int tempIndex = 0;
  6273. uint8_t isStateChanged = TRUE;
  6274. uint8_t isContentIllegal = TRUE;
  6275. DEBUG_INFO("sendStatusNotificationRequest...\n");
  6276. gettimeofday(&tmnow, NULL);
  6277. time_t t;
  6278. t = time(NULL);
  6279. /*UTC time and date*/
  6280. tm = gmtime(&t);
  6281. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6282. #if 0 // remove temporally
  6283. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  6284. strcat(buf,".");
  6285. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  6286. strcat(buf,usec_buf);
  6287. #endif
  6288. //printf("%s",buf);
  6289. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  6290. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  6291. // it's option
  6292. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  6293. /*
  6294. enum _SYSTEM_STATUS
  6295. {
  6296. S_BOOTING = 0,
  6297. S_IDLE, = 1
  6298. S_AUTHORIZING, =2
  6299. S_REASSIGN_CHECK, =3
  6300. S_REASSIGN, =4
  6301. S_PRECHARGE, =5
  6302. S_PREPARING_FOR_EV, =6
  6303. S_PREPARING_FOR_EVSE, =7
  6304. S_CHARGING, =8
  6305. S_TERMINATING, =9
  6306. S_COMPLETE, =10
  6307. S_ALARM, =11
  6308. S_FAULT =12
  6309. }
  6310. */
  6311. //check Transaction active
  6312. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6313. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6314. {
  6315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6316. {
  6317. tempIndex = ((gun_index==2) ? 1: 0);
  6318. }
  6319. else
  6320. {
  6321. tempIndex = gun_index;
  6322. }
  6323. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6324. {
  6325. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  6326. {
  6327. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  6328. {
  6329. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6330. {
  6331. currentStatus = Preparing; //OCPP Status: Preparing
  6332. }
  6333. else
  6334. {
  6335. currentStatus = Available; //OCPP Status: Available
  6336. }
  6337. }
  6338. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6339. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6340. ) //S_PRECHARGE
  6341. {
  6342. currentStatus = Preparing; //OCPP Status: Preparing
  6343. }
  6344. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6345. {
  6346. currentStatus = Charging; //OCPP Status: Charging
  6347. }
  6348. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6349. {
  6350. currentStatus = Finishing; //OCPP Status: Finishing
  6351. }
  6352. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6353. {
  6354. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6355. }
  6356. 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
  6357. {
  6358. currentStatus = Unavailable; //OCPP Status: Unavailable
  6359. }
  6360. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6361. {
  6362. currentStatus = Faulted; //OCPP Status: Faulted
  6363. }
  6364. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6365. {
  6366. currentStatus = Reserved; //OCPP Status: Reserved
  6367. }
  6368. } //end of the same index
  6369. }//end of for CHAdeMO_QUANTITY
  6370. }
  6371. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6372. {
  6373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6374. {
  6375. tempIndex = ((gun_index==2) ? 1: 0);
  6376. }
  6377. else
  6378. {
  6379. tempIndex = gun_index;
  6380. }
  6381. for (int index = 0; index < CCS_QUANTITY; index++)
  6382. {
  6383. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6384. {
  6385. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6386. {
  6387. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  6388. {
  6389. currentStatus = Preparing; //OCPP Status: Preparing
  6390. }
  6391. else
  6392. {
  6393. currentStatus = Available; //OCPP Status: Available
  6394. }
  6395. }
  6396. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6397. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6398. ) //S_PRECHARGE
  6399. {
  6400. currentStatus = Preparing; //OCPP Status: Preparing
  6401. }
  6402. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6403. {
  6404. currentStatus = Charging; //OCPP Status: Charging
  6405. }
  6406. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6407. {
  6408. currentStatus = Finishing; //OCPP Status: Finishing
  6409. }
  6410. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  6411. {
  6412. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6413. }
  6414. 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
  6415. {
  6416. currentStatus = Unavailable; //OCPP Status : Unavailable
  6417. }
  6418. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6419. {
  6420. currentStatus = Faulted; //OCPP Status: Faulted
  6421. }
  6422. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6423. {
  6424. currentStatus = Reserved; //OCPP Status: Reserved
  6425. }
  6426. } //end of the same index
  6427. } // end of for CCS_QUANTITY
  6428. }
  6429. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6430. {
  6431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6432. {
  6433. tempIndex = ((gun_index==2) ? 1: 0);
  6434. }
  6435. else
  6436. {
  6437. tempIndex = gun_index;
  6438. }
  6439. for (int index = 0; index < GB_QUANTITY; index++)
  6440. {
  6441. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6442. {
  6443. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6444. {
  6445. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6446. {
  6447. currentStatus = Preparing; //OCPP Status: Preparing
  6448. }
  6449. else
  6450. {
  6451. currentStatus = Available; //OCPP Status: Available
  6452. }
  6453. }
  6454. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6455. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6456. ) //S_PRECHARGE
  6457. {
  6458. currentStatus = Preparing; //OCPP Status: Preparing
  6459. }
  6460. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6461. {
  6462. currentStatus = Charging; //OCPP Status: Charging
  6463. }
  6464. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6465. {
  6466. currentStatus = Finishing; //OCPP Status: Finishing
  6467. }
  6468. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6469. {
  6470. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6471. }
  6472. 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
  6473. {
  6474. currentStatus = Unavailable; //OCPP Status: Unavailable
  6475. }
  6476. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  6477. {
  6478. currentStatus = Faulted; //OCPP Status: Faulted
  6479. }
  6480. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6481. {
  6482. currentStatus = Reserved; //OCPP Status: Reserved
  6483. }
  6484. } //end of the same index
  6485. } // end of for GB_QUANTITY
  6486. }
  6487. else if(gunType[gun_index] == GUN_TYPE_DO)
  6488. {
  6489. tempIndex = gun_index;
  6490. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6491. {
  6492. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6493. {
  6494. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6495. {
  6496. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  6497. {
  6498. currentStatus = Preparing; //OCPP Status: Preparing
  6499. }
  6500. else
  6501. {
  6502. currentStatus = Available; //OCPP Status: Available
  6503. }
  6504. }
  6505. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  6506. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  6507. ) //S_PRECHARGE
  6508. {
  6509. currentStatus = Preparing; //OCPP Status: Preparing
  6510. }
  6511. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  6512. {
  6513. currentStatus = Charging; //OCPP Status: Charging
  6514. }
  6515. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  6516. {
  6517. currentStatus = Finishing; //OCPP Status: Finishing
  6518. }
  6519. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6520. {
  6521. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6522. }
  6523. 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
  6524. {
  6525. currentStatus = Unavailable; //OCPP Status: Unavailable
  6526. }
  6527. 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
  6528. {
  6529. currentStatus = Faulted; //OCPP Status: Faulted
  6530. }
  6531. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6532. {
  6533. currentStatus = Reserved; //OCPP Status: Reserved
  6534. }
  6535. } //end of the same index
  6536. }
  6537. }
  6538. else
  6539. {
  6540. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6541. {
  6542. tempIndex = 2;
  6543. }
  6544. else
  6545. {
  6546. tempIndex = gun_index;
  6547. }
  6548. for (int index = 0; index < AC_QUANTITY; index++)
  6549. {
  6550. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6551. {
  6552. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  6553. {
  6554. 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))
  6555. {
  6556. currentStatus = Preparing; //OCPP Status: Preparing
  6557. }
  6558. else
  6559. {
  6560. currentStatus = Available; //OCPP Status: Available
  6561. }
  6562. }
  6563. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  6564. {
  6565. currentStatus = Preparing; //OCPP Status: Preparing
  6566. }
  6567. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  6568. {
  6569. currentStatus = Charging; //OCPP Status: Charging
  6570. }
  6571. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  6572. {
  6573. currentStatus = Finishing; //OCPP Status: Finishing
  6574. }
  6575. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  6576. {
  6577. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  6578. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  6579. else
  6580. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  6581. }
  6582. 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
  6583. {
  6584. currentStatus = Unavailable; //OCPP Status: Unavailable
  6585. }
  6586. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  6587. {
  6588. currentStatus = Faulted; //OCPP Status: Faulted
  6589. }
  6590. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  6591. {
  6592. currentStatus = Reserved; //OCPP Status: Reserved
  6593. }
  6594. }//end of the same index
  6595. }//end of for AC_QUANTITY
  6596. }
  6597. //it's option
  6598. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  6599. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  6600. (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  6601. {
  6602. isStateChanged = FALSE;
  6603. }
  6604. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6605. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  6606. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6607. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  6608. isContentIllegal = TRUE;
  6609. for(int index = 0; index < ARRAY_SIZE(ChargePointErrorCodeStr); index++)
  6610. {
  6611. if(strcmp((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[index])==0)
  6612. {
  6613. isContentIllegal = FALSE;
  6614. break;
  6615. }
  6616. }
  6617. if(isContentIllegal)
  6618. {
  6619. //DEBUG_WARN("Detect illegal ErrorCode: %s \n",(char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  6620. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ChargePointErrorCodeStr[6]);
  6621. }
  6622. random_uuid(guid);
  6623. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  6624. , MESSAGE_TYPE_CALL
  6625. , guid
  6626. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  6627. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  6628. , ShmOCPP16Data->StatusNotification[gun_index].Info
  6629. , ShmOCPP16Data->StatusNotification[gun_index].Status
  6630. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  6631. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  6632. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  6633. if((server_sign == TRUE) && isStateChanged)
  6634. {
  6635. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6636. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6637. LWS_Send(message);
  6638. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  6639. 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*/)
  6640. {
  6641. //DEBUG_ERROR("statusNotification mapitem pass");
  6642. result = PASS;
  6643. }
  6644. }
  6645. else
  6646. {
  6647. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  6648. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  6649. result = PASS;
  6650. }
  6651. return result;
  6652. }
  6653. int sendStopTransactionRequest(int gun_index)
  6654. {
  6655. mtrace();
  6656. int result = FAIL;
  6657. //char message[1500]={0};
  6658. char guid[37]={0};
  6659. char tempdata[65]={0};
  6660. int tempIndex = 0;
  6661. char TempStopTransaction[256];
  6662. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  6663. DEBUG_INFO("sendStopTransactionRequest \n");
  6664. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6665. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  6666. //=========================== Stop Transaction Time ===============================================
  6667. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  6668. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  6669. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  6670. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  6671. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6672. {
  6673. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6674. {
  6675. tempIndex = ((gun_index==2) ? 1: 0);
  6676. }
  6677. else
  6678. {
  6679. tempIndex = gun_index;
  6680. }
  6681. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6682. {
  6683. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6684. {
  6685. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  6686. }
  6687. }// END OF CHAdeMO_QUANTITY
  6688. }
  6689. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  6700. {
  6701. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6702. {
  6703. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  6704. }
  6705. }// END OF CCS_QUANTITY
  6706. }
  6707. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  6718. {
  6719. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6720. {
  6721. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  6722. }
  6723. }// END OF GB_QUANTITY
  6724. }
  6725. else if(gunType[gun_index] == GUN_TYPE_DO)
  6726. {
  6727. tempIndex = gun_index;
  6728. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6729. {
  6730. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6731. {
  6732. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  6733. }
  6734. }// END OF GB_QUANTITY
  6735. }
  6736. else
  6737. {
  6738. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6739. {
  6740. tempIndex = 2;
  6741. }
  6742. else
  6743. {
  6744. tempIndex = gun_index;
  6745. }
  6746. for (int index = 0; index < AC_QUANTITY; index++)
  6747. {
  6748. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6749. {
  6750. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  6751. }
  6752. }// END OF AC_QUANTITY
  6753. }
  6754. //================================================ Message create ====================================================
  6755. json_object *StopTransaction = json_object_new_object();
  6756. json_object *transactionDatas = json_object_new_array();
  6757. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  6758. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  6759. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  6760. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  6761. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  6762. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  6763. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  6764. meterValueBufferQuery(gun_index, transactionDatas);
  6765. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6766. random_uuid(guid);
  6767. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6768. ,MESSAGE_TYPE_CALL
  6769. ,guid
  6770. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6771. json_object_put(StopTransaction);
  6772. #if 1 // for TempStopTransaction
  6773. //Delete TempStopTransaction
  6774. if((access(TempStopTransaction,F_OK))!=-1)
  6775. {
  6776. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6777. }
  6778. #endif
  6779. #if 1
  6780. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6781. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6782. {
  6783. result = PASS;
  6784. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6785. }
  6786. #endif
  6787. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6788. OCPP_insert_transaction_msg(NO, queuedata);
  6789. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6790. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6791. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6792. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6793. {
  6794. //SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6795. }
  6796. //for test
  6797. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6798. return result;
  6799. }
  6800. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6801. {
  6802. mtrace();
  6803. int result = FAIL;
  6804. char guid[37]={0};
  6805. char tempdata[65]={0};
  6806. int tempIndex = 0;
  6807. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6808. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6809. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6810. //set value
  6811. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6812. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6813. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6814. -1);
  6815. random_uuid(guid);
  6816. //UTC Date time
  6817. struct timeval tmnow;
  6818. struct tm *tm;
  6819. char buf[28];//, usec_buf[6];
  6820. gettimeofday(&tmnow, NULL);
  6821. time_t t;
  6822. t = time(NULL);
  6823. /*UTC time and date*/
  6824. tm = gmtime(&t);
  6825. if(dataType == ReadingContext_Sample_Clock)
  6826. {
  6827. struct tm *tmTarget;
  6828. struct timeb tbTarget;
  6829. tbTarget.time = mktime(tm);
  6830. tbTarget.time -= (atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6831. tmTarget = gmtime(&tbTarget.time);
  6832. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6833. }
  6834. else
  6835. {
  6836. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6837. }
  6838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6839. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6840. //********************************(1)Current.Import L1************************************************/
  6841. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6842. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6843. (dataType == ReadingContext_Trigger))
  6844. {
  6845. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6846. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6847. {
  6848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6849. {
  6850. tempIndex = ((gun_index==2) ? 1: 0);
  6851. }
  6852. else
  6853. {
  6854. tempIndex = gun_index;
  6855. }
  6856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6857. {
  6858. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6859. {
  6860. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6861. }
  6862. }
  6863. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6864. }
  6865. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6866. {
  6867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6868. {
  6869. tempIndex = ((gun_index==2) ? 1: 0);
  6870. }
  6871. else
  6872. {
  6873. tempIndex = gun_index;
  6874. }
  6875. for (int index = 0; index < CCS_QUANTITY; index++)
  6876. {
  6877. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6878. {
  6879. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6880. }
  6881. }
  6882. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6883. }
  6884. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6885. {
  6886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6887. {
  6888. tempIndex = ((gun_index==2) ? 1: 0);
  6889. }
  6890. else
  6891. {
  6892. tempIndex = gun_index;
  6893. }
  6894. for (int index = 0; index < GB_QUANTITY; index++)
  6895. {
  6896. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6897. {
  6898. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6899. }
  6900. }
  6901. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6902. }
  6903. else if(gunType[gun_index] == GUN_TYPE_DO)
  6904. {
  6905. tempIndex = gun_index;
  6906. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6907. {
  6908. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6909. {
  6910. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6911. }
  6912. }
  6913. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6914. }
  6915. else
  6916. {
  6917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6918. {
  6919. tempIndex = 2;
  6920. }
  6921. else
  6922. {
  6923. tempIndex = gun_index;
  6924. }
  6925. for (int index = 0; index < AC_QUANTITY; index++)
  6926. {
  6927. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6928. {
  6929. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6930. }
  6931. }
  6932. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6933. }
  6934. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6935. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6936. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6937. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6939. }
  6940. //********************************(2)Energy.Active.Import.Register ************************************************/
  6941. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6942. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6943. (dataType == ReadingContext_Trigger))
  6944. {
  6945. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6946. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6947. {
  6948. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6949. {
  6950. tempIndex = ((gun_index==2) ? 1: 0);
  6951. }
  6952. else
  6953. {
  6954. tempIndex = gun_index;
  6955. }
  6956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6957. {
  6958. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6959. {
  6960. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6961. }
  6962. }
  6963. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6964. }
  6965. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6966. {
  6967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6968. {
  6969. tempIndex = ((gun_index==2) ? 1: 0);
  6970. }
  6971. else
  6972. {
  6973. tempIndex = gun_index;
  6974. }
  6975. for (int index = 0; index < CCS_QUANTITY; index++)
  6976. {
  6977. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6978. {
  6979. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6980. }
  6981. }
  6982. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6983. }
  6984. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6985. {
  6986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6987. {
  6988. tempIndex = ((gun_index==2) ? 1: 0);
  6989. }
  6990. else
  6991. {
  6992. tempIndex = gun_index;
  6993. }
  6994. for (int index = 0; index < GB_QUANTITY; index++)
  6995. {
  6996. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6997. {
  6998. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6999. }
  7000. }
  7001. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7002. }
  7003. else if(gunType[gun_index] == GUN_TYPE_DO)
  7004. {
  7005. tempIndex = gun_index;
  7006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7007. {
  7008. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7009. {
  7010. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  7011. }
  7012. }
  7013. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  7014. }
  7015. else
  7016. {
  7017. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7018. {
  7019. tempIndex = 2;
  7020. }
  7021. else
  7022. {
  7023. tempIndex = gun_index;
  7024. }
  7025. for (int index = 0; index < AC_QUANTITY; index++)
  7026. {
  7027. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7028. {
  7029. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  7030. }
  7031. }
  7032. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  7033. }
  7034. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  7035. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  7036. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  7037. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  7038. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7039. }
  7040. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7041. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7042. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  7043. (dataType == ReadingContext_Trigger))
  7044. {
  7045. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7046. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7047. {
  7048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7049. {
  7050. tempIndex = ((gun_index==2) ? 1: 0);
  7051. }
  7052. else
  7053. {
  7054. tempIndex = gun_index;
  7055. }
  7056. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7057. {
  7058. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7059. {
  7060. if(dataType == ReadingContext_Sample_Clock)
  7061. {
  7062. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7063. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7064. }
  7065. else if(dataType == ReadingContext_Sample_Periodic)
  7066. {
  7067. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7068. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  7069. }
  7070. else
  7071. {
  7072. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7073. }
  7074. }
  7075. } // END OF FOR CHAdeMO_QUANTITY
  7076. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7077. }
  7078. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7079. {
  7080. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7081. {
  7082. tempIndex = ((gun_index==2) ? 1: 0);
  7083. }
  7084. else
  7085. {
  7086. tempIndex = gun_index;
  7087. }
  7088. for (int index = 0; index < CCS_QUANTITY; index++)
  7089. {
  7090. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7091. {
  7092. if(dataType == ReadingContext_Sample_Clock)
  7093. {
  7094. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7095. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7096. }
  7097. else if(dataType == ReadingContext_Sample_Periodic)
  7098. {
  7099. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7100. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  7101. }
  7102. else
  7103. {
  7104. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7105. }
  7106. }
  7107. } // END OF CCS_QUANTITY
  7108. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7109. }
  7110. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7111. {
  7112. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7113. {
  7114. tempIndex = ((gun_index==2) ? 1: 0);
  7115. }
  7116. else
  7117. {
  7118. tempIndex = gun_index;
  7119. }
  7120. for (int index = 0; index < GB_QUANTITY; index++)
  7121. {
  7122. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7123. {
  7124. if(dataType == ReadingContext_Sample_Clock)
  7125. {
  7126. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7127. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7128. }
  7129. else if(dataType == ReadingContext_Sample_Periodic)
  7130. {
  7131. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7132. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  7133. }
  7134. else
  7135. {
  7136. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7137. }
  7138. }
  7139. } // END OF GB_QUANTITY
  7140. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7141. }
  7142. else if(gunType[gun_index] == GUN_TYPE_DO)
  7143. {
  7144. tempIndex = gun_index;
  7145. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7146. {
  7147. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7148. {
  7149. if(dataType == ReadingContext_Sample_Clock)
  7150. {
  7151. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousClockPowerConsumption[gun_index]));
  7152. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7153. }
  7154. else if(dataType == ReadingContext_Sample_Periodic)
  7155. {
  7156. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7157. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  7158. }
  7159. else
  7160. {
  7161. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7162. }
  7163. }
  7164. }
  7165. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  7166. }
  7167. else
  7168. {
  7169. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7170. {
  7171. tempIndex = 2;
  7172. }
  7173. else
  7174. {
  7175. tempIndex = gun_index;
  7176. }
  7177. for (int index = 0; index < AC_QUANTITY; index++)
  7178. {
  7179. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7180. {
  7181. if(dataType == ReadingContext_Sample_Clock)
  7182. {
  7183. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousClockPowerConsumption[gun_index]));
  7184. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7185. }
  7186. else if(dataType == ReadingContext_Sample_Periodic)
  7187. {
  7188. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption - periousPeriodicPowerConsumption[gun_index]));
  7189. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  7190. }
  7191. else
  7192. {
  7193. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "0.000");
  7194. }
  7195. }
  7196. }
  7197. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  7198. }
  7199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  7200. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  7201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  7202. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  7203. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  7204. }
  7205. //********************************(4)Power.Active.Import************************************************/
  7206. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7207. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  7208. (dataType == ReadingContext_Trigger))
  7209. {
  7210. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7211. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7212. {
  7213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7214. {
  7215. tempIndex = ((gun_index==2) ? 1: 0);
  7216. }
  7217. else
  7218. {
  7219. tempIndex = gun_index;
  7220. }
  7221. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7222. {
  7223. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7224. {
  7225. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  7226. }
  7227. } // END OF FOR
  7228. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7229. }
  7230. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7231. {
  7232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7233. {
  7234. tempIndex = ((gun_index==2) ? 1: 0);
  7235. }
  7236. else
  7237. {
  7238. tempIndex = gun_index;
  7239. }
  7240. for (int index = 0; index < CCS_QUANTITY; index++)
  7241. {
  7242. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7243. {
  7244. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  7245. }
  7246. }
  7247. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7248. }
  7249. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7250. {
  7251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7252. {
  7253. tempIndex = ((gun_index==2) ? 1: 0);
  7254. }
  7255. else
  7256. {
  7257. tempIndex = gun_index;
  7258. }
  7259. for (int index = 0; index < GB_QUANTITY; index++)
  7260. {
  7261. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7262. {
  7263. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7264. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  7265. }
  7266. }
  7267. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7268. }
  7269. else if(gunType[gun_index] == GUN_TYPE_DO)
  7270. {
  7271. tempIndex = gun_index;
  7272. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7273. {
  7274. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7275. {
  7276. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7277. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  7278. }
  7279. }
  7280. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  7281. }
  7282. else
  7283. {
  7284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7285. {
  7286. tempIndex = 2;
  7287. }
  7288. else
  7289. {
  7290. tempIndex = gun_index;
  7291. }
  7292. for (int index = 0; index < AC_QUANTITY; index++)
  7293. {
  7294. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7295. {
  7296. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  7297. }
  7298. }
  7299. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  7300. }
  7301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  7302. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  7303. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  7304. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  7305. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  7306. }
  7307. //***********************************************(5)VOLTAGE L1******************************************************/
  7308. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7309. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7310. (dataType == ReadingContext_Trigger))
  7311. {
  7312. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7313. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7314. {
  7315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7316. {
  7317. tempIndex = ((gun_index==2) ? 1: 0);
  7318. }
  7319. else
  7320. {
  7321. tempIndex = gun_index;
  7322. }
  7323. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7324. {
  7325. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7326. {
  7327. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  7328. }
  7329. }
  7330. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7331. }
  7332. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7333. {
  7334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7335. {
  7336. tempIndex = ((gun_index==2) ? 1: 0);
  7337. }
  7338. else
  7339. {
  7340. tempIndex = gun_index;
  7341. }
  7342. for (int index = 0; index < CCS_QUANTITY; index++)
  7343. {
  7344. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7345. {
  7346. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  7347. }
  7348. }
  7349. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7350. }
  7351. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7352. {
  7353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7354. {
  7355. tempIndex = ((gun_index==2) ? 1: 0);
  7356. }
  7357. else
  7358. {
  7359. tempIndex = gun_index;
  7360. }
  7361. for (int index = 0; index < GB_QUANTITY; index++)
  7362. {
  7363. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7364. {
  7365. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  7366. }
  7367. }
  7368. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7369. }
  7370. else if(gunType[gun_index] == GUN_TYPE_DO)
  7371. {
  7372. tempIndex = gun_index;
  7373. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7374. {
  7375. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7376. {
  7377. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  7378. }
  7379. }
  7380. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  7381. }
  7382. else
  7383. {
  7384. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7385. {
  7386. tempIndex = 2;
  7387. }
  7388. else
  7389. {
  7390. tempIndex = gun_index;
  7391. }
  7392. for (int index = 0; index < AC_QUANTITY; index++)
  7393. {
  7394. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7395. {
  7396. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  7397. }
  7398. }
  7399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  7400. }
  7401. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  7402. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  7403. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  7404. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  7405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7406. }
  7407. //***********************************************(6)SOC******************************************************/
  7408. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7409. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  7410. (dataType == ReadingContext_Trigger))
  7411. {
  7412. 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))
  7413. {
  7414. //idx_sample=5;
  7415. //sampledValue = NULL;
  7416. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7417. {
  7418. tempIndex = ((gun_index==2) ? 1: 0);
  7419. }
  7420. else
  7421. {
  7422. tempIndex = gun_index;
  7423. }
  7424. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7425. {
  7426. //tempIndex = ((gun_index==2) ? 1: 0);
  7427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7428. {
  7429. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7430. {
  7431. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  7432. }
  7433. }
  7434. }
  7435. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7436. {
  7437. //tempIndex = ((gun_index==2) ? 1: 0);
  7438. for (int index = 0; index < CCS_QUANTITY; index++)
  7439. {
  7440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7441. {
  7442. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  7443. }
  7444. }
  7445. }
  7446. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7447. {
  7448. //tempIndex = ((gun_index==2) ? 1: 0);
  7449. for (int index = 0; index < GB_QUANTITY; index++)
  7450. {
  7451. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7452. {
  7453. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  7454. }
  7455. }
  7456. }
  7457. else if(gunType[gun_index] == GUN_TYPE_DO)
  7458. {
  7459. //tempIndex = ((gun_index==2) ? 1: 0);
  7460. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7461. {
  7462. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7463. {
  7464. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  7465. }
  7466. }
  7467. }
  7468. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  7469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  7470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  7471. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  7472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  7473. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  7474. }
  7475. }
  7476. //********************************(7)Current.Import L2************************************************/
  7477. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7478. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7479. (dataType == ReadingContext_Trigger))
  7480. {
  7481. // Only for AC 3 phase
  7482. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7483. {
  7484. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7485. {
  7486. tempIndex = 2;
  7487. }
  7488. else
  7489. {
  7490. tempIndex = gun_index;
  7491. }
  7492. for (int index = 0; index < AC_QUANTITY; index++)
  7493. {
  7494. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7495. {
  7496. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  7497. }
  7498. }
  7499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  7500. }
  7501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  7502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  7503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  7504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  7505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7506. }
  7507. //********************************(8)Current.Import L3************************************************/
  7508. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7509. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  7510. (dataType == ReadingContext_Trigger))
  7511. {
  7512. // Only for AC 3 phase
  7513. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7514. {
  7515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7516. {
  7517. tempIndex = 2;
  7518. }
  7519. else
  7520. {
  7521. tempIndex = gun_index;
  7522. }
  7523. for (int index = 0; index < AC_QUANTITY; index++)
  7524. {
  7525. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7526. {
  7527. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  7528. }
  7529. }
  7530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  7531. }
  7532. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  7533. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  7534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  7535. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  7536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7537. }
  7538. //***********************************************(9)VOLTAGE L2******************************************************/
  7539. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7540. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7541. (dataType == ReadingContext_Trigger))
  7542. {
  7543. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7544. {
  7545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7546. {
  7547. tempIndex = 2;
  7548. }
  7549. else
  7550. {
  7551. tempIndex = gun_index;
  7552. }
  7553. for (int index = 0; index < AC_QUANTITY; index++)
  7554. {
  7555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7556. {
  7557. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  7558. }
  7559. }
  7560. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  7561. }
  7562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  7563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  7564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  7565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  7566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7567. }
  7568. //***********************************************(10)VOLTAGE L3******************************************************/
  7569. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7570. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  7571. (dataType == ReadingContext_Trigger))
  7572. {
  7573. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  7574. {
  7575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7576. {
  7577. tempIndex = 2;
  7578. }
  7579. else
  7580. {
  7581. tempIndex = gun_index;
  7582. }
  7583. for (int index = 0; index < AC_QUANTITY; index++)
  7584. {
  7585. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7586. {
  7587. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  7588. }
  7589. }
  7590. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  7591. }
  7592. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  7593. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  7594. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  7595. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  7596. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  7597. }
  7598. //***********************************************(11)Current.Offered******************************************************/
  7599. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7600. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  7601. (dataType == ReadingContext_Trigger))
  7602. {
  7603. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7604. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7605. {
  7606. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7607. {
  7608. tempIndex = ((gun_index==2) ? 1: 0);
  7609. }
  7610. else
  7611. {
  7612. tempIndex = gun_index;
  7613. }
  7614. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7615. {
  7616. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7617. {
  7618. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  7619. }
  7620. } // END OF FOR CHAdeMO_QUANTITY
  7621. }
  7622. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  7633. {
  7634. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7635. {
  7636. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  7637. }
  7638. } // END OF CCS_QUANTITY
  7639. }
  7640. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  7651. {
  7652. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7653. {
  7654. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  7655. }
  7656. } // END OF GB_QUANTITY
  7657. }
  7658. else if(gunType[gun_index] == GUN_TYPE_DO)
  7659. {
  7660. tempIndex = gun_index;
  7661. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7662. {
  7663. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7664. {
  7665. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  7666. }
  7667. }
  7668. }
  7669. else
  7670. {
  7671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7672. {
  7673. tempIndex = 2;
  7674. }
  7675. else
  7676. {
  7677. tempIndex = gun_index;
  7678. }
  7679. for (int index = 0; index < AC_QUANTITY; index++)
  7680. {
  7681. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7682. {
  7683. uint16_t currentOffer;
  7684. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7685. {
  7686. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7687. }
  7688. else
  7689. {
  7690. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7691. }
  7692. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7693. }
  7694. }
  7695. }
  7696. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7697. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7698. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7699. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7700. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7701. }
  7702. //***********************************************(12)Power.Offered******************************************************/
  7703. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7704. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7705. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7706. {
  7707. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7708. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7709. {
  7710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7711. {
  7712. tempIndex = ((gun_index==2) ? 1: 0);
  7713. }
  7714. else
  7715. {
  7716. tempIndex = gun_index;
  7717. }
  7718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7719. {
  7720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7721. {
  7722. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  7723. }
  7724. } // END OF FOR CHAdeMO_QUANTITY
  7725. }
  7726. else if(gunType[gun_index] == GUN_TYPE_CCS)
  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 < CCS_QUANTITY; index++)
  7737. {
  7738. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7739. {
  7740. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  7741. }
  7742. } // END OF CCS_QUANTITY
  7743. }
  7744. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  7755. {
  7756. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7757. {
  7758. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  7759. }
  7760. } // END OF GB_QUANTITY
  7761. }
  7762. else if(gunType[gun_index] == GUN_TYPE_DO)
  7763. {
  7764. tempIndex = gun_index;
  7765. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7766. {
  7767. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7768. {
  7769. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  7770. }
  7771. }
  7772. }
  7773. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7774. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7776. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7777. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7778. }
  7779. // Message create ====================================================================================================
  7780. if(TRUE)
  7781. {
  7782. json_object *MeterValueReq = json_object_new_object();
  7783. json_object *MeterValues = json_object_new_array();
  7784. json_object *sampledValues = json_object_new_array();
  7785. json_object *sampledValuesBuffer = json_object_new_array();
  7786. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  7787. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  7788. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  7789. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  7790. {
  7791. json_object *MeterValue = json_object_new_object();
  7792. json_object *MeterValueBuffer = json_object_new_object();
  7793. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7794. {
  7795. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7796. {
  7797. json_object *sampledValue = json_object_new_object();
  7798. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7799. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7800. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7801. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7802. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7803. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7804. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7805. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7806. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7807. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7808. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7809. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7810. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7811. json_object_array_add(sampledValues, sampledValue);
  7812. // For StopTxn data
  7813. 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)) ||
  7814. ((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)))
  7815. {
  7816. json_object *sampledValue = json_object_new_object();
  7817. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7818. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7819. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7820. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7821. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7822. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7823. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7824. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7825. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7826. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7827. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7828. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7829. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7830. json_object_array_add(sampledValuesBuffer, sampledValue);
  7831. }
  7832. }
  7833. }
  7834. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7835. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7836. json_object_array_add(MeterValues, MeterValue);
  7837. // For StopTxn data
  7838. if((dataType != ReadingContext_Trigger) &&
  7839. (json_object_array_length(sampledValuesBuffer) > 0))
  7840. {
  7841. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7842. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  7843. if(meterValueBufferDataQuantity(gun_index, dataType) < 200) meterValueBufferInsert(gun_index, dataType, ShmOCPP16Data->MeterValues[gun_index].TransactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  7844. json_object_put(MeterValueBuffer);
  7845. }
  7846. else
  7847. {
  7848. json_object_put(sampledValuesBuffer);
  7849. json_object_put(MeterValueBuffer);
  7850. }
  7851. }
  7852. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7853. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7854. ,gun_index + 1
  7855. ,MESSAGE_TYPE_CALL
  7856. ,guid
  7857. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7858. json_object_put(MeterValueReq);
  7859. }
  7860. // Put request guid to hash map
  7861. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7862. 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*/)
  7863. {
  7864. result = PASS;
  7865. //DEBUG_INFO("MeterValues mapitem pass\n");
  7866. }
  7867. if((dataType != ReadingContext_Trigger) &&
  7868. (dataType != ReadingContext_Sample_Clock) &&
  7869. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7870. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7871. else
  7872. {
  7873. if(FirstHeartBeat)
  7874. LWS_Send(queuedata +2);
  7875. }
  7876. return result;
  7877. }
  7878. int sendLogStatusNotificationRequest(char *status)
  7879. {
  7880. mtrace();
  7881. int result = PASS;
  7882. char message[4096]={0};
  7883. char guid[37]={0};
  7884. char tempdata[128]={0};
  7885. json_object *LogStatusNotification = json_object_new_object();
  7886. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7887. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  7888. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7889. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7890. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7891. random_uuid(guid);
  7892. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7893. json_object_put(LogStatusNotification);
  7894. LWS_Send(message);
  7895. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7896. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7897. {
  7898. result = PASS;
  7899. }
  7900. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7901. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7902. return result;
  7903. }
  7904. int sendSecurityEventNotificationRequest()
  7905. {
  7906. mtrace();
  7907. int result = PASS;
  7908. char message[4096]={0};
  7909. char guid[37]={0};
  7910. char tempdata[128]={0};
  7911. json_object *SecurityEventNotification = json_object_new_object();
  7912. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7913. //Stop Transaction Time
  7914. struct timeval tmnow;
  7915. struct tm *tm;
  7916. gettimeofday(&tmnow, NULL);
  7917. time_t t;
  7918. t = time(NULL);
  7919. /*UTC time and date*/
  7920. tm = gmtime(&t);
  7921. strftime((char *)ShmOCPP16Data->SecurityEventNotification.timestamp, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.timestamp), "%Y-%m-%dT%H:%M:%SZ", tm);
  7922. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7923. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7924. if(strlen((char*)ShmOCPP16Data->SecurityEventNotification.techInfo) > 0)
  7925. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7926. random_uuid(guid);
  7927. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7928. json_object_put(SecurityEventNotification);
  7929. LWS_Send(message);
  7930. sprintf(tempdata, "SecurityEventNotification,0");
  7931. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7932. {
  7933. result = PASS;
  7934. }
  7935. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7936. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7937. return result;
  7938. }
  7939. int sendSignCertificateRequest()
  7940. {
  7941. mtrace();
  7942. int result = PASS;
  7943. char message[4096]={0};
  7944. char guid[37]={0};
  7945. char tempdata[128]={0};
  7946. json_object *SignCertificate = json_object_new_object();
  7947. DEBUG_INFO("sendSignCertificateRequest...\n");
  7948. // Read csr file content
  7949. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7950. FILE *fp=fopen(CSR_CP,"r");
  7951. char *line = NULL;
  7952. size_t len = 0;
  7953. while(getline(&line, &len, fp) != -1)
  7954. {
  7955. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7956. {
  7957. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7958. }
  7959. }
  7960. fclose(fp);
  7961. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7962. random_uuid(guid);
  7963. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7964. json_object_put(SignCertificate);
  7965. LWS_Send(message);
  7966. sprintf(tempdata, "SignCertificate,0");
  7967. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7968. {
  7969. result = PASS;
  7970. }
  7971. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7972. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7973. return result;
  7974. }
  7975. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7976. {
  7977. mtrace();
  7978. int result = PASS;
  7979. char message[4096]={0};
  7980. char guid[37]={0};
  7981. char tempdata[128]={0};
  7982. json_object *SignedFirmwareStatusNotification = json_object_new_object();
  7983. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7984. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7985. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7986. json_object_object_add(SignedFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7987. json_object_object_add(SignedFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7988. random_uuid(guid);
  7989. sprintf(message,"[%d,\"%s\",\"SignedFirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(SignedFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7990. json_object_put(SignedFirmwareStatusNotification);
  7991. LWS_Send(message);
  7992. sprintf(tempdata, "SignedFirmwareStatusNotification,%d", 0);
  7993. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7994. {
  7995. result = PASS;
  7996. }
  7997. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7998. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7999. return result;
  8000. }
  8001. //==========================================
  8002. // send confirm routine
  8003. //==========================================
  8004. int sendCancelReservationConfirmation(char *uuid,char *payload)
  8005. {
  8006. mtrace();
  8007. int result = FAIL;
  8008. char message[100]={0};
  8009. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8010. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8011. LWS_Send(message);
  8012. result = TRUE;
  8013. return result;
  8014. }
  8015. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  8016. {
  8017. mtrace();
  8018. int result = FAIL;
  8019. char message[100]={0};
  8020. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8021. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8022. LWS_Send(message);
  8023. result = TRUE;
  8024. return result;
  8025. }
  8026. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  8027. {
  8028. mtrace();
  8029. int result = FAIL;
  8030. char message[100]={0};
  8031. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  8032. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  8033. LWS_Send(message);
  8034. result = TRUE;
  8035. return result;
  8036. }
  8037. int sendClearCacheConfirmation(char *uuid,char *payload)
  8038. {
  8039. mtrace();
  8040. int result = FAIL;
  8041. char message[500]={0};
  8042. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8043. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8044. LWS_Send(message);
  8045. return result;
  8046. }
  8047. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8048. {
  8049. mtrace();
  8050. int result = FAIL;
  8051. char message[500]={0};
  8052. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8053. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8054. LWS_Send(message);
  8055. return result;
  8056. }
  8057. int sendDataTransferConfirmation(char *uuid,char *payload)
  8058. {
  8059. mtrace();
  8060. char statusStr[20]={0};
  8061. char dataStr[10]={0};
  8062. char sstr[20]={0};
  8063. int c = 0;
  8064. char *loc;
  8065. int result = FAIL;
  8066. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8067. /**********************status**************************/
  8068. loc = strstr(payload, "status");
  8069. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8070. c = 0;
  8071. while (loc[3+strlen("status")+c] != '\"')
  8072. {
  8073. sstr[c] = loc[3+strlen("status")+c];
  8074. c++;
  8075. }
  8076. sstr[c] = '\0';
  8077. strcpy(statusStr, sstr);
  8078. /**********************data**************************/
  8079. loc = strstr(payload, "data");
  8080. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8081. c = 0;
  8082. while (loc[3+strlen("data")+c] != '\"')
  8083. {
  8084. sstr[c] = loc[3+strlen("data")+c];
  8085. c++;
  8086. }
  8087. sstr[c] = '\0';
  8088. strcpy(dataStr, sstr);
  8089. return result;
  8090. }
  8091. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8092. {
  8093. mtrace();
  8094. int result = FAIL;
  8095. char message[1000]={0};
  8096. int CompositeScheduleIndex = 0;
  8097. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8098. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8099. if(nPeriod == 0)
  8100. {
  8101. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  8102. {
  8103. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  8104. ,MESSAGE_TYPE_CALLRESULT
  8105. ,uuid
  8106. ,payload
  8107. ,connectorIdInt);
  8108. }
  8109. else
  8110. {
  8111. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d}]}}]"
  8112. ,MESSAGE_TYPE_CALLRESULT
  8113. ,uuid
  8114. ,payload
  8115. ,connectorIdInt
  8116. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8117. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8118. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8119. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  8120. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  8121. }
  8122. }
  8123. else
  8124. {
  8125. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  8126. ,MESSAGE_TYPE_CALLRESULT
  8127. ,uuid
  8128. ,payload
  8129. ,connectorIdInt
  8130. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8131. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  8132. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  8133. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  8134. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  8135. {
  8136. if (idx_sample == 0)
  8137. {
  8138. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8139. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8140. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8141. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8142. }
  8143. else
  8144. {
  8145. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  8146. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  8147. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  8148. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  8149. }
  8150. }
  8151. sprintf(message + strlen(message), "]}}]");
  8152. }
  8153. LWS_Send(message);
  8154. result = TRUE;
  8155. return result;
  8156. }
  8157. int sendGetConfigurationConfirmation(char *uuid)
  8158. {
  8159. mtrace();
  8160. int result = FAIL;
  8161. int MaxKeySupported = 0;
  8162. int sentConfigurationNumber= 0;
  8163. int sentunConfigurationNumber= 0;
  8164. char message[1024*10]={0};
  8165. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  8166. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  8167. //configuration key
  8168. json_object *GetConfiguration = json_object_new_object();
  8169. json_object *configurationKey = json_object_new_array();
  8170. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  8171. {
  8172. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  8173. {
  8174. json_object *keyValue = json_object_new_object();
  8175. json_object_object_add(keyValue, "key", json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key));
  8176. 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));
  8177. json_object_object_add(keyValue, "value", json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value));
  8178. json_object_array_add(configurationKey, keyValue);
  8179. sentConfigurationNumber = sentConfigurationNumber + 1;
  8180. }
  8181. }
  8182. json_object *unknownKey = json_object_new_array();
  8183. if(UnknownKeynum != 0)
  8184. {
  8185. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  8186. {
  8187. DEBUG_INFO("unknown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  8188. json_object_array_add(unknownKey, json_object_new_string((char*)ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item));
  8189. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  8190. }
  8191. }
  8192. if((sentConfigurationNumber>0) && (sentunConfigurationNumber>0))
  8193. {
  8194. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  8195. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  8196. }
  8197. else if(sentConfigurationNumber>0)
  8198. {
  8199. json_object_object_add(GetConfiguration, "configurationKey", configurationKey);
  8200. json_object_put(unknownKey);
  8201. }
  8202. else
  8203. {
  8204. json_object_object_add(GetConfiguration, "unknownKey", unknownKey);
  8205. json_object_put(configurationKey);
  8206. }
  8207. sprintf(message,"[%d,\"%s\",%s]"
  8208. ,MESSAGE_TYPE_CALLRESULT
  8209. ,uuid
  8210. ,json_object_to_json_string_ext(GetConfiguration, JSON_C_TO_STRING_PLAIN));
  8211. json_object_put(GetConfiguration);
  8212. LWS_Send(message);
  8213. return result;
  8214. }
  8215. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  8216. {
  8217. mtrace();
  8218. int result = FAIL;
  8219. char message[400]={0};
  8220. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  8221. if(strcmp(payload,"")==0)
  8222. {
  8223. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8224. }
  8225. else
  8226. {
  8227. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8228. }
  8229. LWS_Send(message);
  8230. result = TRUE;
  8231. return result;
  8232. }
  8233. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  8234. {
  8235. mtrace();
  8236. int result = FAIL;
  8237. char message[80]={0};
  8238. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8239. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  8240. LWS_Send(message);
  8241. result = TRUE;
  8242. return result;
  8243. }
  8244. int sendRemoteStartConfirmation(char *uuid,char *payload)
  8245. {
  8246. mtrace();
  8247. int result = FAIL;
  8248. char message[80]={0};
  8249. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8250. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8251. LWS_Send(message);
  8252. result = TRUE;
  8253. return result;
  8254. }
  8255. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  8256. {
  8257. mtrace();
  8258. int result = FAIL;
  8259. char message[80]={0};
  8260. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8261. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8262. LWS_Send(message);
  8263. result = TRUE;
  8264. return result;
  8265. }
  8266. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  8267. {
  8268. mtrace();
  8269. int result = FAIL;
  8270. char message[80]={0};
  8271. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  8272. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8273. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8274. LWS_Send(message);
  8275. result = TRUE;
  8276. return result;
  8277. }
  8278. int sendResetConfirmation(char *uuid,char *payload)
  8279. {
  8280. mtrace();
  8281. int result = FAIL;
  8282. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  8283. char message[80]={0};
  8284. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  8285. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8286. LWS_Send(message);
  8287. result = TRUE;
  8288. return result;
  8289. }
  8290. int sendSendLocalListConfirmation(char *uuid,char *payload)
  8291. {
  8292. mtrace();
  8293. int result = FAIL;
  8294. char message[500]={0};
  8295. // [ 3, "1571284266109", { "status": "Accepted" } ]
  8296. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8297. LWS_Send(message);
  8298. result = TRUE;
  8299. return result;
  8300. }
  8301. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  8302. {
  8303. mtrace();
  8304. int result = FAIL;
  8305. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  8306. char message[80]={0};
  8307. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8308. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8309. LWS_Send(message);
  8310. result = TRUE;
  8311. return result;
  8312. }
  8313. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  8314. {
  8315. mtrace();
  8316. int result = FAIL;
  8317. char message[80]={0};
  8318. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8319. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8320. LWS_Send(message);
  8321. result = TRUE;
  8322. return result;
  8323. }
  8324. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  8325. {
  8326. mtrace();
  8327. int result = FAIL;
  8328. char message[80]={0};
  8329. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8330. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8331. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  8332. LWS_Send(message);
  8333. result = TRUE;
  8334. return result;
  8335. }
  8336. int sendUpdateFirmwareConfirmation(char *uuid)
  8337. {
  8338. mtrace();
  8339. int result = FAIL;
  8340. char message[60]={0};
  8341. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8342. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8343. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  8344. LWS_Send(message);
  8345. result = TRUE;
  8346. return result;
  8347. }
  8348. int sendCertificateSignedConfirmation(char *uuid)
  8349. {
  8350. mtrace();
  8351. int result = PASS;
  8352. char message[4096]={0};
  8353. json_object *CertificateSigned = json_object_new_object();
  8354. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8355. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  8356. sprintf(message,"[%d,\"%s\",%s]"
  8357. ,MESSAGE_TYPE_CALLRESULT
  8358. ,uuid
  8359. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8360. json_object_put(CertificateSigned);
  8361. LWS_Send(message);
  8362. return result;
  8363. }
  8364. int sendDeleteCertificateConfirmation(char *uuid)
  8365. {
  8366. mtrace();
  8367. int result = PASS;
  8368. char message[4096]={0};
  8369. json_object *DeleteCertificate = json_object_new_object();
  8370. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8371. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  8372. sprintf(message,"[%d,\"%s\",%s]"
  8373. ,MESSAGE_TYPE_CALLRESULT
  8374. ,uuid
  8375. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8376. json_object_put(DeleteCertificate);
  8377. LWS_Send(message);
  8378. return result;
  8379. }
  8380. int sendExtendedTriggerMessageConfirmation(char *uuid)
  8381. {
  8382. mtrace();
  8383. int result = PASS;
  8384. char message[4096]={0};
  8385. json_object *ExtendedTriggerMessage = json_object_new_object();
  8386. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  8387. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  8388. sprintf(message,"[%d,\"%s\",%s]"
  8389. ,MESSAGE_TYPE_CALLRESULT
  8390. ,uuid
  8391. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  8392. json_object_put(ExtendedTriggerMessage);
  8393. LWS_Send(message);
  8394. return result;
  8395. }
  8396. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  8397. {
  8398. mtrace();
  8399. int result = PASS;
  8400. char message[4096]={0};
  8401. json_object *GetInstalledCertificateIds = json_object_new_object();
  8402. json_object *certificateHashDataDatas = json_object_new_array();
  8403. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8404. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  8405. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  8406. {
  8407. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  8408. {
  8409. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm) > 0)
  8410. {
  8411. json_object *certificateHashData = json_object_new_object();
  8412. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  8413. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  8414. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  8415. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  8416. json_object_array_add(certificateHashDataDatas, certificateHashData);
  8417. }
  8418. }
  8419. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  8420. }
  8421. else
  8422. {
  8423. json_object_put(certificateHashDataDatas);
  8424. }
  8425. sprintf(message,"[%d,\"%s\",%s]"
  8426. ,MESSAGE_TYPE_CALLRESULT
  8427. ,uuid
  8428. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8429. json_object_put(GetInstalledCertificateIds);
  8430. LWS_Send(message);
  8431. return result;
  8432. }
  8433. int sendGetLogConfirmation(char *uuid)
  8434. {
  8435. mtrace();
  8436. int result = PASS;
  8437. char message[4096]={0};
  8438. json_object *GetLog = json_object_new_object();
  8439. DEBUG_INFO("sendGetLogConfirmation...\n");
  8440. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  8441. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  8442. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  8443. sprintf(message,"[%d,\"%s\",%s]"
  8444. ,MESSAGE_TYPE_CALLRESULT
  8445. ,uuid
  8446. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8447. json_object_put(GetLog);
  8448. LWS_Send(message);
  8449. return result;
  8450. }
  8451. int sendInstallCertificateConfirmation(char *uuid)
  8452. {
  8453. mtrace();
  8454. int result = PASS;
  8455. char message[4096]={0};
  8456. json_object *InstallCertificate = json_object_new_object();
  8457. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8458. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  8459. sprintf(message,"[%d,\"%s\",%s]"
  8460. ,MESSAGE_TYPE_CALLRESULT
  8461. ,uuid
  8462. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8463. json_object_put(InstallCertificate);
  8464. LWS_Send(message);
  8465. return result;
  8466. }
  8467. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  8468. {
  8469. mtrace();
  8470. int result = PASS;
  8471. char message[4096]={0};
  8472. json_object *SignedUpdateFirmware = json_object_new_object();
  8473. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  8474. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  8475. sprintf(message,"[%d,\"%s\",%s]"
  8476. ,MESSAGE_TYPE_CALLRESULT
  8477. ,uuid
  8478. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8479. json_object_put(SignedUpdateFirmware);
  8480. LWS_Send(message);
  8481. return result;
  8482. }
  8483. int sendUnknownConfirmation(char *uuid)
  8484. {
  8485. mtrace();
  8486. int result = PASS;
  8487. char message[256]={0};
  8488. DEBUG_INFO("sendUnknownConfirmation...\n");
  8489. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8490. LWS_Send(message);
  8491. return result;
  8492. }
  8493. //==========================================
  8494. // Handle server request routine Start
  8495. //==========================================
  8496. int handleCancelReservationRequest(char *uuid, char *payload)
  8497. {
  8498. mtrace();
  8499. int result = FAIL;
  8500. int gunNO = 0;
  8501. int reservationIdInt = -1;
  8502. char comfirmstr[20];
  8503. DEBUG_INFO("handleCancelReservationRequest...\n");
  8504. json_object *CancelReservation;
  8505. CancelReservation = json_tokener_parse(payload);
  8506. if(!is_error(CancelReservation))
  8507. {
  8508. // Required data
  8509. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8510. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8511. }
  8512. json_object_put(CancelReservation);
  8513. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8514. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8515. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  8516. if(reservationIdInt != -1)
  8517. {
  8518. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8519. //check Transaction active
  8520. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8521. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8522. {
  8523. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8524. {
  8525. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8526. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8527. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8528. {
  8529. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8530. }
  8531. else
  8532. {
  8533. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8534. }
  8535. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8536. goto end;
  8537. }
  8538. }
  8539. for (int index = 0; index < CCS_QUANTITY; index++)
  8540. {
  8541. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8542. {
  8543. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8544. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8545. if(gunType[2] == GUN_TYPE_CCS)
  8546. {
  8547. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8548. }
  8549. else
  8550. {
  8551. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8552. }
  8553. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8554. goto end;
  8555. }
  8556. }
  8557. for (int index = 0; index < GB_QUANTITY; index++)
  8558. {
  8559. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8560. {
  8561. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8562. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8563. if(gunType[2] == GUN_TYPE_GBT)
  8564. {
  8565. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8566. }
  8567. else
  8568. {
  8569. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8570. }
  8571. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8572. goto end;
  8573. }
  8574. }
  8575. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8576. {
  8577. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8578. {
  8579. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8580. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index].ResponseStatus, "%s", comfirmstr );
  8581. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  8582. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8583. goto end;
  8584. }
  8585. }
  8586. for (int index = 0; index < AC_QUANTITY; index++)
  8587. {
  8588. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  8589. {
  8590. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  8591. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  8592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8593. {
  8594. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  8595. }
  8596. else
  8597. {
  8598. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  8599. }
  8600. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  8601. goto end;
  8602. }
  8603. }
  8604. }
  8605. //The reservationId does NOT match the reservationId
  8606. sendCancelReservationConfirmation(uuid, comfirmstr);
  8607. end:
  8608. // Fill in ocpp packet uuid
  8609. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  8610. return result;
  8611. }
  8612. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  8613. {
  8614. mtrace();
  8615. int result = FAIL;
  8616. int gunIndex = -1;
  8617. char typeStr[16]={0};
  8618. char comfirmstr[20];
  8619. int specificId = FALSE;
  8620. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  8621. json_object *ChangeAvailability;
  8622. ChangeAvailability = json_tokener_parse(payload);
  8623. if(!is_error(ChangeAvailability))
  8624. {
  8625. // Required data
  8626. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  8627. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  8628. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  8629. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  8630. }
  8631. json_object_put(ChangeAvailability);
  8632. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  8633. {
  8634. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  8635. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  8636. }
  8637. else if(gunIndex == 0)
  8638. {
  8639. for(int i=0; i < gunTotalNumber; i++)
  8640. {
  8641. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  8642. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  8643. }
  8644. }
  8645. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  8646. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8647. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  8648. {
  8649. specificId = TRUE;
  8650. }
  8651. if(specificId == FALSE)
  8652. goto end;
  8653. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  8654. {
  8655. //----------------------gunIndex is 0 ------------------------------------------------//
  8656. if(gunIndex == 0)
  8657. {
  8658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8659. {
  8660. for(int i=0; i < gunTotalNumber; i++)
  8661. {
  8662. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8663. {
  8664. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  8665. {
  8666. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8667. {
  8668. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8669. goto end;
  8670. }
  8671. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8672. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8673. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8674. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8675. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8676. {
  8677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8678. goto end;
  8679. }
  8680. }
  8681. }//END FOR CHAdeMO_QUANTITY
  8682. for (int index = 0; index < CCS_QUANTITY; index++)
  8683. {
  8684. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  8685. {
  8686. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  8687. {
  8688. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8689. goto end;
  8690. }
  8691. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8692. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8693. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8694. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8695. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8696. {
  8697. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8698. goto end;
  8699. }
  8700. }
  8701. }//END FOR CCS_QUANTITY
  8702. for (int index = 0; index < GB_QUANTITY; index++)
  8703. {
  8704. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  8705. {
  8706. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8707. {
  8708. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8709. goto end;
  8710. }
  8711. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8712. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8713. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8714. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8715. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8716. {
  8717. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8718. goto end;
  8719. }
  8720. }
  8721. }// END FOR GB_QUANTITY
  8722. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8723. {
  8724. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8725. {
  8726. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8727. {
  8728. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8729. goto end;
  8730. }
  8731. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8732. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8733. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8734. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8735. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8736. {
  8737. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8738. goto end;
  8739. }
  8740. }
  8741. }// END FOR GENERAL_GUN_QUANTITY
  8742. for (int index = 0; index < AC_QUANTITY; index++)
  8743. {
  8744. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8745. {
  8746. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8747. {
  8748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8749. goto end;
  8750. }
  8751. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8752. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8753. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8754. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8755. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8756. {
  8757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8758. goto end;
  8759. }
  8760. }
  8761. }//END FOR AC_QUANTITY
  8762. }// END FOR gunTotalNumber
  8763. }
  8764. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8765. {
  8766. for(int i=0; i < gunTotalNumber; i++)
  8767. {
  8768. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8769. {
  8770. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8771. goto end;
  8772. }
  8773. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8774. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8775. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8776. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8777. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8778. {
  8779. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8780. goto end;
  8781. }
  8782. }
  8783. }
  8784. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8785. goto end;
  8786. }
  8787. //----------------------gunIndex is not 0 ------------------------------------------------//
  8788. //check Transaction active
  8789. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8790. {
  8791. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8792. {
  8793. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8794. {
  8795. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8796. goto end;
  8797. }
  8798. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8799. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8800. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8801. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8802. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8803. {
  8804. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8805. goto end;
  8806. }
  8807. else
  8808. {
  8809. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8810. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8811. goto end;
  8812. }
  8813. }
  8814. }//END FOR CHAdeMO_QUANTITY
  8815. for (int index = 0; index < CCS_QUANTITY; index++)
  8816. {
  8817. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8818. {
  8819. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8820. {
  8821. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8822. goto end;
  8823. }
  8824. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8825. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8826. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8827. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8828. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8829. {
  8830. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8831. goto end;
  8832. }
  8833. else
  8834. {
  8835. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8836. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8837. goto end;
  8838. }
  8839. }
  8840. }//END FOR CCS_QUANTITY
  8841. for (int index = 0; index < GB_QUANTITY; index++)
  8842. {
  8843. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8844. {
  8845. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8846. {
  8847. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8848. goto end;
  8849. }
  8850. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8851. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8852. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8853. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8854. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8855. {
  8856. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8857. goto end;
  8858. }
  8859. else
  8860. {
  8861. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8863. goto end;
  8864. }
  8865. }
  8866. }// END FOR GB_QUANTITY
  8867. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8868. {
  8869. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8870. {
  8871. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8872. {
  8873. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8874. goto end;
  8875. }
  8876. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8877. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8878. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8879. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8880. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8881. {
  8882. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8883. goto end;
  8884. }
  8885. else
  8886. {
  8887. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8888. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8889. goto end;
  8890. }
  8891. }
  8892. }// END FOR GENERAL_GUN_QUANTITY
  8893. for (int index = 0; index < AC_QUANTITY; index++)
  8894. {
  8895. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8896. {
  8897. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8898. {
  8899. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8900. goto end;
  8901. }
  8902. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8903. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8904. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8905. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8906. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8907. {
  8908. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8909. goto end;
  8910. }
  8911. else
  8912. {
  8913. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8914. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8915. goto end;
  8916. }
  8917. }
  8918. }//END FOR AC_QUANTITY
  8919. }//END FOR AvailabilityTypeStr[Inoperative]
  8920. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8921. {
  8922. //----------------------gunIndex is 0 ------------------------------------------------//
  8923. if(gunIndex == 0)
  8924. {
  8925. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8926. {
  8927. for(int i=0; i < gunTotalNumber; i++)
  8928. {
  8929. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8930. {
  8931. 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
  8932. {
  8933. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8934. goto end;
  8935. }
  8936. }//END FOR CHAdeMO_QUANTITY
  8937. for (int index = 0; index < CCS_QUANTITY; index++)
  8938. {
  8939. 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
  8940. {
  8941. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8942. goto end;
  8943. }
  8944. }//END FOR CCS_QUANTITY
  8945. for (int index = 0; index < GB_QUANTITY; index++)
  8946. {
  8947. 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
  8948. {
  8949. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8950. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8951. goto end;
  8952. }
  8953. }// END FOR GB_QUANTITY
  8954. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8955. {
  8956. 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
  8957. {
  8958. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8959. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8960. goto end;
  8961. }
  8962. }// END FOR GENERAL_GUN_QUANTITY
  8963. for (int index = 0; index < AC_QUANTITY; index++)
  8964. {
  8965. 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
  8966. {
  8967. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8968. goto end;
  8969. }
  8970. }//END FOR CHAdeMO_QUANTITY
  8971. }// END FOR gunTotalNumber
  8972. }
  8973. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8974. {
  8975. for(int i=0; i < gunTotalNumber; i++)
  8976. {
  8977. for (int index = 0; index < AC_QUANTITY; index++)
  8978. {
  8979. 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
  8980. {
  8981. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8982. goto end;
  8983. }
  8984. }//END FOR CHAdeMO_QUANTITY
  8985. } // END FOR gunTotalNumber
  8986. }
  8987. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8988. goto end;
  8989. }
  8990. //----------------------gunIndex is not 0 ------------------------------------------------//
  8991. //check Transaction active
  8992. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8993. {
  8994. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8995. {
  8996. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8997. goto end;
  8998. }
  8999. }//END FOR CHAdeMO_QUANTITY
  9000. for (int index = 0; index < CCS_QUANTITY; index++)
  9001. {
  9002. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9003. {
  9004. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9005. goto end;
  9006. }
  9007. }//END FOR CCS_QUANTITY
  9008. for (int index = 0; index < GB_QUANTITY; index++)
  9009. {
  9010. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9011. {
  9012. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9013. goto end;
  9014. }
  9015. }// END FOR GB_QUANTITY
  9016. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9017. {
  9018. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9019. {
  9020. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9021. goto end;
  9022. }
  9023. }// END FOR GENERAL_GUN_QUANTITY
  9024. for (int index = 0; index < AC_QUANTITY; index++)
  9025. {
  9026. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9027. {
  9028. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  9029. goto end;
  9030. }
  9031. }//END FOR AC_QUANTITY
  9032. }//END FOR AvailabilityTypeStr[Operative]
  9033. end:
  9034. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9035. {
  9036. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  9037. }
  9038. else
  9039. {
  9040. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  9041. }
  9042. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9043. {
  9044. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9045. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  9046. }
  9047. else if(gunIndex == 0)
  9048. {
  9049. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  9050. {
  9051. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9052. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  9053. }
  9054. }
  9055. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  9056. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9057. return result;
  9058. }
  9059. int handleChangeConfigurationRequest(char *uuid, char *payload)
  9060. {
  9061. mtrace();
  9062. int valueInvalid = NO;
  9063. int result = FAIL;
  9064. char keystr[40]={0};
  9065. char valuestr[501]={0}; //value should be limited in 500 bytes
  9066. char comfirmstr[20]={0};
  9067. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  9068. json_object *ChangeConfiguration;
  9069. ChangeConfiguration = json_tokener_parse(payload);
  9070. if(!is_error(ChangeConfiguration))
  9071. {
  9072. // Required data
  9073. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  9074. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  9075. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  9076. {
  9077. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  9078. }
  9079. else
  9080. {
  9081. valueInvalid = YES;
  9082. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  9083. }
  9084. }
  9085. json_object_put(ChangeConfiguration);
  9086. if((uuid==NULL) || (payload ==NULL) || (valueInvalid==YES))
  9087. {
  9088. DEBUG_ERROR("Payload is null or value is invalid.\n");
  9089. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9090. }
  9091. else
  9092. {
  9093. int status = setKeyValue(keystr, valuestr);
  9094. switch(status)
  9095. {
  9096. case ConfigurationStatus_Accepted:
  9097. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  9098. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  9099. StoreConfigurationTable();
  9100. break;
  9101. case RebootRequired:
  9102. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  9103. StoreConfigurationTable();
  9104. break;
  9105. case NotSupported:
  9106. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  9107. break;
  9108. case ConfigurationStatus_Rejected:
  9109. default:
  9110. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  9111. break;
  9112. }
  9113. }
  9114. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  9115. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  9116. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9117. {
  9118. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9119. SetOcppConnStatus(FALSE);
  9120. }
  9121. if(((strcmp(keystr,"FreeVend")==0) || (strcmp(keystr,"isEnableLocalPowerSharing")==0) || (strcmp(keystr,"PowerSharingServerIP")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  9122. {
  9123. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9124. }
  9125. return result;
  9126. }
  9127. int handleClearCacheRequest(char *uuid, char *payload)
  9128. {
  9129. mtrace();
  9130. int result = FAIL;
  9131. char comfirmstr[20];
  9132. char rmFileCmd[100]={0};
  9133. struct stat stats;
  9134. DEBUG_INFO("handleClearCacheRequest...\n");
  9135. stat("/Storage/OCPP", &stats);
  9136. // Check for directory existence
  9137. if (S_ISDIR(stats.st_mode) == 1)
  9138. {}
  9139. else
  9140. {
  9141. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9142. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9143. system(rmFileCmd);
  9144. }
  9145. if(OCPP_cleanLocalCache())
  9146. {
  9147. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  9148. }
  9149. else
  9150. {
  9151. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  9152. }
  9153. sendClearCacheConfirmation(uuid, comfirmstr);
  9154. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9155. return result;
  9156. }
  9157. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9158. {
  9159. mtrace();
  9160. int result = FAIL;
  9161. int resultRename;
  9162. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9163. char chargingProfilePurposeStr[26]={0};
  9164. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9165. char tempchargingProfilePurposeStr[26]={0};
  9166. char str[100]={0};
  9167. char fname[200]={0};
  9168. char comfirmstr[20]={0};
  9169. char word[1600]={0};
  9170. int clearflag = FALSE;
  9171. int chargingProfileIdIsNULL = FALSE;
  9172. int connectorIsNULL = FALSE;
  9173. int chargingProfilePurposeIsNULL = FALSE;
  9174. int stackLevelIsNULL = FALSE;
  9175. //int GotoEnd = FALSE;
  9176. FILE *fptr1, *fptr2;
  9177. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9178. int n_chargingProfile=0;
  9179. int isEmptyFile = FALSE;
  9180. char sLineWord[1600]={0};
  9181. char chargingProfiles[10][100]={0};
  9182. int ChargeProfileCount = 0;
  9183. int ch;
  9184. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9185. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9186. json_object *ClearChargingProfile;
  9187. ClearChargingProfile = json_tokener_parse(payload);
  9188. if(!is_error(ClearChargingProfile))
  9189. {
  9190. // Optional data
  9191. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  9192. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  9193. else
  9194. chargingProfileIdIsNULL = TRUE;
  9195. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  9196. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  9197. else
  9198. connectorIsNULL = TRUE;
  9199. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  9200. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  9201. else
  9202. chargingProfilePurposeIsNULL = TRUE;
  9203. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  9204. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  9205. else
  9206. stackLevelIsNULL = TRUE;
  9207. }
  9208. json_object_put(ClearChargingProfile);
  9209. if(connectorIdInt > 0)
  9210. {
  9211. if(chargingProfilePurposeIsNULL == TRUE)
  9212. {
  9213. int m = 0;
  9214. memset(fname, 0, ARRAY_SIZE(fname));
  9215. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9216. if((access(fname,F_OK))!=-1)
  9217. {
  9218. strcpy(chargingProfiles[m], fname);
  9219. m = m + 1;
  9220. }
  9221. memset(fname, 0, ARRAY_SIZE(fname));
  9222. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9223. if((access(fname,F_OK))!=-1)
  9224. {
  9225. strcpy(chargingProfiles[m], fname);
  9226. m = m + 1;
  9227. }
  9228. ChargeProfileCount = m;
  9229. }
  9230. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9231. {
  9232. //strcpy(fname, TxDefaultProfile_1_JSON);
  9233. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9234. if((access(fname,F_OK))!=-1)
  9235. {
  9236. strcpy(chargingProfiles[0], fname);
  9237. ChargeProfileCount = 1;
  9238. }
  9239. }
  9240. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9241. {
  9242. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9243. if((access(fname,F_OK))!=-1)
  9244. {
  9245. strcpy(chargingProfiles[0], fname);
  9246. ChargeProfileCount = 1;
  9247. }
  9248. //strcpy(fname, TxProfile_1_JSON);
  9249. }
  9250. }
  9251. else // Check all Charging Profiles
  9252. {
  9253. int i = 0;
  9254. char fnametemp[200]={0};
  9255. ChargeProfileCount = 0;
  9256. //Check ChargePointMaxProfile.json exit
  9257. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9258. {
  9259. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9260. i = i + 1;
  9261. }
  9262. //Check TxDefaultProfile_0.json exit
  9263. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9264. {
  9265. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9266. i = i + 1;
  9267. }
  9268. //Check TxDefaultProfile_%d.json
  9269. for(int j=1; j <= gunTotalNumber; j++)
  9270. {
  9271. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9272. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9273. if((access(fnametemp,F_OK))!=-1)
  9274. {
  9275. strcpy(chargingProfiles[i], fnametemp);
  9276. i = i + 1;
  9277. }
  9278. }
  9279. //Check TxProfile_%d.json
  9280. for(int j=1; j <= gunTotalNumber; j++)
  9281. {
  9282. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9283. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9284. if((access(fnametemp,F_OK))!=-1)
  9285. {
  9286. strcpy(chargingProfiles[i], fnametemp);
  9287. i = i + 1;
  9288. }
  9289. }
  9290. ChargeProfileCount = i;
  9291. }// End connectorIsNULL is TRUE
  9292. if(ChargeProfileCount == 0)
  9293. {
  9294. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9295. goto end;
  9296. }
  9297. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9298. {
  9299. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9300. goto end;
  9301. }
  9302. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9303. {
  9304. memset(str, 0, ARRAY_SIZE(str));
  9305. // clear temp file
  9306. sprintf(str,"rm -f %s",temp);
  9307. system(str);
  9308. for(int k=0; k < ChargeProfileCount; k++)
  9309. {
  9310. memset(str, 0, ARRAY_SIZE(str));
  9311. //clear file in C
  9312. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9313. system(str);
  9314. }
  9315. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9316. goto end;
  9317. }
  9318. else if(connectorIsNULL == TRUE)
  9319. {
  9320. for(int k=0; k < ChargeProfileCount; k++)
  9321. {
  9322. fptr1 = fopen(chargingProfiles[k], "r");
  9323. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9324. //Check Charging Profile Count
  9325. while(fscanf(fptr1, "%s", word) != EOF)
  9326. {
  9327. //DEBUG_INFO("word=%s\n",word);
  9328. if(strstr(word, "chargingProfileId")!= NULL)
  9329. {
  9330. //DEBUG_INFO("test chargingProfileId \n");
  9331. n_chargingProfile = n_chargingProfile + 1;
  9332. //DEBUG_INFO("chargingProfileId Found\n");
  9333. }
  9334. }
  9335. rewind(fptr1);
  9336. //search Charging Profile Element
  9337. //int i= 0;
  9338. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9339. {
  9340. json_object *tmpProfilee;
  9341. tmpProfilee = json_tokener_parse(sLineWord);
  9342. if(!is_error(tmpProfilee))
  9343. {
  9344. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9345. {
  9346. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9347. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9348. }
  9349. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9350. {
  9351. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9352. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9353. }
  9354. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9355. {
  9356. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9357. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9358. }
  9359. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9360. {
  9361. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9362. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9363. }
  9364. }
  9365. json_object_put(tmpProfilee);
  9366. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9367. {
  9368. //------- not write to fptr2-------//
  9369. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9370. //clearflag = TRUE;
  9371. }
  9372. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9373. {
  9374. //------- not write to fptr2-------//
  9375. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9376. }
  9377. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9378. {
  9379. //------- not write to fptr2-------//
  9380. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9381. }
  9382. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9383. {
  9384. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9385. }
  9386. else
  9387. {
  9388. fprintf(fptr2, sLineWord);//writing data into file
  9389. }
  9390. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9391. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9392. if(clearflag == TRUE)
  9393. {
  9394. fclose(fptr1);
  9395. fclose(fptr2);
  9396. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9397. system(str);
  9398. // clear temp file
  9399. sprintf(str,"rm -f %s",temp);
  9400. system(str);
  9401. }
  9402. else
  9403. {
  9404. fclose(fptr1);
  9405. fclose(fptr2);
  9406. memset(str, 0, ARRAY_SIZE(str));
  9407. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9408. system(str);
  9409. resultRename = rename(temp, chargingProfiles[k]);
  9410. if(resultRename == 0)
  9411. {
  9412. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9413. }
  9414. else
  9415. {
  9416. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9417. }
  9418. if(comfirmstr[0]== 0)
  9419. {
  9420. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9421. }
  9422. //Check chargingProfile is empty file
  9423. /*------ Read the file ----------------*/
  9424. fptr1=fopen(chargingProfiles[k],"r");
  9425. ch=fgetc(fptr1);
  9426. rewind(fptr1);
  9427. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9428. if(ch!=EOF)
  9429. {
  9430. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9431. {
  9432. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9433. if(sLineWord[0]=='\0')
  9434. {
  9435. isEmptyFile = TRUE;
  9436. break;
  9437. }
  9438. else
  9439. {
  9440. isEmptyFile = FALSE;
  9441. break;
  9442. }
  9443. }
  9444. }
  9445. else
  9446. isEmptyFile = TRUE;
  9447. fclose(fptr1);
  9448. if(isEmptyFile == TRUE)
  9449. {
  9450. memset(str, 0, ARRAY_SIZE(str));
  9451. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9452. system(str);
  9453. }
  9454. }
  9455. }// End of while(int k=0; k < ChargePointCount; k++)
  9456. }
  9457. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9458. {
  9459. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9460. for(int k=0; k < ChargeProfileCount; k++)
  9461. {
  9462. fptr1 = fopen(chargingProfiles[k], "r");
  9463. fptr2 = fopen(temp, "w+");
  9464. //Check Charging Profile Count
  9465. while(fscanf(fptr1, "%s", word) != EOF)
  9466. {
  9467. //DEBUG_INFO("word=%s\n",word);
  9468. if(strstr(word, "chargingProfileId")!= NULL)
  9469. {
  9470. n_chargingProfile = n_chargingProfile + 1;
  9471. }
  9472. }
  9473. rewind(fptr1);
  9474. //search Charging Profile Element
  9475. //int i= 0;
  9476. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9477. {
  9478. json_object *tmpProfilee;
  9479. tmpProfilee = json_tokener_parse(sLineWord);
  9480. if(!is_error(tmpProfilee))
  9481. {
  9482. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  9483. {
  9484. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  9485. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  9486. }
  9487. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  9488. {
  9489. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  9490. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  9491. }
  9492. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  9493. {
  9494. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  9495. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  9496. }
  9497. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9498. {
  9499. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  9500. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  9501. }
  9502. }
  9503. json_object_put(tmpProfilee);
  9504. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9505. {
  9506. //------- not write to fptr2-------//
  9507. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9508. //clearflag = TRUE;
  9509. }
  9510. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9511. {
  9512. //------- not write to fptr2-------//
  9513. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9514. }
  9515. else if(stackLevelIsNULL == TRUE)
  9516. {
  9517. //Clear Whole File
  9518. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  9519. clearflag = TRUE;
  9520. break;
  9521. }
  9522. else
  9523. {
  9524. fprintf(fptr2, sLineWord);//writing data into file
  9525. }
  9526. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9527. }
  9528. if(clearflag == TRUE)
  9529. {
  9530. fclose(fptr1);
  9531. fclose(fptr2);
  9532. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9533. system(str);
  9534. // clear temp file
  9535. sprintf(str,"rm -f %s",temp);
  9536. system(str);
  9537. }
  9538. else
  9539. {
  9540. fclose(fptr1);
  9541. fclose(fptr2);
  9542. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9543. system(str);
  9544. resultRename = rename(temp, chargingProfiles[k]);
  9545. if(resultRename == 0)
  9546. {
  9547. DEBUG_INFO("File ChargingProfile renamed successfully");
  9548. }
  9549. else
  9550. {
  9551. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  9552. }
  9553. if(comfirmstr[0]== 0)
  9554. {
  9555. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  9556. }
  9557. //Check chargingProfile is empty file
  9558. /*------ Read the file ----------------*/
  9559. fptr1=fopen(chargingProfiles[k],"r");
  9560. ch=fgetc(fptr1);
  9561. rewind(fptr1);
  9562. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9563. if(ch!=EOF)
  9564. {
  9565. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9566. {
  9567. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9568. if(sLineWord[0]=='\0')
  9569. {
  9570. isEmptyFile = TRUE;
  9571. break;
  9572. }
  9573. else
  9574. {
  9575. isEmptyFile = FALSE;
  9576. break;
  9577. }
  9578. }
  9579. }
  9580. else
  9581. isEmptyFile = TRUE;
  9582. fclose(fptr1);
  9583. if(isEmptyFile == TRUE)
  9584. {
  9585. memset(str, 0, ARRAY_SIZE(str));
  9586. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9587. system(str);
  9588. }
  9589. /*------- End of reading ---------------*/
  9590. }
  9591. } // while(int k=0; k < ChargeProfileCount; k++)
  9592. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  9593. end:
  9594. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  9595. {
  9596. if(connectorIdInt == 0)
  9597. {
  9598. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9599. {
  9600. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  9601. }
  9602. }
  9603. else
  9604. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  9605. }
  9606. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  9607. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9608. return result;
  9609. }
  9610. void createFirmwareVersionByDataTransfer(void)
  9611. {
  9612. json_object *FirmwareDataTransfer = json_object_new_object();
  9613. // AC & DC model
  9614. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  9615. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  9616. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  9617. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  9618. // DC model
  9619. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  9620. {
  9621. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  9622. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  9623. (gunType[3] != GUN_TYPE_UNKNOWN))
  9624. {
  9625. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  9626. }
  9627. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  9628. {
  9629. // DS DM DW
  9630. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9631. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9632. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  9633. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  9634. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9635. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9636. }
  9637. else
  9638. {
  9639. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  9640. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  9641. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  9642. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  9643. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  9644. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  9645. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  9646. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  9647. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  9648. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  9649. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  9650. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  9651. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  9652. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  9653. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  9654. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  9655. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  9656. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  9657. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  9658. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  9659. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  9660. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  9661. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  9662. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  9663. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  9664. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  9665. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  9666. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  9667. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9668. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9669. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9670. }
  9671. }
  9672. // 4G model
  9673. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9674. {
  9675. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9676. }
  9677. sprintf((char*)ShmOCPP16Data->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9678. json_object_put(FirmwareDataTransfer);
  9679. }
  9680. int handleDataTransferRequest(char *uuid, char *payload)
  9681. {
  9682. mtrace();
  9683. json_object *response = json_object_new_object();
  9684. int result = FAIL;
  9685. char tempvendorId[255]={0};
  9686. char tempmessageId[50]={0};
  9687. char tempdata[10240]={0};
  9688. char message[20480]={0};
  9689. DEBUG_INFO("handleDataTransferRequest...\n");
  9690. if((uuid != NULL) && (payload != NULL))
  9691. {
  9692. json_object *DataTransfer;
  9693. DataTransfer = json_tokener_parse(payload);
  9694. if(!is_error(DataTransfer))
  9695. {
  9696. // Required data
  9697. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9698. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9699. // Optional data
  9700. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9701. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9702. if(json_object_object_get(DataTransfer, "data") != NULL)
  9703. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9704. result = PASS;
  9705. }
  9706. json_object_put(DataTransfer);
  9707. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9708. {
  9709. // Send all moudle firmware version on EVSE
  9710. createFirmwareVersionByDataTransfer();
  9711. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9712. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  9713. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9714. json_object_put(response);
  9715. }
  9716. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9717. {
  9718. system("/usr/bin/run_tmate_restart.sh &");
  9719. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9720. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9721. json_object_put(response);
  9722. }
  9723. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9724. {
  9725. json_object *data;
  9726. data = json_tokener_parse(tempdata);
  9727. if(!is_error(data))
  9728. {
  9729. 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))
  9730. {
  9731. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9732. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9733. if(json_object_object_get(data, "SOC") != NULL)
  9734. {
  9735. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9736. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9737. }
  9738. if(json_object_object_get(data, "Energy") != NULL)
  9739. {
  9740. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9741. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9742. }
  9743. if(json_object_object_get(data, "Duration") != NULL)
  9744. {
  9745. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))-1].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9746. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9747. }
  9748. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9749. }
  9750. else
  9751. {
  9752. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9753. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9754. }
  9755. }
  9756. else
  9757. {
  9758. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9759. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9760. }
  9761. json_object_put(data);
  9762. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9763. json_object_put(response);
  9764. }
  9765. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9766. {
  9767. json_object *data;
  9768. data = json_tokener_parse(tempdata);
  9769. if(!is_error(data))
  9770. {
  9771. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9772. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9773. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9774. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9775. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9776. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9777. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9778. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9779. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9780. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9781. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9782. }
  9783. else
  9784. {
  9785. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9786. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9787. }
  9788. json_object_put(data);
  9789. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9790. json_object_put(response);
  9791. }
  9792. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9793. {
  9794. json_object *data;
  9795. data = json_tokener_parse(tempdata);
  9796. if(!is_error(data))
  9797. {
  9798. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9799. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9800. if(json_object_object_get(data, "idToken") != NULL)
  9801. {
  9802. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9803. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9804. }
  9805. else
  9806. {
  9807. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9808. json_object_object_add(response, "data", json_object_new_string("idToken not found."));
  9809. }
  9810. if(json_object_object_get(data, "price") != NULL) //v1.0
  9811. {
  9812. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9813. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9814. }
  9815. else if(json_object_object_get(data, "priceText") != NULL) //v2.0
  9816. {
  9817. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  9818. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  9819. }
  9820. else
  9821. {
  9822. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9823. json_object_object_add(response, "data", json_object_new_string("price or priceText not found."));
  9824. }
  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("Configuration content something wrong."));
  9830. }
  9831. json_object_put(data);
  9832. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9833. json_object_put(response);
  9834. }
  9835. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9836. {
  9837. json_object *data;
  9838. data = json_tokener_parse(tempdata);
  9839. if(!is_error(data))
  9840. {
  9841. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9842. if(json_object_object_get(data, "txId") != NULL)
  9843. {
  9844. // California pricing V1.0
  9845. DEBUG_INFO("California pricing V1.0\n");
  9846. DEBUG_INFO("txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9847. sprintf((char*)dmsVersion, "1.0");
  9848. for(int idx = 0;idx<gunTotalNumber;idx++)
  9849. {
  9850. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9851. {
  9852. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9853. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9854. if(json_object_object_get(data, "description") != NULL)
  9855. {
  9856. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9857. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9858. }
  9859. else
  9860. {
  9861. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9862. json_object_object_add(response, "data", json_object_new_string("description not found."));
  9863. }
  9864. }
  9865. }
  9866. }
  9867. else if(json_object_object_get(data, "transactionId") != NULL)
  9868. {
  9869. // California pricing V2.0
  9870. DEBUG_INFO("California pricing V2.0\n");
  9871. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  9872. sprintf((char*)dmsVersion, "2.0");
  9873. for(int idx=0;idx<gunTotalNumber;idx++)
  9874. {
  9875. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  9876. {
  9877. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  9878. if(json_object_object_get(data, "timestamp") != NULL)
  9879. {
  9880. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9881. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9882. }
  9883. else
  9884. {
  9885. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9886. json_object_object_add(response, "data", json_object_new_string("timestamp not found."));
  9887. }
  9888. if(json_object_object_get(data, "meterValue") != NULL)
  9889. {
  9890. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9891. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9892. }
  9893. else
  9894. {
  9895. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9896. json_object_object_add(response, "data", json_object_new_string("meterValue not found."));
  9897. }
  9898. if(json_object_object_get(data, "cost") != NULL)
  9899. {
  9900. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9901. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9902. }
  9903. else
  9904. {
  9905. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9906. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  9907. }
  9908. if(json_object_object_get(data, "state") != NULL)
  9909. {
  9910. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9911. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9912. }
  9913. else
  9914. {
  9915. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9916. json_object_object_add(response, "data", json_object_new_string("state not found."));
  9917. }
  9918. if(json_object_object_get(data, "chargingPrice") != NULL)
  9919. {
  9920. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9921. {
  9922. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9923. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9924. }
  9925. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9926. {
  9927. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9928. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9929. }
  9930. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9931. {
  9932. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9933. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9934. }
  9935. }
  9936. else
  9937. {
  9938. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9939. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9940. }
  9941. if(json_object_object_get(data, "idlePrice") != NULL)
  9942. {
  9943. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9944. {
  9945. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9946. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9947. }
  9948. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9949. {
  9950. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9951. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9952. }
  9953. }
  9954. if(json_object_object_get(data, "nextPeriod") != NULL)
  9955. {
  9956. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9957. {
  9958. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9959. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9960. }
  9961. else
  9962. {
  9963. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9964. json_object_object_add(response, "data", json_object_new_string("atTime not found."));
  9965. }
  9966. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9967. {
  9968. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9969. {
  9970. 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")));
  9971. 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"));
  9972. }
  9973. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9974. {
  9975. 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")));
  9976. 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"));
  9977. }
  9978. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9979. {
  9980. 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")));
  9981. 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"));
  9982. }
  9983. }
  9984. else
  9985. {
  9986. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9987. json_object_object_add(response, "data", json_object_new_string("chargingPrice not found."));
  9988. }
  9989. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9990. {
  9991. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9992. {
  9993. 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")));
  9994. 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"));
  9995. }
  9996. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9997. {
  9998. 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")));
  9999. 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"));
  10000. }
  10001. }
  10002. }
  10003. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  10004. {
  10005. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  10006. {
  10007. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10008. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  10009. }
  10010. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  10011. {
  10012. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  10013. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  10014. }
  10015. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  10016. {
  10017. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  10018. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  10019. }
  10020. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus") != NULL)
  10021. {
  10022. DEBUG_INFO("triggerMeterValue-atCPStatus: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10023. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atCPStatus, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atCPStatus")));
  10024. }
  10025. }
  10026. }
  10027. }
  10028. }
  10029. else
  10030. {
  10031. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10032. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10033. }
  10034. }
  10035. else
  10036. {
  10037. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10038. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10039. }
  10040. json_object_put(data);
  10041. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10042. json_object_put(response);
  10043. }
  10044. else if(strstr(tempmessageId, "FinalCost") != NULL)
  10045. {
  10046. json_object *data;
  10047. data = json_tokener_parse(tempdata);
  10048. if(!is_error(data))
  10049. {
  10050. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10051. if(json_object_object_get(data, "txId") != NULL)
  10052. {
  10053. DEBUG_INFO("v1.0 txId: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  10054. for(int idx = 0;idx<gunTotalNumber;idx++)
  10055. {
  10056. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10057. {
  10058. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10059. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  10060. if(json_object_object_get(data, "description") != NULL)
  10061. {
  10062. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  10063. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  10064. }
  10065. else
  10066. {
  10067. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10068. json_object_object_add(response, "data", json_object_new_string("description not found."));
  10069. }
  10070. }
  10071. }
  10072. }
  10073. else if(json_object_object_get(data, "transactionId") != NULL)
  10074. {
  10075. DEBUG_INFO("v2.0 transactionId: %d\n", json_object_get_int(json_object_object_get(data, "transactionId")));
  10076. for(int idx = 0;idx<gunTotalNumber;idx++)
  10077. {
  10078. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "transactionId")))
  10079. {
  10080. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  10081. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "transactionId"));
  10082. if(json_object_object_get(data, "cost") != NULL)
  10083. {
  10084. DEBUG_INFO("cost: %s\n", json_object_get_string(json_object_object_get(data, "cost")));
  10085. ShmOCPP16Data->Cost.FinalCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  10086. }
  10087. else
  10088. {
  10089. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10090. json_object_object_add(response, "data", json_object_new_string("cost not found."));
  10091. }
  10092. if(json_object_object_get(data, "priceText") != NULL)
  10093. {
  10094. DEBUG_INFO("priceText: %s\n", json_object_get_string(json_object_object_get(data, "priceText")));
  10095. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].priceText, "%s", json_object_get_string(json_object_object_get(data, "priceText")));
  10096. }
  10097. else
  10098. {
  10099. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10100. json_object_object_add(response, "data", json_object_new_string("priceText not found."));
  10101. }
  10102. if(json_object_object_get(data, "qrCodeText") != NULL)
  10103. {
  10104. DEBUG_INFO(": %s\n", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10105. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].qrCodeText, "%s", json_object_get_string(json_object_object_get(data, "qrCodeText")));
  10106. }
  10107. }
  10108. }
  10109. }
  10110. else
  10111. {
  10112. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10113. json_object_object_add(response, "data", json_object_new_string("txId or transactionId not found."));
  10114. }
  10115. }
  10116. else
  10117. {
  10118. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10119. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10120. }
  10121. json_object_put(data);
  10122. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10123. json_object_put(response);
  10124. }
  10125. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  10126. {
  10127. json_object *data;
  10128. data = json_tokener_parse(tempdata);
  10129. if(!is_error(data))
  10130. {
  10131. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10132. if(json_object_object_get(data, "Content_Type") != NULL)
  10133. {
  10134. 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))
  10135. {
  10136. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10137. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10138. {
  10139. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10140. }
  10141. }
  10142. else
  10143. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10144. }
  10145. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10146. }
  10147. else
  10148. {
  10149. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10150. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10151. }
  10152. json_object_put(data);
  10153. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10154. json_object_put(response);
  10155. }
  10156. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  10157. {
  10158. json_object *data;
  10159. data = json_tokener_parse(tempdata);
  10160. if(!is_error(data))
  10161. {
  10162. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10163. if(json_object_object_get(data, "ConnectorId") != NULL)
  10164. {
  10165. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  10166. }
  10167. if(json_object_object_get(data, "SerialNo") != NULL)
  10168. {
  10169. sprintf((char *)ShmOCPP16Data->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  10170. }
  10171. if(json_object_object_get(data, "Page_Index") != NULL)
  10172. {
  10173. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10174. }
  10175. if(json_object_object_get(data, "Duration") != NULL)
  10176. {
  10177. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10178. }
  10179. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  10180. }
  10181. else
  10182. {
  10183. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10184. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10185. }
  10186. json_object_put(data);
  10187. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10188. json_object_put(response);
  10189. }
  10190. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  10191. {
  10192. json_object *data;
  10193. data = json_tokener_parse(tempdata);
  10194. if(!is_error(data))
  10195. {
  10196. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10197. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10198. {
  10199. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10200. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10201. else
  10202. {
  10203. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10204. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10205. }
  10206. }
  10207. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10208. {
  10209. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10210. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10211. else
  10212. {
  10213. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10214. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10215. }
  10216. }
  10217. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10218. {
  10219. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10220. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10221. else
  10222. {
  10223. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10224. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10225. }
  10226. }
  10227. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10228. {
  10229. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10230. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10231. else
  10232. {
  10233. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10234. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10235. }
  10236. }
  10237. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10238. {
  10239. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10240. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10241. else
  10242. {
  10243. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10244. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10245. }
  10246. }
  10247. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10248. {
  10249. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10250. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10251. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10252. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10253. else
  10254. {
  10255. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10256. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10257. }
  10258. }
  10259. if(json_object_object_get(data, "isAuthentication") != NULL)
  10260. {
  10261. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  10262. {
  10263. case 0:
  10264. case 1:
  10265. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  10266. break;
  10267. default:
  10268. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10269. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10270. break;
  10271. }
  10272. }
  10273. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  10274. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10275. }
  10276. else
  10277. {
  10278. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10279. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10280. }
  10281. json_object_put(data);
  10282. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10283. json_object_put(response);
  10284. }
  10285. else if(strstr(tempmessageId, "ID_TxEnergy") != NULL)
  10286. {
  10287. json_object *data;
  10288. data = json_tokener_parse(tempdata);
  10289. if(!is_error(data))
  10290. {
  10291. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10292. {
  10293. if(OCPP_getPeriodEnergyToDataTransfer(json_object_get_int(json_object_object_get(data, "txId"))) == PASS)
  10294. {
  10295. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10296. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].ResponseData));
  10297. }
  10298. else
  10299. {
  10300. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10301. json_object_object_add(response, "data", json_object_new_string("Present charged energy data can not get."));
  10302. }
  10303. }
  10304. else
  10305. {
  10306. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10307. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10308. }
  10309. }
  10310. else
  10311. {
  10312. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10313. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10314. }
  10315. json_object_put(data);
  10316. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10317. json_object_put(response);
  10318. }
  10319. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  10320. {
  10321. json_object *data;
  10322. data = json_tokener_parse(tempdata);
  10323. if(!is_error(data))
  10324. {
  10325. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10326. if(json_object_object_get(data, "stationName") != NULL)
  10327. {
  10328. sprintf((char *)ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  10329. }
  10330. else
  10331. {
  10332. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10333. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  10334. }
  10335. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10336. {
  10337. ShmOCPP16Data->TcciCustomData.ChargerInfoReq = 1;
  10338. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  10339. ShmOCPP16Data->TcciCustomData.ChargerInfo.station_name);
  10340. }
  10341. }
  10342. else
  10343. {
  10344. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10345. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10346. }
  10347. json_object_put(data);
  10348. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10349. json_object_put(response);
  10350. }
  10351. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  10352. {
  10353. json_object *data;
  10354. data = json_tokener_parse(tempdata);
  10355. if(!is_error(data))
  10356. {
  10357. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10358. if(json_object_object_get(data, "weatherId") != NULL)
  10359. {
  10360. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  10361. }
  10362. else
  10363. {
  10364. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10365. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  10366. }
  10367. if(json_object_object_get(data, "Temperature") != NULL)
  10368. {
  10369. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  10370. }
  10371. else
  10372. {
  10373. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10374. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  10375. }
  10376. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10377. {
  10378. ShmOCPP16Data->TcciCustomData.WeatherInfoReq = 1;
  10379. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  10380. ShmOCPP16Data->TcciCustomData.WeatherInfo.weatherId,
  10381. ShmOCPP16Data->TcciCustomData.WeatherInfo.temperature
  10382. );
  10383. }
  10384. }
  10385. else
  10386. {
  10387. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10388. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  10389. }
  10390. json_object_put(data);
  10391. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10392. json_object_put(response);
  10393. }
  10394. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  10395. {
  10396. json_object *data;
  10397. data = json_tokener_parse(tempdata);
  10398. if(!is_error(data))
  10399. {
  10400. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10401. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  10402. {
  10403. ShmOCPP16Data->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  10404. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  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("ConnectorId does not valid."));
  10410. }
  10411. }
  10412. else
  10413. {
  10414. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10415. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  10416. }
  10417. json_object_put(data);
  10418. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10419. json_object_put(response);
  10420. }
  10421. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  10422. {
  10423. json_object *data;
  10424. data = json_tokener_parse(tempdata);
  10425. if(!is_error(data))
  10426. {
  10427. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  10428. {
  10429. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10430. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10431. if(gun_index < gunTotalNumber)
  10432. {
  10433. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  10434. {
  10435. json_object *responsedata = json_object_new_object();
  10436. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId));
  10437. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  10438. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.SerialNo[gun_index]));
  10439. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  10440. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  10441. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10442. }
  10443. else
  10444. {
  10445. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10446. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  10447. }
  10448. }
  10449. else
  10450. {
  10451. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10452. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  10453. }
  10454. }
  10455. else
  10456. {
  10457. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10458. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10459. }
  10460. }
  10461. else
  10462. {
  10463. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10464. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  10465. }
  10466. json_object_put(data);
  10467. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10468. json_object_put(response);
  10469. }
  10470. else if(strstr(tempmessageId, "ID_OccupancyFeeDisplay") != NULL)
  10471. {
  10472. json_object *data;
  10473. data = json_tokener_parse(tempdata);
  10474. if(!is_error(data))
  10475. {
  10476. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10477. int gun_index = 0;
  10478. if(json_object_object_get(data, "ConnectorId") != NULL)
  10479. {
  10480. gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  10481. if(json_object_object_get(data, "occupancySN") != NULL)
  10482. {
  10483. sprintf((char *)ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].occupancySN, "%s", json_object_get_string(json_object_object_get(data,"occupancySN")));
  10484. }
  10485. else
  10486. {
  10487. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10488. json_object_object_add(response, "data", json_object_new_string("occupancySN data can not get."));
  10489. }
  10490. if(json_object_object_get(data, "actionId") != NULL)
  10491. {
  10492. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].actionId = json_object_get_int(json_object_object_get(data,"actionId"));
  10493. }
  10494. else
  10495. {
  10496. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10497. json_object_object_add(response, "data", json_object_new_string("actionId data can not get."));
  10498. }
  10499. }
  10500. else
  10501. {
  10502. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10503. json_object_object_add(response, "data", json_object_new_string("ConnectorId data can not get."));
  10504. }
  10505. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10506. {
  10507. ShmOCPP16Data->TcciCustomData.OccupancyFeeDisplay[gun_index].OccupancyFeeDisplayReq = 1;
  10508. }
  10509. }
  10510. else
  10511. {
  10512. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10513. json_object_object_add(response, "data", json_object_new_string("OccupancyFeeDisplay content got something wrong."));
  10514. }
  10515. json_object_put(data);
  10516. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10517. json_object_put(response);
  10518. }
  10519. else if(strstr(tempmessageId, "ID_SetOccupancyPrice") != NULL)
  10520. {
  10521. json_object *data;
  10522. data = json_tokener_parse(tempdata);
  10523. if(!is_error(data))
  10524. {
  10525. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10526. if(json_object_object_get(data, "price") != NULL)
  10527. {
  10528. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.price = json_object_get_double(json_object_object_get(data,"price"));
  10529. }
  10530. else
  10531. {
  10532. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10533. json_object_object_add(response, "data", json_object_new_string("price data can not get."));
  10534. }
  10535. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  10536. {
  10537. ShmOCPP16Data->TcciCustomData.SetOccupancyPrice.SetOccupancyPriceReq = 1;
  10538. }
  10539. }
  10540. else
  10541. {
  10542. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10543. json_object_object_add(response, "data", json_object_new_string("SetOccupancyPrice content got something wrong."));
  10544. }
  10545. json_object_put(data);
  10546. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10547. json_object_put(response);
  10548. }
  10549. // Support ISO-15118 related message
  10550. else if(strstr(tempmessageId, "TriggerMessage") != NULL)
  10551. {
  10552. char cmdBuf[1024]={0};
  10553. 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);
  10554. system(cmdBuf);
  10555. ShmOCPP16Data->v2g_extend.SignCertificateReq = 1;
  10556. json_object *responsedata = json_object_new_object();
  10557. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10558. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10559. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10560. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10561. json_object_put(response);
  10562. }
  10563. else if(strstr(tempmessageId, "CertificateSigned") != NULL)
  10564. {
  10565. json_object *data;
  10566. data = json_tokener_parse(tempdata);
  10567. if(!is_error(data))
  10568. {
  10569. FILE *fp = fopen(CERTIFICATE_V2G, "w");
  10570. fprintf(fp, "%s", json_object_get_string(json_object_object_get(data, "certificateChain")));
  10571. fclose(fp);
  10572. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10573. json_object *responsedata = json_object_new_object();
  10574. if(certVerify(PRIVATE_KEY_V2G, CERTIFICATE_V2G) == PASS)
  10575. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10576. else
  10577. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10578. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10579. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10580. }
  10581. else
  10582. {
  10583. json_object *responsedata = json_object_new_object();
  10584. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10585. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10586. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10587. }
  10588. json_object_put(data);
  10589. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10590. json_object_put(response);
  10591. }
  10592. else if(strstr(tempmessageId, "DeleteCertificate") != NULL)
  10593. {
  10594. json_object *data;
  10595. data = json_tokener_parse(tempdata);
  10596. DEBUG_INFO("DeleteCertificate processing...\n");
  10597. if(!is_error(data))
  10598. {
  10599. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm") != NULL)
  10600. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "hashAlgorithm")));
  10601. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash") != NULL)
  10602. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerNameHash")));
  10603. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash") != NULL)
  10604. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "issuerKeyHash")));
  10605. if(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber") != NULL)
  10606. sprintf((char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "certificateHashData"), "serialNumber")));
  10607. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.hashAlgorithm);
  10608. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash);
  10609. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash);
  10610. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber);
  10611. char temp[256] = {0};
  10612. char compareData[256] = {0};
  10613. int isMatch = TRUE;
  10614. // Check certV2G
  10615. if(access(CERTIFICATE_V2G,F_OK) != -1)
  10616. {
  10617. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, compareData);
  10618. if(strcmp(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.serialNumber) != 0)
  10619. isMatch = FALSE;
  10620. if(isMatch == TRUE)
  10621. {
  10622. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, compareData);
  10623. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  10624. isMatch = FALSE;
  10625. }
  10626. if(isMatch == TRUE)
  10627. {
  10628. parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  10629. if(strstr(compareData, (char*)ShmOCPP16Data->v2g_extend.DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  10630. isMatch = FALSE;
  10631. }
  10632. if(isMatch == TRUE)
  10633. {
  10634. sprintf(temp, "rm -f %s", CERTIFICATE_V2G);
  10635. system(temp);
  10636. json_object *responsedata = json_object_new_object();
  10637. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10638. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10639. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10640. }
  10641. else
  10642. {
  10643. json_object *responsedata = json_object_new_object();
  10644. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10645. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10646. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10647. }
  10648. }
  10649. else
  10650. {
  10651. json_object *responsedata = json_object_new_object();
  10652. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10653. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10654. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10655. }
  10656. }
  10657. else
  10658. {
  10659. json_object *responsedata = json_object_new_object();
  10660. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10661. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10662. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10663. }
  10664. json_object_put(data);
  10665. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10666. json_object_put(response);
  10667. }
  10668. else if(strstr(tempmessageId, "GetInstalledCertificateIds") != NULL)
  10669. {
  10670. json_object *data;
  10671. data = json_tokener_parse(tempdata);
  10672. if(!is_error(data))
  10673. {
  10674. /*
  10675. * TODO:
  10676. * 1. Query certificate to response
  10677. */
  10678. json_object *responsedata = json_object_new_object();
  10679. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10680. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10681. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10682. }
  10683. else
  10684. {
  10685. json_object *responsedata = json_object_new_object();
  10686. json_object_object_add(responsedata, "status", json_object_new_string("NotFound"));
  10687. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10688. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10689. }
  10690. json_object_put(data);
  10691. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10692. json_object_put(response);
  10693. }
  10694. else if(strstr(tempmessageId, "InstallCertificate") != NULL)
  10695. {
  10696. json_object *data;
  10697. data = json_tokener_parse(tempdata);
  10698. if(!is_error(data))
  10699. {
  10700. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  10701. if(json_object_object_get(data, "certificateType") != NULL)
  10702. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(data, "certificateType")));
  10703. if(json_object_object_get(data, "certificate") != NULL)
  10704. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(data, "certificate")));
  10705. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType);
  10706. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10707. char temp[1024];
  10708. FILE *fp = fopen(tempCert, "w");
  10709. fprintf(fp, "%s", ShmOCPP16Data->v2g_extend.InstallCertificate.certificate);
  10710. fclose(fp);
  10711. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  10712. char strExpDate[30];
  10713. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  10714. fp = popen(temp, "r");
  10715. if(fp)
  10716. {
  10717. while(fgets(temp, sizeof(temp), fp) != NULL)
  10718. {
  10719. if(strstr(temp, "notAfter=") != NULL)
  10720. {
  10721. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  10722. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  10723. break;
  10724. }
  10725. }
  10726. }
  10727. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  10728. struct tm tmExpDate;
  10729. struct timeb tbExpDate;
  10730. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  10731. tbExpDate.time = mktime(&tmExpDate);
  10732. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  10733. {
  10734. DEBUG_INFO("The enddate is already expired...\n");
  10735. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Rejected");
  10736. }
  10737. else
  10738. sprintf((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted");
  10739. if(strcmp((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.Response_status, "Accepted") == 0)
  10740. {
  10741. if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "V2GRootCertificate") != NULL)
  10742. {
  10743. if(access(ROOTCA_V2G,F_OK) != -1)
  10744. {
  10745. DEBUG_INFO("Existed V2GRootCertificate is found. Replacing...\n");
  10746. rename(ROOTCA_V2G, "/Storage/rootCaV2g_fallback.pem");
  10747. rename(tempCert, ROOTCA_V2G);
  10748. }
  10749. else
  10750. {
  10751. DEBUG_INFO("No existed V2GRootCertificate. Creating...\n");
  10752. rename(tempCert, ROOTCA_V2G);
  10753. }
  10754. json_object *responsedata = json_object_new_object();
  10755. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10756. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10757. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10758. }
  10759. else if(strstr((char*)ShmOCPP16Data->v2g_extend.InstallCertificate.certificateType, "MORootCertificate") != NULL)
  10760. {
  10761. if(access(ROOTCA_MO,F_OK) != -1)
  10762. {
  10763. DEBUG_INFO("Existed MORootCertificate is found. Replacing...\n");
  10764. rename(ROOTCA_MO, "/Storage/rootCaMo_fallback.pem");
  10765. rename(tempCert, ROOTCA_MO);
  10766. }
  10767. else
  10768. {
  10769. DEBUG_INFO("No existed MORootCertificate. Creating...\n");
  10770. rename(tempCert, ROOTCA_MO);
  10771. }
  10772. json_object *responsedata = json_object_new_object();
  10773. json_object_object_add(responsedata, "status", json_object_new_string("Accepted"));
  10774. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10775. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10776. }
  10777. else
  10778. {
  10779. json_object *responsedata = json_object_new_object();
  10780. json_object_object_add(responsedata, "status", json_object_new_string("Failed"));
  10781. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10782. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10783. }
  10784. }
  10785. else
  10786. {
  10787. json_object *responsedata = json_object_new_object();
  10788. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10789. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10790. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  10791. }
  10792. }
  10793. else
  10794. {
  10795. json_object *responsedata = json_object_new_object();
  10796. json_object_object_add(responsedata, "status", json_object_new_string("Rejected"));
  10797. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  10798. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  10799. }
  10800. json_object_put(data);
  10801. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  10802. json_object_put(response);
  10803. }
  10804. else
  10805. {
  10806. // Can not find valid message id
  10807. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  10808. }
  10809. }
  10810. else
  10811. {
  10812. // Payload is null
  10813. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  10814. }
  10815. LWS_Send(message);
  10816. return result;
  10817. }
  10818. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10819. {
  10820. mtrace();
  10821. int result = FAIL;
  10822. int connectorIdInt, durationInt;
  10823. char chargingRateUnitStr[4]={0};
  10824. char comfirmstr[20];
  10825. int confirmPeriods = 0;
  10826. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10827. json_object *GetCompositeSchedule;
  10828. GetCompositeSchedule = json_tokener_parse(payload);
  10829. if(!is_error(GetCompositeSchedule))
  10830. {
  10831. // Required data
  10832. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  10833. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  10834. else
  10835. connectorIdInt = -1;
  10836. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10837. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10838. else
  10839. durationInt = 86400;
  10840. // Optional data
  10841. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10842. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10843. }
  10844. json_object_put(GetCompositeSchedule);
  10845. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10846. if((connectorIdInt == 0) ||
  10847. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10848. {
  10849. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10850. struct StructChargingProfile tmpProfile[1];
  10851. if(strstr(chargingRateUnitStr, "W") != NULL)
  10852. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  10853. else
  10854. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  10855. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10856. {
  10857. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10858. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10859. }
  10860. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  10861. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  10862. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  10863. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  10864. {
  10865. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  10866. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  10867. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  10868. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  10869. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  10870. {
  10871. confirmPeriods = idx;
  10872. break;
  10873. }
  10874. }
  10875. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  10876. {
  10877. confirmPeriods += 1;
  10878. }
  10879. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  10880. }
  10881. else
  10882. {
  10883. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  10884. }
  10885. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10886. return result;
  10887. }
  10888. int handleGetConfigurationRequest(char *uuid, char *payload)
  10889. {
  10890. mtrace();
  10891. int result = FAIL;
  10892. int MaxKeySupported = 0;
  10893. int n_keys = 0;
  10894. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  10895. DEBUG_INFO("handleGetConfigurationRequest...\n");
  10896. json_object *GetConfiguration;
  10897. GetConfiguration = json_tokener_parse(payload);
  10898. if(!is_error(GetConfiguration))
  10899. {
  10900. // Optional data
  10901. if(json_object_object_get(GetConfiguration, "key") != NULL)
  10902. {
  10903. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  10904. {
  10905. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  10906. n_keys = idx + 1;
  10907. }
  10908. }
  10909. }
  10910. json_object_put(GetConfiguration);
  10911. UnknownKeynum = 0;
  10912. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  10913. MaxKeySupported = GetConfigurationMaxKeysNUM;
  10914. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  10915. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  10916. if(n_keys != 0)
  10917. {
  10918. for(int i=0;i<n_keys;i++)
  10919. {
  10920. getKeyValue(requestKey[i]);
  10921. }
  10922. }
  10923. else
  10924. {
  10925. DEBUG_INFO("There is no key in Message, get all configuration\n");
  10926. getKeyValue("");
  10927. }
  10928. processUnkownKey();
  10929. sendGetConfigurationConfirmation(uuid);
  10930. return result;
  10931. }
  10932. static char fnamePlusPath[100]={0};
  10933. static char fnamePWithNoPath[60]={0};
  10934. void checkUploadLog(void)
  10935. {
  10936. FILE *fp;
  10937. /* Open the command for reading. */
  10938. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10939. if (fp == NULL) {
  10940. DEBUG_WARN("Failed to run command\n" );
  10941. exit(1);
  10942. }
  10943. int ftppathlen = 0;
  10944. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10945. int i = 0;
  10946. /* Read the output a line at a time - output it. */
  10947. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10948. if(i==0)
  10949. {
  10950. ftppathlen = strlen(fnamePlusPath);
  10951. DEBUG_INFO("%s\n", fnamePlusPath);
  10952. fnamePlusPath[ftppathlen]='\0';
  10953. break;
  10954. }
  10955. i= i+1;
  10956. }
  10957. /* close */
  10958. pclose(fp);
  10959. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10960. {
  10961. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  10962. {
  10963. fnamePlusPath[k]='\0';
  10964. }
  10965. }
  10966. i=1;
  10967. //char fname[60]={0};
  10968. while(i < ftppathlen)
  10969. {
  10970. int len=ftppathlen-i;
  10971. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10972. {
  10973. DEBUG_INFO("compare '/' all right\n");
  10974. break;
  10975. }
  10976. i=i+1;
  10977. }
  10978. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10979. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10980. fnamePWithNoPath[i+1] = '\0';
  10981. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10982. {
  10983. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10984. {
  10985. fnamePWithNoPath[j]='\0';
  10986. }
  10987. }
  10988. FILE* fp1 = fopen(fnamePlusPath, "r");
  10989. if (fp1)
  10990. {
  10991. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10992. // file exists
  10993. fclose(fp1);
  10994. }
  10995. else
  10996. {
  10997. // file doesn't exist
  10998. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10999. }
  11000. }
  11001. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  11002. {
  11003. mtrace();
  11004. int result = FAIL;
  11005. time_t CurrentTime;
  11006. struct tm *tm;
  11007. pthread_t th_Status;
  11008. CurrentTime = time(NULL);
  11009. tm = localtime(&CurrentTime);
  11010. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  11011. 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);
  11012. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11013. if(!interLock.isGetDiagnosticGoing)
  11014. {
  11015. interLock.isGetDiagnosticGoing = 1;
  11016. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, payload);
  11017. sleep(1);
  11018. }
  11019. else
  11020. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  11021. return result;
  11022. }
  11023. void* GetDiagnosticsProcess(void* data)
  11024. {
  11025. pthread_detach(pthread_self());
  11026. mtrace();
  11027. int retriesInt=0, retryIntervalInt=0;
  11028. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  11029. 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};
  11030. int port=0;
  11031. int isSuccess = FALSE;
  11032. char cmdBuf[2048];
  11033. struct tm *tmNow;
  11034. time_t CurrentTime;
  11035. struct tm tmStart;
  11036. struct tm tmStop;
  11037. CurrentTime = time(NULL);
  11038. tmNow=localtime(&CurrentTime);
  11039. uint16_t targetYear, targetMonth;
  11040. json_object *GetDiagnostics;
  11041. DEBUG_INFO("GetDiagnosticsProcess...\n");
  11042. GetDiagnostics = json_tokener_parse(data);
  11043. if(!is_error(GetDiagnostics))
  11044. {
  11045. // Required data
  11046. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  11047. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  11048. // Optional data
  11049. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  11050. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  11051. else
  11052. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11053. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  11054. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  11055. else
  11056. retryIntervalInt = 30;
  11057. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  11058. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  11059. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  11060. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  11061. }
  11062. json_object_put(GetDiagnostics);
  11063. // Notify CSU to get log of dispensers.
  11064. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  11065. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  11066. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  11067. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O') ||
  11068. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='L'))
  11069. )
  11070. {
  11071. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StartTime,"%s",startTimestr);
  11072. sprintf((char *)ShmOCPP16Data->GetDiagnostics.StopTime,"%s",stopTimestr);
  11073. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = TRUE;
  11074. struct timespec timerGetDiagnostics;
  11075. refreshStartTimer(&timerGetDiagnostics);
  11076. while(ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq != FALSE)
  11077. {
  11078. if(getDiffSecNow(timerGetDiagnostics)>=180)
  11079. {
  11080. ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = FALSE;
  11081. DEBUG_INFO("Waiting log of dispenser timeout.");
  11082. }
  11083. }
  11084. }
  11085. // Pack log to compress file
  11086. 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) &&
  11087. (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))
  11088. {
  11089. // Pack system log
  11090. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11091. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11092. targetYear = tmStart.tm_year;
  11093. targetMonth = tmStart.tm_mon;
  11094. do
  11095. {
  11096. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11097. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  11098. if(targetMonth+1>=13)
  11099. {
  11100. targetYear += 1;
  11101. targetMonth = 1;
  11102. }
  11103. else
  11104. {
  11105. targetMonth += 1;
  11106. }
  11107. }while((targetYear < (tmNow->tm_year+1900)) ||
  11108. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11109. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11110. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  11111. sprintf(cmdBuf, "%s /Storage/OCPP/TransactionRelatedQueue", cmdBuf);
  11112. sprintf(cmdBuf, "%s /Storage/OCPP/QueueTransactionId", cmdBuf);
  11113. sprintf(cmdBuf, "%s /Storage/OCPP/OCPPConfiguration", cmdBuf);
  11114. sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
  11115. system(cmdBuf);
  11116. // Pack charging & event log
  11117. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11118. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11119. targetYear = tmStart.tm_year;
  11120. targetMonth = tmStart.tm_mon;
  11121. do
  11122. {
  11123. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11124. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  11125. if(targetMonth+1>=13)
  11126. {
  11127. targetYear += 1;
  11128. targetMonth = 1;
  11129. }
  11130. else
  11131. {
  11132. targetMonth += 1;
  11133. }
  11134. }while((targetYear < (tmNow->tm_year+1900)) ||
  11135. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11136. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11137. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11138. system(cmdBuf);
  11139. // Combine log file
  11140. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11141. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11142. }
  11143. else
  11144. {
  11145. system("exec /root/logPackTools 'log' 6");
  11146. }
  11147. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  11148. system(cmdBuf);
  11149. checkUploadLog();
  11150. //****************location*******************/
  11151. if(strcmp(locationstr,"")==0)
  11152. {
  11153. DEBUG_INFO("location is <Empty>!\n");
  11154. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11155. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11156. goto end;
  11157. }
  11158. memset(protocol, 0, ARRAY_SIZE(protocol));
  11159. memset(user, 0, ARRAY_SIZE(user) );
  11160. memset(password, 0, ARRAY_SIZE(password));
  11161. memset(host, 0, ARRAY_SIZE(host));
  11162. memset(path, 0, ARRAY_SIZE(path));
  11163. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11164. memset(host1, 0, ARRAY_SIZE(host1));
  11165. memset(path1, 0, ARRAY_SIZE(path1));
  11166. /*location: ftp://user:password@host:port/path*/
  11167. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11168. if((access(fnamePlusPath,F_OK))!=-1)
  11169. {
  11170. DEBUG_INFO("fnamePlusPath exist.\n");
  11171. }
  11172. else
  11173. {
  11174. DEBUG_INFO("fnamePlusPath not exist!\n");
  11175. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11176. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11177. goto end;
  11178. }
  11179. if(strchr(locationstr,'@')==NULL)
  11180. {
  11181. sscanf(locationstr,
  11182. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11183. protocol, host, &port, path);
  11184. strcpy(user,"anonymous");
  11185. strcpy(password,"");
  11186. }
  11187. else
  11188. {
  11189. //DEBUG_INFO("pch=%s\n", pch);
  11190. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11191. protocol, user, password, host, &port, path);
  11192. }
  11193. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11194. {
  11195. DEBUG_INFO("protocol is not ftp/http ! \n");
  11196. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11197. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11198. goto end;
  11199. }
  11200. if(strncmp(locationstr,"http", 4) == 0)
  11201. {
  11202. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11203. sprintf(ftppath,"/%s", path);
  11204. do
  11205. {
  11206. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11207. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11208. sleep(3);
  11209. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  11210. if(!isSuccess)
  11211. {
  11212. DEBUG_INFO("Diagnostics fail.\n");
  11213. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11214. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11215. sleep(retryIntervalInt);
  11216. }
  11217. else
  11218. {
  11219. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11220. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11221. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11222. }
  11223. retriesInt--;
  11224. }while((isSuccess == 0)&&(retriesInt >= 0));
  11225. }
  11226. else
  11227. {
  11228. sscanf(host,"%[^/]%s",host1, path1);
  11229. if(strlen(path) > 0)
  11230. sprintf(ftppath,"/%s", path);
  11231. else
  11232. sprintf(ftppath,"/%s", path1);
  11233. int ftppathlen=strlen(ftppath);
  11234. int i=1;
  11235. char filenametemp[50];
  11236. while(i < ftppathlen)
  11237. {
  11238. int len=ftppathlen-i;
  11239. if(ftppath[len]== 47) // '/' ascll code: 47
  11240. {
  11241. DEBUG_INFO("find '/' all right\n");
  11242. break;
  11243. }
  11244. i=i+1;
  11245. }
  11246. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11247. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11248. filenametemp[i+1] = 0;
  11249. if(port == 0)
  11250. port = 21;
  11251. do
  11252. {
  11253. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  11254. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11255. sleep(3);
  11256. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11257. if(!isSuccess)
  11258. {
  11259. DEBUG_INFO("Diagnostics fail.\n");
  11260. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  11261. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11262. sleep(retryIntervalInt);
  11263. }
  11264. else
  11265. {
  11266. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  11267. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  11268. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11269. }
  11270. retriesInt--;
  11271. }while((!isSuccess)&&(retriesInt >= 0));
  11272. }
  11273. end:
  11274. system("rm -f /mnt/*");
  11275. system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
  11276. sleep(5);
  11277. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11278. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11279. interLock.isGetDiagnosticGoing = 0;
  11280. pthread_exit(NULL);
  11281. }
  11282. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11283. {
  11284. mtrace();
  11285. int result = FAIL;
  11286. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11287. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  11288. {
  11289. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11290. locallistVersion = -1;
  11291. }
  11292. else
  11293. {
  11294. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11295. locallistVersion = 0;
  11296. OCPP_getListVerion();
  11297. }
  11298. //from db.OCPP_getListVerion
  11299. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  11300. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  11301. sendGetLocalListVersionConfirmation(uuid,"");
  11302. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  11303. return result;
  11304. }
  11305. int handleRemoteStartRequest(char *uuid, char *payload)
  11306. {
  11307. mtrace();
  11308. int result = PASS;
  11309. int connectorIdInt=-1;
  11310. int tempIndex = 0;
  11311. char comfirmstr[20]={0};
  11312. char cmdBuf[512];
  11313. json_object *RemoteStartTransaction;
  11314. FILE *fp;
  11315. DEBUG_INFO("handleRemoteStartRequest ...\n");
  11316. if(server_pending == TRUE)
  11317. {
  11318. result = FAIL;
  11319. }
  11320. RemoteStartTransaction = json_tokener_parse(payload);
  11321. if(!is_error(RemoteStartTransaction))
  11322. {
  11323. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  11324. {
  11325. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  11326. }
  11327. else
  11328. {
  11329. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11330. {
  11331. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  11332. {
  11333. connectorIdInt = (gun_index+1);
  11334. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  11335. break;
  11336. }
  11337. }
  11338. }
  11339. if(connectorIdInt == 0)
  11340. {
  11341. DEBUG_WARN("Connector id shall not equal 0.\n");
  11342. result = FAIL;
  11343. }
  11344. else if(json_object_object_get(RemoteStartTransaction, "idTag") == NULL)
  11345. {
  11346. DEBUG_WARN("idTag should not be NULL.\n");
  11347. result = FAIL;
  11348. }
  11349. else if(connectorIdInt == -1)
  11350. {
  11351. DEBUG_INFO("Connector id does not specific.\n");
  11352. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11353. {
  11354. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  11355. // Required data
  11356. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11357. // Optional data
  11358. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11359. {
  11360. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11361. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11362. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11363. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11364. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11365. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11366. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11367. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11368. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11369. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11370. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11371. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11372. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11373. {
  11374. 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")));
  11375. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11376. 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"));
  11377. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11378. 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"));
  11379. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11380. 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")));
  11381. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11382. {
  11383. 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++)
  11384. {
  11385. 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"));
  11386. 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"));
  11387. 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)
  11388. 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"));
  11389. }
  11390. }
  11391. }
  11392. }
  11393. else
  11394. {
  11395. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  11396. }
  11397. }
  11398. }
  11399. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  11400. {
  11401. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  11402. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  11403. // Required data
  11404. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  11405. // Optional data
  11406. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11407. {
  11408. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  11409. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  11410. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  11411. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  11412. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  11413. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  11414. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  11415. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  11416. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  11417. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  11418. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  11419. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  11420. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  11421. {
  11422. 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")));
  11423. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  11424. 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"));
  11425. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  11426. 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"));
  11427. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  11428. 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")));
  11429. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11430. {
  11431. 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++)
  11432. {
  11433. 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"));
  11434. 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"));
  11435. 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)
  11436. 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"));
  11437. }
  11438. }
  11439. }
  11440. }
  11441. else
  11442. {
  11443. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  11444. }
  11445. if((ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'D') && (ShmSysConfigAndInfo->SysConfig.ModelName[1] == 'W'))
  11446. {
  11447. DEBUG_INFO("Checking charging status for DW series...\n");
  11448. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11449. {
  11450. if(cpinitateMsg.bits[gun_index].isOnCharging ||
  11451. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL) ||
  11452. (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing") != NULL))
  11453. {
  11454. DEBUG_INFO("Found gun-%d is in charging.\n", gun_index);
  11455. if(connectorIdInt != (gun_index+1))
  11456. {
  11457. DEBUG_WARN("DWseries--> Other connector is in charging.\n");
  11458. result = FAIL;
  11459. break;
  11460. }
  11461. }
  11462. }
  11463. }
  11464. }
  11465. else
  11466. {
  11467. DEBUG_WARN("Connector id is over maximun value.\n");
  11468. result = FAIL;
  11469. }
  11470. }
  11471. if(result == PASS)
  11472. {
  11473. if(connectorIdInt > 0)
  11474. {
  11475. DEBUG_INFO("Specified gun-%d type: %d\n", (connectorIdInt -1), gunType[connectorIdInt -1]);
  11476. //check Transaction active
  11477. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11478. {
  11479. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11480. {
  11481. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11482. }
  11483. else
  11484. {
  11485. tempIndex = connectorIdInt -1;
  11486. }
  11487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11488. {
  11489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11490. {
  11491. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11492. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11493. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11494. {
  11495. //Reserved
  11496. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  11497. }
  11498. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  11499. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  11500. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11501. {
  11502. //Reserved
  11503. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11504. {
  11505. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  11506. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11507. goto end;
  11508. }
  11509. }
  11510. else
  11511. {
  11512. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11513. {
  11514. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  11515. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11516. goto end;
  11517. }
  11518. }//END FOR ELSE
  11519. }
  11520. }// END FOR CHAdeMO_QUANTITY
  11521. }
  11522. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11523. {
  11524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11525. {
  11526. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11527. }
  11528. else
  11529. {
  11530. tempIndex = connectorIdInt -1;
  11531. }
  11532. for (int index = 0; index < CCS_QUANTITY; index++)
  11533. {
  11534. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11535. {
  11536. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11537. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11538. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11539. {
  11540. //Reserved
  11541. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  11542. }
  11543. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  11544. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  11545. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11546. {
  11547. //Reserved
  11548. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11549. {
  11550. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  11551. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11552. goto end;
  11553. }
  11554. }
  11555. else
  11556. {
  11557. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11558. {
  11559. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  11560. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11561. goto end;
  11562. }
  11563. }// END FOR ELSE
  11564. }
  11565. }// END FOR CCS_QUANTITY
  11566. }
  11567. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11568. {
  11569. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11570. {
  11571. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  11572. }
  11573. else
  11574. {
  11575. tempIndex = connectorIdInt -1;
  11576. }
  11577. for (int index = 0; index < GB_QUANTITY; index++)
  11578. {
  11579. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  11580. {
  11581. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11582. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11583. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11584. {
  11585. //Reserved
  11586. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  11587. }
  11588. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  11589. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  11590. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11591. {
  11592. //Reserved
  11593. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11594. {
  11595. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  11596. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11597. goto end;
  11598. }
  11599. }
  11600. else
  11601. {
  11602. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11603. {
  11604. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  11605. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11606. goto end;
  11607. }
  11608. }// END FOR ELSE
  11609. }
  11610. } // END FOR GB_QUANTITY
  11611. }
  11612. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11613. {
  11614. tempIndex = connectorIdInt -1;
  11615. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11616. {
  11617. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  11618. {
  11619. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11620. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11621. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11622. {
  11623. //Reserved
  11624. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  11625. }
  11626. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  11627. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  11628. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11629. {
  11630. //Reserved
  11631. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11632. {
  11633. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  11634. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11635. goto end;
  11636. }
  11637. }
  11638. else
  11639. {
  11640. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11641. {
  11642. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  11643. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11644. goto end;
  11645. }
  11646. }// END FOR ELSE
  11647. }
  11648. } // END FOR GB_QUANTITY
  11649. }
  11650. else
  11651. {
  11652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11653. {
  11654. tempIndex = 2;
  11655. }
  11656. else
  11657. {
  11658. tempIndex = connectorIdInt -1;
  11659. }
  11660. for (int index = 0; index < AC_QUANTITY; index++)
  11661. {
  11662. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  11663. {
  11664. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11665. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11666. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  11667. {
  11668. //Reserved
  11669. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  11670. }
  11671. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  11672. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  11673. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  11674. {
  11675. //Reserved
  11676. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == NULL)
  11677. {
  11678. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  11679. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11680. goto end;
  11681. }
  11682. }
  11683. else
  11684. {
  11685. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11686. {
  11687. DEBUG_WARN("AC connector not allow start cause busy.\n");
  11688. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11689. goto end;
  11690. }
  11691. }//END FOR ELSE
  11692. }
  11693. }// END FOR AC_QUANTITY
  11694. }
  11695. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  11696. {
  11697. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11698. {
  11699. // Save profile to file
  11700. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11701. system(cmdBuf);
  11702. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11703. fp = fopen(cmdBuf, "w");
  11704. 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));
  11705. fclose(fp);
  11706. }
  11707. else
  11708. {
  11709. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11710. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11711. goto end;
  11712. }
  11713. }
  11714. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  11715. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11716. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  11717. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11718. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  11719. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  11720. }
  11721. else
  11722. {
  11723. uint8_t isHasIdleConnector = FALSE;
  11724. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  11725. {
  11726. DEBUG_INFO("Check not specified gun-%d type: %d\n", gun_index, gunType[gun_index]);
  11727. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  11728. {
  11729. isHasIdleConnector = TRUE;
  11730. break;
  11731. }
  11732. }
  11733. if((isHasIdleConnector == TRUE) && !ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  11734. {
  11735. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11736. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  11737. {
  11738. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11739. {
  11740. // Save profile to file
  11741. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  11742. system(cmdBuf);
  11743. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  11744. fp = fopen(cmdBuf, "w");
  11745. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  11746. fclose(fp);
  11747. refreshStartTimer(&clientTime.RemoteStartWait);
  11748. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11749. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11750. }
  11751. else
  11752. {
  11753. DEBUG_WARN("Profile purpose not TxProfile.\n");
  11754. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11755. }
  11756. }
  11757. else
  11758. {
  11759. refreshStartTimer(&clientTime.RemoteStartWait);
  11760. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  11761. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11762. }
  11763. }
  11764. else
  11765. {
  11766. DEBUG_INFO("There is not any connector is idle.\n");
  11767. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11768. }
  11769. }
  11770. }
  11771. else
  11772. {
  11773. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11774. }
  11775. end:
  11776. json_object_put(RemoteStartTransaction);
  11777. sendRemoteStartConfirmation(uuid, comfirmstr);
  11778. return result;
  11779. }
  11780. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11781. {
  11782. mtrace();
  11783. int result = FAIL;
  11784. int match = FALSE;
  11785. int GunNO = 0;
  11786. int tempIndex = 0;
  11787. int transactionIdInt=0;
  11788. int transactionIdIsNULL= TRUE;
  11789. char comfirmstr[20];
  11790. json_object *RemoteStopTransaction;
  11791. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  11792. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11793. if(server_pending == TRUE)
  11794. {
  11795. return 0;
  11796. }
  11797. RemoteStopTransaction = json_tokener_parse(payload);
  11798. if(!is_error(RemoteStopTransaction))
  11799. {
  11800. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11801. {
  11802. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  11803. transactionIdIsNULL = FALSE;
  11804. }
  11805. }
  11806. json_object_put(RemoteStopTransaction);
  11807. if(transactionIdIsNULL == FALSE)
  11808. {
  11809. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11810. {
  11811. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  11812. {
  11813. //check Transaction active
  11814. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11815. {
  11816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11817. {
  11818. tempIndex = ((gun_index==2) ? 1: 0);
  11819. }
  11820. else
  11821. {
  11822. tempIndex = gun_index;
  11823. }
  11824. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11825. {
  11826. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11827. {
  11828. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11829. {
  11830. match = TRUE;
  11831. GunNO = gun_index;
  11832. }
  11833. }
  11834. }// END FOR CHAdeMO_QUANTITY
  11835. }
  11836. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11837. {
  11838. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11839. {
  11840. tempIndex = ((gun_index==2) ? 1: 0);
  11841. }
  11842. else
  11843. {
  11844. tempIndex = gun_index;
  11845. }
  11846. for (int index = 0; index < CCS_QUANTITY; index++)
  11847. {
  11848. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11849. {
  11850. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11851. {
  11852. match = TRUE;
  11853. GunNO = gun_index;
  11854. }
  11855. }
  11856. }// END FOR CCS_QUANTITY
  11857. }
  11858. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11859. {
  11860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11861. {
  11862. tempIndex = ((gun_index==2) ? 1: 0);
  11863. }
  11864. else
  11865. {
  11866. tempIndex = gun_index;
  11867. }
  11868. for (int index = 0; index < GB_QUANTITY; index++)
  11869. {
  11870. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11871. {
  11872. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11873. {
  11874. match = TRUE;
  11875. GunNO = gun_index;
  11876. }
  11877. }
  11878. }// END FOR GB_QUANTITY
  11879. }
  11880. else if(gunType[gun_index] == GUN_TYPE_DO)
  11881. {
  11882. tempIndex = gun_index;
  11883. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11884. {
  11885. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11886. {
  11887. 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
  11888. {
  11889. match = TRUE;
  11890. GunNO = gun_index;
  11891. }
  11892. }
  11893. }// END FOR GB_QUANTITY
  11894. }
  11895. else
  11896. {
  11897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11898. {
  11899. tempIndex = 2;
  11900. }
  11901. else
  11902. {
  11903. tempIndex = gun_index;
  11904. }
  11905. for (int index = 0; index < AC_QUANTITY; index++)
  11906. {
  11907. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11908. {
  11909. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11910. {
  11911. match = TRUE;
  11912. GunNO = gun_index;
  11913. }
  11914. }
  11915. }// END FOR CHAdeMO_QUANTITY
  11916. } // END FOR AC ELSE
  11917. }// CHECK IF ResponseTransactionId == transactionIdInt
  11918. }//END FOR
  11919. if( match == TRUE)
  11920. {
  11921. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11922. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11923. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11924. }
  11925. else
  11926. {
  11927. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11928. }
  11929. }
  11930. else
  11931. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11932. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11933. return result;
  11934. }
  11935. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11936. {
  11937. mtrace();
  11938. int result = FAIL;
  11939. int connectorIdInt=0, reservationIdInt=0;
  11940. int tempIndex = 0;
  11941. char expiryDatestr[30]={0}, idTagstr[21]={0},parentIdTagstr[21]={0};
  11942. char comfirmstr[20]={0};
  11943. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11944. int c = 0;
  11945. char *loc;
  11946. //char *ptr;
  11947. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11948. strcpy(sstrtemp, stringtrimspace(payload));
  11949. //***(1)connectorId ****/
  11950. c=0;
  11951. loc = strstr(sstrtemp, "connectorId");
  11952. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11953. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11954. {
  11955. sstr[c] = loc[strlen("connectorId")+2+c];
  11956. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11957. c++;
  11958. }
  11959. sstr[c] = '\0';
  11960. connectorIdInt = atoi(sstr);
  11961. //***(2)expiryDate ****/
  11962. loc = strstr(sstrtemp, "expiryDate");
  11963. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11964. c = 0;
  11965. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11966. {
  11967. sstr[c] = loc[3+strlen("expiryDate")+c];
  11968. c++;
  11969. }
  11970. sstr[c] = '\0';
  11971. strcpy(expiryDatestr, sstr);
  11972. //***(3)idTag ****/
  11973. loc = strstr(sstrtemp, "idTag");
  11974. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11975. c = 0;
  11976. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11977. {
  11978. sstr[c] = loc[3+strlen("idTag")+c];
  11979. c++;
  11980. }
  11981. sstr[c] = '\0';
  11982. strcpy(idTagstr, sstr);
  11983. //***(4)parentIdTag ****/
  11984. loc = strstr(sstrtemp, "parentIdTag");
  11985. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11986. c = 0;
  11987. if(loc == NULL)
  11988. {
  11989. strcpy(parentIdTagstr, "");
  11990. }
  11991. else
  11992. {
  11993. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11994. {
  11995. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11996. c++;
  11997. }
  11998. sstr[c] = '\0';
  11999. strcpy(parentIdTagstr, sstr);
  12000. }
  12001. //***(5)reservationId ****/
  12002. c=0;
  12003. loc = strstr(sstrtemp, "reservationId");
  12004. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12005. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  12006. {
  12007. sstr[c] = loc[strlen("reservationId")+2+c];
  12008. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12009. c++;
  12010. }
  12011. sstr[c] = '\0';
  12012. reservationIdInt = atoi(sstr);
  12013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12014. /*
  12015. enum SYSTEM_STATUS
  12016. {
  12017. SYS_MODE_BOOTING = 0,
  12018. SYS_MODE_IDLE = 1,
  12019. SYS_MODE_AUTHORIZING = 2,
  12020. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  12021. SYS_MODE_REASSIGN = 4,
  12022. SYS_MODE_PREPARING = 5,
  12023. SYS_MODE_PREPARE_FOR_EV = 6,
  12024. SYS_MODE_PREPARE_FOR_EVSE = 7,
  12025. SYS_MODE_CHARGING = 8,
  12026. SYS_MODE_TERMINATING = 9,
  12027. SYS_MODE_COMPLETE = 10,
  12028. SYS_MODE_ALARM = 11,
  12029. SYS_MODE_FAULT = 12,
  12030. SYS_MODE_RESERVATION = 13,
  12031. SYS_MODE_BOOKING = 14,
  12032. SYS_MODE_MAINTAIN = 15,
  12033. SYS_MODE_DEBUG = 16,
  12034. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  12035. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  12036. SYS_MODE_UPDATE = 19
  12037. };
  12038. */
  12039. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  12040. {
  12041. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12042. goto end;
  12043. }
  12044. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12045. {
  12046. //check Transaction active
  12047. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12048. {
  12049. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12050. {
  12051. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12052. }
  12053. else
  12054. {
  12055. tempIndex = connectorIdInt -1;
  12056. }
  12057. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12058. {
  12059. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12060. {
  12061. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12062. {
  12063. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12064. {
  12065. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12066. {
  12067. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  12068. {
  12069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12070. }
  12071. else
  12072. {
  12073. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12074. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12075. }
  12076. }
  12077. 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'))
  12078. {
  12079. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12080. }
  12081. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12082. {
  12083. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12084. }
  12085. else
  12086. {
  12087. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12088. }
  12089. }
  12090. 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
  12091. {
  12092. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12093. }
  12094. }
  12095. else
  12096. {
  12097. //replace reservation
  12098. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12100. }
  12101. }
  12102. } // END FOR CHAdeMO_QUANTITY
  12103. }
  12104. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12105. {
  12106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12107. {
  12108. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12109. }
  12110. else
  12111. {
  12112. tempIndex = connectorIdInt -1;
  12113. }
  12114. for (int index = 0; index < CCS_QUANTITY; index++)
  12115. {
  12116. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12117. {
  12118. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12119. {
  12120. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12121. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12122. {
  12123. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12124. {
  12125. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  12126. {
  12127. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12128. }
  12129. else
  12130. {
  12131. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12133. }
  12134. }
  12135. 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'))
  12136. {
  12137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12138. }
  12139. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12140. {
  12141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12142. }
  12143. else
  12144. {
  12145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12146. }
  12147. }
  12148. 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
  12149. {
  12150. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12151. }
  12152. }
  12153. else
  12154. {
  12155. //replace reservation
  12156. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12158. }
  12159. }
  12160. } // END FOR CCS_QUANTITY
  12161. }
  12162. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12163. {
  12164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12165. {
  12166. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12167. }
  12168. else
  12169. {
  12170. tempIndex = connectorIdInt -1;
  12171. }
  12172. for (int index = 0; index < GB_QUANTITY; index++)
  12173. {
  12174. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12175. {
  12176. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12177. {
  12178. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12179. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12180. {
  12181. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12182. {
  12183. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  12184. {
  12185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12186. }
  12187. else
  12188. {
  12189. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12191. }
  12192. }
  12193. 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'))
  12194. {
  12195. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12196. }
  12197. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12198. {
  12199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12200. }
  12201. else
  12202. {
  12203. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12204. }
  12205. }
  12206. 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
  12207. {
  12208. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12209. }
  12210. }
  12211. else
  12212. {
  12213. //replace reservation
  12214. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12216. }
  12217. }
  12218. }// END FOR GB_QUANTITY
  12219. }
  12220. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12221. {
  12222. tempIndex = connectorIdInt -1;
  12223. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12224. {
  12225. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12226. {
  12227. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12228. {
  12229. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12230. 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
  12231. {
  12232. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12233. {
  12234. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  12235. {
  12236. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12237. }
  12238. else
  12239. {
  12240. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12242. }
  12243. }
  12244. 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'))
  12245. {
  12246. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12247. }
  12248. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12249. {
  12250. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12251. }
  12252. else
  12253. {
  12254. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12255. }
  12256. }
  12257. 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
  12258. {
  12259. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12260. }
  12261. }
  12262. else
  12263. {
  12264. //replace reservation
  12265. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12266. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12267. }
  12268. }
  12269. }// END FOR GB_QUANTITY
  12270. }
  12271. else
  12272. {
  12273. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12274. {
  12275. tempIndex = 2;
  12276. }
  12277. else
  12278. {
  12279. tempIndex = (connectorIdInt -1);
  12280. }
  12281. for (int index = 0; index < AC_QUANTITY; index++)
  12282. {
  12283. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12284. {
  12285. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12286. {
  12287. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12288. {
  12289. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12290. {
  12291. 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))
  12292. {
  12293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12294. }
  12295. else
  12296. {
  12297. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12299. }
  12300. }
  12301. 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'))
  12302. {
  12303. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12304. }
  12305. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12306. {
  12307. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12308. }
  12309. else
  12310. {
  12311. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12312. }
  12313. }
  12314. 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
  12315. {
  12316. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12317. }
  12318. }
  12319. else
  12320. {
  12321. //replace reservation
  12322. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  12323. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12324. }
  12325. }
  12326. } // END FOR AC_QUANTITY
  12327. }
  12328. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12329. }
  12330. else if(connectorIdInt == 0)
  12331. {
  12332. //check Transaction active
  12333. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12334. {
  12335. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12336. {
  12337. 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'))
  12338. {
  12339. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12340. goto end;
  12341. }
  12342. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12343. {
  12344. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12345. goto end;
  12346. }
  12347. 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
  12348. {
  12349. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12350. goto end;
  12351. }
  12352. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12353. {
  12354. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12355. goto end;
  12356. }
  12357. }
  12358. }// END FOR CHAdeMO_QUANTITY
  12359. for (int index = 0; index < CCS_QUANTITY; index++)
  12360. {
  12361. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12362. {
  12363. 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'))
  12364. {
  12365. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12366. goto end;
  12367. }
  12368. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12369. {
  12370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12371. goto end;
  12372. }
  12373. 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
  12374. {
  12375. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12376. goto end;
  12377. }
  12378. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12379. {
  12380. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12381. goto end;
  12382. }
  12383. }
  12384. } // END FOR CCS_QUANTITY
  12385. for (int index = 0; index < GB_QUANTITY; index++)
  12386. {
  12387. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12388. {
  12389. 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'))
  12390. {
  12391. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12392. goto end;
  12393. }
  12394. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12395. {
  12396. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12397. goto end;
  12398. }
  12399. 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
  12400. {
  12401. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12402. goto end;
  12403. }
  12404. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12405. {
  12406. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12407. goto end;
  12408. }
  12409. }
  12410. } // END FOR GB_QUANTITY
  12411. for (int index = 0; index < AC_QUANTITY; index++)
  12412. {
  12413. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12414. {
  12415. 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'))
  12416. {
  12417. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  12418. goto end;
  12419. }
  12420. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12421. {
  12422. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12423. goto end;
  12424. }
  12425. 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
  12426. {
  12427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  12428. goto end;
  12429. }
  12430. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12431. {
  12432. 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))
  12433. {
  12434. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  12435. goto end;
  12436. }
  12437. }
  12438. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12439. {
  12440. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12441. goto end;
  12442. }
  12443. }
  12444. }// END FOR AC_QUANTITY
  12445. //The connectorId is 0
  12446. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  12447. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  12448. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  12449. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  12450. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  12451. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  12452. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  12453. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  12454. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  12455. result = TRUE;
  12456. return result;
  12457. }
  12458. else
  12459. {
  12460. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  12461. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  12462. }
  12463. if(strcmp(comfirmstr,"Accepted") == 0)
  12464. {
  12465. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  12466. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  12467. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  12468. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  12469. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  12470. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12471. result = TRUE;
  12472. return result;
  12473. }
  12474. end:
  12475. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  12476. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  12477. return result;
  12478. }
  12479. int handleResetRequest(char *uuid, char *payload)
  12480. {
  12481. mtrace();
  12482. int result = FAIL;
  12483. char sstr[10]={0},sstrtemp[30]={ 0 };
  12484. char typestr[10]={0};
  12485. char comfirmstr[20]={0};
  12486. int c = 0;
  12487. char *loc;
  12488. DEBUG_INFO("handleResetRequest...\n");
  12489. strcpy(sstrtemp, stringtrimspace(payload));
  12490. loc = strstr(sstrtemp, "type");
  12491. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12492. c = 0;
  12493. while (loc[3+strlen("type")+c] != '\"')
  12494. {
  12495. sstr[c] = loc[3+strlen("type")+c];
  12496. c++;
  12497. }
  12498. sstr[c] = '\0';
  12499. strcpy(typestr,sstr);
  12500. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  12501. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  12502. {
  12503. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  12504. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  12505. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  12506. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12507. }
  12508. else
  12509. {
  12510. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  12511. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  12512. result = PASS;
  12513. }
  12514. sendResetConfirmation(uuid, comfirmstr);
  12515. return result;
  12516. }
  12517. int handleSendLocalListRequest(char *uuid, char *payload)
  12518. {
  12519. mtrace();
  12520. int result = FAIL;
  12521. char comfirmstr[20];
  12522. int checkState_Faulted = FALSE;
  12523. json_object *SendLocalList;
  12524. DEBUG_INFO("handleSendLocalListRequest...\n");
  12525. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  12526. {
  12527. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12528. goto end;
  12529. }
  12530. //check Charge Point state
  12531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12532. {
  12533. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12534. {
  12535. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12536. }
  12537. }
  12538. for (int index = 0; index < CCS_QUANTITY; index++)
  12539. {
  12540. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12541. {
  12542. checkState_Faulted = TRUE; //OCPP Status
  12543. }
  12544. }
  12545. for (int index = 0; index < GB_QUANTITY; index++)
  12546. {
  12547. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12548. {
  12549. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12550. }
  12551. }
  12552. //check Charge Point state
  12553. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12554. {
  12555. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12556. {
  12557. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12558. }
  12559. }
  12560. //check Charge Point state
  12561. for (int index = 0; index < AC_QUANTITY; index++)
  12562. {
  12563. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12564. {
  12565. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12566. }
  12567. }
  12568. if(checkState_Faulted == TRUE)
  12569. {
  12570. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12571. goto end;
  12572. }
  12573. // Parsing payload
  12574. SendLocalList = json_tokener_parse(payload);
  12575. if(!is_error(SendLocalList))
  12576. {
  12577. // Required data
  12578. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  12579. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12580. // Optional data
  12581. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12582. {
  12583. //Check UpdateType
  12584. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12585. {
  12586. //Local list full update
  12587. DEBUG_INFO("Local list full update.\n");
  12588. locallistVersion = 0;
  12589. OCPP_getListVerion();
  12590. if((ShmOCPP16Data->SendLocalList.ListVersion > 0) && (ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion))
  12591. {
  12592. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12593. goto end;
  12594. }
  12595. OCPP_cleanLocalList();
  12596. }
  12597. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12598. {
  12599. //Local list different update
  12600. DEBUG_INFO("Local list different update.\n");
  12601. locallistVersion = 0;
  12602. OCPP_getListVerion();
  12603. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  12604. {
  12605. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  12606. goto end;
  12607. }
  12608. }
  12609. else
  12610. {
  12611. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  12612. goto end;
  12613. }
  12614. if(json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList")) > atoi((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData))
  12615. {
  12616. DEBUG_WARN("Local list length is over SendLocalListMaxLength.\n");
  12617. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  12618. goto end;
  12619. }
  12620. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  12621. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12622. {
  12623. 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"))));
  12624. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12625. {
  12626. 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"))));
  12627. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  12628. 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"))));
  12629. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  12630. 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"))));
  12631. }
  12632. // Add to db
  12633. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12634. {
  12635. //Local list full update
  12636. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  12637. idx,
  12638. ShmOCPP16Data->SendLocalList.ListVersion,
  12639. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12640. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12641. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12642. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12643. // update list
  12644. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12645. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12646. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12647. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12648. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12649. }
  12650. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12651. {
  12652. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  12653. idx,
  12654. ShmOCPP16Data->SendLocalList.ListVersion,
  12655. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12656. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12657. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12658. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12659. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  12660. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  12661. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  12662. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  12663. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  12664. }
  12665. }
  12666. }
  12667. else
  12668. {
  12669. //Check UpdateType
  12670. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  12671. {
  12672. //Local list full update
  12673. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  12674. OCPP_cleanLocalList();
  12675. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12676. goto end;
  12677. }
  12678. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  12679. {
  12680. //Local list different update
  12681. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  12682. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12683. goto end;
  12684. }
  12685. }
  12686. result = PASS;
  12687. }
  12688. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  12689. end:
  12690. json_object_put(SendLocalList);
  12691. sendSendLocalListConfirmation(uuid, comfirmstr);
  12692. return result;
  12693. }
  12694. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12695. {
  12696. mtrace();
  12697. int result = FAIL;
  12698. struct StructSetChargingProfile SetProfileReq = {0};
  12699. int tempchargingProfileIdInt;
  12700. int tempstackLevelInt;
  12701. int chargingSchedulePeriodCount = 0;
  12702. char comfirmstr[20]={0};
  12703. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  12704. char rmFileCmd[128]={0};
  12705. int profileQuantity = 0;
  12706. int replaceableProfileCnt = 0;
  12707. json_object *SetChargingProfile;
  12708. DEBUG_INFO("handleSetChargingProfileRequest\n");
  12709. SetChargingProfile = json_tokener_parse(payload);
  12710. if(!is_error(SetChargingProfile))
  12711. {
  12712. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  12713. {
  12714. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  12715. }
  12716. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  12717. {
  12718. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12719. {
  12720. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12721. }
  12722. else
  12723. {
  12724. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12725. DEBUG_WARN("Cannot find chargingProfileId field.");
  12726. goto end;
  12727. }
  12728. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12729. {
  12730. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  12731. }
  12732. else
  12733. {
  12734. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12735. DEBUG_WARN("Cannot find stackLevel field.");
  12736. goto end;
  12737. }
  12738. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12739. {
  12740. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12741. }
  12742. else
  12743. {
  12744. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12745. DEBUG_WARN("Cannot find chargingProfilePurpose field.");
  12746. goto end;
  12747. }
  12748. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  12749. {
  12750. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  12751. }
  12752. else
  12753. {
  12754. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12755. DEBUG_WARN("Cannot find chargingProfileKind field.");
  12756. goto end;
  12757. }
  12758. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  12759. {
  12760. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  12761. }
  12762. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  12763. {
  12764. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  12765. }
  12766. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  12767. {
  12768. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  12769. }
  12770. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  12771. {
  12772. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  12773. }
  12774. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  12775. {
  12776. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  12777. {
  12778. 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")));
  12779. }
  12780. else
  12781. {
  12782. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12783. DEBUG_WARN("Cannot find chargingRateUnit field.");
  12784. goto end;
  12785. }
  12786. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  12787. {
  12788. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  12789. }
  12790. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  12791. {
  12792. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  12793. }
  12794. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  12795. {
  12796. 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")));
  12797. }
  12798. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  12799. {
  12800. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  12801. if(chargingSchedulePeriodCount <= 10)
  12802. {
  12803. 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++)
  12804. {
  12805. 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)
  12806. {
  12807. 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"));
  12808. }
  12809. else
  12810. {
  12811. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12812. DEBUG_WARN("Cannot find startPeriod field.");
  12813. goto end;
  12814. }
  12815. 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)
  12816. {
  12817. 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"));
  12818. }
  12819. else
  12820. {
  12821. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12822. DEBUG_WARN("Cannot find limit field.");
  12823. goto end;
  12824. }
  12825. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  12826. {
  12827. 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"));
  12828. }
  12829. }
  12830. }
  12831. }
  12832. else
  12833. {
  12834. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12835. DEBUG_WARN("Cannot find chargingSchedulePeriod field.");
  12836. goto end;
  12837. }
  12838. }
  12839. else
  12840. {
  12841. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12842. DEBUG_WARN("Cannot find chargingSchedule field.");
  12843. goto end;
  12844. }
  12845. }
  12846. }
  12847. // Profile periods quantity check
  12848. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  12849. {
  12850. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12851. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12852. goto end;
  12853. }
  12854. // Check invalid limit
  12855. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) != 0) ||
  12856. ((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  12857. {
  12858. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  12859. {
  12860. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12861. {
  12862. 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)))) ||
  12863. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  12864. {
  12865. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12866. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12867. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12868. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12869. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12870. goto end;
  12871. }
  12872. }
  12873. }
  12874. else
  12875. {
  12876. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  12877. {
  12878. 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) ||
  12879. (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)))
  12880. {
  12881. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12882. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  12883. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  12884. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  12885. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  12886. goto end;
  12887. }
  12888. }
  12889. }
  12890. }
  12891. // Profile purpose info check
  12892. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12893. {
  12894. FILE *fp;
  12895. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  12896. if(SetProfileReq.ConnectorId != 0)
  12897. {
  12898. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12899. DEBUG_WARN("Profile connector id is not 0.\n");
  12900. goto end;
  12901. }
  12902. fp = fopen(ChargePointMaxProfile_JSON, "r");
  12903. if (!fp)
  12904. {
  12905. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  12906. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  12907. }
  12908. else
  12909. {
  12910. char *line = NULL;
  12911. size_t len = 0;
  12912. while(getline(&line, &len, fp) != -1)
  12913. {
  12914. json_object *obj = NULL;
  12915. obj = json_tokener_parse(line);
  12916. if(is_error(obj))
  12917. {
  12918. DEBUG_ERROR("Parse txProfile from file error.\n");
  12919. }
  12920. else
  12921. {
  12922. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12923. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12924. {
  12925. profileQuantity += 1;
  12926. }
  12927. else
  12928. replaceableProfileCnt += 1;
  12929. }
  12930. }
  12931. }
  12932. fclose(fp);
  12933. }
  12934. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12935. {
  12936. FILE *fp;
  12937. char filename[128]={0};
  12938. int tmpProfileQuantity;
  12939. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  12940. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12941. {
  12942. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12943. DEBUG_WARN("Profile connector id is over max gun number.\n");
  12944. goto end;
  12945. }
  12946. if(SetProfileReq.ConnectorId == 0)
  12947. {
  12948. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12949. {
  12950. tmpProfileQuantity = 0;
  12951. memset(filename, 0, ARRAY_SIZE(filename));
  12952. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  12953. fp = fopen(filename, "r");
  12954. if (!fp)
  12955. {
  12956. DEBUG_INFO("%s does not create.\n", filename);
  12957. fp = fopen(filename, "w+");
  12958. }
  12959. else
  12960. {
  12961. char *line = NULL;
  12962. size_t len = 0;
  12963. while(getline(&line, &len, fp) != -1)
  12964. {
  12965. json_object *obj = NULL;
  12966. obj = json_tokener_parse(line);
  12967. if(is_error(obj))
  12968. {
  12969. DEBUG_ERROR("Parse txProfile from file error.\n");
  12970. }
  12971. else
  12972. {
  12973. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12974. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12975. {
  12976. tmpProfileQuantity += 1;
  12977. }
  12978. else
  12979. replaceableProfileCnt += 1;
  12980. }
  12981. }
  12982. }
  12983. fclose(fp);
  12984. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12985. }
  12986. }
  12987. else
  12988. {
  12989. memset(filename, 0, ARRAY_SIZE(filename));
  12990. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12991. fp = fopen(filename, "r");
  12992. if (!fp)
  12993. {
  12994. DEBUG_INFO("%s does not create.\n", filename);
  12995. fp = fopen(filename, "w+");
  12996. }
  12997. else
  12998. {
  12999. char *line = NULL;
  13000. size_t len = 0;
  13001. while(getline(&line, &len, fp) != -1)
  13002. {
  13003. json_object *obj = NULL;
  13004. obj = json_tokener_parse(line);
  13005. if(is_error(obj))
  13006. {
  13007. DEBUG_ERROR("Parse txProfile from file error.\n");
  13008. }
  13009. else
  13010. {
  13011. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13012. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13013. {
  13014. profileQuantity += 1;
  13015. }
  13016. else
  13017. replaceableProfileCnt += 1;
  13018. }
  13019. }
  13020. }
  13021. fclose(fp);
  13022. }
  13023. }
  13024. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  13025. {
  13026. int isMatchTransactiodId= FALSE;
  13027. FILE *fp;
  13028. char filename[128]={0};
  13029. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  13030. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  13031. if(SetProfileReq.ConnectorId == 0)
  13032. {
  13033. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13034. DEBUG_WARN("Profile connector id is 0.\n");
  13035. goto end;
  13036. }
  13037. int tempIndex = 0;
  13038. //check Transaction active
  13039. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  13040. {
  13041. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13042. {
  13043. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13044. }
  13045. else
  13046. {
  13047. tempIndex = SetProfileReq.ConnectorId -1;
  13048. }
  13049. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13050. {
  13051. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13052. {
  13053. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13054. {
  13055. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13056. {
  13057. isMatchTransactiodId = TRUE;
  13058. break;
  13059. }
  13060. }
  13061. }
  13062. }
  13063. }
  13064. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  13065. {
  13066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13067. {
  13068. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13069. }
  13070. else
  13071. {
  13072. tempIndex = SetProfileReq.ConnectorId -1;
  13073. }
  13074. for (int index = 0; index < CCS_QUANTITY; index++)
  13075. {
  13076. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13077. {
  13078. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  13079. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13080. {
  13081. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13082. {
  13083. isMatchTransactiodId = TRUE;
  13084. break;
  13085. }
  13086. }
  13087. }
  13088. }
  13089. }
  13090. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  13091. {
  13092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13093. {
  13094. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  13095. }
  13096. else
  13097. {
  13098. tempIndex = SetProfileReq.ConnectorId -1;
  13099. }
  13100. for (int index = 0; index < GB_QUANTITY; index++)
  13101. {
  13102. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13103. {
  13104. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  13105. {
  13106. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13107. {
  13108. isMatchTransactiodId = TRUE;
  13109. break;
  13110. }
  13111. }
  13112. }
  13113. }
  13114. }
  13115. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  13116. {
  13117. tempIndex = SetProfileReq.ConnectorId -1;
  13118. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13119. {
  13120. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13121. {
  13122. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  13123. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  13124. {
  13125. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13126. {
  13127. isMatchTransactiodId = TRUE;
  13128. break;
  13129. }
  13130. }
  13131. }
  13132. }
  13133. }
  13134. else
  13135. {
  13136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13137. {
  13138. tempIndex = 2;
  13139. }
  13140. else
  13141. {
  13142. tempIndex = (SetProfileReq.ConnectorId -1);
  13143. }
  13144. for (int index = 0; index < AC_QUANTITY; index++)
  13145. {
  13146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13147. {
  13148. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  13149. {
  13150. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  13151. {
  13152. isMatchTransactiodId = TRUE;
  13153. break;
  13154. }
  13155. }
  13156. }
  13157. }
  13158. }
  13159. //check Transaction active
  13160. if(isMatchTransactiodId == FALSE)
  13161. {
  13162. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13163. DEBUG_WARN("Tx profile transaction id is not match.\n");
  13164. goto end;
  13165. }
  13166. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  13167. {
  13168. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13169. DEBUG_WARN("Connector id is over max gun number.\n");
  13170. goto end;
  13171. }
  13172. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13173. fp = fopen(filename, "r");
  13174. if (!fp)
  13175. {
  13176. DEBUG_INFO("%s does not create.\n", filename);
  13177. fp = fopen(filename, "w+");
  13178. }
  13179. else
  13180. {
  13181. char *line = NULL;
  13182. size_t len = 0;
  13183. while(getline(&line, &len, fp) != -1)
  13184. {
  13185. json_object *obj = NULL;
  13186. obj = json_tokener_parse(line);
  13187. if(is_error(obj))
  13188. {
  13189. DEBUG_ERROR("Parse txProfile from file error.\n");
  13190. }
  13191. else
  13192. {
  13193. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  13194. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  13195. {
  13196. profileQuantity += 1;
  13197. }
  13198. else
  13199. replaceableProfileCnt += 1;
  13200. }
  13201. }
  13202. }
  13203. fclose(fp);
  13204. }
  13205. // Check ChargeProfileMaxStackLevel
  13206. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  13207. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  13208. {
  13209. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  13210. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13211. goto end;
  13212. }
  13213. //------------------------------Start: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13214. {
  13215. FILE *fp;
  13216. char dataLine[4096]={0};
  13217. char fnametemp[128]={0};
  13218. int tmpProfileQuantity;
  13219. //Check ChargePointMaxProfile.json exit
  13220. profileQuantity = 0;
  13221. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  13222. {
  13223. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  13224. //Check Charging Profile Count
  13225. tmpProfileQuantity = 0;
  13226. while(fscanf(fp, "%s", dataLine) != EOF)
  13227. {
  13228. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13229. {
  13230. profileQuantity += 1;
  13231. tmpProfileQuantity += 1;
  13232. }
  13233. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13234. }
  13235. fclose(fp);
  13236. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  13237. }
  13238. //Check TxDefaultProfile_%d.json
  13239. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13240. {
  13241. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13242. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13243. if((access(fnametemp,F_OK))!=-1)
  13244. {
  13245. fp = fopen(fnametemp, "r");
  13246. //Check Charging Profile Count
  13247. tmpProfileQuantity = 0;
  13248. while(fscanf(fp, "%s", dataLine) != EOF)
  13249. {
  13250. //DEBUG_INFO("word=%s\n",word);
  13251. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13252. {
  13253. profileQuantity += 1;
  13254. tmpProfileQuantity += 1;
  13255. }
  13256. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13257. }
  13258. fclose(fp);
  13259. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13260. }
  13261. }
  13262. //Check TxProfile_%d.json
  13263. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  13264. {
  13265. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  13266. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  13267. if((access(fnametemp,F_OK))!=-1)
  13268. {
  13269. fp = fopen(fnametemp, "r");
  13270. //Check Charging Profile Count
  13271. tmpProfileQuantity = 0;
  13272. while(fscanf(fp, "%s", dataLine) != EOF)
  13273. {
  13274. if(strstr(dataLine, "chargingProfileId")!= NULL)
  13275. {
  13276. profileQuantity += 1;
  13277. tmpProfileQuantity += 1;
  13278. }
  13279. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  13280. }
  13281. fclose(fp);
  13282. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  13283. }
  13284. }
  13285. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  13286. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  13287. // To check total Profile quantity
  13288. if((SetProfileReq.ConnectorId > 0) || (strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0))
  13289. {
  13290. if((profileQuantity-replaceableProfileCnt) >= atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13291. {
  13292. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13293. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13294. goto end;
  13295. }
  13296. }
  13297. else
  13298. {
  13299. if((profileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((const char*)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  13300. {
  13301. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected]);
  13302. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13303. goto end;
  13304. }
  13305. }
  13306. }
  13307. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  13308. //**********************************Write to File********************************************************/
  13309. {
  13310. FILE *infile;
  13311. FILE *outfile;
  13312. char dataLine[4096]={0};
  13313. char filename[128]={0};
  13314. int chkChar=0;
  13315. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  13316. {
  13317. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  13318. {
  13319. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  13320. }
  13321. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  13322. {
  13323. if(SetProfileReq.ConnectorId==0)
  13324. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  13325. else
  13326. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  13327. }
  13328. else
  13329. {
  13330. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  13331. }
  13332. infile = fopen (filename, "r");
  13333. outfile = fopen (tempfile, "w");
  13334. chkChar = fgetc(infile);
  13335. rewind(infile);
  13336. if(chkChar == EOF)
  13337. {
  13338. // Profile is empty
  13339. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13340. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13341. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13342. fclose(infile);
  13343. fclose(outfile);
  13344. sprintf(rmFileCmd,"rm -f %s",filename);
  13345. system(rmFileCmd);
  13346. rename(tempfile, filename);
  13347. }
  13348. else
  13349. {
  13350. // Profile is not empty
  13351. int ChargingProfileAdded = FALSE;
  13352. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  13353. {
  13354. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  13355. json_object *tmpChargingProfile;
  13356. tmpChargingProfile = json_tokener_parse(dataLine);
  13357. if(!is_error(SetChargingProfile))
  13358. {
  13359. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13360. {
  13361. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13362. {
  13363. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13364. }
  13365. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13366. {
  13367. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13368. }
  13369. }
  13370. }
  13371. json_object_put(tmpChargingProfile);
  13372. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  13373. {
  13374. if(ChargingProfileAdded == FALSE)
  13375. {
  13376. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13377. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13378. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13379. ChargingProfileAdded = TRUE;
  13380. }
  13381. }
  13382. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  13383. {
  13384. if(ChargingProfileAdded == FALSE)
  13385. {
  13386. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  13387. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  13388. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  13389. ChargingProfileAdded = TRUE;
  13390. }
  13391. }
  13392. else
  13393. {
  13394. fprintf(outfile,"%s\n",dataLine);
  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. } // end of while loop
  13404. fclose(infile);
  13405. fclose(outfile);
  13406. sprintf(rmFileCmd,"rm -f %s",filename);
  13407. system(rmFileCmd);
  13408. rename(tempfile, filename);
  13409. }
  13410. }
  13411. sleep(1);
  13412. result = TRUE;
  13413. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  13414. }
  13415. end:
  13416. json_object_put(SetChargingProfile);
  13417. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  13418. {
  13419. if(SetProfileReq.ConnectorId == 0)
  13420. {
  13421. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13422. {
  13423. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  13424. }
  13425. }
  13426. else
  13427. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  13428. }
  13429. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  13430. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13431. return result;
  13432. }
  13433. int handleTriggerMessageRequest(char *uuid, char *payload)
  13434. {
  13435. mtrace();
  13436. int result = FAIL;
  13437. int connectorIdIsNULL = FALSE;
  13438. int connectorIdInt =0;
  13439. char sstr[40]={0},sstrtemp[100]={ 0 };
  13440. char requestedMessagestr[40]={0};
  13441. char comfirmstr[20]={0};
  13442. int c = 0;
  13443. char *loc;
  13444. DEBUG_INFO("handleTriggerMessageRequest\n");
  13445. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  13446. strcpy(sstrtemp, stringtrimspace(payload));
  13447. c = 0;
  13448. loc = strstr(sstrtemp, "requestedMessage");
  13449. while (loc[3+strlen("requestedMessage")+c] != '\"')
  13450. {
  13451. sstr[c] = loc[3+strlen("requestedMessage")+c];
  13452. c++;
  13453. }
  13454. sstr[c] = '\0';
  13455. strcpy(requestedMessagestr, sstr);
  13456. c = 0;
  13457. loc = strstr(sstrtemp, "connectorId");
  13458. if(loc == NULL)
  13459. {
  13460. connectorIdIsNULL = TRUE;
  13461. }
  13462. else
  13463. {
  13464. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13465. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  13466. {
  13467. sstr[c] = loc[strlen("connectorId")+2+c];
  13468. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13469. c++;
  13470. }
  13471. sstr[c] = '\0';
  13472. connectorIdInt = atoi(sstr);
  13473. }
  13474. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13475. {
  13476. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  13477. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  13478. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13479. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  13480. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  13481. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  13482. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  13483. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  13484. {
  13485. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13486. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13487. return TRUE;
  13488. }
  13489. else
  13490. {
  13491. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13492. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13493. }
  13494. }
  13495. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13496. {
  13497. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  13498. sendTriggerMessageConfirmation(uuid,comfirmstr);
  13499. return TRUE;
  13500. }
  13501. //==========================
  13502. // Trigger message
  13503. //==========================
  13504. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13505. {
  13506. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  13507. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13508. {
  13509. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13510. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13511. }
  13512. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13513. }
  13514. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  13515. {
  13516. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  13517. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  13518. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  13519. }
  13520. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  13521. {
  13522. //sendBootNotificationRequest();
  13523. server_sign = FALSE;
  13524. }
  13525. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  13526. {
  13527. refreshStartTimer(&clientTime.Heartbeat);
  13528. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  13529. }
  13530. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  13531. {
  13532. if(connectorIdIsNULL == FALSE)
  13533. {
  13534. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13535. {
  13536. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13537. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  13538. }
  13539. }
  13540. else
  13541. {
  13542. for(int idx=0;idx< gunTotalNumber;idx++)
  13543. {
  13544. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13545. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13546. }
  13547. }
  13548. }
  13549. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  13550. {
  13551. if(connectorIdIsNULL == FALSE)
  13552. {
  13553. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13554. {
  13555. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  13556. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  13557. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13558. }
  13559. }
  13560. else
  13561. {
  13562. for(int idx=0;idx< gunTotalNumber;idx++)
  13563. {
  13564. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  13565. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  13566. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13567. }
  13568. }
  13569. }
  13570. return result;
  13571. }
  13572. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13573. {
  13574. mtrace();
  13575. int result = FAIL;
  13576. int connectorIdInt =0;
  13577. char comfirmstr[20]={0};
  13578. int tempIndex = 0;
  13579. json_object *UnlockConnector;
  13580. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  13581. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13582. UnlockConnector = json_tokener_parse(payload);
  13583. if(!is_error(UnlockConnector))
  13584. {
  13585. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13586. {
  13587. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13588. }
  13589. }
  13590. json_object_put(UnlockConnector);
  13591. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13592. if(gunTotalNumber == 0)
  13593. {
  13594. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13595. goto end;
  13596. }
  13597. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13598. {
  13599. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13600. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  13601. goto end;
  13602. }
  13603. else
  13604. {
  13605. //check Transaction active
  13606. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13607. {
  13608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13609. {
  13610. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13611. }
  13612. else
  13613. {
  13614. tempIndex = connectorIdInt -1;
  13615. }
  13616. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13617. {
  13618. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  13619. {
  13620. //stop Transaction
  13621. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13622. }
  13623. }
  13624. }
  13625. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13626. {
  13627. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13628. {
  13629. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13630. }
  13631. else
  13632. {
  13633. tempIndex = connectorIdInt -1;
  13634. }
  13635. for (int index = 0; index < CCS_QUANTITY; index++)
  13636. {
  13637. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  13638. {
  13639. //stop Transaction
  13640. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13641. }
  13642. }
  13643. }
  13644. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13645. {
  13646. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13647. {
  13648. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13649. }
  13650. else
  13651. {
  13652. tempIndex = connectorIdInt -1;
  13653. }
  13654. for (int index = 0; index < GB_QUANTITY; index++)
  13655. {
  13656. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  13657. {
  13658. //stop Transaction
  13659. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13660. }
  13661. }
  13662. }
  13663. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13664. {
  13665. tempIndex = connectorIdInt -1;
  13666. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13667. {
  13668. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  13669. {
  13670. //stop Transaction
  13671. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13672. }
  13673. }
  13674. }
  13675. else
  13676. {
  13677. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13678. {
  13679. tempIndex = 2;
  13680. }
  13681. else
  13682. {
  13683. tempIndex = connectorIdInt-1;
  13684. }
  13685. for (int index = 0; index < AC_QUANTITY; index++)
  13686. {
  13687. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  13688. {
  13689. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  13690. }
  13691. }
  13692. }
  13693. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  13694. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13695. result = TRUE;
  13696. return result;
  13697. }
  13698. end:
  13699. //json_object_put(obj); --- remove temporally
  13700. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  13701. return result;
  13702. }
  13703. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13704. {
  13705. mtrace();
  13706. int result = FAIL;
  13707. pthread_t t;
  13708. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13709. sendUpdateFirmwareConfirmation(uuid);
  13710. if(!interLock.isUpdateFirmwareGoing)
  13711. {
  13712. interLock.isUpdateFirmwareGoing = 1;
  13713. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  13714. sleep(1);
  13715. }
  13716. else
  13717. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  13718. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  13719. return result;
  13720. }
  13721. void *UpdateFirmwareProcess(void *data)
  13722. {
  13723. pthread_detach(pthread_self());
  13724. mtrace();
  13725. int retriesInt =0, retryIntervalInt=0;
  13726. char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
  13727. int port=0;
  13728. char locationstr[2048]={0}, retrieveDatestr[36]={0};
  13729. int isSuccess = 0;
  13730. char ftpbuf[2048];
  13731. char temp[2048];
  13732. char * pch;
  13733. char filenametemp[256];
  13734. json_object *UpdateFirmware;
  13735. UpdateFirmware = json_tokener_parse(data);
  13736. if(!is_error(UpdateFirmware))
  13737. {
  13738. // Required data
  13739. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13740. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13741. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13742. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13743. // Optional data
  13744. if(json_object_object_get(UpdateFirmware, "retries"))
  13745. {
  13746. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13747. }
  13748. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13749. {
  13750. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13751. }
  13752. }
  13753. json_object_put(UpdateFirmware);
  13754. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13755. memset(path, 0, ARRAY_SIZE(path));
  13756. // Wait retrieveData
  13757. if(strlen(retrieveDatestr) > 10)
  13758. {
  13759. do
  13760. {
  13761. sleep(1);
  13762. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13763. }
  13764. // Ready to download
  13765. system("rm -f /mnt/*");
  13766. if(strncmp(locationstr,"http", 4) == 0)
  13767. {
  13768. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13769. sprintf(ftppath,"/%s", path);
  13770. DEBUG_INFO("locationstr: %s\n", locationstr);
  13771. DEBUG_INFO("protocol: %s\n",protocol);
  13772. DEBUG_INFO("host: %s\n",host);
  13773. DEBUG_INFO("path: %s\n",path);
  13774. DEBUG_INFO("ftppath: %s\n",ftppath);
  13775. int ftppathlen=strlen(ftppath);
  13776. int i=1;
  13777. while(i < ftppathlen)
  13778. {
  13779. int len=ftppathlen-i;
  13780. if(ftppath[len]== 47) // '/' ascll code: 47
  13781. {
  13782. DEBUG_INFO("compare '/' all right\n");
  13783. break;
  13784. }
  13785. i=i+1;
  13786. }
  13787. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13788. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13789. filenametemp[i+1] = 0;
  13790. do
  13791. {
  13792. sleep(1);
  13793. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13794. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13795. sleep(1);
  13796. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13797. if(!isSuccess)
  13798. {
  13799. sleep(1);
  13800. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13801. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13802. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13803. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13804. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13805. }
  13806. else
  13807. {
  13808. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13809. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13810. }
  13811. retriesInt--;
  13812. }while((isSuccess == 0)&&(retriesInt >= 0));
  13813. }
  13814. else if(strncmp(locationstr,"sftp", 4) == 0) // sftp
  13815. {
  13816. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13817. memset(temp, 0, ARRAY_SIZE(temp));
  13818. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13819. strcpy(ftpbuf, locationstr);
  13820. int ftppathlen=strlen(ftpbuf);
  13821. int i=1;
  13822. while(i < ftppathlen)
  13823. {
  13824. int len=ftppathlen-i;
  13825. if(ftpbuf[len]== 47) // '/' ascii code: 47
  13826. {
  13827. DEBUG_INFO(" compare '/' all right\n");
  13828. break;
  13829. }
  13830. i=i+1;
  13831. }
  13832. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13833. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13834. filenametemp[i+1] = 0;
  13835. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13836. pch=strchr(temp,'@');
  13837. if(pch==NULL)
  13838. {
  13839. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13840. protocol, host, &port, path);
  13841. strcpy(user,"anonymous");
  13842. strcpy(password,"");
  13843. }
  13844. else
  13845. {
  13846. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  13847. protocol, user, host, &port, path);
  13848. }
  13849. sscanf(host,"%[^/]%s",host1, path1);
  13850. sprintf(ftppath,"%s:/%s", host,path);
  13851. if(port == 0)
  13852. {
  13853. port = 21;
  13854. }
  13855. do
  13856. {
  13857. sleep(1);
  13858. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13859. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13860. sleep(1);
  13861. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, filenametemp, locationstr);
  13862. if(!isSuccess)
  13863. {
  13864. //BulldogUtil.sleepMs(interval*1000);
  13865. DEBUG_INFO("Update firmware request and download file fail.\n");
  13866. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13867. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13868. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13869. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13870. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13871. }
  13872. else
  13873. {
  13874. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13875. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13876. }
  13877. retriesInt--;
  13878. }while((!isSuccess)&&(retriesInt >= 0));
  13879. }
  13880. else if((strncmp(locationstr,"ftp", 3) == 0) || (strncmp(locationstr,"ftps", 4) == 0)) // ftp/ftps
  13881. {
  13882. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13883. memset(temp, 0, ARRAY_SIZE(temp));
  13884. //DEBUG_INFO("locationstr=%s\n",locationstr);
  13885. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  13886. int ftppathlen=strlen(ftpbuf);
  13887. int i=1;
  13888. while(i < ftppathlen)
  13889. {
  13890. int len=ftppathlen-i;
  13891. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13892. {
  13893. DEBUG_INFO(" compare '/' all right\n");
  13894. break;
  13895. }
  13896. i=i+1;
  13897. }
  13898. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13899. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13900. filenametemp[i+1] = 0;
  13901. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13902. pch=strchr(temp,'@');
  13903. if(pch==NULL)
  13904. {
  13905. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13906. protocol, host, &port, path);
  13907. strcpy(user,"anonymous");
  13908. strcpy(password,"");
  13909. }
  13910. else
  13911. {
  13912. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13913. protocol, user, password, host, &port, path);
  13914. }
  13915. sscanf(host,"%[^/]%s",host1, path1);
  13916. sprintf(ftppath,"%s", path1);
  13917. //DEBUG_INFO("protocol =%s\n",protocol);
  13918. //DEBUG_INFO("user =%s\n",user);
  13919. //DEBUG_INFO("password =%s\n",password);
  13920. //DEBUG_INFO("host1 =%s\n",host1);
  13921. //DEBUG_INFO("port =%d\n",port);
  13922. //DEBUG_INFO("path1 =%s\n",path1);
  13923. //DEBUG_INFO("ftppath=%s\n",ftppath);
  13924. //ftpFile(host, user, password, port, ftppath, fname);
  13925. //download firmware pthred
  13926. if(port == 0)
  13927. {
  13928. port = 21;
  13929. }
  13930. do
  13931. {
  13932. sleep(1);
  13933. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  13934. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13935. sleep(1);
  13936. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13937. if(!isSuccess)
  13938. {
  13939. //BulldogUtil.sleepMs(interval*1000);
  13940. DEBUG_INFO("Update firmware request and download file fail.\n");
  13941. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13942. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13943. if(retriesInt>0)sleep(retryIntervalInt);else sleep(3);
  13944. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13945. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13946. }
  13947. else
  13948. {
  13949. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  13950. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13951. }
  13952. retriesInt--;
  13953. }while((!isSuccess)&&(retriesInt >= 0));
  13954. }
  13955. else
  13956. {
  13957. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  13958. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13959. sleep(1);
  13960. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  13961. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13962. }
  13963. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)
  13964. {
  13965. sleep(3);
  13966. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  13967. }
  13968. interLock.isUpdateFirmwareGoing = 0;
  13969. pthread_exit(NULL);
  13970. }
  13971. int handleCertificateSignedRequest(char *uuid, char *payload)
  13972. {
  13973. mtrace();
  13974. int result = PASS;
  13975. json_object *CertificateSigned;
  13976. DEBUG_INFO("handleCertificateSignedRequest...\n");
  13977. CertificateSigned = json_tokener_parse(payload);
  13978. if(!is_error(CertificateSigned))
  13979. {
  13980. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  13981. }
  13982. json_object_put(CertificateSigned);
  13983. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  13984. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  13985. fclose(fp);
  13986. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13987. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  13988. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  13989. {
  13990. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  13991. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  13992. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  13993. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  13994. }
  13995. else
  13996. {
  13997. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Rejected");
  13998. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  13999. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14000. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14001. }
  14002. sendCertificateSignedConfirmation(uuid);
  14003. return result;
  14004. }
  14005. int handleDeleteCertificateRequest(char *uuid, char *payload)
  14006. {
  14007. mtrace();
  14008. int result = PASS;
  14009. json_object *DeleteCertificate;
  14010. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  14011. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  14012. DeleteCertificate = json_tokener_parse(payload);
  14013. if(!is_error(DeleteCertificate))
  14014. {
  14015. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  14016. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  14017. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  14018. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  14019. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  14020. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  14021. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  14022. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  14023. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  14024. {
  14025. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  14026. }
  14027. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  14028. {
  14029. ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  14030. }
  14031. for(int i = 0; ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  14032. {
  14033. ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  14034. }
  14035. char temp[256] = {0};
  14036. char compareData[256] = {0};
  14037. int isMatch = TRUE;
  14038. // Check CentralSystemRootCertificate
  14039. if(access(ROOTCA_CS,F_OK) != -1)
  14040. {
  14041. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  14042. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  14043. for(int i = 0; compareData[i]; i++)
  14044. {
  14045. compareData[i] = tolower(compareData[i]);
  14046. }
  14047. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14048. isMatch = FALSE;
  14049. if(isMatch == TRUE)
  14050. {
  14051. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  14052. for(int i = 0; compareData[i]; i++)
  14053. {
  14054. compareData[i] = tolower(compareData[i]);
  14055. }
  14056. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14057. isMatch = FALSE;
  14058. }
  14059. if(isMatch == TRUE)
  14060. {
  14061. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  14062. for(int i = 0; compareData[i]; i++)
  14063. {
  14064. compareData[i] = tolower(compareData[i]);
  14065. }
  14066. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14067. isMatch = FALSE;
  14068. }
  14069. if(isMatch == TRUE)
  14070. {
  14071. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  14072. sprintf(temp, "rm -f %s", ROOTCA_CS);
  14073. system(temp);
  14074. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14075. goto End;
  14076. }
  14077. }
  14078. // Check ManufacturerRootCertificate
  14079. if(access(ROOTCA_MF,F_OK) != -1)
  14080. {
  14081. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  14082. isMatch = TRUE;
  14083. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  14084. for(int i = 0; compareData[i]; i++)
  14085. {
  14086. compareData[i] = tolower(compareData[i]);
  14087. }
  14088. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14089. isMatch = FALSE;
  14090. if(isMatch == TRUE)
  14091. {
  14092. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  14093. for(int i = 0; compareData[i]; i++)
  14094. {
  14095. compareData[i] = tolower(compareData[i]);
  14096. }
  14097. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14098. isMatch = FALSE;
  14099. }
  14100. if(isMatch == TRUE)
  14101. {
  14102. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  14103. for(int i = 0; compareData[i]; i++)
  14104. {
  14105. compareData[i] = tolower(compareData[i]);
  14106. }
  14107. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14108. isMatch = FALSE;
  14109. }
  14110. if(isMatch == TRUE)
  14111. {
  14112. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  14113. sprintf(temp, "rm -f %s", ROOTCA_MF);
  14114. system(temp);
  14115. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14116. goto End;
  14117. }
  14118. }
  14119. // Check certCP
  14120. if(access(CERTIFICATE_CP,F_OK) != -1)
  14121. {
  14122. DEBUG_INFO("Checking certCP...\n");
  14123. isMatch = TRUE;
  14124. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  14125. for(int i = 0; compareData[i]; i++)
  14126. {
  14127. compareData[i] = tolower(compareData[i]);
  14128. }
  14129. if(strcmp(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  14130. isMatch = FALSE;
  14131. if(isMatch == TRUE)
  14132. {
  14133. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  14134. for(int i = 0; compareData[i]; i++)
  14135. {
  14136. compareData[i] = tolower(compareData[i]);
  14137. }
  14138. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  14139. isMatch = FALSE;
  14140. }
  14141. if(isMatch == TRUE)
  14142. {
  14143. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  14144. for(int i = 0; compareData[i]; i++)
  14145. {
  14146. compareData[i] = tolower(compareData[i]);
  14147. }
  14148. if(strstr(compareData, (char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  14149. isMatch = FALSE;
  14150. }
  14151. if(isMatch == TRUE)
  14152. {
  14153. DEBUG_INFO("Deleting certCP...\n");
  14154. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  14155. system(temp);
  14156. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "Accepted");
  14157. goto End;
  14158. }
  14159. }
  14160. }
  14161. End:
  14162. json_object_put(DeleteCertificate);
  14163. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  14164. sendDeleteCertificateConfirmation(uuid);
  14165. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14166. return result;
  14167. }
  14168. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  14169. {
  14170. mtrace();
  14171. int result = PASS;
  14172. json_object *ExtendedTriggerMessage;
  14173. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  14174. ExtendedTriggerMessage = json_tokener_parse(payload);
  14175. if(!is_error(ExtendedTriggerMessage))
  14176. {
  14177. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  14178. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  14179. {
  14180. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  14181. }
  14182. else
  14183. {
  14184. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  14185. }
  14186. }
  14187. json_object_put(ExtendedTriggerMessage);
  14188. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  14189. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  14190. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  14191. {
  14192. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  14193. }
  14194. else
  14195. {
  14196. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  14197. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  14198. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  14199. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  14200. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  14201. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  14202. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  14203. {
  14204. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  14205. }
  14206. else
  14207. {
  14208. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  14209. }
  14210. }
  14211. sendExtendedTriggerMessageConfirmation(uuid);
  14212. //==========================
  14213. // Trigger message
  14214. //==========================
  14215. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  14216. {
  14217. //sendBootNotificationRequest();
  14218. server_sign = FALSE;
  14219. }
  14220. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  14221. {
  14222. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14223. }
  14224. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  14225. {
  14226. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  14227. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  14228. {
  14229. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  14230. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  14231. }
  14232. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  14233. }
  14234. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  14235. {
  14236. refreshStartTimer(&clientTime.Heartbeat);
  14237. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  14238. }
  14239. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  14240. {
  14241. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14242. {
  14243. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  14244. }
  14245. else
  14246. {
  14247. for(int idx=0;idx< gunTotalNumber;idx++)
  14248. {
  14249. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  14250. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  14251. }
  14252. }
  14253. }
  14254. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  14255. {
  14256. char cmdBuf[1024]={0};
  14257. 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);
  14258. system(cmdBuf);
  14259. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  14260. }
  14261. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  14262. {
  14263. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  14264. {
  14265. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  14266. }
  14267. else
  14268. {
  14269. for(int idx=0;idx< gunTotalNumber;idx++)
  14270. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  14271. }
  14272. }
  14273. return result;
  14274. }
  14275. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  14276. {
  14277. mtrace();
  14278. int result = PASS;
  14279. json_object *GetInstalledCertificateIds;
  14280. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  14281. GetInstalledCertificateIds = json_tokener_parse(payload);
  14282. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  14283. if(!is_error(GetInstalledCertificateIds))
  14284. {
  14285. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  14286. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14287. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "Accepted");
  14288. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  14289. // Check CentralSystemRootCertificate
  14290. if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "CentralSystemRootCertificate")!= NULL)
  14291. {
  14292. if(access(ROOTCA_CS,F_OK) != -1)
  14293. {
  14294. char parseData[512] = {0};
  14295. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14296. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14297. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  14298. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14299. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14300. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14301. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14302. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14303. }
  14304. else
  14305. {
  14306. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  14307. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14308. }
  14309. }
  14310. // Check ManufacturerRootCertificate
  14311. else if(strstr((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "ManufacturerRootCertificate") != NULL)
  14312. {
  14313. if(access(ROOTCA_MF,F_OK) != -1)
  14314. {
  14315. char parseData[512] = {0};
  14316. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  14317. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm, parseData);
  14318. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  14319. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].serialNumber, parseData);
  14320. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  14321. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerNameHash, parseData);
  14322. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  14323. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].issuerKeyHash, parseData);
  14324. }
  14325. else
  14326. {
  14327. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  14328. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14329. }
  14330. }
  14331. else
  14332. {
  14333. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  14334. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  14335. }
  14336. }
  14337. json_object_put(GetInstalledCertificateIds);
  14338. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  14339. sendGetInstalledCertificateIdsConfirmation(uuid);
  14340. return result;
  14341. }
  14342. void* GetLogProcess(void* data)
  14343. {
  14344. pthread_detach(pthread_self());
  14345. mtrace();
  14346. 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};
  14347. int port=0;
  14348. int isSuccess = FALSE;
  14349. char cmdBuf[2048];
  14350. struct tm *tmNow;
  14351. time_t CurrentTime;
  14352. struct tm tmStart;
  14353. struct tm tmStop;
  14354. CurrentTime = time(NULL);
  14355. tmNow=localtime(&CurrentTime);
  14356. uint16_t targetYear, targetMonth;
  14357. json_object *GetLog;
  14358. DEBUG_INFO("GetLogProcess...\n");
  14359. GetLog = json_tokener_parse(data);
  14360. if(!is_error(GetLog))
  14361. {
  14362. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  14363. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  14364. if(json_object_object_get(GetLog, "retries") != NULL)
  14365. {
  14366. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  14367. }
  14368. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  14369. {
  14370. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  14371. }
  14372. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  14373. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  14374. {
  14375. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  14376. }
  14377. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  14378. {
  14379. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  14380. }
  14381. }
  14382. json_object_put(GetLog);
  14383. // Pack log to compress file
  14384. 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) &&
  14385. (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))
  14386. {
  14387. // Pack system log
  14388. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14389. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14390. targetYear = tmStart.tm_year;
  14391. targetMonth = tmStart.tm_mon;
  14392. do
  14393. {
  14394. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14395. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  14396. if(targetMonth+1>=13)
  14397. {
  14398. targetYear += 1;
  14399. targetMonth = 1;
  14400. }
  14401. else
  14402. {
  14403. targetMonth += 1;
  14404. }
  14405. }while((targetYear < (tmNow->tm_year+1900)) ||
  14406. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14407. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  14408. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  14409. sprintf(cmdBuf, "%s /Storage/SystemLog/*Dispenser*Log.zip", cmdBuf);
  14410. system(cmdBuf);
  14411. // Pack charging & event log
  14412. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  14413. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  14414. targetYear = tmStart.tm_year;
  14415. targetMonth = tmStart.tm_mon;
  14416. do
  14417. {
  14418. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  14419. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  14420. if(targetMonth+1>=13)
  14421. {
  14422. targetYear += 1;
  14423. targetMonth = 1;
  14424. }
  14425. else
  14426. {
  14427. targetMonth += 1;
  14428. }
  14429. }while((targetYear < (tmNow->tm_year+1900)) ||
  14430. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  14431. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  14432. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  14433. system(cmdBuf);
  14434. // Combine log file
  14435. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  14436. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  14437. }
  14438. else
  14439. {
  14440. system("exec /root/logPackTools 'log' 6");
  14441. }
  14442. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetLog.Response_filename);
  14443. system(cmdBuf);
  14444. checkUploadLog();
  14445. //****************location*******************/
  14446. if(strcmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"")==0)
  14447. {
  14448. DEBUG_INFO("location is <Empty>!\n");
  14449. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14450. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14451. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14452. goto end;
  14453. }
  14454. memset(protocol, 0, ARRAY_SIZE(protocol));
  14455. memset(user, 0, ARRAY_SIZE(user) );
  14456. memset(password, 0, ARRAY_SIZE(password));
  14457. memset(host, 0, ARRAY_SIZE(host));
  14458. memset(path, 0, ARRAY_SIZE(path));
  14459. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14460. memset(host1, 0, ARRAY_SIZE(host1));
  14461. memset(path1, 0, ARRAY_SIZE(path1));
  14462. /*location: ftp://user:password@host:port/path*/
  14463. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  14464. if((access(fnamePlusPath,F_OK))!=-1)
  14465. {
  14466. DEBUG_INFO("fnamePlusPath exist.\n");
  14467. }
  14468. else
  14469. {
  14470. DEBUG_INFO("fnamePlusPath not exist!\n");
  14471. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14472. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14473. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14474. goto end;
  14475. }
  14476. if(strchr((char*)ShmOCPP16Data->GetLog.log.remoteLocation,'@')==NULL)
  14477. {
  14478. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,
  14479. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14480. protocol, host, &port, path);
  14481. strcpy(user,"anonymous");
  14482. strcpy(password,"");
  14483. }
  14484. else
  14485. {
  14486. //DEBUG_INFO("pch=%s\n", pch);
  14487. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14488. protocol, user, password, host, &port, path);
  14489. }
  14490. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  14491. {
  14492. DEBUG_INFO("protocol is not ftp/http ! \n");
  14493. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14494. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14495. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14496. goto end;
  14497. }
  14498. if(strncmp((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"http", 4) == 0)
  14499. {
  14500. sscanf((char*)ShmOCPP16Data->GetLog.log.remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14501. sprintf(ftppath,"/%s", path);
  14502. do
  14503. {
  14504. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14505. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14506. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14507. sleep(3);
  14508. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, (char*)ShmOCPP16Data->GetLog.log.remoteLocation);
  14509. if(!isSuccess)
  14510. {
  14511. DEBUG_INFO("Diagnostics fail.\n");
  14512. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14513. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14514. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14515. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14516. }
  14517. else
  14518. {
  14519. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14520. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14521. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14522. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14523. }
  14524. ShmOCPP16Data->GetLog.retries--;
  14525. }while((isSuccess == 0)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14526. }
  14527. else
  14528. {
  14529. sscanf(host,"%[^/]%s",host1, path1);
  14530. if(strlen(path) > 0)
  14531. sprintf(ftppath,"/%s", path);
  14532. else
  14533. sprintf(ftppath,"/%s", path1);
  14534. int ftppathlen=strlen(ftppath);
  14535. int i=1;
  14536. char filenametemp[50];
  14537. while(i < ftppathlen)
  14538. {
  14539. int len=ftppathlen-i;
  14540. if(ftppath[len]== 47) // '/' ascll code: 47
  14541. {
  14542. DEBUG_INFO("find '/' all right\n");
  14543. break;
  14544. }
  14545. i=i+1;
  14546. }
  14547. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14548. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14549. filenametemp[i+1] = 0;
  14550. if(port == 0)
  14551. port = 21;
  14552. do
  14553. {
  14554. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14555. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploading");
  14556. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14557. sleep(3);
  14558. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14559. if(!isSuccess)
  14560. {
  14561. DEBUG_INFO("Diagnostics fail.\n");
  14562. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14563. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "UploadFailure");
  14564. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14565. sleep(ShmOCPP16Data->GetLog.retryInterval);
  14566. }
  14567. else
  14568. {
  14569. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  14570. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14571. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Uploaded");
  14572. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14573. }
  14574. ShmOCPP16Data->GetLog.retries--;
  14575. }while((!isSuccess)&&(ShmOCPP16Data->GetLog.retries >= 0));
  14576. }
  14577. end:
  14578. system("rm -f /mnt/*");
  14579. system("rm -f /Storage/SystemLog/*Dispenser*Log.zip");
  14580. sleep(5);
  14581. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  14582. sprintf((char*)ShmOCPP16Data->LogStatusNotification.status, "%s", "Idle");
  14583. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  14584. interLock.isGetDiagnosticGoing = 0;
  14585. pthread_exit(NULL);
  14586. }
  14587. int handleGetLogRequest(char *uuid, char *payload)
  14588. {
  14589. mtrace();
  14590. int result = PASS;
  14591. time_t CurrentTime;
  14592. struct tm *tm;
  14593. DEBUG_INFO("handleGetLogRequest...\n");
  14594. pthread_t th_Status;
  14595. CurrentTime = time(NULL);
  14596. tm = localtime(&CurrentTime);
  14597. memset(ShmOCPP16Data->GetLog.Response_filename, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetLog.Response_filename));
  14598. 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);
  14599. if(!interLock.isGetDiagnosticGoing)
  14600. {
  14601. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Accepted");
  14602. interLock.isGetDiagnosticGoing = 1;
  14603. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14604. sleep(1);
  14605. }
  14606. else
  14607. {
  14608. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  14609. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14610. }
  14611. sendGetLogConfirmation(uuid);
  14612. return result;
  14613. }
  14614. int handleInstallCertificateRequest(char *uuid, char *payload)
  14615. {
  14616. mtrace();
  14617. int result = PASS;
  14618. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14619. json_object *InstallCertificate;
  14620. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14621. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14622. InstallCertificate = json_tokener_parse(payload);
  14623. if(!is_error(InstallCertificate))
  14624. {
  14625. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14626. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14627. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  14628. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  14629. char temp[1024];
  14630. FILE *fp = fopen(tempCert, "w");
  14631. fprintf(fp, "%s", ShmOCPP16Data->InstallCertificate.certificate);
  14632. fclose(fp);
  14633. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14634. char strExpDate[30];
  14635. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14636. fp = popen(temp, "r");
  14637. if(fp)
  14638. {
  14639. while(fgets(temp, sizeof(temp), fp) != NULL)
  14640. {
  14641. if(strstr(temp, "notAfter=") != NULL)
  14642. {
  14643. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14644. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14645. break;
  14646. }
  14647. }
  14648. }
  14649. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14650. struct tm tmExpDate;
  14651. struct timeb tbExpDate;
  14652. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14653. tbExpDate.time = mktime(&tmExpDate);
  14654. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14655. {
  14656. DEBUG_INFO("The enddate is already expired...\n");
  14657. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14658. goto End;
  14659. }
  14660. // Verify certificate with rootCA
  14661. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14662. fp = popen(temp, "r");
  14663. if(fp)
  14664. {
  14665. while(fgets(temp, sizeof(temp), fp) != NULL)
  14666. {
  14667. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14668. {
  14669. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14670. break;
  14671. }
  14672. else
  14673. {
  14674. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  14675. }
  14676. }
  14677. }
  14678. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14679. {
  14680. //=====================================================
  14681. // Verify if the certificate is valid or not. (OCSP?)
  14682. //=====================================================
  14683. /*
  14684. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14685. // Get ocsp url
  14686. char ocspUrl[512];
  14687. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14688. fp = popen(temp, "r");
  14689. if(fp)
  14690. {
  14691. while(fgets(temp, sizeof(temp), fp) != NULL)
  14692. {
  14693. if(strstr(temp, "://") != NULL)
  14694. {
  14695. strcpy(ocspUrl, temp);
  14696. break;
  14697. }
  14698. }
  14699. }
  14700. // Get certificate chain for issuer
  14701. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14702. *
  14703. // Execute OCSP
  14704. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14705. fp = popen(temp, "r");
  14706. if(fp)
  14707. {
  14708. while(fgets(temp, sizeof(temp), fp) != NULL)
  14709. {
  14710. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14711. {
  14712. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14713. break;
  14714. }
  14715. }
  14716. }
  14717. system("rm -f /Storage/OCPP/tempChain.pem");
  14718. pclose(fp);
  14719. */
  14720. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14721. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14722. {
  14723. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14724. goto End;
  14725. }
  14726. else
  14727. DEBUG_INFO("OCSP verifying...PASS.\n");
  14728. }
  14729. else
  14730. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14731. }
  14732. End:
  14733. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") == 0)
  14734. {
  14735. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "CentralSystemRootCertificate") == 0)
  14736. {
  14737. if(access(ROOTCA_CS,F_OK) != -1)
  14738. {
  14739. DEBUG_INFO("Existed CentralSystemRootCertificate is found. Replacing...\n");
  14740. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14741. rename(tempCert, ROOTCA_CS);
  14742. }
  14743. else
  14744. {
  14745. DEBUG_INFO("No existed CentralSystemRootCertificate. Creating...\n");
  14746. rename(tempCert, ROOTCA_CS);
  14747. }
  14748. }
  14749. else if(strcmp((char*)ShmOCPP16Data->InstallCertificate.certificateType, "ManufacturerRootCertificate") == 0)
  14750. {
  14751. if(access(ROOTCA_MF,F_OK) != -1)
  14752. {
  14753. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14754. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14755. rename(tempCert, ROOTCA_MF);
  14756. }
  14757. else
  14758. {
  14759. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14760. rename(tempCert, ROOTCA_MF);
  14761. }
  14762. }
  14763. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  14764. }
  14765. sendInstallCertificateConfirmation(uuid);
  14766. if(strcmp((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted") != 0)
  14767. {
  14768. sprintf((char*)ShmOCPP16Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14769. memset(ShmOCPP16Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP16Data->SecurityEventNotification.techInfo));
  14770. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14771. }
  14772. json_object_put(InstallCertificate);
  14773. return result;
  14774. }
  14775. void *SignedUpdateFirmwareProcess(void *data)
  14776. {
  14777. pthread_detach(pthread_self());
  14778. mtrace();
  14779. char protocol[10], user[64],password[64],host[256], path[1024], ftppath[1024],host1[256],path1[1024];
  14780. int port=0;
  14781. int isSuccess = 0;
  14782. char ftpbuf[2048];
  14783. char temp[2048];
  14784. char * pch;
  14785. char firmwareFileName[256];
  14786. DEBUG_INFO("SignedUpdateFirmwareProcess ...\n");
  14787. json_object *SignedUpdateFirmware;
  14788. SignedUpdateFirmware = json_tokener_parse(data);
  14789. if(!is_error(SignedUpdateFirmware))
  14790. {
  14791. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  14792. {
  14793. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  14794. }
  14795. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  14796. {
  14797. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  14798. }
  14799. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  14800. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  14801. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  14802. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  14803. {
  14804. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  14805. }
  14806. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  14807. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  14808. }
  14809. json_object_put(SignedUpdateFirmware);
  14810. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14811. memset(path, 0, ARRAY_SIZE(path));
  14812. // Wait retrieveData
  14813. if(strlen((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location) > 10)
  14814. {
  14815. do
  14816. {
  14817. sleep(1);
  14818. }while(!isOvertNow((uint8_t*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime));
  14819. }
  14820. // Ready to download
  14821. system("rm -f /mnt/*");
  14822. if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"http", 4) == 0)
  14823. {
  14824. sscanf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14825. sprintf(ftppath,"/%s", path);
  14826. DEBUG_INFO("locationstr: %s\n", (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14827. DEBUG_INFO("protocol: %s\n",protocol);
  14828. DEBUG_INFO("host: %s\n",host);
  14829. DEBUG_INFO("path: %s\n",path);
  14830. DEBUG_INFO("ftppath: %s\n",ftppath);
  14831. int ftppathlen=strlen(ftppath);
  14832. int i=1;
  14833. while(i < ftppathlen)
  14834. {
  14835. int len=ftppathlen-i;
  14836. if(ftppath[len]== 47) // '/' ascll code: 47
  14837. {
  14838. DEBUG_INFO("compare '/' all right\n");
  14839. break;
  14840. }
  14841. i=i+1;
  14842. }
  14843. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14844. strncpy(firmwareFileName, ftppath+(ftppathlen-i+1), i+1);
  14845. firmwareFileName[i+1] = 0;
  14846. do
  14847. {
  14848. sleep(1);
  14849. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14850. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14851. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14852. sleep(1);
  14853. isSuccess = httpDownLoadFile(host, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14854. if(!isSuccess)
  14855. {
  14856. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14857. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14858. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14859. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14860. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14861. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14862. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14863. }
  14864. else
  14865. {
  14866. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14867. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14868. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14869. }
  14870. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14871. }while((isSuccess == 0)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14872. }
  14873. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"sftp", 4) == 0) // sftp
  14874. {
  14875. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14876. memset(temp, 0, ARRAY_SIZE(temp));
  14877. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14878. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14879. int ftppathlen=strlen(ftpbuf);
  14880. int i=1;
  14881. while(i < ftppathlen)
  14882. {
  14883. int len=ftppathlen-i;
  14884. if(ftpbuf[len]== 47) // '/' ascii code: 47
  14885. {
  14886. DEBUG_INFO(" compare '/' all right\n");
  14887. break;
  14888. }
  14889. i=i+1;
  14890. }
  14891. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14892. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14893. firmwareFileName[i+1] = 0;
  14894. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14895. pch=strchr(temp,'@');
  14896. if(pch==NULL)
  14897. {
  14898. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14899. protocol, host, &port, path);
  14900. strcpy(user,"anonymous");
  14901. strcpy(password,"");
  14902. }
  14903. else
  14904. {
  14905. sscanf(temp,"%[^:]:%*2[/]%[^@]@%[^:]:%i/%199[^\n]",
  14906. protocol, user, host, &port, path);
  14907. }
  14908. sscanf(host,"%[^/]%s",host1, path1);
  14909. sprintf(ftppath,"%s:/%s", host,path);
  14910. if(port == 0)
  14911. {
  14912. port = 21;
  14913. }
  14914. do
  14915. {
  14916. sleep(1);
  14917. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14918. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14919. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14920. sleep(1);
  14921. isSuccess = sftpDownLoadFile(host1, user, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14922. if(!isSuccess)
  14923. {
  14924. sleep(1);
  14925. DEBUG_INFO("Update firmware request and download file fail.\n");
  14926. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14927. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  14928. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14929. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  14930. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14931. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  14932. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14933. }
  14934. else
  14935. {
  14936. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14937. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  14938. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14939. }
  14940. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  14941. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  14942. }
  14943. else if(strncmp((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location,"ftp", 3) == 0) // ftp
  14944. {
  14945. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14946. memset(temp, 0, ARRAY_SIZE(temp));
  14947. //DEBUG_INFO("locationstr=%s\n",locationstr);
  14948. strcpy(ftpbuf, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  14949. int ftppathlen=strlen(ftpbuf);
  14950. int i=1;
  14951. while(i < ftppathlen)
  14952. {
  14953. int len=ftppathlen-i;
  14954. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14955. {
  14956. DEBUG_INFO(" compare '/' all right\n");
  14957. break;
  14958. }
  14959. i=i+1;
  14960. }
  14961. memset(firmwareFileName, 0, ARRAY_SIZE(firmwareFileName));
  14962. strncpy(firmwareFileName, ftpbuf+(ftppathlen-i+1), i+1);
  14963. firmwareFileName[i+1] = 0;
  14964. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14965. pch=strchr(temp,'@');
  14966. if(pch==NULL)
  14967. {
  14968. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14969. protocol, host, &port, path);
  14970. strcpy(user,"anonymous");
  14971. strcpy(password,"");
  14972. }
  14973. else
  14974. {
  14975. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14976. protocol, user, password, host, &port, path);
  14977. }
  14978. sscanf(host,"%[^/]%s",host1, path1);
  14979. sprintf(ftppath,"%s", path1);
  14980. //DEBUG_INFO("protocol =%s\n",protocol);
  14981. //DEBUG_INFO("user =%s\n",user);
  14982. //DEBUG_INFO("password =%s\n",password);
  14983. //DEBUG_INFO("host1 =%s\n",host1);
  14984. //DEBUG_INFO("port =%d\n",port);
  14985. //DEBUG_INFO("path1 =%s\n",path1);
  14986. //DEBUG_INFO("ftppath=%s\n",ftppath);
  14987. //ftpFile(host, user, password, port, ftppath, fname);
  14988. //download firmware pthred
  14989. if(port == 0)
  14990. {
  14991. port = 21;
  14992. }
  14993. do
  14994. {
  14995. sleep(1);
  14996. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  14997. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloading");
  14998. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  14999. sleep(1);
  15000. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, firmwareFileName, (char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  15001. if(!isSuccess)
  15002. {
  15003. //BulldogUtil.sleepMs(interval*1000);
  15004. DEBUG_INFO("Update firmware request and download file fail.\n");
  15005. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15006. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15007. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15008. if(ShmOCPP16Data->SignedUpdateFirmware.retries>0)sleep(ShmOCPP16Data->SignedUpdateFirmware.retryInterval);else sleep(3);
  15009. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15010. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15011. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15012. }
  15013. else
  15014. {
  15015. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15016. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Downloaded");
  15017. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15018. }
  15019. ShmOCPP16Data->SignedUpdateFirmware.retries--;
  15020. }while((!isSuccess)&&(ShmOCPP16Data->SignedUpdateFirmware.retries >= 0));
  15021. }
  15022. else
  15023. {
  15024. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15025. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "DownloadFailed");
  15026. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15027. sleep(1);
  15028. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15029. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15030. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15031. }
  15032. // Verify firmware image signature
  15033. struct stat st;
  15034. FILE *fp = fopen("/tmp/signingFirmwareUpdate.crt", "w");
  15035. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  15036. fclose(fp);
  15037. system("openssl x509 -pubkey -noout -in /tmp/signingFirmwareUpdate.crt > /tmp/signingFirmwareUpdate.key");
  15038. fp = fopen("/tmp/signingFirmwareUpdate.sign", "w");
  15039. fprintf(fp, "%s", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  15040. fclose(fp);
  15041. system("openssl base64 -d -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15042. stat("/tmp/signingFirmwareUpdate.sign.256", &st);
  15043. if(st.st_size == 0)
  15044. system("openssl base64 -d -A -in /tmp/signingFirmwareUpdate.sign -out /tmp/signingFirmwareUpdate.sign.256");
  15045. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "Downloaded") != NULL)
  15046. {
  15047. sprintf(temp ,"openssl dgst -verify /tmp/signingFirmwareUpdate.key -signature /tmp/signingFirmwareUpdate.sign.256 /mnt/%s", firmwareFileName);
  15048. fp = popen(temp, "r");
  15049. if(fp)
  15050. {
  15051. while(fgets(temp, sizeof(temp), fp) != NULL)
  15052. {
  15053. if(strstr(temp, "Verified OK") != NULL)
  15054. {
  15055. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15056. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "SignatureVerified");
  15057. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15058. }
  15059. else
  15060. {
  15061. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15062. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InvalidSignature");
  15063. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15064. sleep(1);
  15065. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15066. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "InstallationFailed");
  15067. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15068. sleep(1);
  15069. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  15070. sprintf((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "%s", "Idle");
  15071. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 1;
  15072. }
  15073. break;
  15074. }
  15075. }
  15076. pclose(fp);
  15077. if(strstr((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status, "SignatureVerified") != NULL)ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  15078. }
  15079. interLock.isUpdateFirmwareGoing = 0;
  15080. pthread_exit(NULL);
  15081. }
  15082. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  15083. {
  15084. mtrace();
  15085. int result = PASS;
  15086. pthread_t t;
  15087. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  15088. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Accepted");
  15089. sendSignedUpdateFirmwareConfirmation(uuid);
  15090. if(!interLock.isUpdateFirmwareGoing)
  15091. {
  15092. interLock.isUpdateFirmwareGoing = 1;
  15093. pthread_create(&t, NULL, SignedUpdateFirmwareProcess, payload);
  15094. sleep(1);
  15095. }
  15096. else
  15097. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15098. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareConf = 1;
  15099. return result;
  15100. }
  15101. int handleUnknownRequest(char *uuid, char *payload)
  15102. {
  15103. mtrace();
  15104. int result = PASS;
  15105. DEBUG_INFO("handleUnknownRequest...\n");
  15106. sendUnknownConfirmation(uuid);
  15107. return result;
  15108. }
  15109. //==========================================
  15110. // Handle server response routine
  15111. //==========================================
  15112. void handleAuthorizeResponse(char *payload, int gun_index)
  15113. {
  15114. mtrace();
  15115. char expiryDatestr[36]={0};
  15116. char parentIdTagstr[21]={0};
  15117. char statusstr[20]={0};
  15118. int expiryDateISNULL=FALSE;
  15119. int parentIdTagISNULL=FALSE;
  15120. DEBUG_INFO("handleAuthorizeResponse...\n");
  15121. json_object *Authorize;
  15122. Authorize = json_tokener_parse(payload);
  15123. if(!is_error(Authorize))
  15124. {
  15125. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  15126. {
  15127. // Required data
  15128. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  15129. // Optional data
  15130. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  15131. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  15132. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  15133. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  15134. }
  15135. }
  15136. json_object_put(Authorize);
  15137. if(expiryDateISNULL == FALSE)
  15138. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  15139. if(parentIdTagISNULL == FALSE)
  15140. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  15141. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  15142. //Update idTag information to authorization cache if supproted
  15143. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  15144. {
  15145. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  15146. }
  15147. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  15148. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  15149. authorizeRetryTimes = 0;
  15150. }
  15151. void handleBootNotificationResponse(char *payload, int gun_index)
  15152. {
  15153. mtrace();
  15154. char statusStr[12]={0};
  15155. char currentTimeStr[30]={0};
  15156. int intervalInt = 0;
  15157. DEBUG_INFO("handleBootNotificationResponse...\n");
  15158. json_object *BootNotification;
  15159. BootNotification = json_tokener_parse(payload);
  15160. if(!is_error(BootNotification))
  15161. {
  15162. // Required data
  15163. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15164. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15165. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15166. }
  15167. json_object_put(BootNotification);
  15168. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15169. BootNotificationInterval = intervalInt;
  15170. //write back to ShmOCPP16Data->BootNotification
  15171. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  15172. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  15173. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  15174. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  15175. {
  15176. BootNotificationInterval = 0;
  15177. if((intervalInt == 0) || (intervalInt >= 10))
  15178. {
  15179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  15180. HeartBeatWaitTime = intervalInt;
  15181. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15182. }
  15183. server_sign = TRUE;
  15184. server_pending =FALSE;
  15185. }
  15186. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  15187. {
  15188. server_pending = TRUE;
  15189. }
  15190. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  15191. srand(time(NULL));
  15192. refreshStartTimer(&clientTime.Heartbeat);
  15193. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  15194. SetOcppConnStatus(TRUE);
  15195. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  15196. }
  15197. void handleDataTransferResponse(char *payload, int gun_index)
  15198. {
  15199. json_object *DataTransfer = json_tokener_parse(payload);
  15200. DEBUG_INFO("Corresponding gun-%d MessageId: %s\n", gun_index, ShmOCPP16Data->DataTransfer[gun_index].MessageId);
  15201. if(!is_error(DataTransfer))
  15202. {
  15203. // Required data
  15204. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  15205. // Optional data
  15206. if(json_object_object_get(DataTransfer, "data") != NULL)
  15207. {
  15208. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15209. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  15210. if(!is_error(Data))
  15211. {
  15212. if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Authorize") != NULL)
  15213. {
  15214. if(json_object_object_get(Data, "certificateStatus") != NULL)
  15215. {
  15216. sprintf((char*)ShmOCPP16Data->v2g_extend.Authorize.Response_certificateStatus, "%s", json_object_get_string(json_object_object_get(Data, "certificateStatus")));
  15217. }
  15218. if(json_object_object_get(Data, "idTokenInfo") != NULL)
  15219. {
  15220. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "status") != NULL)
  15221. {
  15222. 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")));
  15223. }
  15224. if(json_object_object_get(json_object_object_get(Data, "idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15225. {
  15226. 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")));
  15227. }
  15228. }
  15229. ShmOCPP16Data->v2g_extend.AuthorizeConf = 1;
  15230. }
  15231. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "Get15118EVCertificate") != NULL)
  15232. {
  15233. if(json_object_object_get(Data, "status") != NULL)
  15234. {
  15235. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15236. }
  15237. if(json_object_object_get(Data, "exiResponse") != NULL)
  15238. {
  15239. sprintf((char*)ShmOCPP16Data->v2g_extend.Get15118EVCertificate.Response_exiResponse, "%s", json_object_get_string(json_object_object_get(Data, "exiResponse")));
  15240. }
  15241. ShmOCPP16Data->v2g_extend.Get15118EVCertificateConf = 1;
  15242. }
  15243. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "GetCertificateStatus") != NULL)
  15244. {
  15245. if(json_object_object_get(Data, "status") != NULL)
  15246. {
  15247. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15248. }
  15249. if(json_object_object_get(Data, "ocspResult") != NULL)
  15250. {
  15251. sprintf((char*)ShmOCPP16Data->v2g_extend.GetCertificateStatus.Response_ocspResult, "%s", json_object_get_string(json_object_object_get(Data, "ocspResult")));
  15252. }
  15253. ShmOCPP16Data->v2g_extend.GetCertificateStatusConf = 1;
  15254. }
  15255. else if(strstr((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "SignCertificate") != NULL)
  15256. {
  15257. sprintf((char*)ShmOCPP16Data->v2g_extend.SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(Data, "status")));
  15258. ShmOCPP16Data->v2g_extend.SignCertificateConf = 1;
  15259. }
  15260. else
  15261. {
  15262. if(json_object_object_get(Data, "msgId") != NULL)
  15263. {
  15264. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  15265. {
  15266. 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")));
  15267. }
  15268. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_ReaderStatus") != NULL)
  15269. {
  15270. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15271. ShmOCPP16Data->TcciCustomData.ReaderStatus[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].ReportReaderStatusReq = 0;
  15272. }
  15273. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyFeeAct") != NULL)
  15274. {
  15275. if(json_object_object_get(Data, "ConnectorId") != NULL)
  15276. {
  15277. 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")));
  15278. if(json_object_object_get(Data, "occupancySN") != NULL)
  15279. 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")));
  15280. if(json_object_object_get(Data, "startTime") != NULL)
  15281. 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")));
  15282. if(json_object_object_get(Data, "duration") != NULL)
  15283. 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"));
  15284. if(json_object_object_get(Data, "occupancyFee") != NULL)
  15285. 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"));
  15286. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[json_object_get_int(json_object_object_get(Data, "ConnectorId"))-1].OccupancyFeeActReq = 0;
  15287. }
  15288. else
  15289. {
  15290. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  15291. {
  15292. if(ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq)
  15293. {
  15294. strcpy((char*)ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].response_status, "Rejected");
  15295. ShmOCPP16Data->TcciCustomData.OccupancyFeeAct[idx].OccupancyFeeActReq = 0;
  15296. }
  15297. }
  15298. }
  15299. }
  15300. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_OccupancyDeductResult") != NULL)
  15301. {
  15302. if(json_object_object_get(Data, "occupancySN") != NULL)
  15303. OCPP_update_occupancyDeduct_info((char*)json_object_get_string(json_object_object_get(Data, "occupancySN")));
  15304. }
  15305. }
  15306. }
  15307. }
  15308. json_object_put(Data);
  15309. }
  15310. }
  15311. json_object_put(DataTransfer);
  15312. }
  15313. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  15314. {
  15315. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  15316. //struct json_object *obj;
  15317. // obj = json_tokener_parse(payload);
  15318. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  15319. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  15320. //No fields are defined.
  15321. }
  15322. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15323. {
  15324. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15325. //struct json_object *obj;
  15326. // obj = json_tokener_parse(payload);
  15327. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  15328. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  15329. //No fields are defined.
  15330. }
  15331. void handleHeartbeatResponse(char *payload, int gun_index)
  15332. {
  15333. mtrace();
  15334. DEBUG_INFO("handleHeartbeatResponse...\n");
  15335. json_object *Heartbeat;
  15336. Heartbeat = json_tokener_parse(payload);
  15337. if(!is_error(Heartbeat))
  15338. {
  15339. // Required data
  15340. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15341. }
  15342. json_object_put(Heartbeat);
  15343. if(FirstHeartBeat == 0)
  15344. {
  15345. FirstHeartBeat = 1;
  15346. DEBUG_INFO("FirstHeartBeat \n");
  15347. }
  15348. HeartBeatWithNOResponse = 0;
  15349. refreshStartTimer(&clientTime.Heartbeat);
  15350. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  15351. }
  15352. void handleMeterValuesResponse(char *payload, int gun_index)
  15353. {
  15354. mtrace();
  15355. DEBUG_INFO("handleMeterValuesResponse...\n");
  15356. isQueueSendable = 1;
  15357. }
  15358. void handleStartTransactionResponse(char *payload, int gun_index)
  15359. {
  15360. mtrace();
  15361. //int transactionIdInt = 0;
  15362. FILE *outfile;
  15363. char data[100]={0};
  15364. DEBUG_INFO("handleStartTransactionResponse...\n");
  15365. json_object *StartTransaction;
  15366. StartTransaction = json_tokener_parse(payload);
  15367. if(!is_error(StartTransaction))
  15368. {
  15369. // Required data
  15370. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  15371. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  15372. // Optional data
  15373. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  15374. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  15375. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15376. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  15377. }
  15378. json_object_put(StartTransaction);
  15379. OCPP_updatePeriodEnergy(gun_index);
  15380. //-----------Start : write to the Queue TransactionId file -----------------//
  15381. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  15382. {}
  15383. else
  15384. {
  15385. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  15386. if(log == NULL)
  15387. {
  15388. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  15389. return ;
  15390. }
  15391. else
  15392. {
  15393. fclose(log);
  15394. }
  15395. }
  15396. // open file for writing
  15397. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  15398. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  15399. {
  15400. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  15401. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  15402. fputs(data, outfile);
  15403. fclose (outfile);
  15404. DEBUG_INFO("Update QueueTransactionId done...\n");
  15405. }
  15406. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15407. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15408. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  15409. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  15410. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15411. isQueueSendable = 1;
  15412. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  15413. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  15414. }
  15415. void handleStatusNotificationResponse(char *payload, int gun_index)
  15416. {
  15417. mtrace();
  15418. DEBUG_INFO("handleStatusNotificationResponse...\n");
  15419. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15420. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15421. if(gun_index != 99)
  15422. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  15423. }
  15424. void handleStopTransactionnResponse(char *payload, int gun_index)
  15425. {
  15426. mtrace();
  15427. DEBUG_INFO("handleStopTransactionnResponse...\n");
  15428. json_object *StopTransaction;
  15429. StopTransaction = json_tokener_parse(payload);
  15430. if(!is_error(StopTransaction))
  15431. {
  15432. // Optional data
  15433. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  15434. {
  15435. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  15436. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  15437. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  15438. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  15439. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  15440. }
  15441. }
  15442. json_object_put(StopTransaction);
  15443. isQueueSendable = 1;
  15444. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  15445. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  15446. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  15447. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  15448. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  15449. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  15450. }
  15451. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15452. {
  15453. mtrace();
  15454. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15455. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  15456. }
  15457. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15458. {
  15459. mtrace();
  15460. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15461. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  15462. }
  15463. void handleSignCertificateResponse(char *payload, int gun_index)
  15464. {
  15465. mtrace();
  15466. DEBUG_INFO("handleSignCertificateResponse...\n");
  15467. json_object *SignCertificate;
  15468. SignCertificate = json_tokener_parse(payload);
  15469. if(!is_error(SignCertificate))
  15470. {
  15471. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  15472. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  15473. }
  15474. json_object_put(SignCertificate);
  15475. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  15476. }
  15477. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15478. {
  15479. mtrace();
  15480. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  15481. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  15482. }
  15483. //==========================================
  15484. // Handle Error routine
  15485. //==========================================
  15486. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15487. {
  15488. mtrace();
  15489. #ifdef SystemLogMessage
  15490. DEBUG_INFO("errorCode: %s\n", errorCode);
  15491. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15492. DEBUG_INFO("errorDetails: %s\n", payload);
  15493. #endif
  15494. }
  15495. //===============================================
  15496. // Common routine
  15497. //===============================================
  15498. int initialConfigurationTable(void)
  15499. {
  15500. //clock_t start_t, end_t, total_t;
  15501. FILE *fp;
  15502. FILE *outfile;
  15503. char str[512]={0};
  15504. int confVersion = 25;
  15505. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  15506. //start_t = clock();
  15507. //printf("Starting of the program, start_t = %ld\n", start_t);
  15508. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  15509. // Check configuration file size is correct
  15510. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  15511. {
  15512. struct stat st;
  15513. stat("/Storage/OCPP/OCPPConfiguration", &st);
  15514. if(st.st_size < 3100)
  15515. {
  15516. system("rm -f /Storage/OCPP/OCPPConfiguration");
  15517. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  15518. }
  15519. }
  15520. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  15521. {
  15522. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  15523. if(outfile == NULL)
  15524. {
  15525. DEBUG_INFO("Error opening file\n");
  15526. return FALSE;
  15527. }
  15528. /*Core Profile*/
  15529. //AllowOfflineTxForUnknownId
  15530. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  15531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  15532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  15533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  15534. //AuthorizationCacheEnabled
  15535. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  15536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  15537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  15538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  15539. //AuthorizeRemoteTxRequests
  15540. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  15541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  15542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  15543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  15544. //BlinkRepeat
  15545. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  15546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  15547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  15548. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  15549. //ClockAlignedDataInterval
  15550. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  15551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  15552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  15553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  15554. //ConnectionTimeOut
  15555. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  15556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  15557. if(ShmSysConfigAndInfo->SysConfig.ModelName[3]=='J')
  15558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "55" );
  15559. else
  15560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  15561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  15562. //GetConfigurationMaxKeys
  15563. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  15564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  15565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  15566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  15567. // HeartbeatInterval
  15568. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  15569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  15570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  15571. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  15572. // LightIntensity
  15573. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  15574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  15575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  15576. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  15577. // LocalAuthorizeOffline
  15578. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  15579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  15580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  15581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15582. // LocalPreAuthorize
  15583. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  15584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  15585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  15586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  15587. // MaxEnergyOnInvalidId
  15588. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  15589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  15590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  15591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  15592. // MeterValuesAlignedData
  15593. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  15594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  15595. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15596. 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" );
  15597. else
  15598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  15600. // MeterValuesAlignedDataMaxLength
  15601. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  15602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  15603. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  15605. else
  15606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  15607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  15608. // MeterValuesSampledData
  15609. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  15610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  15611. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15612. 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" );
  15613. else
  15614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  15615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  15616. // MeterValuesSampledDataMaxLength
  15617. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  15618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  15619. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  15621. else
  15622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  15623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  15624. // MeterValueSampleInterval
  15625. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  15626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  15627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  15628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  15629. // MinimumStatusDuration
  15630. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  15631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  15632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  15633. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  15634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15635. // NumberOfConnectors
  15636. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  15637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  15638. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15639. {
  15640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  15641. }
  15642. else
  15643. {
  15644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  15645. }
  15646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  15647. // ResetRetries
  15648. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  15649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  15650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  15651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  15652. // ConnectorPhaseRotation
  15653. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  15654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  15655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  15656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  15657. // ConnectorPhaseRotationMaxLength
  15658. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  15659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  15660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  15661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  15662. // StopTransactionOnEVSideDisconnect
  15663. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  15664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  15665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  15666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  15667. // StopTransactionOnInvalidId
  15668. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  15669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  15670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  15671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  15672. // StopTxnAlignedData
  15673. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  15674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  15675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  15676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  15677. // StopTxnAlignedDataMaxLength
  15678. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  15679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  15680. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15681. {
  15682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 8);
  15683. }
  15684. else
  15685. {
  15686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", 10);
  15687. }
  15688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  15689. // StopTxnSampledData
  15690. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  15691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  15692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "" );
  15693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  15694. // StopTxnSampledDataMaxLength
  15695. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  15696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  15697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15698. {
  15699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 8);
  15700. }
  15701. else
  15702. {
  15703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 10);
  15704. }
  15705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  15706. // SupportedFeatureProfiles
  15707. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  15708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  15709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  15710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  15711. // SupportedFeatureProfilesMaxLength
  15712. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  15713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  15714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  15715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  15716. // TransactionMessageAttempts
  15717. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  15718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  15719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  15720. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15722. // TransactionMessageRetryInterval
  15723. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  15724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  15725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  15726. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15728. // UnlockConnectorOnEVSideDisconnect
  15729. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  15730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  15731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  15732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  15733. // WebSocketPingInterval
  15734. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  15735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  15736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  15737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15738. // QueueOffLineMeterValues
  15739. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  15740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  15741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  15742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  15743. // AuthorizationKey
  15744. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  15745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  15746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  15747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15748. // SecurityProfile
  15749. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  15750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  15751. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  15752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15753. // DefaultPrice
  15754. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  15755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  15756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  15757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  15758. // CustomDisplayCostAndPrice
  15759. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  15760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  15761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  15762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  15763. // CustomIdleFeeAfterStop
  15764. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  15765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  15766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  15767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  15768. // TimeOffset
  15769. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  15770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  15771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  15772. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  15773. // NextTimeOffsetTransitionDateTime
  15774. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  15775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  15776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  15777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  15778. // TimeOffsetNextTransition
  15779. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  15780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  15781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  15782. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  15783. // SystemUptimeSec
  15784. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  15785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  15786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  15787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  15788. // FreeVend
  15789. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  15790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  15791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  15793. // FreeVendIdtag
  15794. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  15795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  15796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  15797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15798. // OcppServer
  15799. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  15800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  15801. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  15802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15803. // MaintainServer
  15804. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  15805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  15806. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  15807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15808. // StatusNotificationPeriodically
  15809. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  15810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  15811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  15812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  15813. // StatusNotificationInterval
  15814. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  15815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  15816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  15817. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  15818. // PreAuthAmount
  15819. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  15820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  15821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "888" );
  15822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  15823. // isEnableLocalPowerSharing
  15824. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  15825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  15826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  15827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  15828. // PowerSharingServerIP
  15829. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  15830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  15831. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, 500);
  15832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  15833. // EVCCID_PREFIX
  15834. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  15835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  15836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  15837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  15838. // OffLineMaxChargingPower
  15839. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  15840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  15841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "0" );
  15842. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  15843. // Configuration Version
  15844. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  15845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  15846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  15847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  15848. // Charging profile refresh interval
  15849. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  15850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  15851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "30");
  15852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  15853. // CpoName
  15854. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  15855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  15856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "Zerova");
  15857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  15858. // Ocpp Software certificated version
  15859. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 0;
  15860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  15861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", "V1.00");
  15862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  15863. // Check certificate of download link
  15864. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  15865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  15866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "FALSE");
  15867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  15868. // RFID endian type
  15869. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = 1;
  15870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemName, "RfidEndianType");
  15871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE");
  15872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","RfidEndianType", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData);
  15873. // Authorization timeout
  15874. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = 1;
  15875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemName, "AuthorizeTimeout");
  15876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "15");
  15877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeTimeout", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  15878. //* Local Auth List Management Profile*/
  15879. #if 0
  15880. //For OCTT Test Case
  15881. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  15883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15884. #endif
  15885. #if 1
  15886. //LocalAuthListEnabled
  15887. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  15888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  15889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  15890. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15891. #endif
  15892. //LocalAuthListMaxLength
  15893. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  15894. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  15895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  15896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  15897. //SendLocalListMaxLength
  15898. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  15899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  15900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "1000" );
  15901. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  15902. //ReserveConnectorZeroSupported
  15903. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  15904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  15905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  15906. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15907. //* Smart Charging Profile */
  15908. //ChargeProfileMaxStackLevel
  15909. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  15910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  15911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "8" );
  15912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15913. // ChargingScheduleAllowedChargingRateUnit
  15914. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  15915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  15916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  15917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15918. // ChargingScheduleMaxPeriods
  15919. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  15920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  15921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  15922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15923. // ConnectorSwitch3to1PhaseSupported
  15924. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  15925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  15926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  15927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15928. // MaxChargingProfilesInstalled
  15929. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  15930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  15931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "50" );
  15932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15933. fclose(outfile);
  15934. }
  15935. else
  15936. {
  15937. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  15938. char keystr[60]={0};
  15939. char readonlystr[10]={0};
  15940. char valuestr[256]={0};
  15941. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  15942. if(fp == NULL) {
  15943. DEBUG_INFO("Error opening file");
  15944. return FALSE;
  15945. }
  15946. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  15947. {
  15948. //DEBUG_INFO("Get Configuration \n");
  15949. if(strlen(str) > 0)
  15950. {
  15951. json_object *OCPPConfiguration;
  15952. OCPPConfiguration = json_tokener_parse(str);
  15953. if(json_object_object_get(OCPPConfiguration, "key") != NULL)
  15954. strcpy(keystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"key")));
  15955. if(json_object_object_get(OCPPConfiguration, "readonly") != NULL)
  15956. strcpy(readonlystr, json_object_get_string(json_object_object_get(OCPPConfiguration,"readonly")));
  15957. if(json_object_object_get(OCPPConfiguration, "value") != NULL)
  15958. strcpy(valuestr, json_object_get_string(json_object_object_get(OCPPConfiguration,"value")));
  15959. json_object_put(OCPPConfiguration);
  15960. // DEBUG_INFO("keystr=%s\n",keystr);
  15961. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  15962. // DEBUG_INFO("valuestr=%s\n",valuestr);
  15963. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  15964. {
  15965. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15966. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  15968. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15969. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  15970. }
  15971. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  15972. {
  15973. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15974. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  15976. }
  15977. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  15978. {
  15979. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  15981. }
  15982. if(strcmp(keystr, "BlinkRepeat") == 0)
  15983. {
  15984. //Charger.BlinkRepeat = Integer.parseInt(value);
  15985. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  15987. }
  15988. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  15989. {
  15990. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15991. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  15992. }
  15993. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  15994. {
  15995. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  15996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  15997. }
  15998. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  15999. {
  16000. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  16002. }
  16003. if(strcmp(keystr, "HeartbeatInterval") == 0)
  16004. {
  16005. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  16007. HeartBeatWaitTime = atoi(valuestr);
  16008. }
  16009. if(strcmp(keystr, "LightIntensity") == 0)
  16010. {
  16011. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  16013. }
  16014. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  16015. {
  16016. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  16018. }
  16019. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  16020. {
  16021. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16022. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  16023. }
  16024. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  16025. {
  16026. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16027. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  16028. }
  16029. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  16030. {
  16031. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  16033. }
  16034. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  16035. {
  16036. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  16038. }
  16039. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  16040. {
  16041. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16042. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  16043. }
  16044. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  16045. {
  16046. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16047. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  16048. }
  16049. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  16050. {
  16051. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  16053. }
  16054. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  16055. {
  16056. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  16058. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  16059. }
  16060. if(strcmp(keystr, "NumberOfConnectors") == 0)
  16061. {
  16062. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  16064. }
  16065. if(strcmp(keystr, "ResetRetries") == 0)
  16066. {
  16067. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  16069. }
  16070. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  16071. {
  16072. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  16074. }
  16075. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  16076. {
  16077. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16078. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  16079. }
  16080. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  16081. {
  16082. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  16084. }
  16085. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  16086. {
  16087. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  16089. }
  16090. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  16091. {
  16092. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  16094. }
  16095. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  16096. {
  16097. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16099. }
  16100. if(strcmp(keystr, "StopTxnSampledData") == 0)
  16101. {
  16102. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  16104. }
  16105. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  16106. {
  16107. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  16109. }
  16110. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  16111. {
  16112. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  16114. }
  16115. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  16116. {
  16117. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  16119. }
  16120. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  16121. {
  16122. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  16124. TransactionMessageAttemptsValue = atoi(valuestr);
  16125. }
  16126. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  16127. {
  16128. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  16130. TransactionMessageRetryIntervalValue = atoi(valuestr);
  16131. }
  16132. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  16133. {
  16134. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  16136. }
  16137. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  16138. {
  16139. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  16141. }
  16142. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  16143. {
  16144. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16145. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  16146. }
  16147. if(strcmp(keystr, "AuthorizationKey") == 0)
  16148. {
  16149. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16150. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  16151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  16152. }
  16153. if(strcmp(keystr, "SecurityProfile") == 0)
  16154. {
  16155. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  16157. }
  16158. if(strcmp(keystr, "DefaultPrice") == 0)
  16159. {
  16160. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  16162. }
  16163. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  16164. {
  16165. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  16167. }
  16168. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  16169. {
  16170. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  16172. }
  16173. if(strcmp(keystr, "TimeOffset") == 0)
  16174. {
  16175. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16176. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  16177. }
  16178. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  16179. {
  16180. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  16182. }
  16183. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  16184. {
  16185. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16186. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  16187. }
  16188. if(strcmp(keystr, "SystemUptimeSec") == 0)
  16189. {
  16190. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  16192. }
  16193. if(strcmp(keystr, "FreeVend") == 0)
  16194. {
  16195. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  16197. }
  16198. if(strcmp(keystr, "FreeVendIdtag") == 0)
  16199. {
  16200. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  16202. }
  16203. if(strcmp(keystr, "OcppServer") == 0)
  16204. {
  16205. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16206. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  16207. }
  16208. if(strcmp(keystr, "MaintainServer") == 0)
  16209. {
  16210. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16211. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  16212. }
  16213. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  16214. {
  16215. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16216. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  16217. }
  16218. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  16219. {
  16220. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16221. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  16222. }
  16223. if(strcmp(keystr, "PreAuthAmount") == 0)
  16224. {
  16225. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16226. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(valuestr));
  16227. }
  16228. if(strcmp(keystr, "isEnableLocalPowerSharing") == 0)
  16229. {
  16230. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16231. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing);
  16232. }
  16233. if(strcmp(keystr, "PowerSharingServerIP") == 0)
  16234. {
  16235. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16236. memcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP,500);
  16237. }
  16238. if(strcmp(keystr, "EVCCID_PREFIX") == 0)
  16239. {
  16240. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", valuestr);
  16242. }
  16243. if(strcmp(keystr, "OffLineMaxChargingPower") == 0)
  16244. {
  16245. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16246. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", valuestr);
  16247. }
  16248. if(strcmp(keystr, "ConfigurationVersion") == 0)
  16249. {
  16250. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  16252. }
  16253. if(strcmp(keystr, "CharingProfileRefreshInterval") == 0)
  16254. {
  16255. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", valuestr);
  16257. }
  16258. if(strcmp(keystr, "CpoName") == 0)
  16259. {
  16260. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", valuestr);
  16262. }
  16263. if(strcmp(keystr, "OcppSoftwareVersion") == 0)
  16264. {
  16265. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", valuestr);
  16267. }
  16268. if(strcmp(keystr, "AuthDownloadlinkCertificate") == 0)
  16269. {
  16270. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", valuestr);
  16272. }
  16273. if(strcmp(keystr, "RfidEndianType") == 0)
  16274. {
  16275. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE");
  16277. }
  16278. if(strcmp(keystr, "AuthorizeTimeout") == 0)
  16279. {
  16280. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "%s", valuestr);
  16282. }
  16283. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  16284. {
  16285. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  16287. }
  16288. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  16289. {
  16290. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  16292. }
  16293. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  16294. {
  16295. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  16297. }
  16298. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  16299. {
  16300. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  16302. }
  16303. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  16304. {
  16305. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  16307. }
  16308. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16309. {
  16310. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  16312. }
  16313. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  16314. {
  16315. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  16317. }
  16318. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  16319. {
  16320. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  16322. }
  16323. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  16324. {
  16325. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  16326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  16327. }
  16328. }
  16329. }
  16330. fclose(fp);
  16331. }
  16332. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  16333. {
  16334. return PASS;
  16335. }
  16336. else
  16337. {
  16338. return FAIL;
  16339. }
  16340. }
  16341. void StoreConfigurationTable(void)
  16342. {
  16343. FILE *outfile;
  16344. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  16345. if(outfile == NULL)
  16346. {
  16347. DEBUG_INFO("Error opening file");
  16348. return ;
  16349. }
  16350. /*Core Profile*/
  16351. //AllowOfflineTxForUnknownId
  16352. /*
  16353. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  16354. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  16355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  16356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  16357. */
  16358. //DEBUG_INFO("data=%s\n",data);
  16359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  16360. //AuthorizationCacheEnabled
  16361. /*
  16362. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  16363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  16364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  16365. */
  16366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  16367. //AuthorizeRemoteTxRequests
  16368. /*
  16369. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 1;
  16370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  16371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  16372. */
  16373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  16374. //BlinkRepeat
  16375. /*
  16376. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  16377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  16378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  16379. */
  16380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  16381. //ClockAlignedDataInterval
  16382. /*
  16383. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  16384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  16385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  16386. */
  16387. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  16388. //ConnectionTimeOut
  16389. /*
  16390. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  16391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  16392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  16393. */
  16394. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  16395. //GetConfigurationMaxKeys
  16396. /*
  16397. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  16398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  16399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  16400. */
  16401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  16402. // HeartbeatInterval
  16403. /*
  16404. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  16405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  16406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  16407. */
  16408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  16409. // LightIntensity
  16410. /*
  16411. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  16412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  16413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  16414. */
  16415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  16416. // LocalAuthorizeOffline
  16417. /*
  16418. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  16419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  16420. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  16421. */
  16422. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  16423. // LocalPreAuthorize
  16424. /*
  16425. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  16426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  16427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  16428. */
  16429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  16430. // MaxEnergyOnInvalidId
  16431. /*
  16432. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  16433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  16434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  16435. */
  16436. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  16437. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  16438. // MeterValuesAlignedData
  16439. /*
  16440. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  16441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  16442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16443. */
  16444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  16445. // MeterValuesAlignedDataMaxLength
  16446. /*
  16447. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  16448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  16449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  16450. */
  16451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  16452. // MeterValuesSampledData
  16453. /*
  16454. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  16455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  16456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  16457. */
  16458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  16459. // MeterValuesSampledDataMaxLength
  16460. /*
  16461. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  16462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  16463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  16464. */
  16465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  16466. // MeterValueSampleInterval
  16467. /*
  16468. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  16469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  16470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  16471. */
  16472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  16473. // MinimumStatusDuration
  16474. /*
  16475. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  16476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  16477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  16478. */
  16479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16480. // NumberOfConnectors
  16481. /*
  16482. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  16483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  16484. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16485. {
  16486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  16487. }
  16488. else
  16489. {
  16490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  16491. }
  16492. */
  16493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  16494. // ResetRetries
  16495. /*
  16496. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  16497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  16498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  16499. */
  16500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  16501. // ConnectorPhaseRotation
  16502. /*
  16503. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  16504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  16505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  16506. */
  16507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  16508. // ConnectorPhaseRotationMaxLength
  16509. /*
  16510. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  16511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  16512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  16513. */
  16514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  16515. // StopTransactionOnEVSideDisconnect
  16516. /*
  16517. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;
  16518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  16519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  16520. */
  16521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  16522. // StopTransactionOnInvalidId
  16523. /*
  16524. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  16525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  16526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  16527. */
  16528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  16529. // StopTxnAlignedData
  16530. /*
  16531. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  16532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  16533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  16534. */
  16535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  16536. // StopTxnAlignedDataMaxLength
  16537. /*
  16538. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  16539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  16540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  16541. */
  16542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  16543. // StopTxnSampledData
  16544. /*
  16545. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  16546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  16547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  16548. */
  16549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  16550. // StopTxnSampledDataMaxLength
  16551. /*
  16552. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  16553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  16554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  16555. */
  16556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  16557. // SupportedFeatureProfiles
  16558. /*
  16559. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  16560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  16561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  16562. */
  16563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  16564. // SupportedFeatureProfilesMaxLength
  16565. /*
  16566. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  16567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  16568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  16569. */
  16570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  16571. // TransactionMessageAttempts
  16572. /*
  16573. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  16574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  16575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  16576. */
  16577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16578. // TransactionMessageRetryInterval
  16579. /*
  16580. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  16581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  16582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  16583. */
  16584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16585. // UnlockConnectorOnEVSideDisconnect
  16586. /*
  16587. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;
  16588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  16589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  16590. */
  16591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  16592. // WebSocketPingInterval
  16593. /*
  16594. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  16595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  16596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  16597. */
  16598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16599. // QueueOffLineMeterValues
  16600. /*
  16601. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  16602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  16603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  16604. */
  16605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  16606. // AuthorizationKey
  16607. /*
  16608. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  16609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  16610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  16611. */
  16612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16613. // SecurityProfile
  16614. /*
  16615. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  16616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  16617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  16618. */
  16619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16620. // DefaultPrice
  16621. /*
  16622. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  16623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  16624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  16625. */
  16626. json_object *tmp;
  16627. tmp = json_tokener_parse((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16628. if(!is_error(tmp))
  16629. {
  16630. DEBUG_INFO("JSON string type\n");
  16631. json_object *target = json_object_new_object();
  16632. json_object_object_add(target, "key", json_object_new_string("DefaultPrice"));
  16633. json_object_object_add(target, "readonly", (ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility?json_object_new_boolean(0):json_object_new_boolean(1)));
  16634. json_object_object_add(target, "value", json_object_new_string((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData));
  16635. fprintf(outfile, "%s\n", json_object_to_json_string_ext(target, JSON_C_TO_STRING_PLAIN));
  16636. json_object_put(target);
  16637. }
  16638. else
  16639. {
  16640. DEBUG_INFO("Normal string type\n");
  16641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  16642. }
  16643. json_object_put(tmp);
  16644. // CustomDisplayCostAndPrice
  16645. /*
  16646. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  16647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  16648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  16649. */
  16650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  16651. // CustomIdleFeeAfterStop
  16652. /*
  16653. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  16654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  16655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  16656. */
  16657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  16658. // TimeOffset
  16659. /*
  16660. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  16661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  16662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  16663. */
  16664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  16665. // NextTimeOffsetTransitionDateTime
  16666. /*
  16667. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  16668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  16669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  16670. */
  16671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  16672. // TimeOffsetNextTransition
  16673. /*
  16674. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  16675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  16676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  16677. */
  16678. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  16679. // SystemUptimeSec
  16680. /*
  16681. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  16682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  16683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  16684. */
  16685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  16686. // FreeVend
  16687. /*
  16688. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  16689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  16690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  16691. */
  16692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  16693. // FreeVendIdtag
  16694. /*
  16695. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  16696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  16697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  16698. */
  16699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  16700. // OcppServer
  16701. /*
  16702. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  16703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  16704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  16705. */
  16706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  16707. // MaintainServer
  16708. /*
  16709. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  16710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  16711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  16712. */
  16713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  16714. // StatusNotificationPeriodically
  16715. /*
  16716. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  16717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  16718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  16719. */
  16720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  16721. // StatusNotificationInterval
  16722. /*
  16723. ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  16724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  16725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  16726. */
  16727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  16728. // PreAuthAmount
  16729. /*
  16730. ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility = 1;
  16731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemName, "PreAuthAmount");
  16732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "120" );
  16733. */
  16734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PreAuthAmount", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData);
  16735. // isEnableLocalPowerSharing
  16736. /*
  16737. ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility = 1;
  16738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemName, "isEnableLocalPowerSharing");
  16739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "0" );
  16740. */
  16741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","isEnableLocalPowerSharing", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData);
  16742. // PowerSharingServerIP
  16743. /*
  16744. ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility = 1;
  16745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemName, "PowerSharingServerIP");
  16746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "" );
  16747. */
  16748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","PowerSharingServerIP", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData);
  16749. // EVCCID_PREFIX
  16750. /*
  16751. ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility = 1;
  16752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemName, "EVCCID_PREFIX");
  16753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "" );
  16754. */
  16755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","EVCCID_PREFIX", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData);
  16756. // OffLineMaxChargingPower
  16757. /*
  16758. ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility = 1;
  16759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemName, "OffLineMaxChargingPower");
  16760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "" );
  16761. */
  16762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OffLineMaxChargingPower", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData);
  16763. // ConfigurationVersion
  16764. /*
  16765. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  16766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  16767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  16768. */
  16769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  16770. // CharingProfileRefreshInterval
  16771. /*
  16772. ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility = 1;
  16773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemName, "CharingProfileRefreshInterval");
  16774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "" );
  16775. */
  16776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CharingProfileRefreshInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData);
  16777. // CpoName
  16778. /*
  16779. ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility = 1;
  16780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemName, "CpoName");
  16781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "" );
  16782. */
  16783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CpoName", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData);
  16784. // OcppSoftwareVersion
  16785. /*
  16786. ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility = 1;
  16787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemName, "OcppSoftwareVersion");
  16788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "" );
  16789. */
  16790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppSoftwareVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData);
  16791. // AuthDownloadlinkCertificate
  16792. /*
  16793. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility = 1;
  16794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemName, "AuthDownloadlinkCertificate");
  16795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE" );
  16796. */
  16797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthDownloadlinkCertificate", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData);
  16798. // RfidEndianType
  16799. /*
  16800. ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility = 1;
  16801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemName, "RfidEndianType");
  16802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "BIG" );
  16803. */
  16804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","RfidEndianType", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData);
  16805. // AuthorizeTimeout
  16806. /*
  16807. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility = 1;
  16808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemName, "AuthorizeTimeout");
  16809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "60" );
  16810. */
  16811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeTimeout", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  16812. //* Local Auth List Management Profile*/
  16813. //LocalAuthListEnabled
  16814. /*
  16815. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  16816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  16817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  16818. */
  16819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16820. //LocalAuthListMaxLength
  16821. /*
  16822. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  16823. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  16824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  16825. */
  16826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  16827. //SendLocalListMaxLength
  16828. /*
  16829. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  16830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  16831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  16832. */
  16833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  16834. //ReserveConnectorZeroSupported
  16835. /*
  16836. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  16837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  16838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  16839. */
  16840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  16841. //* Smart Charging Profile */
  16842. //ChargeProfileMaxStackLevel
  16843. /*
  16844. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  16845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  16846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  16847. */
  16848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  16849. // ChargingScheduleAllowedChargingRateUnit
  16850. /*
  16851. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  16852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  16853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  16854. */
  16855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  16856. // ChargingScheduleMaxPeriods
  16857. /*
  16858. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  16859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  16860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  16861. */
  16862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  16863. // ConnectorSwitch3to1PhaseSupported
  16864. /*
  16865. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  16866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  16867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  16868. */
  16869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  16870. // MaxChargingProfilesInstalled
  16871. /*
  16872. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  16873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  16874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  16875. */
  16876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  16877. fclose(outfile);
  16878. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16879. }
  16880. void getKeyValue(char *keyReq)
  16881. {
  16882. int isEmpty = FALSE;
  16883. int isKnowKey = FALSE;
  16884. DEBUG_INFO("keyReq = %s\n", keyReq);
  16885. if((keyReq == NULL) || (strlen(keyReq) == 0))
  16886. isEmpty = TRUE;
  16887. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  16888. {
  16889. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  16890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  16891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  16892. {
  16893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  16894. }
  16895. else
  16896. {
  16897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  16898. }
  16899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  16900. isKnowKey = TRUE;
  16901. }
  16902. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  16903. {
  16904. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  16905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  16906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  16907. {
  16908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  16909. }
  16910. else
  16911. {
  16912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  16913. }
  16914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  16915. isKnowKey = TRUE;
  16916. }
  16917. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  16918. {
  16919. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  16920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  16921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  16922. {
  16923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  16924. }
  16925. else
  16926. {
  16927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  16928. }
  16929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  16930. isKnowKey = TRUE;
  16931. }
  16932. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  16933. {
  16934. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  16935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  16936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  16937. {
  16938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  16939. }
  16940. else
  16941. {
  16942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  16943. }
  16944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  16945. isKnowKey = TRUE;
  16946. }
  16947. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  16948. {
  16949. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  16950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  16951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  16952. {
  16953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  16954. }
  16955. else
  16956. {
  16957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  16958. }
  16959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  16960. isKnowKey = TRUE;
  16961. }
  16962. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  16963. {
  16964. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  16965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  16966. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  16967. {
  16968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  16969. }
  16970. else
  16971. {
  16972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  16973. }
  16974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  16975. isKnowKey = TRUE;
  16976. }
  16977. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  16978. {
  16979. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  16980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  16981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  16982. {
  16983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  16984. }
  16985. else
  16986. {
  16987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  16988. }
  16989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  16990. isKnowKey = TRUE;
  16991. }
  16992. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  16993. {
  16994. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  16995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  16996. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  16997. {
  16998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  16999. }
  17000. else
  17001. {
  17002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  17003. }
  17004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  17005. isKnowKey = TRUE;
  17006. }
  17007. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  17008. {
  17009. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  17010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  17011. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  17012. {
  17013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  17014. }
  17015. else
  17016. {
  17017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  17018. }
  17019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  17020. isKnowKey = TRUE;
  17021. }
  17022. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  17023. {
  17024. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  17025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  17026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  17027. {
  17028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  17029. }
  17030. else
  17031. {
  17032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  17033. }
  17034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  17035. isKnowKey = TRUE;
  17036. }
  17037. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  17038. {
  17039. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  17040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  17041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  17042. {
  17043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  17044. }
  17045. else
  17046. {
  17047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  17048. }
  17049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  17050. isKnowKey = TRUE;
  17051. }
  17052. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  17053. {
  17054. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  17055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  17056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  17057. {
  17058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17059. }
  17060. else
  17061. {
  17062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17063. }
  17064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  17065. isKnowKey = TRUE;
  17066. }
  17067. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  17068. {
  17069. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  17070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  17071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  17072. {
  17073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17074. }
  17075. else
  17076. {
  17077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17078. }
  17079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  17080. isKnowKey = TRUE;
  17081. }
  17082. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  17083. {
  17084. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  17085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  17086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  17087. {
  17088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17089. }
  17090. else
  17091. {
  17092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17093. }
  17094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  17095. isKnowKey = TRUE;
  17096. }
  17097. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  17098. {
  17099. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  17100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  17101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  17102. {
  17103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  17104. }
  17105. else
  17106. {
  17107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  17108. }
  17109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  17110. isKnowKey = TRUE;
  17111. }
  17112. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  17113. {
  17114. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  17115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  17116. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  17117. {
  17118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17119. }
  17120. else
  17121. {
  17122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17123. }
  17124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  17125. isKnowKey = TRUE;
  17126. }
  17127. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  17128. {
  17129. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  17130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  17131. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  17132. {
  17133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  17134. }
  17135. else
  17136. {
  17137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  17138. }
  17139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  17140. isKnowKey = TRUE;
  17141. }
  17142. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  17143. {
  17144. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  17145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  17146. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  17147. {
  17148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  17149. }
  17150. else
  17151. {
  17152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  17153. }
  17154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  17155. isKnowKey = TRUE;
  17156. }
  17157. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  17158. {
  17159. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  17160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  17161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  17162. {
  17163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  17164. }
  17165. else
  17166. {
  17167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  17168. }
  17169. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  17170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  17171. isKnowKey = TRUE;
  17172. }
  17173. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  17174. {
  17175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  17176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  17177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  17178. {
  17179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  17180. }
  17181. else
  17182. {
  17183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  17184. }
  17185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  17186. isKnowKey = TRUE;
  17187. }
  17188. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  17189. {
  17190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  17191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  17192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  17193. {
  17194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  17195. }
  17196. else
  17197. {
  17198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  17199. }
  17200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  17201. isKnowKey = TRUE;
  17202. }
  17203. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  17204. {
  17205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  17206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  17207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  17208. {
  17209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17210. }
  17211. else
  17212. {
  17213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17214. }
  17215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  17216. isKnowKey = TRUE;
  17217. }
  17218. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  17219. {
  17220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  17221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  17222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  17223. {
  17224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17225. }
  17226. else
  17227. {
  17228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17229. }
  17230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  17231. isKnowKey = TRUE;
  17232. }
  17233. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  17234. {
  17235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  17236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  17237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  17238. {
  17239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  17240. }
  17241. else
  17242. {
  17243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  17244. }
  17245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  17246. isKnowKey = TRUE;
  17247. }
  17248. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  17249. {
  17250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  17251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  17252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  17253. {
  17254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  17255. }
  17256. else
  17257. {
  17258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  17259. }
  17260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  17261. isKnowKey = TRUE;
  17262. }
  17263. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  17264. {
  17265. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  17266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  17267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  17268. {
  17269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17270. }
  17271. else
  17272. {
  17273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17274. }
  17275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  17276. isKnowKey = TRUE;
  17277. }
  17278. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  17279. {
  17280. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  17281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  17282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  17283. {
  17284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  17285. }
  17286. else
  17287. {
  17288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  17289. }
  17290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  17291. isKnowKey = TRUE;
  17292. }
  17293. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  17294. {
  17295. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  17296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  17297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  17298. {
  17299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17300. }
  17301. else
  17302. {
  17303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17304. }
  17305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  17306. isKnowKey = TRUE;
  17307. }
  17308. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  17309. {
  17310. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  17311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  17312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  17313. {
  17314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  17315. }
  17316. else
  17317. {
  17318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  17319. }
  17320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  17321. isKnowKey = TRUE;
  17322. }
  17323. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  17324. {
  17325. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  17326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  17327. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  17328. {
  17329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17330. }
  17331. else
  17332. {
  17333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17334. }
  17335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  17336. isKnowKey = TRUE;
  17337. }
  17338. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  17339. {
  17340. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  17341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  17342. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  17343. {
  17344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  17345. }
  17346. else
  17347. {
  17348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  17349. }
  17350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  17351. isKnowKey = TRUE;
  17352. }
  17353. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  17354. {
  17355. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  17356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  17357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  17358. {
  17359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  17360. }
  17361. else
  17362. {
  17363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  17364. }
  17365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  17366. isKnowKey = TRUE;
  17367. }
  17368. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  17369. {
  17370. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  17371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  17372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  17373. {
  17374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  17375. }
  17376. else
  17377. {
  17378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  17379. }
  17380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  17381. isKnowKey = TRUE;
  17382. }
  17383. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  17384. {
  17385. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  17386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  17387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  17388. {
  17389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  17390. }
  17391. else
  17392. {
  17393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  17394. }
  17395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  17396. isKnowKey = TRUE;
  17397. }
  17398. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  17399. {
  17400. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  17401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  17402. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  17403. {
  17404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  17405. }
  17406. else
  17407. {
  17408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  17409. }
  17410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  17411. isKnowKey = TRUE;
  17412. }
  17413. /*
  17414. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  17415. {
  17416. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  17417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  17418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  17419. {
  17420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  17421. }
  17422. else
  17423. {
  17424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  17425. }
  17426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  17427. isKnowKey = TRUE;
  17428. }*/
  17429. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  17430. {
  17431. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  17432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  17433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  17434. {
  17435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  17436. }
  17437. else
  17438. {
  17439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  17440. }
  17441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  17442. isKnowKey = TRUE;
  17443. }
  17444. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  17445. {
  17446. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  17447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  17448. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  17449. {
  17450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  17451. }
  17452. else
  17453. {
  17454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  17455. }
  17456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  17457. isKnowKey = TRUE;
  17458. }
  17459. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  17460. {
  17461. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  17462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  17463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  17464. {
  17465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  17466. }
  17467. else
  17468. {
  17469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  17470. }
  17471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  17472. isKnowKey = TRUE;
  17473. }
  17474. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  17475. {
  17476. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  17477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  17478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  17479. {
  17480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  17481. }
  17482. else
  17483. {
  17484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  17485. }
  17486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  17487. isKnowKey = TRUE;
  17488. }
  17489. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  17490. {
  17491. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  17492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  17493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  17494. {
  17495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  17496. }
  17497. else
  17498. {
  17499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  17500. }
  17501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  17502. isKnowKey = TRUE;
  17503. }
  17504. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  17505. {
  17506. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  17507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  17508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  17509. {
  17510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  17511. }
  17512. else
  17513. {
  17514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  17515. }
  17516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  17517. isKnowKey = TRUE;
  17518. }
  17519. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  17520. {
  17521. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  17522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  17523. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  17524. {
  17525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  17526. }
  17527. else
  17528. {
  17529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  17530. }
  17531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  17532. isKnowKey = TRUE;
  17533. }
  17534. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  17535. {
  17536. struct sysinfo s_info;
  17537. int error = sysinfo(&s_info);
  17538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  17539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  17540. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  17541. {
  17542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  17543. }
  17544. else
  17545. {
  17546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  17547. }
  17548. if(error != 0)
  17549. {
  17550. DEBUG_WARN("System uptime get error: %d\n", error);
  17551. }
  17552. else
  17553. {
  17554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  17555. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  17556. }
  17557. isKnowKey = TRUE;
  17558. }
  17559. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  17560. {
  17561. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  17562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  17563. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  17564. {
  17565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  17566. }
  17567. else
  17568. {
  17569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  17570. }
  17571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  17572. isKnowKey = TRUE;
  17573. }
  17574. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  17575. {
  17576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  17577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  17578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  17579. {
  17580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  17581. }
  17582. else
  17583. {
  17584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  17585. }
  17586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  17587. isKnowKey = TRUE;
  17588. }
  17589. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  17590. {
  17591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  17592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  17593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  17594. {
  17595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  17596. }
  17597. else
  17598. {
  17599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  17600. }
  17601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  17602. isKnowKey = TRUE;
  17603. }
  17604. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  17605. {
  17606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  17607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  17608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  17609. {
  17610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  17611. }
  17612. else
  17613. {
  17614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  17615. }
  17616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  17617. isKnowKey = TRUE;
  17618. }
  17619. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  17620. {
  17621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  17622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  17623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  17624. {
  17625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  17626. }
  17627. else
  17628. {
  17629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  17630. }
  17631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  17632. isKnowKey = TRUE;
  17633. }
  17634. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  17635. {
  17636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  17637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  17638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  17639. {
  17640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  17641. }
  17642. else
  17643. {
  17644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  17645. }
  17646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  17647. isKnowKey = TRUE;
  17648. }
  17649. if(isEmpty || strcmp(keyReq, "PreAuthAmount") == 0 )
  17650. {
  17651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PreAuthAmount].Item, "PreAuthAmount");
  17652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Key, "PreAuthAmount");
  17653. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  17654. {
  17655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "0"/*"FALSE"*/);
  17656. }
  17657. else
  17658. {
  17659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].ReadOnly, "1"/*"TRUE"*/);
  17660. }
  17661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PreAuthAmount].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData );
  17662. isKnowKey = TRUE;
  17663. }
  17664. if(isEmpty || strcmp(keyReq, "isEnableLocalPowerSharing") == 0 )
  17665. {
  17666. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_isEnableLocalPowerSharing].Item, "isEnableLocalPowerSharing");
  17667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Key, "isEnableLocalPowerSharing");
  17668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  17669. {
  17670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "0"/*"FALSE"*/);
  17671. }
  17672. else
  17673. {
  17674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].ReadOnly, "1"/*"TRUE"*/);
  17675. }
  17676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_isEnableLocalPowerSharing].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData );
  17677. isKnowKey = TRUE;
  17678. }
  17679. if(isEmpty || strcmp(keyReq, "PowerSharingServerIP") == 0 )
  17680. {
  17681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_PowerSharingServerIP].Item, "PowerSharingServerIP");
  17682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Key, "PowerSharingServerIP");
  17683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  17684. {
  17685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "0"/*"FALSE"*/);
  17686. }
  17687. else
  17688. {
  17689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].ReadOnly, "1"/*"TRUE"*/);
  17690. }
  17691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_PowerSharingServerIP].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData );
  17692. isKnowKey = TRUE;
  17693. }
  17694. if(isEmpty || strcmp(keyReq, "EVCCID_PREFIX") == 0 )
  17695. {
  17696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_EVCCID_PREFIX].Item, "EVCCID_PREFIX");
  17697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Key, "EVCCID_PREFIX");
  17698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  17699. {
  17700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "0"/*"FALSE"*/);
  17701. }
  17702. else
  17703. {
  17704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].ReadOnly, "1"/*"TRUE"*/);
  17705. }
  17706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_EVCCID_PREFIX].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData );
  17707. isKnowKey = TRUE;
  17708. }
  17709. if(isEmpty || strcmp(keyReq, "OffLineMaxChargingPower") == 0 )
  17710. {
  17711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OffLineMaxChargingPower].Item, "OffLineMaxChargingPower");
  17712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Key, "OffLineMaxChargingPower");
  17713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  17714. {
  17715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "0"/*"FALSE"*/);
  17716. }
  17717. else
  17718. {
  17719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].ReadOnly, "1"/*"TRUE"*/);
  17720. }
  17721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OffLineMaxChargingPower].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData );
  17722. isKnowKey = TRUE;
  17723. }
  17724. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  17725. {
  17726. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  17727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  17728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  17729. {
  17730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  17731. }
  17732. else
  17733. {
  17734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  17735. }
  17736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  17737. isKnowKey = TRUE;
  17738. }
  17739. if(isEmpty || strcmp(keyReq, "CharingProfileRefreshInterval") == 0 )
  17740. {
  17741. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CharingProfileRefreshInterval].Item, "CharingProfileRefreshInterval");
  17742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Key, "CharingProfileRefreshInterval");
  17743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  17744. {
  17745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "0"/*"FALSE"*/);
  17746. }
  17747. else
  17748. {
  17749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].ReadOnly, "1"/*"TRUE"*/);
  17750. }
  17751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CharingProfileRefreshInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData );
  17752. isKnowKey = TRUE;
  17753. }
  17754. if(isEmpty || strcmp(keyReq, "CpoName") == 0 )
  17755. {
  17756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CpoName].Item, "CpoName");
  17757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Key, "CpoName");
  17758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  17759. {
  17760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "0"/*"FALSE"*/);
  17761. }
  17762. else
  17763. {
  17764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].ReadOnly, "1"/*"TRUE"*/);
  17765. }
  17766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CpoName].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData );
  17767. isKnowKey = TRUE;
  17768. }
  17769. if(isEmpty || strcmp(keyReq, "OcppSoftwareVersion") == 0 )
  17770. {
  17771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_OcppSoftwareVersion].Item, "OcppSoftwareVersion");
  17772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Key, "OcppSoftwareVersion");
  17773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  17774. {
  17775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "0"/*"FALSE"*/);
  17776. }
  17777. else
  17778. {
  17779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].ReadOnly, "1"/*"TRUE"*/);
  17780. }
  17781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppSoftwareVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData );
  17782. isKnowKey = TRUE;
  17783. }
  17784. if(isEmpty || strcmp(keyReq, "AuthDownloadlinkCertificate") == 0 )
  17785. {
  17786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthDownloadlinkCertificate].Item, "AuthDownloadlinkCertificate");
  17787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Key, "AuthDownloadlinkCertificate");
  17788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  17789. {
  17790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "0"/*"FALSE"*/);
  17791. }
  17792. else
  17793. {
  17794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].ReadOnly, "1"/*"TRUE"*/);
  17795. }
  17796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthDownloadlinkCertificate].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData );
  17797. isKnowKey = TRUE;
  17798. }
  17799. if(isEmpty || strcmp(keyReq, "RfidEndianType") == 0 )
  17800. {
  17801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_RfidEndianType].Item, "RfidEndianType");
  17802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].Key, "RfidEndianType");
  17803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility == 1)
  17804. {
  17805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].ReadOnly, "0"/*"FALSE"*/);
  17806. }
  17807. else
  17808. {
  17809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].ReadOnly, "1"/*"TRUE"*/);
  17810. }
  17811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_RfidEndianType].Value, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"BIG":"LITTLE");
  17812. isKnowKey = TRUE;
  17813. }
  17814. if(isEmpty || strcmp(keyReq, "AuthorizeTimeout") == 0 )
  17815. {
  17816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeTimeout].Item, "AuthorizeTimeout");
  17817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].Key, "AuthorizeTimeout");
  17818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility == 1)
  17819. {
  17820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].ReadOnly, "0"/*"FALSE"*/);
  17821. }
  17822. else
  17823. {
  17824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].ReadOnly, "1"/*"TRUE"*/);
  17825. }
  17826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeTimeout].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData);
  17827. isKnowKey = TRUE;
  17828. }
  17829. #if 1
  17830. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  17831. {
  17832. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  17833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  17834. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  17835. {
  17836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  17837. }
  17838. else
  17839. {
  17840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  17841. }
  17842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  17843. isKnowKey = TRUE;
  17844. }
  17845. #endif
  17846. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  17847. {
  17848. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  17849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  17850. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  17851. {
  17852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17853. }
  17854. else
  17855. {
  17856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17857. }
  17858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  17859. isKnowKey = TRUE;
  17860. }
  17861. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  17862. {
  17863. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  17864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  17865. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  17866. {
  17867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  17868. }
  17869. else
  17870. {
  17871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  17872. }
  17873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  17874. isKnowKey = TRUE;
  17875. }
  17876. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  17877. {
  17878. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  17879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  17880. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  17881. {
  17882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  17883. }
  17884. else
  17885. {
  17886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  17887. }
  17888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  17889. isKnowKey = TRUE;
  17890. }
  17891. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  17892. {
  17893. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  17894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  17895. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  17896. {
  17897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  17898. }
  17899. else
  17900. {
  17901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  17902. }
  17903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  17904. isKnowKey = TRUE;
  17905. }
  17906. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  17907. {
  17908. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  17909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  17910. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  17911. {
  17912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  17913. }
  17914. else
  17915. {
  17916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  17917. }
  17918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  17919. isKnowKey = TRUE;
  17920. }
  17921. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  17922. {
  17923. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  17924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  17925. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  17926. {
  17927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  17928. }
  17929. else
  17930. {
  17931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  17932. }
  17933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  17934. isKnowKey = TRUE;
  17935. }
  17936. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  17937. {
  17938. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  17939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  17940. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  17941. {
  17942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  17943. }
  17944. else
  17945. {
  17946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  17947. }
  17948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  17949. isKnowKey = TRUE;
  17950. }
  17951. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  17952. {
  17953. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  17954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  17955. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  17956. {
  17957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  17958. }
  17959. else
  17960. {
  17961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  17962. }
  17963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  17964. isKnowKey = TRUE;
  17965. }
  17966. //=========================================================
  17967. if(!isEmpty && !isKnowKey)
  17968. {
  17969. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  17970. strcpy(unknownkey[UnknownKeynum], keyReq);
  17971. UnknownKeynum = UnknownKeynum + 1;
  17972. }
  17973. }
  17974. void processUnkownKey(void)
  17975. {
  17976. DEBUG_INFO("processUnkownKey...\n");
  17977. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  17978. for(int index=0; index < UnknownKeynum; index++)
  17979. {
  17980. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  17981. {
  17982. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  17983. }
  17984. }
  17985. }
  17986. int setKeyValue(char *key, char *value)
  17987. {
  17988. int isSuccess = NotSupported;
  17989. int check_ascii=0;
  17990. char str[501]={0};
  17991. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  17992. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  17993. {
  17994. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  17995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  17996. {
  17997. strcpy(str, (const char*)value);
  17998. for(int i = 0; str[i]; i++){
  17999. str[i] = tolower(str[i]);
  18000. }
  18001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18002. isSuccess = ConfigurationStatus_Accepted;
  18003. }
  18004. else
  18005. {
  18006. isSuccess = ConfigurationStatus_Rejected;
  18007. }
  18008. }
  18009. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  18010. {
  18011. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  18012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  18013. {
  18014. strcpy(str, (const char*)value);
  18015. for(int i = 0; str[i]; i++){
  18016. str[i] = tolower(str[i]);
  18017. }
  18018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18019. isSuccess = ConfigurationStatus_Accepted;
  18020. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  18021. }
  18022. else
  18023. {
  18024. isSuccess = ConfigurationStatus_Rejected;
  18025. }
  18026. }
  18027. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  18028. {
  18029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  18030. {
  18031. strcpy(str, (const char*)value);
  18032. for(int i = 0; str[i]; i++)
  18033. {
  18034. str[i] = tolower(str[i]);
  18035. }
  18036. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  18037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18038. isSuccess = ConfigurationStatus_Accepted;
  18039. }
  18040. else
  18041. {
  18042. isSuccess = ConfigurationStatus_Rejected;
  18043. }
  18044. }
  18045. if(strcmp(key, "BlinkRepeat") == 0)
  18046. {
  18047. //Charger.BlinkRepeat = Integer.parseInt(value);
  18048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  18049. {
  18050. check_ascii = value[0];
  18051. if( (check_ascii < 48) || (check_ascii > 57) )
  18052. {
  18053. isSuccess = ConfigurationStatus_Rejected;
  18054. }
  18055. else
  18056. {
  18057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  18058. isSuccess = ConfigurationStatus_Accepted;
  18059. }
  18060. }
  18061. else
  18062. {
  18063. isSuccess = ConfigurationStatus_Rejected;
  18064. }
  18065. }
  18066. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  18067. {
  18068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  18069. {
  18070. check_ascii = value[0];
  18071. if( (check_ascii < 48) || (check_ascii > 57) )
  18072. {
  18073. isSuccess = ConfigurationStatus_Rejected;
  18074. }
  18075. else
  18076. {
  18077. if((atoi(value) == 0) || (atoi(value) >= 5))
  18078. {
  18079. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  18080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  18081. isSuccess = ConfigurationStatus_Accepted;
  18082. }
  18083. else
  18084. isSuccess = ConfigurationStatus_Rejected;
  18085. }
  18086. }
  18087. else
  18088. {
  18089. isSuccess = ConfigurationStatus_Rejected;
  18090. }
  18091. }
  18092. if(strcmp(key, "ConnectionTimeOut") == 0 )
  18093. {
  18094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  18095. {
  18096. check_ascii = value[0];
  18097. if( (check_ascii < 48) || (check_ascii > 57) )
  18098. {
  18099. isSuccess = ConfigurationStatus_Rejected;
  18100. }
  18101. else
  18102. {
  18103. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  18104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  18105. isSuccess = ConfigurationStatus_Accepted;
  18106. }
  18107. }
  18108. else
  18109. {
  18110. isSuccess = ConfigurationStatus_Rejected;
  18111. }
  18112. }
  18113. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  18114. {
  18115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  18116. {
  18117. check_ascii = value[0];
  18118. if( (check_ascii < 48) || (check_ascii > 57) )
  18119. {
  18120. isSuccess = ConfigurationStatus_Rejected;
  18121. }
  18122. else
  18123. {
  18124. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  18126. isSuccess = ConfigurationStatus_Accepted;
  18127. }
  18128. }
  18129. else
  18130. {
  18131. isSuccess = ConfigurationStatus_Rejected;
  18132. }
  18133. }
  18134. if(strcmp(key, "HeartbeatInterval") == 0)
  18135. {
  18136. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  18137. {
  18138. check_ascii = value[0];
  18139. if( (check_ascii < 48) || (check_ascii > 57) )
  18140. {
  18141. isSuccess = ConfigurationStatus_Rejected;
  18142. }
  18143. else
  18144. {
  18145. if((atoi(value) == 0) || (atoi(value) >= 10))
  18146. {
  18147. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  18148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  18149. HeartBeatWaitTime = atoi(value);
  18150. isSuccess = ConfigurationStatus_Accepted;
  18151. }
  18152. else
  18153. {
  18154. isSuccess = ConfigurationStatus_Rejected;
  18155. }
  18156. }
  18157. }
  18158. else
  18159. {
  18160. isSuccess = ConfigurationStatus_Rejected;
  18161. }
  18162. }
  18163. if(strcmp(key, "LightIntensity") == 0)
  18164. {
  18165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  18166. {
  18167. check_ascii = value[0];
  18168. if( (check_ascii < 48) || (check_ascii > 57) )
  18169. {
  18170. isSuccess = ConfigurationStatus_Rejected;
  18171. }
  18172. else
  18173. {
  18174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  18175. isSuccess = ConfigurationStatus_Accepted;
  18176. }
  18177. }
  18178. else
  18179. {
  18180. isSuccess = ConfigurationStatus_Rejected;
  18181. }
  18182. }
  18183. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  18184. {
  18185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  18186. {
  18187. strcpy(str, (const char*)value);
  18188. for(int i = 0; str[i]; i++)
  18189. {
  18190. str[i] = tolower(str[i]);
  18191. }
  18192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18193. isSuccess = ConfigurationStatus_Accepted;
  18194. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  18195. }
  18196. else
  18197. {
  18198. isSuccess = ConfigurationStatus_Rejected;
  18199. }
  18200. }
  18201. if(strcmp(key, "LocalPreAuthorize") == 0)
  18202. {
  18203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  18204. {
  18205. strcpy(str, (const char*)value);
  18206. for(int i = 0; str[i]; i++)
  18207. {
  18208. str[i] = tolower(str[i]);
  18209. }
  18210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18211. isSuccess = ConfigurationStatus_Accepted;
  18212. }
  18213. else
  18214. {
  18215. isSuccess = ConfigurationStatus_Rejected;
  18216. }
  18217. }
  18218. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  18219. {
  18220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  18221. {
  18222. check_ascii = value[0];
  18223. if( (check_ascii < 48) || (check_ascii > 57) )
  18224. {
  18225. isSuccess = ConfigurationStatus_Rejected;
  18226. }
  18227. else
  18228. {
  18229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  18230. isSuccess = ConfigurationStatus_Accepted;
  18231. }
  18232. }
  18233. else
  18234. {
  18235. isSuccess = ConfigurationStatus_Rejected;
  18236. }
  18237. }
  18238. if(strcmp(key, "MeterValuesAlignedData") == 0)
  18239. {
  18240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  18241. {
  18242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  18243. isSuccess = ConfigurationStatus_Accepted;
  18244. }
  18245. else
  18246. {
  18247. isSuccess = ConfigurationStatus_Rejected;
  18248. }
  18249. }
  18250. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  18251. {
  18252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  18253. {
  18254. check_ascii = value[0];
  18255. if( (check_ascii < 48) || (check_ascii > 57) )
  18256. {
  18257. isSuccess = ConfigurationStatus_Rejected;
  18258. }
  18259. else
  18260. {
  18261. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  18263. isSuccess = ConfigurationStatus_Accepted;
  18264. }
  18265. }
  18266. else
  18267. {
  18268. isSuccess = ConfigurationStatus_Rejected;
  18269. }
  18270. }
  18271. if(strcmp(key, "MeterValuesSampledData") == 0 )
  18272. {
  18273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  18274. {
  18275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  18276. isSuccess = ConfigurationStatus_Accepted;
  18277. }
  18278. else
  18279. {
  18280. isSuccess = ConfigurationStatus_Rejected;
  18281. }
  18282. }
  18283. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  18284. {
  18285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  18286. {
  18287. check_ascii = value[0];
  18288. if( (check_ascii < 48) || (check_ascii > 57) )
  18289. {
  18290. isSuccess = ConfigurationStatus_Rejected;
  18291. }
  18292. else
  18293. {
  18294. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  18296. isSuccess = ConfigurationStatus_Accepted;
  18297. }
  18298. }
  18299. else
  18300. {
  18301. isSuccess = ConfigurationStatus_Rejected;
  18302. }
  18303. }
  18304. if(strcmp(key, "MeterValueSampleInterval") == 0)
  18305. {
  18306. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  18307. {
  18308. check_ascii = value[0];
  18309. if( (check_ascii < 48) || (check_ascii > 57) )
  18310. {
  18311. isSuccess = ConfigurationStatus_Rejected;
  18312. }
  18313. else
  18314. {
  18315. if((atoi(value) == 0) || (atoi(value) >= 3))
  18316. {
  18317. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  18318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  18319. isSuccess = ConfigurationStatus_Accepted;
  18320. }
  18321. else
  18322. {
  18323. isSuccess = ConfigurationStatus_Rejected;
  18324. }
  18325. }
  18326. }
  18327. else
  18328. {
  18329. isSuccess = ConfigurationStatus_Rejected;
  18330. }
  18331. }
  18332. if(strcmp(key, "MinimumStatusDuration") == 0)
  18333. {
  18334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  18335. {
  18336. check_ascii = value[0];
  18337. if( (check_ascii < 48) || (check_ascii > 57) )
  18338. {
  18339. isSuccess = ConfigurationStatus_Rejected;
  18340. }
  18341. else
  18342. {
  18343. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  18344. {
  18345. isSuccess = ConfigurationStatus_Rejected;
  18346. }
  18347. else
  18348. {
  18349. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  18350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  18351. server_cycle_Status = atoi(value); //StatusNotification Cycle
  18352. isSuccess = ConfigurationStatus_Accepted;
  18353. }
  18354. }
  18355. }
  18356. else
  18357. {
  18358. isSuccess = ConfigurationStatus_Rejected;
  18359. }
  18360. }
  18361. if(strcmp(key, "NumberOfConnectors") == 0)
  18362. {
  18363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  18364. {
  18365. check_ascii = value[0];
  18366. if( (check_ascii < 48) || (check_ascii > 57) )
  18367. {
  18368. isSuccess = ConfigurationStatus_Rejected;
  18369. }
  18370. else
  18371. {
  18372. //Charger.ResetRetries = Integer.parseInt(value);
  18373. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  18374. isSuccess = ConfigurationStatus_Accepted;
  18375. }
  18376. }
  18377. else
  18378. {
  18379. isSuccess = ConfigurationStatus_Rejected;
  18380. }
  18381. }
  18382. if(strcmp(key, "ResetRetries") == 0)
  18383. {
  18384. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  18385. {
  18386. check_ascii = value[0];
  18387. if( (check_ascii < 48) || (check_ascii > 57) )
  18388. {
  18389. isSuccess = ConfigurationStatus_Rejected;
  18390. }
  18391. else
  18392. {
  18393. //Charger.ResetRetries = Integer.parseInt(value);
  18394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  18395. isSuccess = ConfigurationStatus_Accepted;
  18396. }
  18397. }
  18398. else
  18399. {
  18400. isSuccess = ConfigurationStatus_Rejected;
  18401. }
  18402. }
  18403. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  18404. {
  18405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  18406. {
  18407. strcpy(str, (const char*)value);
  18408. for(int i = 0; str[i]; i++)
  18409. {
  18410. str[i] = tolower(str[i]);
  18411. }
  18412. if(strcmp(str, "notapplicable")== 0)
  18413. {
  18414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  18415. isSuccess = ConfigurationStatus_Accepted;
  18416. }
  18417. else if(strcmp(str, "unknown")== 0)
  18418. {
  18419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  18420. isSuccess = ConfigurationStatus_Accepted;
  18421. }
  18422. else if(strcmp(str, "rst")== 0)
  18423. {
  18424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  18425. isSuccess = ConfigurationStatus_Accepted;
  18426. }
  18427. else if(strcmp(str, "rts")== 0)
  18428. {
  18429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  18430. isSuccess = ConfigurationStatus_Accepted;
  18431. }
  18432. else if(strcmp(str, "srt")== 0)
  18433. {
  18434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  18435. isSuccess = ConfigurationStatus_Accepted;
  18436. }
  18437. else if(strcmp(str, "str")== 0)
  18438. {
  18439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  18440. isSuccess = ConfigurationStatus_Accepted;
  18441. }
  18442. else if(strcmp(str, "trs")== 0)
  18443. {
  18444. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  18445. isSuccess = ConfigurationStatus_Accepted;
  18446. }
  18447. else if(strcmp(str, "tsr")== 0)
  18448. {
  18449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  18450. isSuccess = ConfigurationStatus_Accepted;
  18451. }
  18452. else
  18453. {
  18454. isSuccess = ConfigurationStatus_Rejected;
  18455. }
  18456. }
  18457. else
  18458. {
  18459. isSuccess = ConfigurationStatus_Rejected;
  18460. }
  18461. }
  18462. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  18463. {
  18464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  18465. {
  18466. check_ascii = value[0];
  18467. if( (check_ascii < 48) || (check_ascii > 57) )
  18468. {
  18469. isSuccess = ConfigurationStatus_Rejected;
  18470. }
  18471. else
  18472. {
  18473. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  18474. isSuccess = ConfigurationStatus_Accepted;
  18475. }
  18476. }
  18477. else
  18478. {
  18479. isSuccess = ConfigurationStatus_Rejected;
  18480. }
  18481. }
  18482. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  18483. {
  18484. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  18485. {
  18486. strcpy(str, (const char*)value);
  18487. for(int i = 0; str[i]; i++)
  18488. {
  18489. str[i] = tolower(str[i]);
  18490. }
  18491. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18493. isSuccess = ConfigurationStatus_Accepted;
  18494. }
  18495. else
  18496. {
  18497. isSuccess = ConfigurationStatus_Rejected;
  18498. }
  18499. }
  18500. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  18501. {
  18502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  18503. {
  18504. strcpy(str, (const char*)value);
  18505. for(int i = 0; str[i]; i++)
  18506. {
  18507. str[i] = tolower(str[i]);
  18508. }
  18509. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  18510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18511. isSuccess = ConfigurationStatus_Accepted;
  18512. }
  18513. else
  18514. {
  18515. isSuccess = ConfigurationStatus_Rejected;
  18516. }
  18517. }
  18518. if(strcmp(key, "StopTxnAlignedData") == 0)
  18519. {
  18520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  18521. {
  18522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  18523. isSuccess = ConfigurationStatus_Accepted;
  18524. }
  18525. else
  18526. {
  18527. isSuccess = ConfigurationStatus_Rejected;
  18528. }
  18529. }
  18530. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  18531. {
  18532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  18533. {
  18534. check_ascii = value[0];
  18535. if( (check_ascii < 48) || (check_ascii > 57) )
  18536. {
  18537. isSuccess = ConfigurationStatus_Rejected;
  18538. }
  18539. else
  18540. {
  18541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  18542. isSuccess = ConfigurationStatus_Accepted;
  18543. }
  18544. }
  18545. else
  18546. {
  18547. isSuccess = ConfigurationStatus_Rejected;
  18548. }
  18549. }
  18550. if(strcmp(key, "StopTxnSampledData") == 0)
  18551. {
  18552. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  18553. {
  18554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  18555. isSuccess = ConfigurationStatus_Accepted;
  18556. }
  18557. else
  18558. {
  18559. isSuccess = ConfigurationStatus_Rejected;
  18560. }
  18561. }
  18562. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  18563. {
  18564. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  18565. {
  18566. check_ascii = value[0];
  18567. if( (check_ascii < 48) || (check_ascii > 57) )
  18568. {
  18569. isSuccess = ConfigurationStatus_Rejected;
  18570. }
  18571. else
  18572. {
  18573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  18574. isSuccess = ConfigurationStatus_Accepted;
  18575. }
  18576. }
  18577. else
  18578. {
  18579. isSuccess = ConfigurationStatus_Rejected;
  18580. }
  18581. }
  18582. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  18583. {
  18584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  18585. {
  18586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  18587. isSuccess = ConfigurationStatus_Accepted;
  18588. }
  18589. else
  18590. {
  18591. isSuccess = ConfigurationStatus_Rejected;
  18592. }
  18593. }
  18594. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  18595. {
  18596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  18597. {
  18598. check_ascii = value[0];
  18599. if( (check_ascii < 48) || (check_ascii > 57) )
  18600. {
  18601. isSuccess = ConfigurationStatus_Rejected;
  18602. }
  18603. else
  18604. {
  18605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  18606. isSuccess = ConfigurationStatus_Accepted;
  18607. }
  18608. }
  18609. else
  18610. {
  18611. isSuccess = ConfigurationStatus_Rejected;
  18612. }
  18613. }
  18614. if(strcmp(key, "TransactionMessageAttempts") == 0)
  18615. {
  18616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  18617. {
  18618. check_ascii = value[0];
  18619. if( (check_ascii < 48) || (check_ascii > 57) )
  18620. {
  18621. isSuccess = ConfigurationStatus_Rejected;
  18622. }
  18623. else
  18624. {
  18625. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  18626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  18627. TransactionMessageAttemptsValue = atoi(value);
  18628. isSuccess = ConfigurationStatus_Accepted;
  18629. }
  18630. }
  18631. else
  18632. {
  18633. isSuccess = ConfigurationStatus_Rejected;
  18634. }
  18635. }
  18636. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  18637. {
  18638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  18639. {
  18640. check_ascii = value[0];
  18641. if( (check_ascii < 48) || (check_ascii > 57) )
  18642. {
  18643. isSuccess = ConfigurationStatus_Rejected;
  18644. }
  18645. else
  18646. {
  18647. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  18648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  18649. TransactionMessageRetryIntervalValue = atoi(value);
  18650. isSuccess = ConfigurationStatus_Accepted;
  18651. }
  18652. }
  18653. else
  18654. {
  18655. isSuccess = ConfigurationStatus_Rejected;
  18656. }
  18657. }
  18658. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  18659. {
  18660. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  18661. {
  18662. strcpy(str, (const char*)value);
  18663. for(int i = 0; str[i]; i++)
  18664. {
  18665. str[i] = tolower(str[i]);
  18666. }
  18667. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  18668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18669. isSuccess = ConfigurationStatus_Accepted;
  18670. }
  18671. else
  18672. {
  18673. isSuccess = ConfigurationStatus_Rejected;
  18674. }
  18675. }
  18676. if(strcmp(key, "WebSocketPingInterval") == 0)
  18677. {
  18678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  18679. {
  18680. check_ascii = value[0];
  18681. if( (check_ascii < 48) || (check_ascii > 57) )
  18682. {
  18683. isSuccess = ConfigurationStatus_Rejected;
  18684. }
  18685. else
  18686. {
  18687. if((atoi(value) == 0) || (atoi(value) >= 10))
  18688. {
  18689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  18690. isSuccess = ConfigurationStatus_Accepted;
  18691. }
  18692. else
  18693. isSuccess = ConfigurationStatus_Rejected;
  18694. }
  18695. }
  18696. else
  18697. {
  18698. isSuccess = ConfigurationStatus_Rejected;
  18699. }
  18700. }
  18701. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  18702. {
  18703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  18704. {
  18705. strcpy(str, (const char*)value);
  18706. for(int i = 0; str[i]; i++)
  18707. {
  18708. str[i] = tolower(str[i]);
  18709. }
  18710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18711. isSuccess = ConfigurationStatus_Accepted;
  18712. }
  18713. else
  18714. {
  18715. isSuccess = ConfigurationStatus_Rejected;
  18716. }
  18717. }
  18718. if(strcmp(key, "AuthorizationKey") == 0)
  18719. {
  18720. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  18721. {
  18722. strcpy(str, (const char*)value);
  18723. int strlength = strlen(str);
  18724. char capture[3];
  18725. char stackItem = 0;
  18726. char password[21] = {0};
  18727. printf("String length: %d\n", strlength);
  18728. for(int idx=0; idx<(strlength/2); idx++)
  18729. {
  18730. capture[0] = str[(idx*2)];
  18731. capture[1] = str[(idx*2)+1];
  18732. capture[2] = 0;
  18733. stackItem = (char)strtol(capture, NULL, 16); // number base 16
  18734. sprintf(password,"%s%c", password, stackItem);
  18735. }
  18736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", password);
  18737. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18738. isSuccess = ConfigurationStatus_Accepted;
  18739. }
  18740. else
  18741. {
  18742. isSuccess = ConfigurationStatus_Rejected;
  18743. }
  18744. }
  18745. if(strcmp(key, "SecurityProfile") == 0)
  18746. {
  18747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  18748. {
  18749. check_ascii = value[0];
  18750. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  18751. {
  18752. isSuccess = ConfigurationStatus_Rejected;
  18753. }
  18754. else if(check_ascii == 0x33)
  18755. {
  18756. isSuccess = NotSupported;
  18757. }
  18758. else
  18759. {
  18760. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  18761. {
  18762. if(((check_ascii - 0x30) == 1) ||
  18763. ((check_ascii - 0x30) == 2) ||
  18764. (((check_ascii - 0x30) == 3) && (access(CERTIFICATE_CP,F_OK) != -1)))
  18765. {
  18766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  18767. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  18768. isSuccess = ConfigurationStatus_Accepted;
  18769. }
  18770. else
  18771. isSuccess = ConfigurationStatus_Rejected;
  18772. }
  18773. else
  18774. isSuccess = ConfigurationStatus_Rejected;
  18775. }
  18776. }
  18777. else
  18778. {
  18779. isSuccess = ConfigurationStatus_Rejected;
  18780. }
  18781. }
  18782. if(strcmp(key, "DefaultPrice") == 0)
  18783. {
  18784. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  18785. {
  18786. strcpy(str, (const char*)value);
  18787. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  18788. isSuccess = ConfigurationStatus_Accepted;
  18789. }
  18790. else
  18791. {
  18792. isSuccess = ConfigurationStatus_Rejected;
  18793. }
  18794. }
  18795. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  18796. {
  18797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  18798. {
  18799. strcpy(str, (const char*)value);
  18800. for(int i = 0; str[i]; i++)
  18801. {
  18802. str[i] = tolower(str[i]);
  18803. }
  18804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18805. isSuccess = ConfigurationStatus_Accepted;
  18806. }
  18807. else
  18808. {
  18809. isSuccess = ConfigurationStatus_Rejected;
  18810. }
  18811. }
  18812. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  18813. {
  18814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  18815. {
  18816. strcpy(str, (const char*)value);
  18817. for(int i = 0; str[i]; i++)
  18818. {
  18819. str[i] = tolower(str[i]);
  18820. }
  18821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18822. isSuccess = ConfigurationStatus_Accepted;
  18823. }
  18824. else
  18825. {
  18826. isSuccess = ConfigurationStatus_Rejected;
  18827. }
  18828. }
  18829. if(strcmp(key, "TimeOffset") == 0)
  18830. {
  18831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  18832. {
  18833. strcpy(str, (const char*)value);
  18834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  18835. isSuccess = ConfigurationStatus_Accepted;
  18836. }
  18837. else
  18838. {
  18839. isSuccess = ConfigurationStatus_Rejected;
  18840. }
  18841. }
  18842. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  18843. {
  18844. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  18845. {
  18846. strcpy(str, (const char*)value);
  18847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  18848. isSuccess = ConfigurationStatus_Accepted;
  18849. }
  18850. else
  18851. {
  18852. isSuccess = ConfigurationStatus_Rejected;
  18853. }
  18854. }
  18855. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  18856. {
  18857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  18858. {
  18859. strcpy(str, (const char*)value);
  18860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  18861. isSuccess = ConfigurationStatus_Accepted;
  18862. }
  18863. else
  18864. {
  18865. isSuccess = ConfigurationStatus_Rejected;
  18866. }
  18867. }
  18868. if(strcmp(key, "SystemUptimeSec") == 0)
  18869. {
  18870. isSuccess = NotSupported;
  18871. }
  18872. if(strcmp(key, "FreeVend") == 0)
  18873. {
  18874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  18875. {
  18876. strcpy(str, (const char*)value);
  18877. for(int i = 0; str[i]; i++)
  18878. {
  18879. str[i] = tolower(str[i]);
  18880. }
  18881. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  18882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  18883. isSuccess = ConfigurationStatus_Accepted;
  18884. }
  18885. else
  18886. {
  18887. isSuccess = ConfigurationStatus_Rejected;
  18888. }
  18889. }
  18890. if(strcmp(key, "FreeVendIdtag") == 0)
  18891. {
  18892. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  18893. {
  18894. strcpy(str, (const char*)value);
  18895. if(strlen(str) <= 20)
  18896. {
  18897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  18898. isSuccess = ConfigurationStatus_Accepted;
  18899. }
  18900. else
  18901. {
  18902. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  18903. isSuccess = ConfigurationStatus_Rejected;
  18904. }
  18905. }
  18906. else
  18907. {
  18908. isSuccess = ConfigurationStatus_Rejected;
  18909. }
  18910. }
  18911. if(strcmp(key, "OcppServer") == 0)
  18912. {
  18913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  18914. {
  18915. strcpy(str, (const char*)value);
  18916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  18917. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  18918. isSuccess = ConfigurationStatus_Accepted;
  18919. }
  18920. else
  18921. {
  18922. isSuccess = ConfigurationStatus_Rejected;
  18923. }
  18924. }
  18925. if(strcmp(key, "MaintainServer") == 0)
  18926. {
  18927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  18928. {
  18929. strcpy(str, (const char*)value);
  18930. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  18931. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  18932. isSuccess = ConfigurationStatus_Accepted;
  18933. }
  18934. else
  18935. {
  18936. isSuccess = ConfigurationStatus_Rejected;
  18937. }
  18938. }
  18939. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  18940. {
  18941. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  18942. {
  18943. strcpy(str, (const char*)value);
  18944. for(int i = 0; str[i]; i++)
  18945. {
  18946. str[i] = tolower(str[i]);
  18947. }
  18948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  18949. isSuccess = ConfigurationStatus_Accepted;
  18950. }
  18951. else
  18952. {
  18953. isSuccess = ConfigurationStatus_Rejected;
  18954. }
  18955. }
  18956. if(strcmp(key, "StatusNotificationInterval") == 0)
  18957. {
  18958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  18959. {
  18960. check_ascii = value[0];
  18961. if( (check_ascii < 48) || (check_ascii > 57) )
  18962. {
  18963. isSuccess = ConfigurationStatus_Rejected;
  18964. }
  18965. else
  18966. {
  18967. if((atoi(value) == 0) || (atoi(value) >= 10))
  18968. {
  18969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  18970. isSuccess = ConfigurationStatus_Accepted;
  18971. }
  18972. else
  18973. isSuccess = ConfigurationStatus_Rejected;
  18974. }
  18975. }
  18976. else
  18977. {
  18978. isSuccess = ConfigurationStatus_Rejected;
  18979. }
  18980. }
  18981. if(strcmp(key, "PreAuthAmount") == 0)
  18982. {
  18983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemAccessibility == 1)
  18984. {
  18985. check_ascii = value[0];
  18986. if( (check_ascii < 48) || (check_ascii > 57) )
  18987. {
  18988. isSuccess = ConfigurationStatus_Rejected;
  18989. }
  18990. else
  18991. {
  18992. if(atof(value) >= 0)
  18993. {
  18994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PreAuthAmount].ItemData, "%.2f", atof(value) );
  18995. isSuccess = ConfigurationStatus_Accepted;
  18996. }
  18997. else
  18998. isSuccess = ConfigurationStatus_Rejected;
  18999. }
  19000. }
  19001. else
  19002. {
  19003. isSuccess = ConfigurationStatus_Rejected;
  19004. }
  19005. }
  19006. if(strcmp(key, "isEnableLocalPowerSharing") == 0)
  19007. {
  19008. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemAccessibility == 1)
  19009. {
  19010. check_ascii = value[0];
  19011. if( (check_ascii < 48) || (check_ascii > 57) )
  19012. {
  19013. isSuccess = ConfigurationStatus_Rejected;
  19014. }
  19015. else
  19016. {
  19017. if(atoi(value) >= 0)
  19018. {
  19019. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[isEnableLocalPowerSharing].ItemData, "%d", atoi(value));
  19020. ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing = (unsigned char)atoi(value);
  19021. isSuccess = ConfigurationStatus_Accepted;
  19022. }
  19023. else
  19024. isSuccess = ConfigurationStatus_Rejected;
  19025. }
  19026. }
  19027. else
  19028. {
  19029. isSuccess = ConfigurationStatus_Rejected;
  19030. }
  19031. }
  19032. if(strcmp(key, "PowerSharingServerIP") == 0)
  19033. {
  19034. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemAccessibility == 1)
  19035. {
  19036. strcpy(str, (const char*)value);
  19037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[PowerSharingServerIP].ItemData, "%s", str );
  19038. sprintf((char *)ShmSysConfigAndInfo->SysConfig.PowerSharingServerIP, "%s", str );
  19039. isSuccess = ConfigurationStatus_Accepted;
  19040. }
  19041. else
  19042. {
  19043. isSuccess = ConfigurationStatus_Rejected;
  19044. }
  19045. }
  19046. if(strcmp(key, "EVCCID_PREFIX") == 0)
  19047. {
  19048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemAccessibility == 1)
  19049. {
  19050. strcpy(str, (const char*)value);
  19051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[EVCCID_PREFIX].ItemData, "%s", str );
  19052. isSuccess = ConfigurationStatus_Accepted;
  19053. }
  19054. else
  19055. {
  19056. isSuccess = ConfigurationStatus_Rejected;
  19057. }
  19058. }
  19059. if(strcmp(key, "OffLineMaxChargingPower") == 0)
  19060. {
  19061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemAccessibility == 1)
  19062. {
  19063. if(atoi(value) > modelnameInfo.ratedPower)
  19064. {
  19065. isSuccess = ConfigurationStatus_Rejected;
  19066. }
  19067. else{
  19068. strcpy(str, (const char*)value);
  19069. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OffLineMaxChargingPower].ItemData, "%s", str );
  19070. isSuccess = ConfigurationStatus_Accepted;
  19071. }
  19072. }
  19073. else
  19074. {
  19075. isSuccess = ConfigurationStatus_Rejected;
  19076. }
  19077. }
  19078. if(strcmp(key, "CharingProfileRefreshInterval") == 0)
  19079. {
  19080. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemAccessibility == 1)
  19081. {
  19082. if((atoi(value) != 0) && (atoi(value) < 5))
  19083. {
  19084. isSuccess = ConfigurationStatus_Rejected;
  19085. }
  19086. else{
  19087. strcpy(str, (const char*)value);
  19088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CharingProfileRefreshInterval].ItemData, "%s", str );
  19089. isSuccess = ConfigurationStatus_Accepted;
  19090. }
  19091. }
  19092. else
  19093. {
  19094. isSuccess = ConfigurationStatus_Rejected;
  19095. }
  19096. }
  19097. if(strcmp(key, "CpoName") == 0)
  19098. {
  19099. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemAccessibility == 1)
  19100. {
  19101. strcpy(str, (const char*)value);
  19102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CpoName].ItemData, "%s", str );
  19103. isSuccess = ConfigurationStatus_Accepted;
  19104. }
  19105. else
  19106. {
  19107. isSuccess = ConfigurationStatus_Rejected;
  19108. }
  19109. }
  19110. if(strcmp(key, "OcppSoftwareVersion") == 0)
  19111. {
  19112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemAccessibility == 1)
  19113. {
  19114. strcpy(str, (const char*)value);
  19115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[OcppSoftwareVersion].ItemData, "%s", str );
  19116. isSuccess = ConfigurationStatus_Accepted;
  19117. }
  19118. else
  19119. {
  19120. isSuccess = ConfigurationStatus_Rejected;
  19121. }
  19122. }
  19123. if(strcmp(key, "AuthDownloadlinkCertificate") == 0)
  19124. {
  19125. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemAccessibility == 1)
  19126. {
  19127. strcpy(str, (const char*)value);
  19128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "%s", str );
  19129. isSuccess = ConfigurationStatus_Accepted;
  19130. }
  19131. else
  19132. {
  19133. isSuccess = ConfigurationStatus_Rejected;
  19134. }
  19135. }
  19136. if(strcmp(key, "RfidEndianType") == 0)
  19137. {
  19138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemAccessibility == 1)
  19139. {
  19140. strcpy(str, (const char*)value);
  19141. if((strcmp(str, "BIG")==0) || (strcmp(str, "LITTLE")==0))
  19142. {
  19143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[RfidEndianType].ItemData, "%s", str );
  19144. ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = (strcmp(str, "BIG")==0)?1:0;
  19145. isSuccess = ConfigurationStatus_Accepted;
  19146. }
  19147. else
  19148. isSuccess = ConfigurationStatus_Rejected;
  19149. }
  19150. else
  19151. {
  19152. isSuccess = ConfigurationStatus_Rejected;
  19153. }
  19154. }
  19155. if(strcmp(key, "AuthorizeTimeout") == 0)
  19156. {
  19157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemAccessibility == 1)
  19158. {
  19159. strcpy(str, (const char*)value);
  19160. check_ascii = value[0];
  19161. if((check_ascii < 48) || (check_ascii > 57))
  19162. {
  19163. isSuccess = ConfigurationStatus_Rejected;
  19164. }
  19165. else
  19166. {
  19167. if((atoi(value) >= 10) && (atoi(value) <= 300))
  19168. {
  19169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeTimeout].ItemData, "%s", str );
  19170. isSuccess = ConfigurationStatus_Accepted;
  19171. }
  19172. else
  19173. {
  19174. isSuccess = ConfigurationStatus_Rejected;
  19175. }
  19176. }
  19177. }
  19178. else
  19179. {
  19180. isSuccess = ConfigurationStatus_Rejected;
  19181. }
  19182. }
  19183. #if 0
  19184. //For OCPP Test Case
  19185. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  19186. {
  19187. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19188. {
  19189. strcpy(str, (const char*)value);
  19190. for(int i = 0; str[i]; i++)
  19191. {
  19192. str[i] = tolower(str[i]);
  19193. }
  19194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19195. isSuccess = ConfigurationStatus_Accepted;
  19196. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19197. }
  19198. else
  19199. {
  19200. isSuccess = ConfigurationStatus_Rejected;
  19201. }
  19202. }
  19203. #endif
  19204. #if 1
  19205. if(strcmp(key, "LocalAuthListEnabled") == 0)
  19206. {
  19207. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  19208. {
  19209. strcpy(str, (const char*)value);
  19210. for(int i = 0; str[i]; i++)
  19211. {
  19212. str[i] = tolower(str[i]);
  19213. }
  19214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19215. isSuccess = ConfigurationStatus_Accepted;
  19216. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  19217. }
  19218. else
  19219. {
  19220. isSuccess = ConfigurationStatus_Rejected;
  19221. }
  19222. }
  19223. #endif
  19224. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  19225. {
  19226. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  19227. {
  19228. check_ascii = value[0];
  19229. if( (check_ascii < 48) || (check_ascii > 57) )
  19230. {
  19231. isSuccess = ConfigurationStatus_Rejected;
  19232. }
  19233. else
  19234. {
  19235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  19236. isSuccess = ConfigurationStatus_Accepted;
  19237. }
  19238. }
  19239. else
  19240. {
  19241. isSuccess = ConfigurationStatus_Rejected;
  19242. }
  19243. }
  19244. if(strcmp(key, "SendLocalListMaxLength") == 0)
  19245. {
  19246. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  19247. {
  19248. check_ascii = value[0];
  19249. if( (check_ascii < 48) || (check_ascii > 57) )
  19250. {
  19251. isSuccess = ConfigurationStatus_Rejected;
  19252. }
  19253. else
  19254. {
  19255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  19256. isSuccess = ConfigurationStatus_Accepted;
  19257. }
  19258. }
  19259. else
  19260. {
  19261. isSuccess = ConfigurationStatus_Rejected;
  19262. }
  19263. }
  19264. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  19265. {
  19266. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].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.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19274. isSuccess = ConfigurationStatus_Accepted;
  19275. }
  19276. else
  19277. {
  19278. isSuccess = ConfigurationStatus_Rejected;
  19279. }
  19280. }
  19281. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  19282. {
  19283. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  19284. {
  19285. check_ascii = value[0];
  19286. if( (check_ascii < 48) || (check_ascii > 57) )
  19287. {
  19288. isSuccess = ConfigurationStatus_Rejected;
  19289. }
  19290. else
  19291. {
  19292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  19293. isSuccess = ConfigurationStatus_Accepted;
  19294. }
  19295. }
  19296. else
  19297. {
  19298. isSuccess = ConfigurationStatus_Rejected;
  19299. }
  19300. }
  19301. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  19302. {
  19303. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  19304. {
  19305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  19306. isSuccess = ConfigurationStatus_Accepted;
  19307. }
  19308. else
  19309. {
  19310. isSuccess = ConfigurationStatus_Rejected;
  19311. }
  19312. }
  19313. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  19314. {
  19315. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  19316. {
  19317. check_ascii = value[0];
  19318. if( (check_ascii < 48) || (check_ascii > 57) )
  19319. {
  19320. isSuccess = ConfigurationStatus_Rejected;
  19321. }
  19322. else
  19323. {
  19324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  19325. isSuccess = ConfigurationStatus_Accepted;
  19326. }
  19327. }
  19328. else
  19329. {
  19330. isSuccess = ConfigurationStatus_Rejected;
  19331. }
  19332. }
  19333. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  19334. {
  19335. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  19336. {
  19337. strcpy(str, (const char*)value);
  19338. for(int i = 0; str[i]; i++)
  19339. {
  19340. str[i] = tolower(str[i]);
  19341. }
  19342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  19343. isSuccess = ConfigurationStatus_Accepted;
  19344. }
  19345. else
  19346. {
  19347. isSuccess = ConfigurationStatus_Rejected;
  19348. }
  19349. }
  19350. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  19351. {
  19352. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  19353. {
  19354. check_ascii = value[0];
  19355. if( (check_ascii < 48) || (check_ascii > 57) )
  19356. {
  19357. isSuccess = ConfigurationStatus_Rejected;
  19358. }
  19359. else
  19360. {
  19361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  19362. isSuccess = ConfigurationStatus_Accepted;
  19363. }
  19364. }
  19365. else
  19366. {
  19367. isSuccess = ConfigurationStatus_Rejected;
  19368. }
  19369. }
  19370. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  19371. return isSuccess;
  19372. }
  19373. int TransactionMessageAttemptsGet(void)
  19374. {
  19375. return TransactionMessageAttemptsValue;
  19376. }
  19377. int FirstHeartBeatResponse(void)
  19378. {
  19379. return FirstHeartBeat;
  19380. }
  19381. int TransactionMessageRetryIntervalGet(void)
  19382. {
  19383. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  19384. }
  19385. int ReadHttpStatus(int sock)
  19386. {
  19387. //char c;
  19388. char buff[1024]="",*ptr=buff+1;
  19389. int bytes_received, status;
  19390. DEBUG_INFO("Begin Response ..\n");
  19391. while((bytes_received = recv(sock, ptr, 1, 0))){
  19392. if(bytes_received==-1){
  19393. perror("ReadHttpStatus");
  19394. exit(1);
  19395. }
  19396. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  19397. ptr++;
  19398. }
  19399. *ptr=0;
  19400. ptr=buff+1;
  19401. sscanf(ptr,"%*s %d ", &status);
  19402. DEBUG_INFO("%s\n",ptr);
  19403. DEBUG_INFO("status=%d\n",status);
  19404. DEBUG_INFO("End Response ..\n");
  19405. return (bytes_received>0)?status:0;
  19406. }
  19407. //the only filed that it parsed is 'Content-Length'
  19408. int ParseHeader(int sock)
  19409. {
  19410. //char c;
  19411. char buff[1024]="",*ptr=buff+4;
  19412. int bytes_received;
  19413. DEBUG_INFO("Begin HEADER ..\n");
  19414. while((bytes_received = recv(sock, ptr, 1, 0))){
  19415. if(bytes_received==-1){
  19416. perror("Parse Header");
  19417. exit(1);
  19418. }
  19419. if(
  19420. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  19421. (ptr[-1]=='\r') && (*ptr=='\n' )
  19422. ) break;
  19423. ptr++;
  19424. }
  19425. *ptr=0;
  19426. ptr=buff+4;
  19427. //printf("%s",ptr);
  19428. if(bytes_received){
  19429. ptr=strstr(ptr,"Content-Length:");
  19430. if(ptr){
  19431. sscanf(ptr,"%*s %d",&bytes_received);
  19432. }else
  19433. bytes_received=-1; //unknown size
  19434. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  19435. }
  19436. DEBUG_INFO("End HEADER ..\n");
  19437. return bytes_received ;
  19438. }
  19439. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  19440. {
  19441. int result = TRUE;
  19442. char rmFileCmd[300]={0};
  19443. char FilePath[256]={0};
  19444. char ftpbuf[2048];
  19445. int systemresult;
  19446. sprintf(FilePath,"/mnt/%s",filename);
  19447. system("ping 8.8.8.8 &");
  19448. if((access(FilePath,F_OK))!=-1)
  19449. {
  19450. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19451. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19452. system(rmFileCmd);
  19453. }
  19454. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19455. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19456. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  19457. else
  19458. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19459. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19460. systemresult = system(ftpbuf);
  19461. if(systemresult != 0)
  19462. {
  19463. DEBUG_INFO("HTTP/HTTPS downLoad fail!\n");
  19464. result = FALSE;
  19465. }
  19466. system("pkill ping");
  19467. return result;
  19468. }
  19469. int sftpDownLoadFile(char *location, char *user, int port, char *path, char *filename,char *url)
  19470. {
  19471. int result = TRUE;
  19472. char rmFileCmd[300]={0};
  19473. char FilePath[256]={0};
  19474. char ftpbuf[2048];
  19475. int systemresult;
  19476. sprintf(FilePath,"/mnt/%s",filename);
  19477. system("ping 8.8.8.8 &");
  19478. if((access(FilePath,F_OK))!=-1)
  19479. {
  19480. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19481. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19482. system(rmFileCmd);
  19483. }
  19484. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19485. sprintf(ftpbuf,"timeout -t 360 scp -i /root/.ssh/id_rsa_bear -P %d %s@%s%s /mnt/%s", port, user, path, filename, filename);
  19486. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19487. systemresult = system(ftpbuf);
  19488. if(systemresult != 0)
  19489. {
  19490. DEBUG_WARN("scp error!\n");
  19491. result = FALSE;
  19492. }
  19493. system("pkill ping");
  19494. return result;
  19495. }
  19496. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  19497. {
  19498. int result = TRUE;
  19499. char rmFileCmd[300]={0};
  19500. char FilePath[256]={0};
  19501. char ftpbuf[2048];
  19502. int systemresult;
  19503. sprintf(FilePath,"/mnt/%s",filename);
  19504. system("ping 8.8.8.8 &");
  19505. if((access(FilePath,F_OK))!=-1)
  19506. {
  19507. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19508. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19509. system(rmFileCmd);
  19510. }
  19511. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19512. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19513. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --ca-certificate=/root/cacert.pem",filename, url);
  19514. else
  19515. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  19516. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19517. systemresult = system(ftpbuf);
  19518. if(systemresult != 0)
  19519. {
  19520. if(strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthDownloadlinkCertificate].ItemData, "TRUE") != NULL)
  19521. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --ca-certificate=/root/cacert.pem",filename, url);
  19522. else
  19523. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp --no-check-certificate",filename, url);
  19524. DEBUG_INFO("Download command: %s\n",ftpbuf);
  19525. systemresult = system(ftpbuf);
  19526. if(systemresult != 0)
  19527. {
  19528. DEBUG_WARN("FTP download fail!\n");
  19529. result = FALSE;
  19530. }
  19531. }
  19532. system("pkill ping");
  19533. return result;
  19534. }
  19535. int httpUploadFile(char *location, char *path, char *filename,char *url)
  19536. {
  19537. char rmFileCmd[100]={0};
  19538. char FilePath[100]={0};
  19539. char buf[512];
  19540. int systemresult = 0;
  19541. //DEBUG_INFO("filename=%s\n",filename);
  19542. //DEBUG_INFO("url=%s\n",url);
  19543. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  19544. if((access(FilePath,F_OK))!=-1)
  19545. {
  19546. DEBUG_INFO("filename=%s exist.\n",FilePath);
  19547. sprintf(rmFileCmd,"rm -f %s",FilePath);
  19548. system(rmFileCmd);
  19549. }
  19550. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  19551. if(fp == NULL)
  19552. {
  19553. DEBUG_INFO("log is NULL\n");
  19554. return FALSE;
  19555. }
  19556. else
  19557. {
  19558. fprintf(fp, "%s\n", url);
  19559. fprintf(fp, "%s\n", filename);
  19560. fclose(fp);
  19561. }
  19562. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  19563. if(phpFP == NULL)
  19564. {
  19565. DEBUG_INFO("PHP upload fail.\n");
  19566. return FALSE;
  19567. }
  19568. else
  19569. {
  19570. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19571. {
  19572. if(strstr(buf, "result") != NULL)
  19573. {
  19574. sscanf(buf, "result: %d", &systemresult);
  19575. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  19576. }
  19577. }
  19578. pclose(phpFP);
  19579. }
  19580. if(systemresult != 1)
  19581. {
  19582. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  19583. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  19584. if(phpFP == NULL)
  19585. {
  19586. DEBUG_WARN("PHP PUT upload fail.\n");
  19587. return FALSE;
  19588. }
  19589. else
  19590. {
  19591. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  19592. {
  19593. if(strstr(buf, "result") != NULL)
  19594. {
  19595. sscanf(buf, "result: %d", &systemresult);
  19596. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  19597. }
  19598. }
  19599. pclose(phpFP);
  19600. }
  19601. }
  19602. if(systemresult != 1)
  19603. {
  19604. DEBUG_WARN("PHP PUT upload fail.\n");
  19605. return FALSE;
  19606. }
  19607. return TRUE;
  19608. }
  19609. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  19610. {
  19611. int result = FALSE;
  19612. char ftpbuf[200];
  19613. int systemresult;
  19614. /*
  19615. // Domaind name transfer to IP address
  19616. struct hostent* server;
  19617. char *IPbuffer;
  19618. server = gethostbyname(location);
  19619. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  19620. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  19621. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  19622. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  19623. systemresult = system(ftpbuf);
  19624. if(systemresult != 0)
  19625. {
  19626. DEBUG_INFO("ftpput error!\n");
  19627. }
  19628. else
  19629. {
  19630. result = TRUE;
  19631. DEBUG_INFO("ftpput OK!\n");
  19632. }
  19633. return result;
  19634. }
  19635. int GetOcppServerURL()
  19636. {
  19637. int result = FALSE;
  19638. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  19639. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  19640. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  19641. struct yuarel url;
  19642. char urlStr[512];
  19643. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  19644. {
  19645. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  19646. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19647. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19648. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  19649. if(yuarel_parse(&url, urlStr) != -1)
  19650. {
  19651. sprintf(OcppProtocol, "%s", url.scheme);
  19652. sprintf(OcppHost, "%s", url.host);
  19653. if(url.path == NULL)
  19654. OcppTempPath[0] = '\0';
  19655. else
  19656. {
  19657. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  19658. {
  19659. sprintf(OcppTempPath, "%s/", url.path);
  19660. }
  19661. else
  19662. {
  19663. sprintf(OcppTempPath, "%s", url.path);
  19664. }
  19665. }
  19666. if(url.port == 0)
  19667. {
  19668. if(strcmp(OcppProtocol, "wss") == 0)
  19669. OcppPort = 443;
  19670. else
  19671. OcppPort = 80;
  19672. }
  19673. else
  19674. OcppPort = url.port;
  19675. result = TRUE;
  19676. }
  19677. }
  19678. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  19679. {
  19680. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  19681. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  19682. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  19683. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  19684. if(yuarel_parse(&url, urlStr) != -1)
  19685. {
  19686. sprintf(OcppProtocol, "%s", url.scheme);
  19687. sprintf(OcppHost, "%s", url.host);
  19688. if(url.path == NULL)
  19689. OcppTempPath[0] = '\0';
  19690. else
  19691. sprintf(OcppTempPath, "%s", url.path);
  19692. if(url.port == 0)
  19693. {
  19694. if(strcmp(OcppProtocol, "wss") == 0)
  19695. OcppPort = 443;
  19696. else
  19697. OcppPort = 80;
  19698. }
  19699. else
  19700. OcppPort = url.port;
  19701. result = TRUE;
  19702. }
  19703. }
  19704. else
  19705. {
  19706. strcpy(OcppHost,"");
  19707. }
  19708. return result;
  19709. }
  19710. int GetOcppPath()
  19711. {
  19712. int result = FALSE;
  19713. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  19714. {
  19715. if(OcppTempPath == NULL)
  19716. {
  19717. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19718. }
  19719. else
  19720. {
  19721. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  19722. }
  19723. result = TRUE;
  19724. goto End;
  19725. }
  19726. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  19727. {
  19728. if(OcppTempPath == NULL)
  19729. {
  19730. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  19731. }
  19732. else
  19733. {
  19734. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  19735. }
  19736. result = TRUE;
  19737. goto End;
  19738. }
  19739. else
  19740. {
  19741. strcpy(OcppPath,"");
  19742. }
  19743. End:
  19744. return result;
  19745. }
  19746. int GetOcppPort()
  19747. {
  19748. return OcppPort;
  19749. }
  19750. int GetOcppConnStatus(void)
  19751. {
  19752. return ShmOCPP16Data->OcppConnStatus;
  19753. }
  19754. void SetOcppConnStatus(uint8_t status)
  19755. {
  19756. ShmOCPP16Data->OcppConnStatus = status;
  19757. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  19758. }
  19759. int GetHeartBeatWithNOResponse(void)
  19760. {
  19761. return HeartBeatWithNOResponse;
  19762. }
  19763. void SetHeartBeatWithNOResponse(void)
  19764. {
  19765. HeartBeatWithNOResponse = 0;
  19766. }
  19767. void GetStartTransactionIdTag(int gun_index)
  19768. {
  19769. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  19770. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  19771. }
  19772. int GetStartTransactionId(int gun_index)
  19773. {
  19774. return ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19775. }
  19776. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  19777. {
  19778. char ch;
  19779. FILE *fptr1;
  19780. int temptransactionId;
  19781. char str[100]={0};
  19782. temptransactionId = 0;
  19783. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  19784. {
  19785. DEBUG_INFO("IdTag is empty.\n");
  19786. return temptransactionId;
  19787. }
  19788. /*------ Read the file ----------------*/
  19789. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  19790. if (!fptr1)
  19791. {
  19792. DEBUG_INFO("QueueTransactionId file open error.\n");
  19793. //printf(" File not found or unable to open the input file!!\n");
  19794. return temptransactionId;
  19795. }
  19796. ch=fgetc(fptr1);
  19797. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  19798. rewind(fptr1);
  19799. if(ch!=EOF)
  19800. {
  19801. // printf("%c",ch);
  19802. while (fgets(str, 100, fptr1) != NULL)
  19803. {
  19804. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19805. if(str[0]=='\0')
  19806. {
  19807. break;
  19808. }
  19809. char *revbuf[8] = {0}; // Variable store string split
  19810. int num = 0;// Quantity after string split
  19811. DEBUG_INFO("Transaction queue data= %s\n", str);
  19812. splitstring(str,",",revbuf,&num); // String split
  19813. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  19814. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  19815. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  19816. DEBUG_INFO("------------------------------\n");
  19817. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  19818. {
  19819. if(isStopTransaction)
  19820. {
  19821. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  19822. {
  19823. temptransactionId = atoi(revbuf[2]);
  19824. //break;
  19825. }
  19826. }
  19827. else
  19828. {
  19829. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  19830. {
  19831. temptransactionId = atoi(revbuf[2]);
  19832. //break;
  19833. }
  19834. }
  19835. }
  19836. }
  19837. }
  19838. else
  19839. DEBUG_INFO("EOF\n");
  19840. fclose(fptr1);
  19841. /*------- End of reading ---------------*/
  19842. return temptransactionId;
  19843. }
  19844. void SetTransactionIdZero(int transactionId)
  19845. {
  19846. char ch;
  19847. FILE *fptr1, *fptr2;
  19848. int temptransactionId = 0;
  19849. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  19850. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  19851. if (!fptr1)
  19852. {
  19853. //printf(" File not found or unable to open the input file!!\n");
  19854. return ;
  19855. }
  19856. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  19857. if (!fptr2)
  19858. {
  19859. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  19860. fclose(fptr1);
  19861. return ;
  19862. }
  19863. ch=fgetc(fptr1);
  19864. rewind(fptr1);
  19865. if(ch!=EOF)
  19866. {
  19867. // copy all contents to the temporary file except the specific line
  19868. while (fgets(str, 100, fptr1) != NULL)
  19869. {
  19870. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  19871. if(str[0]=='\0')
  19872. {
  19873. break;
  19874. }
  19875. char *revbuf[8] = {0};
  19876. int num = 0;
  19877. strcpy(strtemp, str);
  19878. splitstring(str,",",revbuf,&num);
  19879. if(revbuf[2][0] != '\0')
  19880. {
  19881. temptransactionId = atoi(revbuf[2]);
  19882. if(transactionId != temptransactionId)
  19883. {
  19884. fprintf(fptr2, "%s\n", strtemp);
  19885. }
  19886. }
  19887. }
  19888. }
  19889. fclose(fptr1);
  19890. fclose(fptr2);
  19891. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  19892. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  19893. /*------ Read the file ----------------*/
  19894. }
  19895. int InternetDisconnect(void)
  19896. {
  19897. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  19898. }
  19899. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  19900. void storeTempStopTransaction(int gun_index)
  19901. {
  19902. char guid[37]={0};
  19903. int tempIndex = 0;
  19904. char TempStopTransaction[256];
  19905. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  19906. DEBUG_INFO("storeTempStopTransaction...\n");
  19907. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  19908. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  19909. //=========================== Stop Transaction Time ===============================================
  19910. getNowDatetime(ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  19911. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  19912. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  19913. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  19914. {
  19915. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19916. {
  19917. tempIndex = ((gun_index==2) ? 1: 0);
  19918. }
  19919. else
  19920. {
  19921. tempIndex = gun_index;
  19922. }
  19923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19924. {
  19925. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  19926. {
  19927. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  19928. }
  19929. }// END OF CHAdeMO_QUANTITY
  19930. }
  19931. else if(gunType[gun_index] == GUN_TYPE_CCS)
  19932. {
  19933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19934. {
  19935. tempIndex = ((gun_index==2) ? 1: 0);
  19936. }
  19937. else
  19938. {
  19939. tempIndex = gun_index;
  19940. }
  19941. for (int index = 0; index < CCS_QUANTITY; index++)
  19942. {
  19943. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  19944. {
  19945. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  19946. }
  19947. }// END OF CCS_QUANTITY
  19948. }
  19949. else if(gunType[gun_index] == GUN_TYPE_GBT)
  19950. {
  19951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  19952. {
  19953. tempIndex = ((gun_index==2) ? 1: 0);
  19954. }
  19955. else
  19956. {
  19957. tempIndex = gun_index;
  19958. }
  19959. for (int index = 0; index < GB_QUANTITY; index++)
  19960. {
  19961. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  19962. {
  19963. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  19964. }
  19965. }// END OF GB_QUANTITY
  19966. }
  19967. else if(gunType[gun_index] == GUN_TYPE_DO)
  19968. {
  19969. tempIndex = gun_index;
  19970. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19971. {
  19972. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  19973. {
  19974. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  19975. }
  19976. }
  19977. }
  19978. else
  19979. {
  19980. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  19981. {
  19982. tempIndex = 2;
  19983. }
  19984. else
  19985. {
  19986. tempIndex = gun_index;
  19987. }
  19988. for (int index = 0; index < AC_QUANTITY; index++)
  19989. {
  19990. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19991. {
  19992. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  19993. }
  19994. }// END OF AC_QUANTITY
  19995. }
  19996. //======================================== Message create ==============================================
  19997. json_object *StopTransaction = json_object_new_object();
  19998. json_object *transactionDatas = json_object_new_array();
  19999. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  20000. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  20001. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  20002. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  20003. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  20004. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  20005. meterValueBufferQuery(gun_index, transactionDatas);
  20006. if(json_object_array_length(transactionDatas) > 0) json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  20007. random_uuid(guid);
  20008. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  20009. ,MESSAGE_TYPE_CALL
  20010. ,guid
  20011. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  20012. json_object_put(StopTransaction);
  20013. // Check File "TempStopTransaction" Exist
  20014. if((access(TempStopTransaction,F_OK))!=-1)
  20015. {
  20016. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  20017. fclose(fopen(TempStopTransaction, "w"));
  20018. }
  20019. else
  20020. {
  20021. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  20022. FILE *log = fopen(TempStopTransaction, "w+");
  20023. if(log == NULL)
  20024. {
  20025. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  20026. return ;
  20027. }
  20028. else
  20029. {
  20030. fclose(log);
  20031. }
  20032. }
  20033. //Add TempStopTransaction | Update TempStopTransaction
  20034. // open file for writing
  20035. FILE *outfile;
  20036. outfile = fopen (TempStopTransaction, "a");
  20037. //DEBUG_INFO("data = %s\n", queuedata);
  20038. fputs(queuedata, outfile);
  20039. fputs("\n", outfile);
  20040. fclose (outfile);
  20041. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20042. OCPP_updatePeriodEnergy(gun_index);
  20043. }
  20044. void checkTempStopTransaction(int gun_index)
  20045. {
  20046. FILE *fptr1;
  20047. char ch;
  20048. char str[QUEUE_MESSAGE_LENGTH]={0};
  20049. char guid[37]={0};
  20050. char tempdata[65]={0};
  20051. char connectorStr[2]={0};
  20052. char TempStopTransaction[256];
  20053. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  20054. fptr1 = fopen(TempStopTransaction, "r");
  20055. //TempStopTransaction格式: 槍號,StopTransaction封包
  20056. if (!fptr1)
  20057. {
  20058. //printf(" File not found or unable to open the input file!!\n");
  20059. return ;
  20060. }
  20061. ch=fgetc(fptr1);
  20062. //printf(" Now the content of the file %s is : \n",fname);
  20063. rewind(fptr1);
  20064. if(ch!=EOF)
  20065. {
  20066. // copy all contents to the temporary file except the specific line
  20067. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  20068. {
  20069. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  20070. if(str[0]=='\0')
  20071. {
  20072. break;
  20073. }
  20074. //TempStopTransaction格式: 槍號,StopTransaction封包
  20075. strncpy(connectorStr, str, 1);
  20076. if(atoi(connectorStr) != (gun_index+1))
  20077. {
  20078. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  20079. fclose(fptr1);
  20080. return ;
  20081. }
  20082. //random_uuid(guid);
  20083. strncpy(guid, str+6, 36); //copy guid
  20084. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  20085. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  20086. {
  20087. //DEBUG_INFO("StopTransaction mapitem pass\n");
  20088. }
  20089. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  20090. OCPP_insert_transaction_msg(NO, str);
  20091. memset(str,0,ARRAY_SIZE(str));
  20092. }
  20093. }
  20094. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  20095. fclose(fptr1);
  20096. remove(TempStopTransaction); // remove the original file
  20097. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  20098. }
  20099. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  20100. {
  20101. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20102. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  20103. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  20104. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  20105. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  20106. }
  20107. void FillTransactionId(int ConnectorId, int TransactionId)
  20108. {
  20109. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  20110. ShmOCPP16Data->StartTransaction[ConnectorId-1].ResponseTransactionId = TransactionId;
  20111. }
  20112. int GetWebSocketPingInterval(void)
  20113. {
  20114. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  20115. }
  20116. int GetServerSign(void)
  20117. {
  20118. return server_sign;
  20119. }
  20120. uint8_t GetOcppSecurityProfile()
  20121. {
  20122. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  20123. }
  20124. void MergeCertificates()
  20125. {
  20126. char cmdBuf[2048]={0};
  20127. if(access(ROOTCA_CS,F_OK) != -1)
  20128. {
  20129. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  20130. }
  20131. else
  20132. {
  20133. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  20134. }
  20135. system(cmdBuf);
  20136. }
  20137. void GetOcppChargerBoxId(uint8_t *data)
  20138. {
  20139. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  20140. }
  20141. void GetOcppSecurityPassword(uint8_t *data)
  20142. {
  20143. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  20144. }
  20145. void SetOcppVersion(uint8_t *version)
  20146. {
  20147. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  20148. DEBUG_INFO("ocpp version: %s\n", version);
  20149. if(strstr((char*)version, "ocpp1.6") != NULL)
  20150. {
  20151. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  20152. }
  20153. else if(strstr((char*)version, "ocpp2.0") != NULL)
  20154. {
  20155. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  20156. system("pkill OcppBackend");
  20157. }
  20158. }
  20159. void SetServerSign(int value)
  20160. {
  20161. server_sign = value;
  20162. }
  20163. int GetBootNotificationInterval(void)
  20164. {
  20165. return BootNotificationInterval;
  20166. }
  20167. int GetInternetConn(void)
  20168. {
  20169. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  20170. }
  20171. int GetBackendConnectionTimeout(void)
  20172. {
  20173. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  20174. }
  20175. int isConnectorInitMode(int gun_index)
  20176. {
  20177. int tempIndex = 0;
  20178. int result = TRUE;
  20179. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  20180. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  20181. {
  20182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20183. {
  20184. tempIndex = ((gun_index==2) ? 1: 0);
  20185. }
  20186. else
  20187. {
  20188. tempIndex = gun_index;
  20189. }
  20190. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20191. {
  20192. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  20193. {
  20194. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20195. } //end of the same index
  20196. }//end of for CHAdeMO_QUANTITY
  20197. }
  20198. else if(gunType[gun_index] == GUN_TYPE_CCS)
  20199. {
  20200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20201. {
  20202. tempIndex = ((gun_index==2) ? 1: 0);
  20203. }
  20204. else
  20205. {
  20206. tempIndex = gun_index;
  20207. }
  20208. for (int index = 0; index < CCS_QUANTITY; index++)
  20209. {
  20210. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  20211. {
  20212. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20213. } //end of the same index
  20214. } // end of for CCS_QUANTITY
  20215. }
  20216. else if(gunType[gun_index] == GUN_TYPE_GBT)
  20217. {
  20218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  20219. {
  20220. tempIndex = ((gun_index==2) ? 1: 0);
  20221. }
  20222. else
  20223. {
  20224. tempIndex = gun_index;
  20225. }
  20226. for (int index = 0; index < GB_QUANTITY; index++)
  20227. {
  20228. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  20229. {
  20230. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20231. } //end of the same index
  20232. } // end of for GB_QUANTITY
  20233. }
  20234. else if(gunType[gun_index] == GUN_TYPE_DO)
  20235. {
  20236. tempIndex = gun_index;
  20237. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20238. {
  20239. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  20240. {
  20241. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20242. } //end of the same index
  20243. }
  20244. }
  20245. else
  20246. {
  20247. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  20248. {
  20249. tempIndex = 2;
  20250. }
  20251. else
  20252. {
  20253. tempIndex = gun_index;
  20254. }
  20255. for (int index = 0; index < AC_QUANTITY; index++)
  20256. {
  20257. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  20258. {
  20259. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  20260. }//end of the same index
  20261. }//end of for AC_QUANTITY
  20262. }
  20263. return result;
  20264. }
  20265. void refreshProcDogTimer()
  20266. {
  20267. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  20268. }
  20269. void InitialSystemValue(void)
  20270. {
  20271. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  20272. locallistVersion=0;
  20273. BootNotificationInterval = 0;
  20274. authorizeRetryTimes = 0;
  20275. GunStatusInterval = 10;
  20276. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  20277. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  20278. //Heart Beat
  20279. HeartBeatWithNOResponse = 0;
  20280. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  20281. if(HeartBeatWaitTime == 0)
  20282. FirstHeartBeat = TRUE;
  20283. else
  20284. FirstHeartBeat = FALSE;
  20285. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  20286. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  20287. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  20288. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  20289. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  20290. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  20291. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  20292. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  20293. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  20294. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  20295. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  20296. //Status && ConnectorPlugIn Setting
  20297. Connector0PreviousSystemStatus = 99;
  20298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  20299. {
  20300. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  20301. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  20302. }
  20303. for (int index = 0; index < CCS_QUANTITY; index++)
  20304. {
  20305. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  20306. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  20307. }
  20308. for (int index = 0; index < GB_QUANTITY; index++)
  20309. {
  20310. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  20311. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  20312. }
  20313. for (int index = 0; index < AC_QUANTITY; index++)
  20314. {
  20315. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  20316. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  20317. }
  20318. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  20319. {
  20320. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  20321. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  20322. }
  20323. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  20324. {
  20325. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  20326. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  20327. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  20328. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  20329. //memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  20330. memset(&ShmOCPP16Data->StatusNotification[gun_index].Status, 0x00, sizeof(ShmOCPP16Data->StatusNotification[gun_index].Status));
  20331. }
  20332. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  20333. refreshStartTimer(&clientTime.Heartbeat);
  20334. sleep(1);
  20335. }
  20336. void LWS_Send(char *str)
  20337. {
  20338. //=====================================================
  20339. // Check InternetConn 0: disconnected, 1: connected
  20340. //====================================================
  20341. if(GetOcppConnStatus() == 0)
  20342. {
  20343. DEBUG_INFO("offline now !!!\n");
  20344. return;
  20345. }
  20346. // Only disable isWebsocketSendable operation initiated by charger
  20347. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20348. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20349. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20350. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20351. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20352. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20353. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20354. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20355. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20356. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20357. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20358. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20359. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20360. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20361. {
  20362. isWebsocketSendable = 0;
  20363. }
  20364. pthread_mutex_lock(&lock_send);
  20365. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20366. sprintf((char *)SendBuffer, "%s", str);
  20367. SendBufLen = strlen(str);
  20368. pthread_mutex_unlock(&lock_send);
  20369. lws_callback_on_writable(wsi_client);
  20370. //lws_service(context, 0);
  20371. //sleep(1);
  20372. }
  20373. void LWS_SendNow(char *str)
  20374. {
  20375. //=====================================================
  20376. // Check InternetConn 0: disconnected, 1: connected
  20377. //====================================================
  20378. if(GetOcppConnStatus() == 0)
  20379. {
  20380. DEBUG_INFO("offline now !!!\n");
  20381. return;
  20382. }
  20383. // Only disable isWebsocketSendable operation initiated by charger
  20384. if((strstr((char*)str, "\"Authorize\"") != NULL)
  20385. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  20386. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  20387. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  20388. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  20389. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  20390. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  20391. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  20392. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  20393. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  20394. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  20395. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  20396. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  20397. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  20398. {
  20399. isWebsocketSendable = 0;
  20400. }
  20401. pthread_mutex_lock(&lock_send);
  20402. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  20403. sprintf((char *)SendBuffer, "%s", str);
  20404. SendBufLen = strlen(str);
  20405. pthread_mutex_unlock(&lock_send);
  20406. lws_callback_on_writable(wsi_client);
  20407. lws_service(context, 0);
  20408. //sleep(1);
  20409. }