MessageHandler.c 330 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include <json.h>
  19. #include <json_config.h>
  20. #include <json_object.h>
  21. #include <json_tokener.h>
  22. //#include <json-c/json.h> remove temporally
  23. //#include <json-c/json_config.h> remove temporally
  24. //#include <json-c/json_object.h> remove temporally
  25. //#include <json-c/json_tokener.h> remove temporally
  26. #include <libwebsockets.h>
  27. #include <lws_config.h>
  28. //#include "./json-c/JsonParser.h" remove temporally
  29. #include "JsonParser.h"
  30. #include "hashmap.h"
  31. #include "ShareMemory.h"
  32. #include "TransactionQueue.h"
  33. #include "SystemLogMessage.h"
  34. #include "../../Projects/define.h"
  35. #include "ShareMemory.h"
  36. #include "SystemLogMessage.h"
  37. //#include "config.h"
  38. #include <sys/socket.h>
  39. #include <netinet/in.h>
  40. #include <stdlib.h>
  41. /*for sendfile()*/
  42. #include <sys/sendfile.h>
  43. /*for O_RDONLY*/
  44. #include <fcntl.h>
  45. #include "sqlite3.h"
  46. #include <arpa/inet.h>
  47. #define _GNU_SOURCE
  48. #include <time.h>
  49. #include "MessageHandler.h"
  50. #include <assert.h>
  51. #include <pthread.h>
  52. #define PASS 1
  53. #define FAIL -1
  54. #define FALSE 0
  55. #define TRUE 1 // Option 1
  56. #define ChargingProfile_0_JSON "chargingprofile_0.json"
  57. #define ChargingProfile_1_JSON "chargingprofile_1.json"
  58. #define ChargingProfile_2_JSON "chargingprofile_2.json"
  59. #define AuthorizationCache_JSON "AuthorizationCache.json"
  60. #define LocalAuthorizationList_JSON "LocalAuthorizationList.json"
  61. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  62. struct StatusCodeData *ShmStatusCodeData;
  63. struct PsuData *ShmPsuData ;
  64. struct OCPP16Data *ShmOCPP16Data;
  65. /* define Macro */
  66. #define SystemLogMessage
  67. /* OCPP Message Type */
  68. #define MESSAGE_TYPE_CALL 2
  69. #define MESSAGE_TYPE_CALLRESULT 3
  70. #define MESSAGE_TYPE_CALLERROR 4
  71. /* */
  72. #define server_cycle_Status 120
  73. #define MACROSTR(k) #k
  74. extern struct lws *wsi_client;
  75. extern struct lws_context *context;
  76. extern unsigned char *SendBuffer;
  77. extern int SendBufLen;
  78. //char guid[37];
  79. char queuedata[2000];
  80. static char unknownkey[10][20];
  81. static int UnknownKeynum = 0;
  82. static int localversion=0;
  83. static char idTagAuthorization[32]={};
  84. char OcppPath[100]={};
  85. char OcppProtocol[10],OcppHost[50], OcppTempPath[50];
  86. int OcppPort=0;
  87. extern map_t hashMap;
  88. extern data_struct_t* mapItem;
  89. extern char *random_uuid( char buf[37] );
  90. extern void split(char **arr, char *str, const char *del);
  91. extern pthread_mutex_t mutex1;
  92. int updateSetting(char *key, char *value);
  93. int setKeyValue(char *key, char *value);
  94. int server_sign = FALSE;
  95. int server_pending = FALSE;
  96. int authenrequest = FALSE;
  97. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  98. int BootNotificationInterval = 0;
  99. //number of Retry times
  100. int authorizeRetryTimes = 0;
  101. int isUpdateRequest = FALSE;
  102. int statusModeChage = FALSE;
  103. int HeartBeatWaitTime = 10;
  104. //Test Variables
  105. int teststatus =100; //0: enter test ; 100: test
  106. int testCount= 5;
  107. int testCountInc = 0;
  108. int UserPlugGun = 0; // user plug gun or not
  109. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  110. extern struct Charger_Info Charger;
  111. extern sqlite3 *db;
  112. struct ClientTime
  113. {
  114. unsigned int Heartbeat;
  115. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  116. unsigned int StartTransaction;
  117. unsigned int StopTransaction;
  118. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  119. }clientTime;
  120. typedef union
  121. {
  122. //Operations Initiated by Central System
  123. unsigned char CsMsgValue[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  124. struct
  125. {
  126. //CsMsgValue[0]
  127. unsigned char StatusNotificationReq :1; //bit 0,
  128. unsigned char StatusNotificationConf :1; //bit 0,
  129. unsigned char :6; //bit 2~7
  130. }bits[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  131. }CpinitiateMsg;
  132. CpinitiateMsg cpinitateMsg;
  133. //==========================================
  134. // Init all Enumeration & Mapping String
  135. //==========================================
  136. /*ChargePointErrorCode*/
  137. typedef enum {
  138. ConnectorLockFailure,
  139. EVCommunicationError,
  140. GroundFailure,
  141. HighTemperature,
  142. InternalError,
  143. LocalListConflict,
  144. NoError,
  145. OtherError,
  146. OverCurrentFailure,
  147. OverVoltage,
  148. PowerMeterFailure,
  149. PowerSwitchFailure,
  150. ReaderFailure,
  151. ResetFailure,
  152. UnderVoltage,
  153. WeakSignal
  154. } ChargePointErrorCode;
  155. static char *ChargePointErrorCodeStr[] = {
  156. MACROSTR(ConnectorLockFailure),
  157. MACROSTR(EVCommunicationError),
  158. MACROSTR(GroundFailure),
  159. MACROSTR(HighTemperature),
  160. MACROSTR(InternalError),
  161. MACROSTR(LocalListConflict),
  162. MACROSTR(NoError),
  163. MACROSTR(OtherError),
  164. MACROSTR(OverCurrentFailure),
  165. MACROSTR(OverVoltage),
  166. MACROSTR(PowerMeterFailure),
  167. MACROSTR(PowerSwitchFailure),
  168. MACROSTR(ReaderFailure),
  169. MACROSTR(ResetFailure),
  170. MACROSTR(UnderVoltage),
  171. MACROSTR(WeakSignal)
  172. };
  173. /*ChargePointStatus*/
  174. typedef enum {
  175. Available,
  176. Preparing,
  177. Charging,
  178. SuspendedEVSE,
  179. SuspendedEV,
  180. Finishing,
  181. Reserved,
  182. Unavailable,
  183. Faulted
  184. } ChargePointStatus;
  185. static char * ChargePointStatusStr[] = {
  186. MACROSTR(Available),
  187. MACROSTR(Preparing),
  188. MACROSTR(Charging),
  189. MACROSTR(SuspendedEVSE),
  190. MACROSTR(SuspendedEV),
  191. MACROSTR(Finishing),
  192. MACROSTR(Reserved),
  193. MACROSTR(Unavailable),
  194. MACROSTR(Faulted)
  195. };
  196. /*AvailabilityType*/
  197. typedef enum {
  198. RegistrationStatus_Accepted,
  199. RegistrationStatus_Pending,
  200. RegistrationStatus_Rejected
  201. } RegistrationStatus;
  202. static char *RegistrationStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Pending),
  205. MACROSTR(Rejected)
  206. };
  207. /*AvailabilityType*/
  208. typedef enum {
  209. Inoperative,
  210. Operative
  211. } AvailabilityType;
  212. static char *AvailabilityTypeStr[] = {
  213. MACROSTR(Inoperative),
  214. MACROSTR(Operative)
  215. };
  216. /*AvailabilityStatus*/
  217. typedef enum {
  218. Accepted,
  219. Rejected,
  220. Scheduled
  221. } AvailabilityStatus;
  222. static char *AvailabilityStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected),
  225. MACROSTR(Scheduled)
  226. };
  227. /*ConfigurationStatus*/
  228. typedef enum {
  229. ConfigurationStatus_Accepted,
  230. ConfigurationStatus_Rejected,
  231. RebootRequired,
  232. NotSupported
  233. } ConfigurationStatus;
  234. static char *ConfigurationStatusStr[] = {
  235. MACROSTR(Accepted),
  236. MACROSTR(Rejected),
  237. MACROSTR(RebootRequired),
  238. MACROSTR(NotSupported)
  239. };
  240. /*ClearCacheStatus*/
  241. typedef enum {
  242. ClearCacheStatus_Accepted,
  243. ClearCacheStatus_Rejected
  244. } ClearCacheStatus;
  245. static char *ClearCacheStatusStr[] = {
  246. MACROSTR(Accepted),
  247. MACROSTR(Rejected)
  248. };
  249. /*ChargingProfilePurposeType*/
  250. typedef enum {
  251. ChargePointMaxProfile,
  252. TxDefaultProfile,
  253. TxProfile
  254. } ChargingProfilePurposeType;
  255. static char *ChargingProfilePurposeTypeStr[] = {
  256. MACROSTR(ChargePointMaxProfile),
  257. MACROSTR(TxDefaultProfile),
  258. MACROSTR(TxProfile)
  259. };
  260. /*ChargingProfileStatus*/
  261. typedef enum {
  262. ChargingProfileStatus_Accepted,
  263. ChargingProfileStatus_Rejected,
  264. ChargingProfileStatus_NotSupported
  265. } ChargingProfileStatus;
  266. static char *ChargingProfileStatusStr[] = {
  267. MACROSTR(Accepted),
  268. MACROSTR(Rejected),
  269. MACROSTR(NotSupported)
  270. };
  271. /*ClearChargingProfileStatus*/
  272. typedef enum {
  273. ClearChargingProfileStatus_Accepted,
  274. ClearChargingProfileStatus_Unknown
  275. } ClearChargingProfileStatus;
  276. static char *ClearChargingProfileStatusStr[] = {
  277. MACROSTR(Accepted),
  278. MACROSTR(Unknown)
  279. };
  280. /*GetCompositeScheduleStatus*/
  281. typedef enum {
  282. GetCompositeScheduleStatus_Accepted,
  283. GetCompositeScheduleStatus_Rejected
  284. } GetCompositeScheduleStatus;
  285. static char *GetCompositeScheduleStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected)
  288. };
  289. /*ChargingRateUnitType*/
  290. typedef enum {
  291. ChargingRateUnitType_W,
  292. ChargingRateUnitType_A
  293. } ChargingRateUnitType;
  294. static char *ChargingRateUnitTypeStr[] = {
  295. MACROSTR(W),
  296. MACROSTR(A)
  297. };
  298. /*AuthorizationStatus*/
  299. typedef enum {
  300. AuthorizationStatus_Accepted ,
  301. AuthorizationStatus_Blocked ,
  302. AuthorizationStatus_Expired ,
  303. AuthorizationStatus_Invalid ,
  304. AuthorizationStatus_ConcurrentTx
  305. } AuthorizationStatus;
  306. static char *AuthorizationStatusStr[] = {
  307. MACROSTR(Accepted),
  308. MACROSTR(Blocked),
  309. MACROSTR(Expired),
  310. MACROSTR(Invalid),
  311. MACROSTR(ConcurrentTx)
  312. };
  313. /*UpdateType*/
  314. typedef enum {
  315. Differential ,
  316. Full
  317. } UpdateType;
  318. static char *UpdateTypeStr[] = {
  319. MACROSTR(Differential),
  320. MACROSTR(Full)
  321. };
  322. /*UpdateStatus*/
  323. typedef enum {
  324. UpdateStatus_Accepted ,
  325. UpdateStatus_Failed ,
  326. UpdateStatus_NotSupported ,
  327. UpdateStatus_VersionMismatch
  328. } UpdateStatus;
  329. static char *UpdateStatusStr[] = {
  330. MACROSTR(Accepted),
  331. MACROSTR(Failed),
  332. MACROSTR(NotSupported),
  333. MACROSTR(VersionMismatch)
  334. };
  335. /*RemoteStartStopStatus*/
  336. typedef enum {
  337. RemoteStartStopStatus_Accepted,
  338. RemoteStartStopStatus_Rejected
  339. } RemoteStartStopStatus;
  340. static char *RemoteStartStopStatusStr[] = {
  341. MACROSTR(Accepted),
  342. MACROSTR(Rejected)
  343. };
  344. /*ReservationStatus*/
  345. typedef enum {
  346. ReservationStatus_Accepted,
  347. ReservationStatus_Faulted,
  348. ReservationStatus_Occupied,
  349. ReservationStatus_Rejected,
  350. ReservationStatus_Unavailable
  351. } ReservationStatus;
  352. static char *ReservationStatusStr[] = {
  353. MACROSTR(Accepted),
  354. MACROSTR(Faulted),
  355. MACROSTR(Occupied),
  356. MACROSTR(Rejected),
  357. MACROSTR(Unavailable)
  358. };
  359. /*ResetType*/
  360. typedef enum {
  361. Hard,
  362. Soft
  363. } ResetType;
  364. static char *ResetTypeStr[] = {
  365. MACROSTR(Hard),
  366. MACROSTR(Soft)
  367. };
  368. /*ResetStatus*/
  369. typedef enum {
  370. ResetStatus_Accepted,
  371. ResetStatus_Rejected
  372. } ResetStatus;
  373. static char *ResetStatusStr[] = {
  374. MACROSTR(Accepted),
  375. MACROSTR(Rejected)
  376. };
  377. /*DiagnosticsStatus*/
  378. typedef enum {
  379. DiagnosticsStatus_Idle,
  380. DiagnosticsStatus_Uploaded,
  381. DiagnosticsStatus_UploadFailed,
  382. DiagnosticsStatus_Uploading
  383. } DiagnosticsStatus;
  384. static char * DiagnosticsStatusStr[] = {
  385. MACROSTR(Idle),
  386. MACROSTR(Uploaded),
  387. MACROSTR(UploadFailed),
  388. MACROSTR(Uploading)
  389. };
  390. /*FirmwareStatus*/
  391. typedef enum {
  392. FirmwareStatus_Downloaded,
  393. FirmwareStatus_DownloadFailed,
  394. FirmwareStatus_Downloading,
  395. FirmwareStatus_Idle,
  396. FirmwareStatus_InstallationFailed,
  397. FirmwareStatus_Installing,
  398. FirmwareStatus_Installed
  399. } FirmwareStatus;
  400. static char * FirmwareStatusStr[] = {
  401. MACROSTR(Downloaded),
  402. MACROSTR(DownloadFailed),
  403. MACROSTR(Downloading),
  404. MACROSTR(Idle),
  405. MACROSTR(InstallationFailed),
  406. MACROSTR(Installing),
  407. MACROSTR(Installed)
  408. };
  409. /*MessageTrigger*/
  410. typedef enum {
  411. BootNotification,
  412. DiagnosticsStatusNotification,
  413. FirmwareStatusNotification,
  414. Heartbeat,
  415. MeterValues,
  416. StatusNotification
  417. } MessageTrigger;
  418. static char * MessageTriggerStr[] = {
  419. MACROSTR(BootNotification),
  420. MACROSTR(DiagnosticsStatusNotification),
  421. MACROSTR(FirmwareStatusNotification),
  422. MACROSTR(Heartbeat),
  423. MACROSTR(MeterValues),
  424. MACROSTR(StatusNotification)
  425. };
  426. /*TriggerMessageStatus*/
  427. typedef enum {
  428. TriggerMessageStatus_Accepted ,
  429. TriggerMessageStatus_Rejected ,
  430. TriggerMessageStatus_NotImplemented
  431. } TriggerMessageStatus;
  432. static char * TriggerMessageStatusStr[] = {
  433. MACROSTR(Accepted),
  434. MACROSTR(Rejected),
  435. MACROSTR(NotImplemented)
  436. };
  437. /*UnlockStatus*/
  438. typedef enum {
  439. Unlocked,
  440. UnlockFailed,
  441. UnlockStatus_NotSupported
  442. } UnlockStatus;
  443. static char * UnlockStatusStr[] = {
  444. MACROSTR(Unlocked),
  445. MACROSTR(UnlockFailed),
  446. MACROSTR(NotSupported)
  447. };
  448. /*StopTransactionReason*/
  449. typedef enum {
  450. EmergencyStop,
  451. EVDisconnected,
  452. HardReset,
  453. Local,
  454. Other,
  455. PowerLoss,
  456. Reboot,
  457. Remote,
  458. SoftReset,
  459. UnlockCommand,
  460. DeAuthorized
  461. } StopTransactionReason;
  462. static char * StopTransactionReasonStr[] = {
  463. MACROSTR(EmergencyStop),
  464. MACROSTR(EVDisconnected),
  465. MACROSTR(HardReset),
  466. MACROSTR(Local),
  467. MACROSTR(Other),
  468. MACROSTR(PowerLoss),
  469. MACROSTR(Reboot),
  470. MACROSTR(Remote),
  471. MACROSTR(SoftReset),
  472. MACROSTR(UnlockCommand),
  473. MACROSTR(DeAuthorized)
  474. };
  475. /*CancelReservationStatus*/
  476. typedef enum {
  477. CancelReservationStatus_Accepted,
  478. CancelReservationStatus_Rejected
  479. } CancelReservationStatus;
  480. static char * CancelReservationStatusStr[] = {
  481. MACROSTR(Accepted),
  482. MACROSTR(Rejected)
  483. };
  484. /*ReadingContext*/
  485. typedef enum {
  486. ReadingContext_Interruption_Begin,
  487. ReadingContext_Interruption_End,
  488. ReadingContext_Other,
  489. ReadingContext_Sample_Clock,
  490. ReadingContext_Sample_Periodic ,
  491. ReadingContext_Transaction_Begin ,
  492. ReadingContext_Transaction_End,
  493. ReadingContext_Trigger
  494. } ReadingContext;
  495. static char * ReadingContextStr[] = {
  496. MACROSTR(Interruption.Begin),
  497. MACROSTR(Interruption.End),
  498. MACROSTR(Other),
  499. MACROSTR(Sample.Clock),
  500. MACROSTR(Sample.Periodic),
  501. MACROSTR(Transaction.Begin),
  502. MACROSTR(Transaction.End),
  503. MACROSTR(Trigger)
  504. };
  505. /*ValueFormat*/
  506. typedef enum {
  507. Raw,
  508. SignedData
  509. } ValueFormat;
  510. static char * ValueFormatStr[] = {
  511. MACROSTR(Raw),
  512. MACROSTR(SignedData)
  513. };
  514. /*Measurand*/
  515. typedef enum {
  516. Current_Export ,
  517. Current_Import,
  518. Current_Offered,
  519. Energy_Active_Export_Register,
  520. Energy_Active_Import_Register,
  521. Energy_Reactive_Export_Register,
  522. Energy_Reactive_Import_Register,
  523. Energy_Active_Export_Interval,
  524. Energy_Active_Import_Interval,
  525. Energy_Reactive_Export_Interval,
  526. Energy_Reactive_Import_Interval,
  527. Frequency,
  528. Power_Active_Export ,
  529. Power_Active_Import,
  530. Power_Factor,
  531. Power_Offered,
  532. Power_Reactive_Export,
  533. Power_Reactive_Import,
  534. RPM,
  535. SoC,
  536. Temperature ,
  537. Voltage
  538. } Measurand;
  539. static char * MeasurandStr[] = {
  540. MACROSTR(Current.Export),
  541. MACROSTR(Current.Import),
  542. MACROSTR(Current.Offered),
  543. MACROSTR(Energy.Active.Export.Register),
  544. MACROSTR(Energy.Active.Import.Register),
  545. MACROSTR(Energy_Reactive_Export_Register),
  546. MACROSTR(Energy_Reactive_Import_Register),
  547. MACROSTR(Energy_Active_Export_Interval),
  548. MACROSTR(Energy_Active_Import_Interval),
  549. MACROSTR(Energy_Reactive_Export_Interval),
  550. MACROSTR(Energy_Reactive_Import_Interval),
  551. MACROSTR(Frequency),
  552. MACROSTR(Power_Active_Export),
  553. MACROSTR(Power_Active_Import),
  554. MACROSTR(Power_Factor),
  555. MACROSTR(Power_Offered),
  556. MACROSTR(Power_Reactive_ExportMACROSTR),
  557. MACROSTR(Power_Reactive_Import),
  558. MACROSTR(RPM),
  559. MACROSTR(SoC),
  560. MACROSTR(Temperature),
  561. MACROSTR(Voltage)
  562. };
  563. /*Location*/
  564. typedef enum {
  565. Location_Body,
  566. Location_Cable,
  567. Location_EV,
  568. Location_Inlet ,
  569. Location_Outlet
  570. } Location;
  571. static char * LocationStr[] = {
  572. MACROSTR(Body),
  573. MACROSTR(Cable),
  574. MACROSTR(EV),
  575. MACROSTR(Inlet),
  576. MACROSTR(Outlet)
  577. };
  578. /*Phase*/
  579. typedef enum {
  580. L1,
  581. L2,
  582. L3,
  583. N,
  584. L1_N,
  585. L2_N,
  586. L3_N,
  587. L1_L2,
  588. L2_L3,
  589. L3_L1
  590. } Phase;
  591. static char * PhaseStr[] = {
  592. MACROSTR(L1),
  593. MACROSTR(L2),
  594. MACROSTR(L3),
  595. MACROSTR(N),
  596. MACROSTR(L1-N),
  597. MACROSTR(L2-N),
  598. MACROSTR(L3-N),
  599. MACROSTR(L1-L2),
  600. MACROSTR(L2-L3),
  601. MACROSTR(L3-L1)
  602. };
  603. /*UnitOfMeasure*/
  604. typedef enum {
  605. UnitOfMeasure_Wh,
  606. UnitOfMeasure_kWh ,
  607. UnitOfMeasure_varh ,
  608. UnitOfMeasure_kvarh ,
  609. UnitOfMeasure_W ,
  610. UnitOfMeasure_kW ,
  611. UnitOfMeasure_VA ,
  612. UnitOfMeasure_kVA ,
  613. UnitOfMeasure_var ,
  614. UnitOfMeasure_kvar ,
  615. UnitOfMeasure_A ,
  616. UnitOfMeasure_V ,
  617. UnitOfMeasure_Celsius ,
  618. UnitOfMeasure_Fahrenheit ,
  619. UnitOfMeasure_K ,
  620. UnitOfMeasure_Percent
  621. } UnitOfMeasure;
  622. static char * UnitOfMeasureStr[] = {
  623. MACROSTR(Wh),
  624. MACROSTR(kWh),
  625. MACROSTR(varh),
  626. MACROSTR(kvarh),
  627. MACROSTR(W),
  628. MACROSTR(kW),
  629. MACROSTR(VA),
  630. MACROSTR(kVA),
  631. MACROSTR(var),
  632. MACROSTR(kvar),
  633. MACROSTR(A),
  634. MACROSTR(V),
  635. MACROSTR(Celsius),
  636. MACROSTR(Fahrenheit),
  637. MACROSTR(K),
  638. MACROSTR(Percent)
  639. };
  640. /*Configuration enum*/
  641. enum CoreProfile {
  642. AllowOfflineTxForUnknownId=0,
  643. AuthorizationCacheEnabled,
  644. AuthorizeRemoteTxRequests,
  645. BlinkRepeat,
  646. ClockAlignedDataInterval,
  647. ConnectionTimeOut,
  648. GetConfigurationMaxKeys,
  649. HeartbeatInterval,
  650. LightIntensity,
  651. LocalAuthorizeOffline,
  652. LocalPreAuthorize,
  653. MaxEnergyOnInvalidId,
  654. MeterValuesAlignedData,
  655. MeterValuesAlignedDataMaxLength,
  656. MeterValuesSampledData,
  657. MeterValuesSampledDataMaxLength,
  658. MeterValueSampleInterval,
  659. MinimumStatusDuration,
  660. NumberOfConnectors,
  661. ResetRetries,
  662. ConnectorPhaseRotation,
  663. ConnectorPhaseRotationMaxLength,
  664. StopTransactionOnEVSideDisconnect,
  665. StopTransactionOnInvalidId,
  666. StopTxnAlignedData,
  667. StopTxnAlignedDataMaxLength,
  668. StopTxnSampledData,
  669. StopTxnSampledDataMaxLength,
  670. SupportedFeatureProfiles,
  671. SupportedFeatureProfilesMaxLength,
  672. TransactionMessageAttempts,
  673. TransactionMessageRetryInterval,
  674. UnlockConnectorOnEVSideDisconnect,
  675. WebSocketPingInterval,
  676. _CoreProfile_CNT
  677. };
  678. enum LocalAuthListManagementProfile{
  679. LocalAuthListEnabled=0,
  680. LocalAuthListMaxLength,
  681. SendLocalListMaxLength,
  682. _LocalAuthListManagementProfile_CNT
  683. };
  684. enum ReservationProfile{
  685. ReserveConnectorZeroSupported
  686. };
  687. enum SmartChargingProfile{
  688. ChargeProfileMaxStackLevel,
  689. ChargingScheduleAllowedChargingRateUnit,
  690. ChargingScheduleMaxPeriods,
  691. ConnectorSwitch3to1PhaseSupported,
  692. MaxChargingProfilesInstalled
  693. };
  694. enum ChargerSystemStatus{
  695. ChargerSystemStatus_Booting,
  696. ChargerSystemStatus_Idle,
  697. ChargerSystemStatus_Authorizing,
  698. ChargerSystemStatus_Preparing,
  699. ChargerSystemStatus_Charging,
  700. ChargerSystemStatus_Terminating,
  701. ChargerSystemStatus_Alarm,
  702. ChargerSystemStatus_Fault
  703. };
  704. enum GetConfigurationKey {
  705. GetConfiguration_AllowOfflineTxForUnknownId=0,
  706. GetConfiguration_AuthorizationCacheEnabled,
  707. GetConfiguration_AuthorizeRemoteTxRequests,
  708. GetConfiguration_BlinkRepeat,
  709. GetConfiguration_ClockAlignedDataInterval,
  710. GetConfiguration_ConnectionTimeOut,
  711. GetConfiguration_GetConfigurationMaxKeys,
  712. GetConfiguration_HeartbeatInterval,
  713. GetConfiguration_LightIntensity,
  714. GetConfiguration_LocalAuthorizeOffline,
  715. GetConfiguration_LocalPreAuthorize,
  716. GetConfiguration_MaxEnergyOnInvalidId,
  717. GetConfiguration_MeterValuesAlignedData,
  718. GetConfiguration_MeterValuesAlignedDataMaxLength,
  719. GetConfiguration_MeterValuesSampledData,
  720. GetConfiguration_MeterValuesSampledDataMaxLength,
  721. GetConfiguration_MeterValueSampleInterval,
  722. GetConfiguration_MinimumStatusDuration,
  723. GetConfiguration_NumberOfConnectors,
  724. GetConfiguration_ResetRetries,
  725. GetConfiguration_ConnectorPhaseRotation,
  726. GetConfiguration_ConnectorPhaseRotationMaxLength,
  727. GetConfiguration_StopTransactionOnEVSideDisconnect,
  728. GetConfiguration_StopTransactionOnInvalidId,
  729. GetConfiguration_StopTxnAlignedData,
  730. GetConfiguration_StopTxnAlignedDataMaxLength,
  731. GetConfiguration_StopTxnSampledData,
  732. GetConfiguration_StopTxnSampledDataMaxLength,
  733. GetConfiguration_SupportedFeatureProfiles,
  734. GetConfiguration_SupportedFeatureProfilesMaxLength,
  735. GetConfiguration_TransactionMessageAttempts,
  736. GetConfiguration_TransactionMessageRetryInterval,
  737. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  738. GetConfiguration_WebSocketPingInterval,
  739. GetConfiguration_LocalAuthListEnabled,
  740. GetConfiguration_LocalAuthListMaxLength,
  741. GetConfiguration_SendLocalListMaxLength,
  742. GetConfiguration_ReserveConnectorZeroSupported,
  743. GetConfiguration_ChargeProfileMaxStackLevel,
  744. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  745. GetConfiguration_ChargingScheduleMaxPeriods,
  746. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  747. GetConfiguration_MaxChargingProfilesInstalled,
  748. };
  749. //==========================================
  750. // Init all share memory
  751. //==========================================
  752. int InitShareMemory()
  753. {
  754. int result = PASS;
  755. int MeterSMId;
  756. printf("1\n");
  757. //creat ShmSysConfigAndInfo
  758. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  759. {
  760. #ifdef SystemLogMessage
  761. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  762. #endif
  763. result = FAIL;
  764. }
  765. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  766. {
  767. #ifdef SystemLogMessage
  768. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  769. #endif
  770. result = FAIL;
  771. }
  772. else
  773. {}
  774. printf("2\n");
  775. //creat ShmStatusCodeData
  776. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  777. {
  778. #ifdef SystemLogMessage
  779. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  780. #endif
  781. result = FAIL;
  782. }
  783. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  784. {
  785. #ifdef SystemLogMessage
  786. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  787. #endif
  788. result = FAIL;
  789. }
  790. else
  791. {}
  792. printf("3\n");
  793. //creat ShmPsuData
  794. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  795. {
  796. #ifdef SystemLogMessage
  797. DEBUG_ERROR("shmget ShmPsuData NG\n");
  798. #endif
  799. result = FAIL;
  800. }
  801. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  802. {
  803. #ifdef SystemLogMessage
  804. DEBUG_ERROR("shmat ShmPsuData NG\n");
  805. #endif
  806. result = FAIL;
  807. }
  808. else
  809. {}
  810. printf("4\n");
  811. //creat ShmOCPP16Data
  812. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  813. {
  814. #ifdef SystemLogMessage
  815. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  816. #endif
  817. result = FAIL;
  818. }
  819. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  820. {
  821. #ifdef SystemLogMessage
  822. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  823. #endif
  824. result = FAIL;
  825. }
  826. else
  827. {}
  828. printf("5\n");
  829. //memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
  830. /****************************** For TEST ************************************************/
  831. //strcpy(ShmOCPP16Data->OcppServerURL,"172.17.40.13");
  832. //strcpy(ShmOCPP16Data->ChargeBoxId,"RDTEST103");
  833. //inital settings
  834. #if 0 // For Test
  835. sprintf(ShmOCPP16Data->BootNotification.CbSN, "");
  836. sprintf(ShmOCPP16Data->BootNotification.CpModel, "EA873E3EF8P1");
  837. sprintf(ShmOCPP16Data->BootNotification.CpSN, "RDTEST103");
  838. sprintf(ShmOCPP16Data->BootNotification.CpVendor, "Phihong Technology");
  839. sprintf(ShmOCPP16Data->BootNotification.CpFwVersion, "D0.13.50.0087.PH");
  840. sprintf(ShmOCPP16Data->BootNotification.CpIccid, "");
  841. sprintf(ShmOCPP16Data->BootNotification.CpImsi,"");
  842. sprintf(ShmOCPP16Data->BootNotification.CpMeterSerialNumber,"N/A");
  843. sprintf(ShmOCPP16Data->BootNotification.CpMeterType,"AC");
  844. memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  845. for(int gun_index=0; gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY); gun_index++ )
  846. {
  847. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  848. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  849. //allocate memory
  850. if(ShmOCPP16Data->StopTransaction[gun_index].TransactionData == NULL)
  851. {
  852. ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  853. }
  854. if(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue == NULL)
  855. {
  856. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*5);
  857. }
  858. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  859. strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  860. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Info, "N/A");
  861. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  862. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Timestamp, "2019-05-04T18:15:33Z");
  863. strcpy(ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  864. strcpy(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  865. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  866. }
  867. printf("6\n");
  868. strcpy(ShmOCPP16Data->Authorize.IdTag,"PaHdImHiOnNG");
  869. // ShmOCPP16Data->CpMsg.bits[0].StartTransactionReq = 1;
  870. //Authorize
  871. //memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
  872. //strcpy(ShmSysConfigAndInfo->SysConfig.UserId, "B014EA9C");
  873. //gun index
  874. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].Index = 0;
  875. ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].Index = 1;
  876. ShmSysConfigAndInfo->SysInfo.GbChargingData[0].Index = 2;
  877. //Chademo
  878. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus ='1'; //idle
  879. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].PreviousSystemStatus = '1';
  880. cpinitateMsg.bits[0].StatusNotificationReq = 1;
  881. #endif
  882. printf("7\n");
  883. // Charger PRE_SYS_MODE
  884. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  885. memset( (void *)unknownkey, 0, sizeof(char)*10*20 );
  886. clientTime.Heartbeat=time((time_t*)NULL);
  887. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY/*+ CCS_QUANTITY + GB_QUANTITY*/) ;gun_index++)
  888. {
  889. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  890. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  891. }
  892. printf("8\n");
  893. HeartBeatWaitTime = 10;
  894. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  895. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  896. //memset(unknownkey, 0, 10);
  897. return result;
  898. }
  899. int ProcessShareMemory()
  900. {
  901. if(InitShareMemory() == FAIL)
  902. {
  903. #ifdef SystemLogMessage
  904. DEBUG_ERROR("InitShareMemory NG\n");
  905. #endif
  906. if(ShmStatusCodeData!=NULL)
  907. {
  908. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  909. }
  910. sleep(5);
  911. return FAIL;
  912. }
  913. return PASS;
  914. }
  915. void CheckSystemValue(void)
  916. {
  917. printf("CheckSystemValue \n");
  918. int meterValueSend=0;
  919. int IdleModeCnt = 0;
  920. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  921. {
  922. //parameter for test
  923. sendHeartbeatRequest(0);
  924. //==============================================
  925. // Reset Waiting Time
  926. //==============================================
  927. clientTime.Heartbeat=time((time_t*)NULL);
  928. }
  929. //==============================================
  930. // Update request
  931. //==============================================
  932. if(isUpdateRequest == TRUE )
  933. {
  934. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  935. {
  936. //check SystemStatus // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  937. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  938. {
  939. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 1)) //S_IDLE
  940. {
  941. IdleModeCnt = IdleModeCnt + 1;
  942. }
  943. }
  944. for (int index = 0; index < CCS_QUANTITY; index++)
  945. {
  946. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 1)) //S_IDLE
  947. {
  948. IdleModeCnt = IdleModeCnt + 1;
  949. }
  950. }
  951. for (int index = 0; index < GB_QUANTITY; index++)
  952. {
  953. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  954. {
  955. IdleModeCnt = IdleModeCnt + 1;
  956. }
  957. }
  958. }
  959. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  960. {
  961. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installed]);
  962. isUpdateRequest = FALSE;
  963. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  964. }
  965. }
  966. printf("gun no %d\n",(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY));
  967. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ) ;gun_index++)
  968. {
  969. //==============================================
  970. // Charger status report
  971. //==============================================
  972. /* Check Mode Change */
  973. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  974. {
  975. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  976. {
  977. printf("Chademo Mode status:\n");
  978. printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus: %c\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  979. printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus: %c\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus);
  980. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus/*PRE_SYS_MODE[gun_index]*/ )
  981. {
  982. printf("Chademo Mode Change\n");
  983. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  984. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  985. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  986. statusModeChage = TRUE;
  987. }
  988. }
  989. }
  990. for (int index = 0; index < CCS_QUANTITY; index++)
  991. {
  992. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  993. {
  994. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus/*PRE_SYS_MODE[gun_index]*/ )
  995. {
  996. printf("Ccs Mode Change\n");
  997. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  998. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  999. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1000. statusModeChage = TRUE;
  1001. }
  1002. }
  1003. }
  1004. for (int index = 0; index < GB_QUANTITY; index++)
  1005. {
  1006. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1007. {
  1008. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus/*PRE_SYS_MODE[gun_index]*/ )
  1009. {
  1010. printf("Gb Mode Change\n");
  1011. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1012. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1013. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1014. statusModeChage = TRUE;
  1015. }
  1016. }
  1017. }
  1018. if((server_sign == TRUE) && ((statusModeChage == TRUE)||((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > server_cycle_Status)|| ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30))))
  1019. {
  1020. sendStatusNotificationRequest(gun_index);
  1021. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1022. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1023. statusModeChage = FALSE;
  1024. }
  1025. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1026. {
  1027. sendAuthorizeRequest(0);
  1028. authorizeRetryTimes = authorizeRetryTimes + 1;
  1029. /* authenrequest = TRUE; */
  1030. if(authorizeRetryTimes < 3)
  1031. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1032. //Test Variables
  1033. UserPlugGun = 1;
  1034. teststatus = 0;
  1035. }
  1036. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1037. {
  1038. authorizeRetryTimes = 0;
  1039. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1040. }
  1041. #if 1
  1042. //==============================================
  1043. // Charger start transaction
  1044. //==============================================
  1045. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1046. {
  1047. #if 0 // for test
  1048. if(teststatus == 0)
  1049. {
  1050. #endif
  1051. sendStartTransactionRequest(gun_index);
  1052. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1053. clientTime.StartTransaction = time((time_t*)NULL);
  1054. #if 0// for test
  1055. teststatus = 1; // finish startTransaction
  1056. }
  1057. #endif
  1058. }
  1059. //==============================================
  1060. // Charger stop transaction
  1061. //==============================================
  1062. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1063. {
  1064. #if 0 // for test
  1065. if(teststatus == 2)
  1066. {
  1067. #endif
  1068. sendStopTransactionRequest(gun_index);
  1069. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1070. clientTime.StopTransaction = time((time_t*)NULL);
  1071. #if 0// for test
  1072. teststatus = 100;
  1073. }
  1074. #endif
  1075. }
  1076. //==============================================
  1077. // Meter report
  1078. //==============================================
  1079. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)) )
  1080. {
  1081. //check Transaction active
  1082. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1083. {
  1084. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1085. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8))
  1086. {
  1087. meterValueSend =1;
  1088. }
  1089. }
  1090. for (int index = 0; index < CCS_QUANTITY; index++)
  1091. {
  1092. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1093. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8))
  1094. {
  1095. meterValueSend =1;
  1096. }
  1097. }
  1098. for (int index = 0; index < GB_QUANTITY; index++)
  1099. {
  1100. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1101. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8))
  1102. {
  1103. meterValueSend =1;
  1104. }
  1105. }
  1106. printf("sendMeterValuesRequest \n");
  1107. // if(meterValueSend == 1)
  1108. #if 0 // for test
  1109. if((teststatus == 1) && (testCountInc <= testCount))
  1110. {
  1111. #endif
  1112. sleep(1); //?��?1�
  1113. if(meterValueSend == 1)
  1114. sendMeterValuesRequest(gun_index);
  1115. #if 0 //for test
  1116. testCountInc = testCountInc + 1;
  1117. printf("testCountInc=%d\n",testCountInc);
  1118. }
  1119. else if((meterValueSend == 1) && (testCountInc > testCount))
  1120. {
  1121. teststatus = 2;
  1122. meterValueSend = 0;
  1123. testCountInc = 0;
  1124. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 1;
  1125. }
  1126. #endif
  1127. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1128. }
  1129. #endif
  1130. //==============================================
  1131. // Check Connector reserved
  1132. //==============================================
  1133. printf("ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate=%s\n",ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate);
  1134. if((server_sign == TRUE) && (strcmp(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "") != 0) )
  1135. {
  1136. double diff_t;
  1137. struct tm tp;
  1138. // current time
  1139. time_t t = time(NULL);
  1140. sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1141. printf("ExpiryDate : %s\n", (char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate);
  1142. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1143. printf("handle check value 1\n");
  1144. tp.tm_isdst = -1;
  1145. printf("handle check value 2\n");
  1146. time_t utc = mktime(&tp);
  1147. printf("handle check value 3\n");
  1148. struct tm e0 = { .tm_year = tp.tm_year, .tm_mday = tp.tm_mday, .tm_mon = tp.tm_mon, .tm_hour = tp.tm_hour, .tm_isdst = -1 };
  1149. time_t pseudo = mktime(&e0);
  1150. struct tm e1 = *gmtime(&pseudo);
  1151. e0.tm_sec += utc - diff_tm(&e1, &e0);
  1152. time_t local = e0.tm_sec;
  1153. // ?�到��??�起始�???- chargingScedule起�??��?
  1154. diff_t = difftime(t, local);
  1155. if(diff_t < 0)
  1156. {
  1157. printf("reserve expired !!! \n");
  1158. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1159. }
  1160. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1161. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1162. (strcmp(ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1163. {
  1164. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1165. }
  1166. else
  1167. {
  1168. //check Transaction active
  1169. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1170. {
  1171. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1172. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(1/*?�ç??—æ?*//*ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != '8'*/))
  1173. {
  1174. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1175. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 12) ) // S_ALARM, S_FAULT
  1176. {
  1177. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1178. }
  1179. }
  1180. }
  1181. for (int index = 0; index < CCS_QUANTITY; index++)
  1182. {
  1183. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1184. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(1/*?�ç??—æ?*//*ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != '8'*/))
  1185. {
  1186. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1187. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 12) ) // S_ALARM, S_FAULT
  1188. {
  1189. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1190. }
  1191. }
  1192. }
  1193. for (int index = 0; index < GB_QUANTITY; index++)
  1194. {
  1195. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1196. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(1/*?�ç??—æ?*//*ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != '8'*/) )
  1197. {
  1198. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1199. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 12) ) // S_ALARM, S_FAULT
  1200. {
  1201. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1202. }
  1203. }
  1204. }
  1205. }
  1206. }
  1207. // csu trigger FirmwareStatusNotificationReq
  1208. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1209. {
  1210. sendFirmwareStatusNotificationRequest(ShmOCPP16Data->FirmwareStatusNotification.Status);
  1211. }
  1212. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1213. {
  1214. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1215. sendCancelReservationConfirmation(ShmOCPP16Data->CancelReservation[gun_index].guid, ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1216. }
  1217. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1218. {
  1219. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1220. }
  1221. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1222. {
  1223. sendUnlockConnectorConfirmation(ShmOCPP16Data->UnlockConnector[gun_index].guid, ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1224. }
  1225. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1226. {
  1227. sendReserveNowTransactionConfirmation(ShmOCPP16Data->ReserveNow[gun_index].guid, ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1228. }
  1229. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1230. {
  1231. sendResetConfirmation(ShmOCPP16Data->Reset.guid, ShmOCPP16Data->Reset.ResponseStatus);
  1232. }
  1233. }
  1234. }
  1235. //==========================================
  1236. // send request routine
  1237. //==========================================
  1238. int sendAuthorizeRequest(int gun_index)
  1239. {
  1240. printf("sendAuthorizeRequest \n");
  1241. int result = FAIL;
  1242. int i = 0;
  1243. char *str = NULL;
  1244. char *arr[1];
  1245. const char *del = ",";
  1246. char *senstr = NULL;
  1247. char *temp = NULL;
  1248. struct json_object *message, *payload;
  1249. char guid[37];
  1250. message = json_object_new_array();
  1251. payload = json_object_new_object();
  1252. //initailize struct Authorize
  1253. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1254. //get data from shared memory
  1255. strcpy(ShmOCPP16Data->Authorize.IdTag, ShmSysConfigAndInfo->SysConfig.UserId);
  1256. //json_object_object_add(payload, "idTag", json_object_new_string((const char *)request.IdTag));
  1257. json_object_object_add(payload, "idTag", json_object_new_string((const char *)ShmOCPP16Data->Authorize.IdTag));
  1258. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1259. random_uuid(guid);
  1260. json_object_array_add(message, json_object_new_string(guid));
  1261. json_object_array_add(message, json_object_new_string("Authorize"));
  1262. json_object_array_add(message, payload);
  1263. Send(message);
  1264. // Put request guid to hash map
  1265. if(mapItem == NULL)
  1266. {
  1267. mapItem = malloc(sizeof(data_struct_t));
  1268. printf("mapItem is null\n");
  1269. }
  1270. sprintf(mapItem->key_string, "%s", guid);
  1271. sprintf(mapItem->key_value, "Authorize,%d", gun_index);//sprintf(mapItem->key_value, senstr);//sprintf(mapItem->key_value, "Authorize");
  1272. printf("Authorize mapItem->key_string=%s\n",mapItem->key_string);
  1273. printf("Authorize mapItem->key_value=%s\n",mapItem->key_value);
  1274. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1275. {
  1276. result = PASS;
  1277. printf("Authorize mapItem pass\n");
  1278. }
  1279. #ifdef SystemLogMessage
  1280. DEBUG_INFO(">>>>>Authorize request\n");
  1281. DEBUG_INFO("Message: %s\n", SendBuffer);
  1282. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1283. #endif
  1284. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1285. json_object_put(message); // Delete the json object
  1286. //for test
  1287. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus ='3'; //preparing
  1288. //ShmOCPP16Data->CpMsg.bits[0].StartTransactionReq = 1;
  1289. return result;
  1290. }
  1291. int sendBootNotificationRequest(void)
  1292. {
  1293. int result = FAIL;
  1294. int i = 0;
  1295. struct json_object *message, *payload;
  1296. int count = 0;
  1297. int gun_index = 0;
  1298. char guid[37];
  1299. message = json_object_new_array();
  1300. payload = json_object_new_object();
  1301. // Fill BootNotification fields
  1302. strcpy(ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1303. strcpy(ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1304. strcpy(ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1305. strcpy(ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1306. json_object_object_add(payload, "chargeBoxSerialNumber", json_object_new_string((const char *)ShmOCPP16Data->ChargeBoxId));
  1307. json_object_object_add(payload, "chargePointModel", json_object_new_string((const char *)ShmSysConfigAndInfo->SysConfig.ModelName));
  1308. json_object_object_add(payload, "chargePointSerialNumber", json_object_new_string((const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber));
  1309. json_object_object_add(payload, "chargePointVendor", json_object_new_string((const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor));
  1310. json_object_object_add(payload, "firmwareVersion", json_object_new_string((const char *)ShmOCPP16Data->BootNotification.CpFwVersion));
  1311. json_object_object_add(payload, "iccid", json_object_new_string((const char *)ShmOCPP16Data->BootNotification.CpIccid));
  1312. json_object_object_add(payload, "imsi", json_object_new_string((const char *)ShmOCPP16Data->BootNotification.CpImsi));
  1313. json_object_object_add(payload, "meterSerialNumber", json_object_new_string((const char *)ShmOCPP16Data->BootNotification.CpMeterSerialNumber));
  1314. json_object_object_add(payload, "meterType", json_object_new_string((const char *)ShmOCPP16Data->BootNotification.CpMeterType));
  1315. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1316. random_uuid(guid);
  1317. json_object_array_add(message, json_object_new_string(guid));
  1318. json_object_array_add(message, json_object_new_string("BootNotification"));
  1319. json_object_array_add(message, payload);
  1320. Send(message);
  1321. // Put request guid to hash map
  1322. sprintf(mapItem->key_string, "%s", guid);
  1323. sprintf(mapItem->key_value, "BootNotification,0");
  1324. printf("BootNotification mapItem->key_string=%s\n",mapItem->key_string);
  1325. printf("BootNotification mapItem->key_value=%s\n",mapItem->key_value);
  1326. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1327. {
  1328. result = PASS;
  1329. }
  1330. printf("8-2\n");
  1331. memset(queuedata, 0, strlen(queuedata));
  1332. strcpy(queuedata,(char*)json_object_to_json_string(message));
  1333. //addq(guid, queuedata);
  1334. #ifdef SystemLogMessage
  1335. DEBUG_INFO(">>>>>BootNotification request\n");
  1336. DEBUG_INFO("Message: %s\n", SendBuffer);
  1337. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1338. #endif
  1339. json_object_put(message); // Delete the json object
  1340. //ShmOCPP16Data->SpMsg.bits.BootNotificationReq = 1;
  1341. return result;
  1342. }
  1343. int sendDataTransferRequest(int gun_index)
  1344. {
  1345. int result = FAIL;
  1346. struct json_object *message, *payload, *data;
  1347. char *senstr = NULL;
  1348. char *temp = NULL;
  1349. const char *del = ",";
  1350. char guid[37];
  1351. message = json_object_new_array();
  1352. payload = json_object_new_object();
  1353. data = json_object_new_object();
  1354. json_object_object_add(payload, "vendorId", json_object_new_string("PhihongTechnology"));
  1355. json_object_object_add(payload, "messageId", json_object_new_string("TestingMessage"));
  1356. json_object_object_add(data, "data-1", json_object_new_string("data1 content"));
  1357. json_object_object_add(data, "data-2", json_object_new_string("data2 content"));
  1358. json_object_object_add(payload, "data", json_object_new_string(json_object_get_string(data)));
  1359. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1360. random_uuid(guid);
  1361. json_object_array_add(message, json_object_new_string(guid));
  1362. json_object_array_add(message, json_object_new_string("DataTransfer"));
  1363. json_object_array_add(message, payload);
  1364. Send(message);
  1365. // Put request guid to hash map
  1366. if(mapItem == NULL)
  1367. {
  1368. mapItem = malloc(sizeof(data_struct_t));
  1369. printf("mapItem is null\n");
  1370. }
  1371. if(guid == NULL || mapItem->key_string == NULL)
  1372. {
  1373. printf("guid is NULL \n");
  1374. }
  1375. if(mapItem->key_string == NULL)
  1376. {
  1377. printf("mapItem->key_string is NULL\n");
  1378. }
  1379. sprintf(mapItem->key_string, "%s", guid);
  1380. sprintf(mapItem->key_value, "DataTransfer,%d", (gun_index + 1));
  1381. printf("DataTransfer mapItem->key_string=%s\n", mapItem->key_string);
  1382. printf("DataTransfer mapItem->key_value=%s\n", mapItem->key_value);
  1383. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1384. {
  1385. result = PASS;
  1386. printf("DataTransfer mapItem pass\n");
  1387. }
  1388. #ifdef SystemLogMessage
  1389. DEBUG_INFO(">>>>>DataTransfer request\n");
  1390. DEBUG_INFO("Message: %s\n", SendBuffer);
  1391. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1392. #endif
  1393. json_object_put(message); // Delete the json object
  1394. return result;
  1395. }
  1396. int sendDiagnosticsStatusNotificationRequest(char *status)
  1397. {
  1398. int result = FAIL;
  1399. char *str = NULL;
  1400. struct json_object *message, *payload;
  1401. char guid[37];
  1402. message = json_object_new_array();
  1403. payload = json_object_new_object();
  1404. printf("sendDiagnosticsStatusNotificationRequest \n");
  1405. printf("DiagnosticsStatusNotification-1\n");
  1406. printf("DiagnosticsStatusNotification.Status=%s\n", status);
  1407. sprintf(ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1408. printf("DiagnosticsStatusNotification.Status=%s\n", str);
  1409. json_object_object_add(payload, "status", json_object_new_string((const char *)status));
  1410. printf("DiagnosticsStatusNotification-2\n");
  1411. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1412. random_uuid(guid);
  1413. json_object_array_add(message, json_object_new_string(guid));
  1414. json_object_array_add(message, json_object_new_string("DiagnosticsStatusNotification"));
  1415. json_object_array_add(message, payload);
  1416. Send(message);
  1417. if(mapItem == NULL)
  1418. {
  1419. mapItem = malloc(sizeof(data_struct_t));
  1420. printf("mapItem is null\n");
  1421. }
  1422. if(guid == NULL || mapItem->key_string == NULL)
  1423. {
  1424. printf("guid is NULL \n");
  1425. }
  1426. if(mapItem->key_string == NULL)
  1427. {
  1428. printf("mapItem->key_string is NULL\n");
  1429. }
  1430. // Put request guid to hash map
  1431. sprintf(mapItem->key_string, "%s", guid);
  1432. sprintf(mapItem->key_value, "DiagnosticsStatusNotification,%d", 0);
  1433. printf("DiagnosticsStatusNotification mapItem->key_string=%s\n", mapItem->key_string);
  1434. printf("DiagnosticsStatusNotification mapItem->key_value=%s\n", mapItem->key_value);
  1435. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1436. {
  1437. result = PASS;
  1438. printf("DiagnosticsStatusNotification mapItem pass\n");
  1439. }
  1440. #ifdef SystemLogMessage
  1441. DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1442. DEBUG_INFO("Message: %s\n", SendBuffer);
  1443. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1444. #endif
  1445. json_object_put(message); // Delete the json object
  1446. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  1447. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1448. return result;
  1449. }
  1450. int sendFirmwareStatusNotificationRequest(char *status)
  1451. {
  1452. int result = FAIL;
  1453. char *str = NULL;
  1454. struct json_object *message, *payload;
  1455. char guid[37];
  1456. message = json_object_new_array();
  1457. payload = json_object_new_object();
  1458. sprintf(ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1459. json_object_object_add(payload, "status", json_object_new_string((const char *)status));
  1460. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1461. random_uuid(guid);
  1462. json_object_array_add(message, json_object_new_string(guid));
  1463. json_object_array_add(message, json_object_new_string("FirmwareStatusNotification"));
  1464. json_object_array_add(message, payload);
  1465. Send(message);
  1466. if(mapItem == NULL)
  1467. {
  1468. mapItem = malloc(sizeof(data_struct_t));
  1469. printf("mapItem is null\n");
  1470. }
  1471. if(guid == NULL || mapItem->key_string == NULL)
  1472. {
  1473. printf("guid is NULL \n");
  1474. }
  1475. if(mapItem->key_string == NULL)
  1476. {
  1477. printf("mapItem->key_string is NULL\n");
  1478. }
  1479. // Put request guid to hash map
  1480. sprintf(mapItem->key_string, "%s", guid);
  1481. sprintf(mapItem->key_value, "FirmwareStatusNotification,%d", 0);
  1482. printf("FirmwareStatusNotification mapItem->key_string=%s\n", mapItem->key_string);
  1483. printf("FirmwareStatusNotification mapItem->key_value=%s\n", mapItem->key_value);
  1484. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1485. {
  1486. result = PASS;
  1487. printf("FirmwareStatusNotification mapItem pass\n");
  1488. }
  1489. #ifdef SystemLogMessage
  1490. DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1491. DEBUG_INFO("Message: %s\n", SendBuffer);
  1492. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1493. #endif
  1494. json_object_put(message); // Delete the json object
  1495. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  1496. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1497. return result;
  1498. }
  1499. int sendHeartbeatRequest(int gun_index)
  1500. {
  1501. int result = FAIL;
  1502. struct json_object *message, *payload;
  1503. char *senstr = NULL;
  1504. char *temp = NULL;
  1505. const char *del = ",";
  1506. char guid[37];
  1507. message = json_object_new_array();
  1508. payload = json_object_new_object();
  1509. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1510. random_uuid(guid);
  1511. json_object_array_add(message, json_object_new_string(guid));
  1512. json_object_array_add(message, json_object_new_string("Heartbeat"));
  1513. json_object_array_add(message, payload);
  1514. Send(message);
  1515. if(mapItem == NULL)
  1516. {
  1517. mapItem = malloc(sizeof(data_struct_t));
  1518. printf("mapItem is null\n");
  1519. }
  1520. if(guid == NULL || mapItem->key_string == NULL)
  1521. {
  1522. printf("guid is NULL \n");
  1523. }
  1524. if(mapItem->key_string == NULL)
  1525. {
  1526. printf("mapItem->key_string is NULL\n");
  1527. }
  1528. sprintf(mapItem->key_string, "%s", guid);
  1529. sprintf(mapItem->key_value, "Heartbeat,%d", 0);
  1530. printf("Heartbeat mapItem->key_string=%s\n", mapItem->key_string);
  1531. printf("Heartbeat mapItem->key_value=%s\n", mapItem->key_value);
  1532. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1533. {
  1534. result = PASS;
  1535. printf("Heartbeat mapItem\n");
  1536. }
  1537. #ifdef SystemLogMessage
  1538. DEBUG_INFO(">>>>>Heartbeat request\n");
  1539. DEBUG_INFO("Message: %s\n", SendBuffer);
  1540. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1541. #endif
  1542. json_object_put(message);
  1543. return result;
  1544. }
  1545. int sendStartTransactionRequest(int gun_index)
  1546. {
  1547. int result = FAIL;
  1548. struct json_object *message, *payload;
  1549. char *senstr = NULL;
  1550. char *temp = NULL;
  1551. const char *del = ",";
  1552. char guid[37];
  1553. struct timeval tmnow;
  1554. struct tm *tm;
  1555. char buf[30], usec_buf[6];
  1556. message = json_object_new_array();
  1557. payload = json_object_new_object();
  1558. gettimeofday(&tmnow, NULL);
  1559. time_t t;
  1560. t = time(NULL);
  1561. /*UTC time and date*/
  1562. tm = gmtime(&t);
  1563. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1564. strcat(buf,".");
  1565. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1566. strcat(buf,usec_buf);
  1567. printf("%s",buf);
  1568. // set value
  1569. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1570. strcpy(ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1571. strcpy(ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmSysConfigAndInfo->SysConfig.UserId);
  1572. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1573. {
  1574. printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index );
  1575. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1576. {
  1577. printf("Chademo : 0\n");
  1578. #if 1 // for test
  1579. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy =100.0;
  1580. #endif
  1581. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1582. }
  1583. }
  1584. for (int index = 0; index < CCS_QUANTITY; index++)
  1585. {
  1586. printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  1587. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1588. {
  1589. printf("Ccs : 0\n");
  1590. #if 1 // fo test
  1591. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  1592. #endif
  1593. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1594. }
  1595. }
  1596. for (int index = 0; index < GB_QUANTITY; index++)
  1597. {
  1598. printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index );
  1599. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1600. {
  1601. printf("Gb : 0\n");
  1602. #if 1 // fo test
  1603. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  1604. #endif
  1605. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1606. }
  1607. }
  1608. //ShmOCPP16Data->StartTransaction[gun_index].MeterStart = 100;
  1609. json_object_object_add(payload, "connectorId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ConnectorId));
  1610. json_object_object_add(payload, "idTag", json_object_new_string((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag));
  1611. json_object_object_add(payload, "meterStart", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].MeterStart));
  1612. json_object_object_add(payload, "reservationId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ReservationId));
  1613. json_object_object_add(payload, "timestamp", json_object_new_string((const char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  1614. printf("test s 1\n");
  1615. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1616. random_uuid(guid);
  1617. json_object_array_add(message, json_object_new_string(guid));
  1618. json_object_array_add(message, json_object_new_string("StartTransaction"));
  1619. json_object_array_add(message, payload);
  1620. Send(message);
  1621. //usleep(500); // 等�??��?微�?
  1622. printf("test s 2\n");
  1623. if(mapItem == NULL)
  1624. {
  1625. mapItem = malloc(sizeof(data_struct_t));
  1626. printf("mapItem is null\n");
  1627. }
  1628. if(guid == NULL || mapItem->key_string == NULL)
  1629. {
  1630. printf("guid is NULL \n");
  1631. }
  1632. if(mapItem->key_string == NULL)
  1633. {
  1634. printf("mapItem->key_string is NULL\n");
  1635. }
  1636. // Put request guid to hash map
  1637. sprintf(mapItem->key_string, "%s", guid);
  1638. printf("test s 2-0-1\n");
  1639. sprintf(mapItem->key_value, "StartTransaction,%d", (gun_index));
  1640. printf("test s 2-0-2\n");
  1641. printf("StartTransaction mapItem->key_string=%s\n",mapItem->key_string);
  1642. printf("StartTransaction mapItem->key_value=%s\n",mapItem->key_value);
  1643. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1644. {
  1645. printf("test s 2-1\n");
  1646. result = PASS;
  1647. }
  1648. printf("test s 3\n");
  1649. strcpy(queuedata, (char*)json_object_to_json_string(message));
  1650. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1651. #ifdef SystemLogMessage
  1652. DEBUG_INFO(">>>>>StartTransaction request\n");
  1653. DEBUG_INFO("Message: %s\n", SendBuffer);
  1654. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1655. #endif
  1656. json_object_put(message);
  1657. return result;
  1658. }
  1659. int sendStatusNotificationRequest(int gun_index)
  1660. {
  1661. int result = FAIL;
  1662. struct json_object *message, *payload;
  1663. char *senstr = NULL;
  1664. char *temp = NULL;
  1665. const char *del = ",";
  1666. char guid[37];
  1667. int currentStatus = 0;
  1668. struct timeval tmnow;
  1669. struct tm *tm;
  1670. char buf[30], usec_buf[6];
  1671. message = json_object_new_array();
  1672. payload = json_object_new_object();
  1673. gettimeofday(&tmnow, NULL);
  1674. time_t t;
  1675. t = time(NULL);
  1676. /*UTC time and date*/
  1677. tm = gmtime(&t);
  1678. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1679. strcat(buf,".");
  1680. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1681. strcat(buf,usec_buf);
  1682. printf("%s",buf);
  1683. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1684. strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  1685. // it's option
  1686. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1687. /*
  1688. enum _SYSTEM_STATUS
  1689. {
  1690. S_BOOTING = 0,
  1691. S_IDLE, = 1
  1692. S_AUTHORIZING, =2
  1693. S_REASSIGN_CHECK, =3
  1694. S_REASSIGN, =4
  1695. S_PRECHARGE, =5
  1696. S_PREPARING_FOR_EV, =6
  1697. S_PREPARING_FOR_EVSE, =7
  1698. S_CHARGING, =8
  1699. S_TERMINATING, =9
  1700. S_COMPLETE, =10
  1701. S_ALARM, =11
  1702. S_FAULT =12
  1703. }
  1704. */
  1705. //check Transaction active
  1706. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1707. {
  1708. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 1)) //S_IDLE
  1709. {
  1710. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1711. currentStatus = 0;
  1712. }
  1713. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 5)) //S_PRECHARGE
  1714. {
  1715. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1716. currentStatus = 1;
  1717. }
  1718. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8)) //S_CHARGING
  1719. {
  1720. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1721. currentStatus = 2;
  1722. }
  1723. }
  1724. for (int index = 0; index < CCS_QUANTITY; index++)
  1725. {
  1726. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 1)) //S_IDLE
  1727. {
  1728. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1729. currentStatus = 0;
  1730. }
  1731. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 5)) //S_PRECHARGE
  1732. {
  1733. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1734. currentStatus = 1;
  1735. }
  1736. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8)) //S_CHARGING
  1737. {
  1738. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1739. currentStatus = 2;
  1740. }
  1741. }
  1742. for (int index = 0; index < GB_QUANTITY; index++)
  1743. {
  1744. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1745. {
  1746. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1747. currentStatus = 0;
  1748. }
  1749. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 5)) //S_PRECHARGE
  1750. {
  1751. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1752. currentStatus = 1;
  1753. }
  1754. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8)) //S_CHARGING
  1755. {
  1756. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1757. currentStatus = 2;
  1758. }
  1759. }
  1760. //it's option
  1761. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1762. strcpy(ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1763. strcpy(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  1764. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1765. json_object_object_add(payload, "connectorId", json_object_new_int(ShmOCPP16Data->StatusNotification[gun_index].ConnectorId));
  1766. json_object_object_add(payload, "errorCode", json_object_new_string((const char *)(&ShmOCPP16Data->StatusNotification[gun_index].ErrorCode)));
  1767. json_object_object_add(payload, "info", json_object_new_string((const char *)ShmOCPP16Data->StatusNotification[gun_index].Info));
  1768. json_object_object_add(payload, "status", json_object_new_string((const char *)ShmOCPP16Data->StatusNotification[gun_index].Status));
  1769. json_object_object_add(payload, "timestamp", json_object_new_string((const char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp));
  1770. json_object_object_add(payload, "vendorId", json_object_new_string((const char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId));
  1771. json_object_object_add(payload, "vendorErrorCode", json_object_new_string((const char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode));
  1772. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1773. random_uuid(guid);
  1774. json_object_array_add(message, json_object_new_string(guid));
  1775. json_object_array_add(message, json_object_new_string("StatusNotification"));
  1776. json_object_array_add(message, payload);
  1777. Send(message);
  1778. //usleep(500); // 等�??��?微�?
  1779. // Put request guid to hash map
  1780. if(mapItem == NULL)
  1781. {
  1782. mapItem = malloc(sizeof(data_struct_t));
  1783. printf("mapItem is null\n");
  1784. }
  1785. sprintf(mapItem->key_string, "%s", guid);
  1786. sprintf(mapItem->key_value, "StatusNotification,%d", (gun_index));
  1787. //sprintf(mapItem->key_value, "StatusNotification,%d", gun_index + 1);
  1788. printf("statusNotification mapItem->key_string=%s\n",mapItem->key_string);
  1789. printf("statusNotification mapItem->key_value=%s\n",mapItem->key_value);
  1790. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1791. {
  1792. printf("statusNotification mapitem pass");
  1793. result = PASS;
  1794. }
  1795. #ifdef SystemLogMessage
  1796. DEBUG_INFO(">>>>>StatusNotification request\n");
  1797. DEBUG_INFO("Message: %s\n", SendBuffer);
  1798. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1799. #endif
  1800. json_object_put(message);
  1801. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1802. //for test
  1803. #if 0
  1804. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1805. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus =='1' )
  1806. {
  1807. //ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 1;
  1808. }
  1809. if(UserPlugGun == 0 && ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus == '3')
  1810. {
  1811. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus = '1';
  1812. }
  1813. #endif
  1814. return result;
  1815. }
  1816. int sendStopTransactionRequest(int gun_index)
  1817. {
  1818. int result = FAIL;
  1819. struct json_object *message, *payload, *transactionDataArray, *transactionData, *sampledArray, *sampledValue;
  1820. char *senstr = NULL;
  1821. char *temp = NULL;
  1822. const char *del = ",";
  1823. char guid[37];
  1824. int idx_sample=0;
  1825. message = json_object_new_array();
  1826. payload = json_object_new_object();
  1827. transactionDataArray = json_object_new_array();
  1828. sampledArray = json_object_new_array();
  1829. printf("sendStopTransactionRequest \n");
  1830. strcpy(ShmOCPP16Data->StopTransaction[gun_index].IdTag, ShmOCPP16Data->Authorize.IdTag);
  1831. //ENERGY_ACTIVE_IMPORT_REGISTER
  1832. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1833. {
  1834. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1835. {
  1836. //for test
  1837. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy =100.0;
  1838. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1839. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  1840. }
  1841. }
  1842. for (int index = 0; index < CCS_QUANTITY; index++)
  1843. {
  1844. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1845. {
  1846. //for test
  1847. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  1848. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1849. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  1850. }
  1851. }
  1852. for (int index = 0; index < GB_QUANTITY; index++)
  1853. {
  1854. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1855. {
  1856. // for test
  1857. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  1858. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1859. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  1860. }
  1861. }
  1862. struct timeval tmnow;
  1863. struct tm *tm;
  1864. char buf[30], usec_buf[6];
  1865. gettimeofday(&tmnow, NULL);
  1866. time_t t;
  1867. t = time(NULL);
  1868. /*UTC time and date*/
  1869. tm = gmtime(&t);
  1870. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1871. strcat(buf,".");
  1872. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1873. strcat(buf,usec_buf);
  1874. printf("%s",buf);
  1875. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  1876. strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  1877. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  1878. strcpy(ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  1879. json_object_object_add(payload, "idTag", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  1880. json_object_object_add(payload, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  1881. json_object_object_add(payload, "timestamp", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  1882. json_object_object_add(payload, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  1883. json_object_object_add(payload, "reason", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  1884. printf("sendStopTransactionRequest 1\n");
  1885. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*3);
  1886. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  1887. {
  1888. transactionData = json_object_new_object();
  1889. //json_object_object_add(transactionData, "timestamp", json_object_new_string("2019-05-04T18:15:33Z"));
  1890. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp, buf/*"2019-05-04T18:15:33Z"*/);
  1891. json_object_object_add(transactionData, "timestamp", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp));
  1892. //for(int idx_sample=0;idx_sample<1;idx_sample++)
  1893. {
  1894. sampledValue = json_object_new_object();
  1895. printf("sendStopTransactionRequest -2\n");
  1896. //Transaction_Begin
  1897. idx_sample=0;
  1898. printf("ShmOCPP16Data->StartTransaction[gun_index].MeterStart=%d\n",ShmOCPP16Data->StartTransaction[gun_index].MeterStart);
  1899. printf("ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value=%s\n",ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value);
  1900. sprintf(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d",ShmOCPP16Data->StartTransaction[gun_index].MeterStart);
  1901. printf("sendStopTransactionRequest -2-1\n");
  1902. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  1903. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  1904. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Import_Register]);
  1905. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  1906. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  1907. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  1908. printf("sendStopTransactionRequest -2-0\n");
  1909. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value));
  1910. json_object_object_add(sampledValue, "context", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context));
  1911. json_object_object_add(sampledValue, "format", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format));
  1912. json_object_object_add(sampledValue, "measurand", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand));
  1913. json_object_object_add(sampledValue, "phase", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase));
  1914. json_object_object_add(sampledValue, "location", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location));
  1915. json_object_object_add(sampledValue, "unit", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit));
  1916. json_object_array_add(sampledArray, sampledValue);
  1917. //Transaction_End
  1918. idx_sample=1;
  1919. //sampledValue = NULL;
  1920. sampledValue = json_object_new_object();
  1921. //ENERGY_ACTIVE_IMPORT_REGISTER
  1922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1923. {
  1924. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1925. {
  1926. // for test
  1927. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower = 100.0;
  1928. sprintf(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  1929. }
  1930. }
  1931. for (int index = 0; index < CCS_QUANTITY; index++)
  1932. {
  1933. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1934. {
  1935. // for test
  1936. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower = 100.0;
  1937. sprintf(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  1938. }
  1939. }
  1940. for (int index = 0; index < GB_QUANTITY; index++)
  1941. {
  1942. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1943. {
  1944. // for test
  1945. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  1946. sprintf(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );
  1947. }
  1948. }
  1949. //sprintf(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%s",ShmOCPP16Data->StartTransaction[gun_index].MeterStart);
  1950. printf("sendStopTransactionRequest -2-1\n");
  1951. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  1952. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  1953. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Import_Register]);
  1954. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  1955. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  1956. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  1957. printf("sendStopTransactionRequest -2-0\n");
  1958. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value));
  1959. json_object_object_add(sampledValue, "context", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context));
  1960. json_object_object_add(sampledValue, "format", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format));
  1961. json_object_object_add(sampledValue, "measurand", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand));
  1962. json_object_object_add(sampledValue, "phase", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase));
  1963. json_object_object_add(sampledValue, "location", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location));
  1964. json_object_object_add(sampledValue, "unit", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit));
  1965. json_object_array_add(sampledArray, sampledValue);
  1966. }
  1967. printf("sendStopTransactionRequest -2-1\n");
  1968. json_object_object_add(transactionData, "sampledValue", sampledArray);
  1969. json_object_array_add(transactionDataArray, transactionData);
  1970. }
  1971. printf("sendStopTransactionRequest -3\n");
  1972. json_object_object_add(payload, "transactionData", transactionDataArray);
  1973. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1974. random_uuid(guid);
  1975. json_object_array_add(message, json_object_new_string(guid));
  1976. json_object_array_add(message, json_object_new_string("StopTransaction"));
  1977. json_object_array_add(message, payload);
  1978. Send(message);
  1979. if(mapItem == NULL)
  1980. {
  1981. mapItem = malloc(sizeof(data_struct_t));
  1982. printf("mapItem is null\n");
  1983. }
  1984. // Put request guid to hash map
  1985. sprintf(mapItem->key_string, "%s", guid);
  1986. sprintf(mapItem->key_value, "StopTransaction,%d", (gun_index));
  1987. printf("StopTransaction mapItem->key_string=%s\n",mapItem->key_string);
  1988. printf("StopTransaction mapItem->key_value=%s\n",mapItem->key_value);
  1989. //sprintf(mapItem->key_value, senstr);//sprintf(mapItem->key_value, "StopTransaction");
  1990. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1991. {
  1992. result = PASS;
  1993. printf("StopTransaction mapitem pass");
  1994. }
  1995. strcpy(queuedata, (char*)json_object_to_json_string(message));
  1996. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1997. //addq(guid, (char*)json_object_to_json_string(message));
  1998. #ifdef SystemLogMessage
  1999. DEBUG_INFO(">>>>>StopTransaction request\n");
  2000. DEBUG_INFO("Message: %s\n", SendBuffer);
  2001. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  2002. #endif
  2003. json_object_put(message);
  2004. //for test
  2005. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2006. return result;
  2007. }
  2008. int sendMeterValuesRequest(int gun_index)
  2009. {
  2010. int result = FAIL;
  2011. struct json_object *message, *payload, *meterValueDataArray, *transactionData, *sampledArray, *sampledValue;
  2012. char *senstr = NULL;
  2013. char *temp = NULL;
  2014. const char *del = ",";
  2015. char guid[37];
  2016. int idx_sample=0;
  2017. message = json_object_new_array();
  2018. payload = json_object_new_object();
  2019. meterValueDataArray = json_object_new_array();
  2020. sampledArray = json_object_new_array();
  2021. //set value
  2022. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2023. //ShmOCPP16Data->MeterValues[gun_index].TransactionId = 93507754;
  2024. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2025. json_object_object_add(payload, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  2026. json_object_object_add(payload, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  2027. printf("enter sendMeterValuesRequest -2\n");
  2028. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2029. {
  2030. transactionData = json_object_new_object();
  2031. //allocate memory space
  2032. ShmOCPP16Data->MeterValues[gun_index].MeterValue = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2033. //UTC Date time
  2034. struct timeval tmnow;
  2035. struct tm *tm;
  2036. char buf[30], usec_buf[6];
  2037. gettimeofday(&tmnow, NULL);
  2038. time_t t;
  2039. t = time(NULL);
  2040. /*UTC time and date*/
  2041. tm = gmtime(&t);
  2042. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2043. strcat(buf,".");
  2044. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2045. strcat(buf,usec_buf);
  2046. printf("%s",buf);
  2047. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp, buf);
  2048. json_object_object_add(transactionData, "timestamp", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp));
  2049. //allocate memory space
  2050. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*5);
  2051. //for(int idx_sample=0;idx_sample<1;idx_sample++)
  2052. //{
  2053. sampledValue = json_object_new_object();
  2054. #if 1 //DC
  2055. /****************************************************(1)ENERGY_ACTIVE_IMPORT_REGISTER*********************************************/
  2056. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2057. {
  2058. printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index );
  2059. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2060. {
  2061. printf("Chademo : 0\n");
  2062. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy =100.0;
  2063. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2064. }
  2065. }
  2066. for (int index = 0; index < CCS_QUANTITY; index++)
  2067. {
  2068. printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2069. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2070. {
  2071. printf("Ccs : 0\n");
  2072. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2073. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2074. }
  2075. }
  2076. for (int index = 0; index < GB_QUANTITY; index++)
  2077. {
  2078. printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index );
  2079. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2080. {
  2081. printf("Gb : 0\n");
  2082. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2083. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2084. }
  2085. }
  2086. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2087. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2088. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  2089. // strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2090. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2091. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh]);
  2092. printf("meter error 1\n");
  2093. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value));
  2094. printf("meter error 2\n");
  2095. json_object_object_add(sampledValue, "context", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context));
  2096. printf("meter error 3\n");
  2097. json_object_object_add(sampledValue, "format", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format));
  2098. printf("meter error 4\n");
  2099. json_object_object_add(sampledValue, "measurand", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand));
  2100. // json_object_object_add(sampledValue, "phase", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase));
  2101. printf("meter error 5\n");
  2102. json_object_object_add(sampledValue, "location", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location));
  2103. printf("meter error 6\n");
  2104. json_object_object_add(sampledValue, "unit", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit));
  2105. printf("meter error 7\n");
  2106. json_object_array_add(sampledArray, sampledValue);
  2107. printf("meter error 8\n");
  2108. idx_sample=1;
  2109. //sampledValue = NULL;
  2110. sampledValue = json_object_new_object();
  2111. /***********************************************(2)VOLTAGE******************************************************/
  2112. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2113. {
  2114. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2115. {
  2116. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage = 80.0;
  2117. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2118. }
  2119. }
  2120. for (int index = 0; index < CCS_QUANTITY; index++)
  2121. {
  2122. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2123. {
  2124. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage = 80.0;
  2125. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2126. }
  2127. }
  2128. for (int index = 0; index < GB_QUANTITY; index++)
  2129. {
  2130. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2131. {
  2132. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage = 80.0;
  2133. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2134. }
  2135. }
  2136. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2137. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2138. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Voltage]);
  2139. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2140. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2141. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2142. printf("meter error 9\n");
  2143. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value));
  2144. printf("meter error 10\n");
  2145. json_object_object_add(sampledValue, "context", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context));
  2146. printf("meter error 11\n");
  2147. json_object_object_add(sampledValue, "format", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format));
  2148. printf("meter error 12\n");
  2149. json_object_object_add(sampledValue, "measurand", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand));
  2150. printf("meter error 13\n");
  2151. json_object_object_add(sampledValue, "phase", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase));
  2152. printf("meter error 14\n");
  2153. json_object_object_add(sampledValue, "location", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location));
  2154. printf("meter error 15\n");
  2155. json_object_object_add(sampledValue, "unit", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit));
  2156. printf("meter error 16\n");
  2157. json_object_array_add(sampledArray, sampledValue);
  2158. idx_sample=2;
  2159. //sampledValue = NULL;
  2160. sampledValue = json_object_new_object();
  2161. /********************************(3)Current************************************************/
  2162. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2163. {
  2164. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2165. {
  2166. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent = 60.0;
  2167. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2168. }
  2169. }
  2170. for (int index = 0; index < CCS_QUANTITY; index++)
  2171. {
  2172. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2173. {
  2174. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent = 60.0;
  2175. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2176. }
  2177. }
  2178. for (int index = 0; index < GB_QUANTITY; index++)
  2179. {
  2180. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2181. {
  2182. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent = 60.0;
  2183. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2184. }
  2185. }
  2186. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2187. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2188. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Current_Import]);
  2189. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2190. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2191. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2192. printf("meter error 17\n");
  2193. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value));
  2194. printf("meter error 18\n");
  2195. json_object_object_add(sampledValue, "context", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context));
  2196. printf("meter error 19\n");
  2197. json_object_object_add(sampledValue, "format", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format));
  2198. printf("meter error 20\n");
  2199. json_object_object_add(sampledValue, "measurand", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand));
  2200. printf("meter error 21\n");
  2201. json_object_object_add(sampledValue, "phase", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase));
  2202. printf("meter error 22\n");
  2203. json_object_object_add(sampledValue, "location", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location));
  2204. printf("meter error 23\n");
  2205. json_object_object_add(sampledValue, "unit", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit));
  2206. printf("meter error 24\n");
  2207. json_object_array_add(sampledArray, sampledValue);
  2208. printf("meter error 25\n");
  2209. idx_sample=3;
  2210. //sampledValue = NULL;
  2211. sampledValue = json_object_new_object();
  2212. /********************************(4)Power.Active.Import************************************************/
  2213. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2214. {
  2215. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2216. {
  2217. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower = 100.0;
  2218. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2219. }
  2220. }
  2221. for (int index = 0; index < CCS_QUANTITY; index++)
  2222. {
  2223. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2224. {
  2225. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower = 100.0;
  2226. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2227. }
  2228. }
  2229. for (int index = 0; index < GB_QUANTITY; index++)
  2230. {
  2231. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2232. {
  2233. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2234. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2235. }
  2236. }
  2237. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2238. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2239. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Power_Active_Import]);
  2240. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2241. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2242. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2243. printf("meter error 35\n");
  2244. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value));
  2245. printf("meter error 36\n");
  2246. json_object_object_add(sampledValue, "context", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context));
  2247. printf("meter error 37\n");
  2248. json_object_object_add(sampledValue, "format", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format));
  2249. printf("meter error 38\n");
  2250. json_object_object_add(sampledValue, "measurand", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand));
  2251. printf("meter error 39\n");
  2252. json_object_object_add(sampledValue, "phase", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase));
  2253. printf("meter error 40\n");
  2254. json_object_object_add(sampledValue, "location", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location));
  2255. printf("meter error 41\n");
  2256. json_object_object_add(sampledValue, "unit", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit));
  2257. printf("meter error 42\n");
  2258. json_object_array_add(sampledArray, sampledValue);
  2259. printf("meter error 43\n");
  2260. #endif
  2261. //}
  2262. json_object_object_add(transactionData, "sampledValue", sampledArray);
  2263. json_object_array_add(meterValueDataArray, transactionData);
  2264. }
  2265. json_object_object_add(payload, "meterValue", meterValueDataArray);
  2266. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  2267. random_uuid(guid);
  2268. json_object_array_add(message, json_object_new_string(guid));
  2269. json_object_array_add(message, json_object_new_string("MeterValues"));
  2270. json_object_array_add(message, payload);
  2271. printf("enter sendMeterValuesRequest -3\n");
  2272. printf("before send message=%s\n",json_object_to_json_string(message));
  2273. Send(message);
  2274. if(mapItem == NULL)
  2275. {
  2276. mapItem = malloc(sizeof(data_struct_t));
  2277. printf("mapItem is null\n");
  2278. }
  2279. if(guid == NULL || mapItem->key_string == NULL)
  2280. {
  2281. printf("guid is NULL \n");
  2282. }
  2283. if(mapItem->key_string == NULL)
  2284. {
  2285. printf("mapItem->key_string is NULL\n");
  2286. }
  2287. printf("enter sendMeterValuesRequest -4\n");
  2288. // Put request guid to hash map
  2289. sprintf(mapItem->key_string, "%s", guid);
  2290. sprintf(mapItem->key_value, "MeterValues,%d", (gun_index));
  2291. //sprintf(mapItem->key_value, senstr);//sprintf(mapItem->key_value, "StopTransaction");
  2292. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2293. {
  2294. result = PASS;
  2295. printf("MeterValues mapitem pass");
  2296. }
  2297. strcpy(queuedata, (char*)json_object_to_json_string(message));
  2298. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2299. printf("enter sendMeterValuesRequest -5\n");
  2300. //addq(guid, (char*)json_object_to_json_string(message));
  2301. #ifdef SystemLogMessage
  2302. DEBUG_INFO(">>>>>MeerValues request\n");
  2303. DEBUG_INFO("Message: %s\n", SendBuffer);
  2304. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  2305. #endif
  2306. json_object_put(message);
  2307. return result;
  2308. }
  2309. //==========================================
  2310. // send confirm routine
  2311. //==========================================
  2312. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2313. {
  2314. int result = FAIL;
  2315. struct json_object *message, *comfirmpayload;
  2316. char guid[37];
  2317. printf("handle CancelReservationRequest\n");
  2318. message = json_object_new_array();
  2319. comfirmpayload = json_object_new_object();
  2320. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2321. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2322. json_object_array_add(message, json_object_new_string(uuid));
  2323. json_object_array_add(message, comfirmpayload);
  2324. Send(message);
  2325. json_object_put(message);
  2326. return result;
  2327. }
  2328. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2329. {
  2330. int result = FAIL;
  2331. struct json_object *message, *comfirmpayload;
  2332. char guid[37];
  2333. printf("handle sendChangeAvailabilityConfirmation\n");
  2334. message = json_object_new_array();
  2335. comfirmpayload = json_object_new_object();
  2336. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2337. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2338. json_object_array_add(message, json_object_new_string(uuid));
  2339. json_object_array_add(message, comfirmpayload);
  2340. Send(message);
  2341. json_object_put(message);
  2342. return result;
  2343. }
  2344. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2345. {
  2346. int result = FAIL;
  2347. struct json_object *message, *comfirmpayload;
  2348. char guid[37];
  2349. printf("handle sendChangeConfigurationConfirmation\n");
  2350. message = json_object_new_array();
  2351. comfirmpayload = json_object_new_object();
  2352. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2353. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2354. json_object_array_add(message, json_object_new_string(uuid));
  2355. json_object_array_add(message, comfirmpayload);
  2356. printf("handle sendChangeConfigurationConfirmation -1\n");
  2357. Send(message);
  2358. printf("handle sendChangeConfigurationConfirmation- 2\n");
  2359. json_object_put(message);
  2360. return result;
  2361. }
  2362. int sendClearCacheConfirmation(char *uuid,char *payload)
  2363. {
  2364. int result = FAIL;
  2365. struct json_object *message, *comfirmpayload;
  2366. char guid[37];
  2367. printf("sendClearCacheConfirmation\n");
  2368. message = json_object_new_array();
  2369. comfirmpayload = json_object_new_object();
  2370. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2371. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2372. json_object_array_add(message, json_object_new_string(uuid));
  2373. json_object_array_add(message, comfirmpayload);
  2374. Send(message);
  2375. json_object_put(message);
  2376. return result;
  2377. }
  2378. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2379. {
  2380. int result = FAIL;
  2381. struct json_object *message, *comfirmpayload;
  2382. char guid[37];
  2383. printf("sendClearChargingProfileConfirmation\n");
  2384. message = json_object_new_array();
  2385. comfirmpayload = json_object_new_object();
  2386. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2387. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2388. json_object_array_add(message, json_object_new_string(uuid));
  2389. json_object_array_add(message, comfirmpayload);
  2390. Send(message);
  2391. json_object_put(message);
  2392. return result;
  2393. }
  2394. int sendDataTransferConfirmation(char *uuid,char *payload)
  2395. {
  2396. int result = FAIL;
  2397. struct json_object *obj;
  2398. char guid[37];
  2399. obj = json_tokener_parse(payload);
  2400. printf("handle DataTransferRequest\n");
  2401. return result;
  2402. }
  2403. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2404. {
  2405. int result = FAIL;
  2406. struct json_object *message, *comfirmpayload, *chargingSchedule, *sampledArray, *sampledValue;
  2407. printf("handle sendGetCompositeScheduleConfirmation\n");
  2408. message = json_object_new_array();
  2409. comfirmpayload = json_object_new_object();
  2410. chargingSchedule = json_object_new_object();
  2411. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2412. json_object_object_add(comfirmpayload, "connectorId ", json_object_new_int(connectorIdInt));
  2413. json_object_object_add(comfirmpayload, "scheduleStart", json_object_new_string((const char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule));
  2414. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration) );
  2415. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((const char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule) );
  2416. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((const char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit) );
  2417. sampledArray = json_object_new_array();
  2418. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  2419. printf("sendGetCompositeScheduleConfirmation nPeriod =%d\n", len);
  2420. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2421. {
  2422. sampledValue = json_object_new_object();
  2423. json_object_object_add(sampledValue, "startPeriod", json_object_new_int(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].StartPeriod));
  2424. json_object_object_add(sampledValue, "limit", json_object_new_double((double)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].Limit));
  2425. json_object_object_add(sampledValue, "numberPhases", json_object_new_int(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].NumberPhases));
  2426. json_object_array_add(sampledArray, sampledValue);
  2427. }
  2428. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", sampledArray);
  2429. json_object_object_add(chargingSchedule, "minChargingRate ", json_object_new_double((double)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate) );
  2430. json_object_object_add(comfirmpayload, "chargingSchedule", chargingSchedule );
  2431. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2432. json_object_array_add(message, json_object_new_string(uuid));
  2433. json_object_array_add(message, comfirmpayload);
  2434. Send(message);
  2435. json_object_put(message);
  2436. return result;
  2437. }
  2438. int sendGetConfigurationConfirmation(char *uuid)
  2439. {
  2440. int result = FAIL;
  2441. int MaxKeySupported = 0;
  2442. struct json_object *message, *comfirmpayload, *configurationKeyArray, *unknownKeyArray, *sampledValue;
  2443. printf("handle sendGetConfigurationConfirmation\n");
  2444. message = json_object_new_array();
  2445. comfirmpayload = json_object_new_object();
  2446. configurationKeyArray = json_object_new_array();
  2447. MaxKeySupported = atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2448. printf("MaxKeySupported=%d\n",MaxKeySupported);
  2449. // int configurationKeyArraylen = sizeof(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey)/sizeof(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[0]);
  2450. sampledValue = json_object_new_object();
  2451. // printf("configurationKeyArraylen =%d\n", configurationKeyArraylen);
  2452. //configuration key
  2453. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2454. {
  2455. if(strcmp(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2456. {
  2457. printf("test test enter add configurationKey\n");
  2458. printf("ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key=%s\n",ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key);
  2459. printf("ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly=%d\n", atoi(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly));
  2460. printf("ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value=%s\n",ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value);
  2461. json_object_object_add(sampledValue, "key", json_object_new_string((const char *)(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key)));
  2462. printf("error 1\n");
  2463. json_object_object_add(sampledValue, "readonly", json_object_new_boolean(atoi(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly)));
  2464. printf("error 2\n");
  2465. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value)));
  2466. printf("error 3\n");
  2467. json_object_array_add(configurationKeyArray, sampledValue);
  2468. printf("error 4\n");
  2469. }
  2470. }
  2471. json_object_object_add(comfirmpayload, "configurationKey", configurationKeyArray );
  2472. printf("error 5\n");
  2473. unknownKeyArray = json_object_new_array();
  2474. printf("error 6\n");
  2475. //sampledValue = NULL;
  2476. //unkown key
  2477. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  2478. {
  2479. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  2480. printf("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  2481. json_object *jstring1 = json_object_new_string((const char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item));
  2482. json_object_array_add(unknownKeyArray, jstring1);
  2483. }
  2484. printf("error 7\n");
  2485. if(UnknownKeynum != 0)
  2486. json_object_object_add(comfirmpayload, "unknownKey ", unknownKeyArray );
  2487. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2488. json_object_array_add(message, json_object_new_string(uuid));
  2489. json_object_array_add(message, comfirmpayload);
  2490. printf("error 8\n");
  2491. Send(message);
  2492. if(UnknownKeynum == 0)
  2493. json_object_put(unknownKeyArray);
  2494. json_object_put(message);
  2495. printf("error 9\n");
  2496. return result;
  2497. }
  2498. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  2499. {
  2500. int result = FAIL;
  2501. printf("handle GetDiagnosticsRequest\n");
  2502. struct json_object *message, *comfirmpayload;
  2503. printf("handle sendChangeConfigurationConfirmation\n");
  2504. message = json_object_new_array();
  2505. comfirmpayload = json_object_new_object();
  2506. json_object_object_add(comfirmpayload, "fileName", json_object_new_string((const char *)payload));
  2507. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2508. json_object_array_add(message, json_object_new_string(uuid));
  2509. json_object_array_add(message, comfirmpayload);
  2510. Send(message);
  2511. json_object_put(message);
  2512. return result;
  2513. }
  2514. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  2515. {
  2516. int result = FAIL;
  2517. printf("handle GetLocalListVersionRequest\n");
  2518. struct json_object *message, *comfirmpayload;
  2519. message = json_object_new_array();
  2520. comfirmpayload = json_object_new_object();
  2521. json_object_object_add(comfirmpayload, "listVersion", json_object_new_int(ShmOCPP16Data->GetLocalListVersion.ResponseListVersion));
  2522. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2523. json_object_array_add(message, json_object_new_string(uuid));
  2524. json_object_array_add(message, comfirmpayload);
  2525. Send(message);
  2526. json_object_put(message);
  2527. return result;
  2528. }
  2529. int sendRemoteStartConfirmation(char *uuid,char *payload)
  2530. {
  2531. int result = FAIL;
  2532. printf("handleRemoteStartRequest\n");
  2533. struct json_object *message, *comfirmpayload;
  2534. message = json_object_new_array();
  2535. comfirmpayload = json_object_new_object();
  2536. json_object_object_add(comfirmpayload, "status", json_object_new_string(payload));
  2537. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2538. json_object_array_add(message, json_object_new_string(uuid));
  2539. json_object_array_add(message, comfirmpayload);
  2540. Send(message);
  2541. json_object_put(message);
  2542. return result;
  2543. }
  2544. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  2545. {
  2546. int result = FAIL;
  2547. struct json_object *message, *comfirmpayload;
  2548. printf("handleRemoteStopTransactionRequest\n");
  2549. message = json_object_new_array();
  2550. comfirmpayload = json_object_new_object();
  2551. json_object_object_add(comfirmpayload, "status", json_object_new_string(payload));
  2552. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2553. json_object_array_add(message, json_object_new_string(uuid));
  2554. json_object_array_add(message, comfirmpayload);
  2555. Send(message);
  2556. json_object_put(message);
  2557. return result;
  2558. }
  2559. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  2560. {
  2561. int result = FAIL;
  2562. struct json_object *message, *comfirmpayload;
  2563. printf("sendReserveNowTransactionConfirmation\n");
  2564. message = json_object_new_array();
  2565. comfirmpayload = json_object_new_object();
  2566. json_object_object_add(comfirmpayload, "status", json_object_new_string(payload));
  2567. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2568. json_object_array_add(message, json_object_new_string(uuid));
  2569. json_object_array_add(message, comfirmpayload);
  2570. Send(message);
  2571. json_object_put(message);
  2572. return result;
  2573. }
  2574. int sendResetConfirmation(char *uuid,char *payload)
  2575. {
  2576. int result = FAIL;
  2577. struct json_object *message, *comfirmpayload;
  2578. printf("sendResetConfirmation\n");
  2579. message = json_object_new_array();
  2580. comfirmpayload = json_object_new_object();
  2581. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2582. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2583. json_object_array_add(message, json_object_new_string(uuid));
  2584. json_object_array_add(message, comfirmpayload);
  2585. Send(message);
  2586. json_object_put(message);
  2587. return result;
  2588. }
  2589. int sendSendLocalListConfirmation(char *uuid,char *payload)
  2590. {
  2591. int result = FAIL;
  2592. struct json_object *message, *comfirmpayload;
  2593. printf("handle sendSendLocalListConfirmation\n");
  2594. message = json_object_new_array();
  2595. comfirmpayload = json_object_new_object();
  2596. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2597. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2598. json_object_array_add(message, json_object_new_string(uuid));
  2599. json_object_array_add(message, comfirmpayload);
  2600. Send(message);
  2601. json_object_put(message);
  2602. return result;
  2603. }
  2604. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  2605. {
  2606. int result = FAIL;
  2607. printf("handleSetChargingProfileRequest\n");
  2608. struct json_object *message, *comfirmpayload;
  2609. message = json_object_new_array();
  2610. comfirmpayload = json_object_new_object();
  2611. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2612. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2613. json_object_array_add(message, json_object_new_string(uuid));
  2614. json_object_array_add(message, comfirmpayload);
  2615. Send(message);
  2616. json_object_put(message);
  2617. return result;
  2618. }
  2619. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  2620. {
  2621. int result = FAIL;
  2622. printf("sendTriggerMessageConfirmation\n");
  2623. struct json_object *message, *comfirmpayload;
  2624. message = json_object_new_array();
  2625. comfirmpayload = json_object_new_object();
  2626. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2627. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2628. json_object_array_add(message, json_object_new_string(uuid));
  2629. json_object_array_add(message, comfirmpayload);
  2630. Send(message);
  2631. json_object_put(message);
  2632. return result;
  2633. }
  2634. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  2635. {
  2636. int result = FAIL;
  2637. printf("sendUnlockConnectorConfirmation\n");
  2638. struct json_object *message, *comfirmpayload;
  2639. message = json_object_new_array();
  2640. comfirmpayload = json_object_new_object();
  2641. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2642. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2643. json_object_array_add(message, json_object_new_string(uuid));
  2644. json_object_array_add(message, comfirmpayload);
  2645. Send(message);
  2646. json_object_put(message);
  2647. return result;
  2648. }
  2649. int sendUpdateFirmwareConfirmation(char *uuid)
  2650. {
  2651. int result = FAIL;
  2652. printf("sendUpdateFirmwareConfirmation\n");
  2653. struct json_object *message, *comfirmpayload;
  2654. message = json_object_new_array();
  2655. comfirmpayload = json_object_new_object();
  2656. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2657. json_object_array_add(message, json_object_new_string(uuid));
  2658. json_object_array_add(message, comfirmpayload);
  2659. Send(message);
  2660. json_object_put(message);
  2661. return result;
  2662. }
  2663. //==========================================
  2664. // send CallError routine
  2665. //==========================================
  2666. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  2667. {
  2668. #ifdef SystemLogMessage
  2669. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  2670. uniqueId, action, errorCode, errorDescription);
  2671. #endif
  2672. printf("SendCallError\n");
  2673. struct json_object *message/*, *comfirmpayload*/;
  2674. message = json_object_new_array();
  2675. //comfirmpayload = json_object_new_object();
  2676. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLERROR));
  2677. json_object_array_add(message, json_object_new_string(uniqueId));
  2678. json_object_array_add(message, json_object_new_string(errorCode));
  2679. json_object_array_add(message, json_object_new_string(errorDescription));
  2680. json_object_array_add(message, json_object_new_string("{}"));
  2681. Send(message);
  2682. json_object_put(message);
  2683. }
  2684. //==========================================
  2685. // Handle server request routine Start
  2686. //==========================================
  2687. #define GUN_NUM 1
  2688. int handleCancelReservationRequest(char *uuid, char *payload)
  2689. {
  2690. int result = FAIL;
  2691. int gunNO = 0;
  2692. struct json_object *obj, *reservationId;
  2693. int reservationIdInt =0;
  2694. char comfirmstr[20];
  2695. obj = json_tokener_parse(payload);
  2696. printf("handle CancelReservationRequest\n");
  2697. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  2698. reservationId = json_object_object_get(obj, "reservationId");
  2699. reservationIdInt = json_object_get_int(reservationId);
  2700. memset(comfirmstr, 0, sizeof comfirmstr);
  2701. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  2702. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  2703. //check Transaction active
  2704. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2705. {
  2706. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  2707. {
  2708. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  2709. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  2710. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  2711. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  2712. }
  2713. }
  2714. for (int index = 0; index < CCS_QUANTITY; index++)
  2715. {
  2716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  2717. {
  2718. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  2719. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  2720. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  2721. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  2722. }
  2723. }
  2724. for (int index = 0; index < GB_QUANTITY; index++)
  2725. {
  2726. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  2727. {
  2728. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  2729. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  2730. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  2731. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  2732. }
  2733. }
  2734. // Fill in ocpp packet uuid
  2735. strcpy(ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  2736. json_object_put(obj);
  2737. #if 0 // CSU Will do it.
  2738. sendCancelReservationConfirmation(uuid, comfirmstr);
  2739. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationConf = 1;
  2740. #endif
  2741. return result;
  2742. }
  2743. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  2744. {
  2745. int result = FAIL;
  2746. int gunIndex = 0;
  2747. struct json_object *obj, *connectorId, *type;
  2748. char comfirmstr[20];
  2749. int specificId = FALSE;
  2750. obj = json_tokener_parse(payload);
  2751. printf("handle ChangeAvailabilityRequest\n");
  2752. connectorId = json_object_object_get(obj, "connectorId");
  2753. type = json_object_object_get(obj, "type");
  2754. gunIndex = json_object_get_int(connectorId);
  2755. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  2756. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", json_object_get_string(type) );
  2757. memset(comfirmstr, 0, sizeof comfirmstr);
  2758. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  2759. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  2760. if((gunIndex == 0) || ((gunIndex - 1) < (CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)))
  2761. {
  2762. specificId = TRUE;
  2763. }
  2764. if(specificId == FALSE)
  2765. goto end;
  2766. /*
  2767. enum _SYSTEM_STATUS
  2768. {
  2769. S_BOOTING = 0,
  2770. S_IDLE, = 1
  2771. S_AUTHORIZING, =2
  2772. S_REASSIGN_CHECK, =3
  2773. S_REASSIGN, =4
  2774. S_PRECHARGE, =5
  2775. S_PREPARING_FOR_EV, =6
  2776. S_PREPARING_FOR_EVSE, =7
  2777. S_CHARGING, =8
  2778. S_TERMINATING, =9
  2779. S_COMPLETE, =10
  2780. S_ALARM, =11
  2781. S_FAULT =12
  2782. }
  2783. */
  2784. if(strcmp((const char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, AvailabilityTypeStr[Inoperative]) == 0)
  2785. {
  2786. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  2787. //check Transaction active
  2788. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2789. {
  2790. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  2791. {
  2792. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 5) // S_PRECHARGE
  2793. {
  2794. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  2795. }
  2796. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8) // S_CHARGING
  2797. {
  2798. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  2799. }
  2800. else
  2801. {
  2802. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  2803. }
  2804. goto end;
  2805. }
  2806. }
  2807. for (int index = 0; index < CCS_QUANTITY; index++)
  2808. {
  2809. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  2810. {
  2811. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 5)// S_PRECHARGE
  2812. {
  2813. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  2814. }
  2815. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8) // S_CHARGING
  2816. {
  2817. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  2818. }
  2819. else
  2820. {
  2821. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  2822. }
  2823. goto end;
  2824. }
  2825. }
  2826. for (int index = 0; index < GB_QUANTITY; index++)
  2827. {
  2828. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  2829. {
  2830. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 5) // S_PRECHARGE
  2831. {
  2832. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  2833. }
  2834. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8) // S_CHARGING
  2835. {
  2836. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  2837. }
  2838. else
  2839. {
  2840. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  2841. }
  2842. goto end;
  2843. }
  2844. }
  2845. }
  2846. if(strcmp((const char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, AvailabilityTypeStr[Operative]) == 0)
  2847. {
  2848. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  2849. //check Transaction active
  2850. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2851. {
  2852. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 12)) //S_FAULT
  2853. {
  2854. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  2855. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  2856. goto end;
  2857. }
  2858. }
  2859. for (int index = 0; index < CCS_QUANTITY; index++)
  2860. {
  2861. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 12)) //S_FAULT
  2862. {
  2863. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  2864. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  2865. goto end;
  2866. }
  2867. }
  2868. for (int index = 0; index < GB_QUANTITY; index++)
  2869. {
  2870. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 12)) //S_FAULT
  2871. {
  2872. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  2873. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  2874. goto end;
  2875. }
  2876. }
  2877. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  2878. }
  2879. end:
  2880. json_object_put(obj);
  2881. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  2882. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  2883. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  2884. return result;
  2885. }
  2886. int handleChangeConfigurationRequest(char *uuid, char *payload)
  2887. {
  2888. int result = FAIL;
  2889. char comfirmstr[20];
  2890. printf("handle ChangeConfigurationRequest\n");
  2891. struct json_object *obj, *key, *value;
  2892. char *keystr, *valuestr;
  2893. obj = json_tokener_parse(payload);
  2894. key = json_object_object_get(obj, "key");
  2895. value = json_object_object_get(obj, "value");
  2896. keystr= json_object_get_string(key);
  2897. valuestr = json_object_get_string(value);
  2898. if((uuid==NULL) || (payload ==NULL) )
  2899. {
  2900. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  2901. }
  2902. else
  2903. {
  2904. int status = setKeyValue(keystr, valuestr);
  2905. switch(status)
  2906. {
  2907. case ConfigurationStatus_Accepted:
  2908. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  2909. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  2910. break;
  2911. case ConfigurationStatus_Rejected:
  2912. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  2913. break;
  2914. case RebootRequired:
  2915. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  2916. break;
  2917. case NotSupported:
  2918. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  2919. break;
  2920. default:
  2921. break;
  2922. }
  2923. }
  2924. if(errno >=1)
  2925. {
  2926. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  2927. fprintf(stderr,"%d %s\\n",errno,strerror(errno));
  2928. }
  2929. //confirmation.setStatus(ConfigurationStatus.Rejected);
  2930. json_object_put(obj);
  2931. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  2932. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  2933. return result;
  2934. }
  2935. int handleClearCacheRequest(char *uuid, char *payload)
  2936. {
  2937. int result = FAIL;
  2938. char comfirmstr[20];
  2939. int fd;
  2940. printf("handle ClearCacheRequest\n");
  2941. /* ?��?一个�?�*/
  2942. fd = open(AuthorizationCache_JSON,O_RDWR);
  2943. if(fd < 0)
  2944. {
  2945. printf("open AuthorizationCache file failed\n");
  2946. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  2947. }
  2948. else
  2949. {
  2950. printf("open AuthorizationCache file successful\n");
  2951. /* 清空?�件 */
  2952. ftruncate(fd,0);
  2953. /* ?�新设置?�件?�移??*/
  2954. lseek(fd,0,SEEK_SET);
  2955. close(fd);
  2956. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  2957. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  2958. }
  2959. sendClearCacheConfirmation(uuid, comfirmstr);
  2960. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  2961. return result;
  2962. }
  2963. int handleClearChargingProfileRequest(char *uuid, char *payload)
  2964. {
  2965. int result = FAIL;
  2966. struct json_object *obj, *connectorId, *csChargingProfiles, *chargingProfileId, *stackLevel, *chargingProfilePurpose;
  2967. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  2968. const char*chargingProfilePurposeStr;
  2969. struct json_object *tempobj, *tempconnectorId, *tempcsChargingProfiles, *tempchargingProfileId, *tempstackLevel, *tempchargingProfilePurpose;
  2970. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  2971. char *tempchargingProfilePurposeStr;
  2972. char fname[200];
  2973. json_object *test_obj = NULL;
  2974. json_object *tmp_obj = NULL;
  2975. struct array_list *json_list;
  2976. struct json_object *jsonitem;
  2977. char comfirmstr[20];
  2978. size_t n_friends;
  2979. int clearflag = FALSE;
  2980. FILE *fptr1, *fptr2;
  2981. char temp[] = "temp.json";
  2982. struct json_object *newHeatMap = json_object_new_array();
  2983. obj = json_tokener_parse(payload);
  2984. printf("handle ClearChargingProfileRequest\n");
  2985. connectorId = json_object_object_get(obj, "connectorId");
  2986. chargingProfileId = json_object_object_get(obj, "id");
  2987. stackLevel = json_object_object_get(obj, "stackLevel");
  2988. chargingProfilePurpose = json_object_object_get(obj, "chargingProfilePurpose");
  2989. printf("handle ClearChargingProfileRequest error 1\n");
  2990. if(connectorId != NULL)
  2991. connectorIdInt = json_object_get_int(connectorId);
  2992. if(chargingProfileId != NULL)
  2993. chargingProfileIdInt = json_object_get_int(chargingProfileId);
  2994. if(stackLevel != NULL)
  2995. stackLevelInt = json_object_get_int(stackLevel);
  2996. if(chargingProfilePurpose != NULL)
  2997. chargingProfilePurposeStr = json_object_get_string(chargingProfilePurpose);
  2998. printf("handle ClearChargingProfileRequest error 2\n");
  2999. if(connectorId != NULL)
  3000. {
  3001. switch(connectorIdInt)
  3002. {
  3003. case 0:
  3004. strcpy(fname, ChargingProfile_0_JSON );
  3005. break;
  3006. case 1:
  3007. strcpy(fname, ChargingProfile_1_JSON );
  3008. break;
  3009. case 2:
  3010. strcpy(fname, ChargingProfile_2_JSON );
  3011. break;
  3012. default:
  3013. strcpy(fname, ChargingProfile_0_JSON );
  3014. break;
  3015. }
  3016. }
  3017. else
  3018. {
  3019. strcpy(fname, ChargingProfile_0_JSON );
  3020. }
  3021. printf("handle ClearChargingProfileRequest error 3\n");
  3022. fptr1 = fopen(fname, "r");
  3023. if (!fptr1)
  3024. {
  3025. //file not exist
  3026. printf("Unable to open the input file!!\n");
  3027. fptr1 = fopen(fname, "w+");
  3028. }
  3029. fclose(fptr1);
  3030. printf("handle ClearChargingProfileRequest error 4\n");
  3031. if(connectorId != NULL && (connectorIdInt != 0) && ( (connectorIdInt-1) > (CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY) ) )
  3032. {
  3033. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3034. goto end;
  3035. }
  3036. //get json object from file
  3037. test_obj = json_object_from_file(fname);
  3038. printf("handle ClearChargingProfileRequest error 5\n");
  3039. if(json_object_get_type(test_obj) == json_type_array)
  3040. {
  3041. //
  3042. if(connectorId == NULL || connectorIdInt == 0 )
  3043. {
  3044. printf("handle ClearChargingProfileRequest error 6\n");
  3045. //clear the whole contents of a file in C
  3046. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3047. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3048. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3049. printf("handle ClearChargingProfileRequest error 7\n");
  3050. }
  3051. else
  3052. {
  3053. printf("handle ClearChargingProfileRequest error 8\n");
  3054. n_friends = json_object_array_length(test_obj);
  3055. printf("Found %lu friends\n",n_friends);
  3056. for(int i=0;i<n_friends;i++)
  3057. {
  3058. jsonitem = json_object_array_get_idx(test_obj, i);
  3059. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  3060. tempconnectorId = json_object_object_get(jsonitem, "connectorId");
  3061. tempcsChargingProfiles = json_object_object_get(jsonitem, "csChargingProfiles");
  3062. tempchargingProfileId = json_object_object_get(tempcsChargingProfiles, "chargingProfileId");
  3063. tempstackLevel = json_object_object_get(tempcsChargingProfiles, "stackLevel");
  3064. tempchargingProfilePurpose = json_object_object_get(tempcsChargingProfiles, "chargingProfilePurpose");
  3065. tempconnectorIdInt = json_object_get_int(tempconnectorId);
  3066. tempchargingProfileIdInt = json_object_get_int(tempchargingProfileId);
  3067. tempstackLevelInt = json_object_get_int(tempstackLevel);
  3068. tempchargingProfilePurposeStr = (char *)json_object_get_string(tempchargingProfilePurpose);
  3069. if(chargingProfileId != NULL)
  3070. {
  3071. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3072. {
  3073. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3074. clearflag = TRUE;
  3075. continue;
  3076. }
  3077. else
  3078. {
  3079. json_object_array_add(newHeatMap, jsonitem);
  3080. }
  3081. }
  3082. else
  3083. {
  3084. if((tempconnectorIdInt == connectorIdInt) && ((tempchargingProfileIdInt == chargingProfileIdInt) || (tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3085. {
  3086. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3087. clearflag = TRUE;
  3088. continue;
  3089. }
  3090. else
  3091. {
  3092. json_object_array_add(newHeatMap, jsonitem);
  3093. }
  3094. }
  3095. }
  3096. printf("handle ClearChargingProfileRequest error 9\n");
  3097. if(clearflag == FALSE)
  3098. {
  3099. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3100. goto end;
  3101. }
  3102. }
  3103. FILE *fp;
  3104. fp=fopen(temp,"w");
  3105. fclose(fp);
  3106. remove(fname);
  3107. rename(temp, fname);
  3108. json_object_to_file(fname, newHeatMap);
  3109. printf("handle ClearChargingProfileRequest error 12\n");
  3110. }
  3111. else
  3112. {
  3113. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3114. printf("handle ClearChargingProfileRequest error 13\n");
  3115. }
  3116. end:
  3117. json_object_put(obj);
  3118. printf("handle ClearChargingProfileRequest error 14\n");
  3119. json_object_put(test_obj);
  3120. printf("handle ClearChargingProfileRequest error 15\n");
  3121. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3122. return result;
  3123. }
  3124. int handleDataTransferRequest(char *uuid, char *payload)
  3125. {
  3126. int result = FAIL;
  3127. struct json_object *obj;
  3128. obj = json_tokener_parse(payload);
  3129. printf("handle DataTransferRequest\n");
  3130. return result;
  3131. }
  3132. long long diff_tm(struct tm *a, struct tm *b) {
  3133. return a->tm_sec - b->tm_sec
  3134. + 60LL * (a->tm_min - b->tm_min)
  3135. + 3600LL * (a->tm_hour - b->tm_hour)
  3136. + 86400LL * (a->tm_yday - b->tm_yday)
  3137. + (a->tm_year - 70) * 31536000LL
  3138. - (a->tm_year - 69) / 4 * 86400LL
  3139. + (a->tm_year - 1) / 100 * 86400LL
  3140. - (a->tm_year + 299) / 400 * 86400LL
  3141. - (b->tm_year - 70) * 31536000LL
  3142. + (b->tm_year - 69) / 4 * 86400LL
  3143. - (b->tm_year - 1) / 100 * 86400LL
  3144. + (b->tm_year + 299) /400 * 86400LL;
  3145. }
  3146. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  3147. {
  3148. int result = FAIL;
  3149. struct json_object *obj, *connectorId, *duration, *chargingRateUnit;
  3150. int connectorIdInt, durationInt;
  3151. const char*chargingRateUnitStr;
  3152. struct json_object *tempobj, *tempconnectorId, *tempcsChargingProfiles, *tempvalidFrom,*tempChargingSchedule, *tempstartSchedule, *tempchargingSchedulePeriod, *tempminChargingRate;
  3153. int tempconnectorIdInt, tempdurationInt;
  3154. float tempminChargingRateFloat = 0.0;
  3155. char *tempvalidFromStr,*tempchargingRateUnitStr, *tempstartScheduleStr;
  3156. char fname[200];
  3157. json_object *test_obj = NULL;
  3158. json_object *tmp_obj = NULL;
  3159. struct array_list *json_list;
  3160. struct json_object *jsonitem;
  3161. char comfirmstr[20];
  3162. size_t n_friends;
  3163. float totallimit =0.0;
  3164. float MinChargingRate =0.0;
  3165. int clearflag = FALSE;
  3166. int n_periods = 0;
  3167. int nPeriod = 0;
  3168. FILE *fptr1, *fptr2;
  3169. char temp[] = "temp.json";
  3170. struct json_object *newHeatMap = json_object_new_array();
  3171. printf("handle GetCompositeScheduleRequest\n");
  3172. obj = json_tokener_parse(payload);
  3173. connectorId = json_object_object_get(obj, "connectorId");
  3174. duration = json_object_object_get(obj, "duration");
  3175. chargingRateUnit = json_object_object_get(obj, "chargingRateUnit");
  3176. connectorIdInt = json_object_get_int(connectorId);
  3177. durationInt = json_object_get_int(duration);
  3178. if(chargingRateUnit != NULL)
  3179. chargingRateUnitStr = json_object_get_string(chargingRateUnit);
  3180. // current time
  3181. time_t t = time(NULL);
  3182. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)* (CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY) );
  3183. if(connectorIdInt==0) // connectorId is 0
  3184. {
  3185. strcpy(fname, ChargingProfile_0_JSON );
  3186. test_obj = NULL;
  3187. test_obj = json_object_from_file(fname);
  3188. n_friends = 0;
  3189. n_friends = json_object_array_length(test_obj);
  3190. printf("Found %lu friends\n",n_friends);
  3191. for(int i=0;i<n_friends;i++)
  3192. {
  3193. printf("handle GetCompositeScheduleRequest -1\n");
  3194. jsonitem = json_object_array_get_idx(test_obj, i);
  3195. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  3196. printf("handle GetCompositeScheduleRequest -2\n");
  3197. tempconnectorId = json_object_object_get(jsonitem, "connectorId");
  3198. tempcsChargingProfiles = json_object_object_get(jsonitem, "csChargingProfiles");
  3199. tempvalidFrom = json_object_object_get(tempcsChargingProfiles, "validFrom");
  3200. tempChargingSchedule = json_object_object_get(tempcsChargingProfiles, "chargingSchedule");
  3201. printf("handle GetCompositeScheduleRequest -3\n");
  3202. tempstartSchedule = json_object_object_get(tempChargingSchedule, "startSchedule");
  3203. tempminChargingRate = json_object_object_get(tempstartSchedule, "minChargingRate");
  3204. printf("handle GetCompositeScheduleRequest -4n");
  3205. tempminChargingRateFloat = (float)json_object_get_double(tempminChargingRate);
  3206. tempchargingSchedulePeriod = json_object_object_get(tempChargingSchedule, "chargingSchedulePeriod");
  3207. tempstartScheduleStr = (char *)json_object_get_string(tempstartSchedule);
  3208. printf("handle GetCompositeScheduleRequest -5\n");
  3209. tempvalidFromStr = (char *)json_object_get_string(tempvalidFrom);
  3210. double diff_t;
  3211. struct tm tp;
  3212. printf("tempstartScheduleStr 1 : %s\n", tempstartScheduleStr);
  3213. printf("handle GetCompositeScheduleRequest -6\n");
  3214. printf("tempstartScheduleStr 2 : %s\n", tempstartScheduleStr);
  3215. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3216. printf("handle GetCompositeScheduleRequest -6 -1\n");
  3217. tp.tm_isdst = -1;
  3218. printf("handle GetCompositeScheduleRequest -6 -2\n");
  3219. time_t utc = mktime(&tp);
  3220. printf("handle GetCompositeScheduleRequest -7\n");
  3221. struct tm e0 = { .tm_year = tp.tm_year, .tm_mday = tp.tm_mday, .tm_mon = tp.tm_mon, .tm_hour = tp.tm_hour, .tm_isdst = -1 };
  3222. time_t pseudo = mktime(&e0);
  3223. struct tm e1 = *gmtime(&pseudo);
  3224. e0.tm_sec += utc - diff_tm(&e1, &e0);
  3225. time_t local = e0.tm_sec;
  3226. printf("handle GetCompositeScheduleRequest -8\n");
  3227. // ?�到��??�起始�???- chargingScedule起�??��?
  3228. diff_t = difftime(t, local);
  3229. n_periods = json_object_array_length(tempchargingSchedulePeriod);
  3230. printf("handle GetCompositeScheduleRequest -9\n");
  3231. for(int i=0;i<n_periods;i++)
  3232. {
  3233. struct json_object *tempstartPeriod, *templimit, *tempnumberPhases;
  3234. jsonitem = json_object_array_get_idx(tempchargingSchedulePeriod, i);
  3235. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  3236. tempstartPeriod = json_object_object_get(jsonitem, "startPeriod");
  3237. templimit = json_object_object_get(jsonitem, "limit");
  3238. tempnumberPhases = json_object_object_get(jsonitem, "numberPhases");
  3239. int tempstartPeriodInt = json_object_get_int(tempstartPeriod);
  3240. if(diff_t >= 0)
  3241. {
  3242. diff_t = ((diff_t - tempstartPeriodInt) <=0) ? 0 : (diff_t - tempstartPeriodInt);
  3243. printf("diff_t=%d\n",diff_t);
  3244. }
  3245. float temp = (float)json_object_get_double(templimit);
  3246. if(diff_t == 0)
  3247. {
  3248. //loat temp = (float)json_object_get_double(templimit);
  3249. if(totallimit < temp)
  3250. {
  3251. totallimit = temp;
  3252. printf("totallimit=%d\n",totallimit);
  3253. }
  3254. }
  3255. }
  3256. if(MinChargingRate < tempminChargingRateFloat)
  3257. MinChargingRate = tempminChargingRateFloat;
  3258. }
  3259. printf("handle GetCompositeScheduleRequest -10\n");
  3260. /* Define temporary variables */
  3261. struct tm *gtime;
  3262. time_t now;
  3263. char buf[28];
  3264. /* Read the current system time */
  3265. printf("handle GetCompositeScheduleRequest -11\n");
  3266. time(&now);
  3267. printf("handle GetCompositeScheduleRequest -12\n");
  3268. /* Convert the system time to GMT (now UTC) */
  3269. gtime = gmtime(&now);
  3270. printf("handle GetCompositeScheduleRequest -13\n");
  3271. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  3272. printf("handle GetCompositeScheduleRequest -14\n");
  3273. // make .conf
  3274. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  3275. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* n_periods);
  3276. memset(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* n_periods);
  3277. nPeriod = 1;
  3278. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].Limit = 100.0;//totallimit;
  3279. printf("(1)ChargingSchedulePeriod[0].Limit =%d\n",ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].Limit);
  3280. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].NumberPhases = 3.0;
  3281. printf("(2)NumberPhases =%f\n",ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].NumberPhases);
  3282. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].StartPeriod = 0;
  3283. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = durationInt;
  3284. sleep(10);
  3285. printf("1.totallimit =%d\n",totallimit);
  3286. printf("2. totallimit =%d\n",ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].Limit);
  3287. printf("NumberPhases =%f\n",ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].NumberPhases);
  3288. printf("StartPeriod = %d\n",ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].StartPeriod);
  3289. printf("durationInt = %d\n",ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration);
  3290. printf("handle GetCompositeScheduleRequest -14 -1\n");
  3291. if(chargingRateUnitStr != NULL)
  3292. {
  3293. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  3294. }
  3295. else
  3296. {
  3297. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, "" );
  3298. }
  3299. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  3300. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  3301. printf("handle GetCompositeScheduleRequest -15\n");
  3302. }
  3303. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < (CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)) )
  3304. {
  3305. //connectorId is specific Id
  3306. switch(connectorIdInt)
  3307. {
  3308. case 0:
  3309. strcpy(fname, ChargingProfile_0_JSON );
  3310. break;
  3311. case 1:
  3312. strcpy(fname, ChargingProfile_1_JSON );
  3313. break;
  3314. case 2:
  3315. strcpy(fname, ChargingProfile_2_JSON );
  3316. break;
  3317. default:
  3318. strcpy(fname, ChargingProfile_0_JSON );
  3319. break;
  3320. }
  3321. //get json object from file
  3322. test_obj = json_object_from_file(fname);
  3323. n_friends = 0;
  3324. n_friends = json_object_array_length(test_obj);
  3325. printf("Found %lu friends\n",n_friends);
  3326. for(int i=0;i<n_friends;i++)
  3327. {
  3328. printf("GetCompositeScheduleRequest -1\n");
  3329. jsonitem = json_object_array_get_idx(test_obj, i);
  3330. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  3331. tempconnectorId = json_object_object_get(jsonitem, "connectorId");
  3332. tempcsChargingProfiles = json_object_object_get(jsonitem, "csChargingProfiles");
  3333. tempvalidFrom = json_object_object_get(tempcsChargingProfiles, "validFrom");
  3334. tempChargingSchedule = json_object_object_get(tempcsChargingProfiles, "ChargingSchedule");
  3335. tempstartSchedule = json_object_object_get(tempChargingSchedule, "startSchedule");
  3336. tempminChargingRate = json_object_object_get(tempChargingSchedule, "minChargingRate");
  3337. tempminChargingRateFloat = (float)json_object_get_double(tempminChargingRate);
  3338. tempchargingSchedulePeriod = json_object_object_get(tempChargingSchedule, "chargingSchedulePeriod");
  3339. tempstartScheduleStr =(char *) json_object_get_string(tempstartSchedule);
  3340. printf("GetCompositeScheduleRequest -2\n");
  3341. tempvalidFromStr = (char *)json_object_get_string(tempvalidFrom);
  3342. double diff_t;
  3343. struct tm tp;
  3344. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3345. tp.tm_isdst = -1;
  3346. time_t utc = mktime(&tp);
  3347. struct tm e0 = { .tm_year = tp.tm_year, .tm_mday = tp.tm_mday, .tm_mon = tp.tm_mon, .tm_hour = tp.tm_hour, .tm_isdst = -1 };
  3348. time_t pseudo = mktime(&e0);
  3349. struct tm e1 = *gmtime(&pseudo);
  3350. e0.tm_sec += utc - diff_tm(&e1, &e0);
  3351. time_t local = e0.tm_sec;
  3352. // ?�到��??�起始�???- chargingScedule起�??��?
  3353. diff_t = difftime(t, local);
  3354. n_periods = json_object_array_length(tempchargingSchedulePeriod);
  3355. nPeriod = n_periods;
  3356. printf("GetCompositeScheduleRequest -3\n");
  3357. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* nPeriod);
  3358. for(int i=0;i<n_periods;i++)
  3359. {
  3360. struct json_object *tempstartPeriod, *templimit, *tempnumberPhases;
  3361. printf("GetCompositeScheduleRequest -4\n");
  3362. jsonitem = json_object_array_get_idx(tempchargingSchedulePeriod, i);
  3363. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  3364. tempstartPeriod = json_object_object_get(jsonitem, "startPeriod");
  3365. templimit = json_object_object_get(jsonitem, "limit");
  3366. tempnumberPhases = json_object_object_get(jsonitem, "numberPhases");
  3367. int tempstartPeriodInt = json_object_get_int(tempstartPeriod);
  3368. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[i].Limit = json_object_get_int(templimit);
  3369. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[i].NumberPhases = (float)json_object_get_double(templimit);
  3370. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[i].StartPeriod = json_object_get_int(tempstartPeriod);
  3371. if(diff_t >= 0)
  3372. diff_t = ((diff_t - tempstartPeriodInt) <=0) ? 0 : (diff_t - tempstartPeriodInt);
  3373. if(diff_t < 0)
  3374. {
  3375. float temp = (float)json_object_get_double(templimit);
  3376. if(totallimit < temp)
  3377. {
  3378. totallimit = temp;
  3379. }
  3380. }
  3381. }
  3382. if(MinChargingRate < tempminChargingRateFloat)
  3383. MinChargingRate = tempminChargingRateFloat;
  3384. }
  3385. /* Define temporary variables */
  3386. struct tm *gtime;
  3387. time_t now;
  3388. char buf[28];
  3389. /* Read the current system time */
  3390. time(&now);
  3391. /* Convert the system time to GMT (now UTC) */
  3392. gtime = gmtime(&now);
  3393. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  3394. // make .conf
  3395. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  3396. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = durationInt;
  3397. if(chargingRateUnitStr != NULL)
  3398. {
  3399. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  3400. }
  3401. else
  3402. {
  3403. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, "" );
  3404. }
  3405. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  3406. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  3407. }
  3408. else
  3409. {
  3410. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  3411. }
  3412. json_object_put(obj);
  3413. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, nPeriod);
  3414. return result;
  3415. }
  3416. int handleGetConfigurationRequest(char *uuid, char *payload)
  3417. {
  3418. int result = FAIL;
  3419. struct json_object *obj, *key, *test_obj, *jsonitem;
  3420. int MaxKeySupported = 0;
  3421. obj = json_tokener_parse(payload);
  3422. printf("handle GetConfigurationRequest\n");
  3423. key = json_object_object_get(obj, "key");
  3424. int n_keys = json_object_array_length(key);
  3425. UnknownKeynum = 0;
  3426. memset( (void *)unknownkey, 0, sizeof(int)*10*20 );
  3427. MaxKeySupported = atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3428. if(ShmOCPP16Data->GetConfiguration.Key == NULL)
  3429. {
  3430. ShmOCPP16Data->GetConfiguration.Key = (struct StructConfigurationKeyItems *)malloc(sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  3431. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  3432. printf("memset 0 for GetConfiguration table \n");
  3433. }
  3434. else
  3435. {
  3436. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  3437. }
  3438. if(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey == NULL)
  3439. {
  3440. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = (struct StructConfigurationKey *)malloc(sizeof(struct StructConfigurationKey)*MaxKeySupported);
  3441. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  3442. }
  3443. else
  3444. {
  3445. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  3446. }
  3447. if(n_keys != 0)
  3448. {
  3449. printf("key sent num=%d\n",n_keys);
  3450. for(int i=0;i<n_keys;i++)
  3451. {
  3452. printf("test test 1\n");
  3453. jsonitem = json_object_array_get_idx(key, i);
  3454. printf("test test 2\n");
  3455. getKeyValue((char *)json_object_get_string(jsonitem));
  3456. printf("test test 3\n");
  3457. }
  3458. }
  3459. else
  3460. {
  3461. printf("no key sent, get all configuration\n");
  3462. getKeyValue("");
  3463. }
  3464. printf("test test 4\n");
  3465. processUnkownKey();
  3466. printf("test test 5\n");
  3467. //ShmOCPP16Data->MsMsg.bits.GetConfigurationReq = 1;
  3468. json_object_put(obj);
  3469. printf("test test 6\n");
  3470. sendGetConfigurationConfirmation(uuid);
  3471. printf("test test 7\n");
  3472. //ShmOCPP16Data->MsMsg.bits.GetConfigurationConf = 1;
  3473. return result;
  3474. }
  3475. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  3476. {
  3477. int result = FAIL;
  3478. void *ret; // �執行�??��???
  3479. pthread_t t; // �? pthread 變數
  3480. pthread_create(&t, NULL, GetDiagnosticsProcess, payload); // 建�?�執行�?
  3481. pthread_join(t, &ret);
  3482. // ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = 1;
  3483. //sendGetDiagnosticsConfirmation(uuid,fname);
  3484. sendGetDiagnosticsConfirmation(uuid,(char*) ret);
  3485. // ShmOCPP16Data->MsMsg.bits.GetDiagnosticsConf = 1;
  3486. return result;
  3487. }
  3488. void* GetDiagnosticsProcess(void* data)
  3489. {
  3490. struct json_object *obj, *location , *retries, *retryInterval , *startTime , *stopTime;
  3491. int retriesInt=0, retryIntervalInt=0;
  3492. const char *locationstr, *startTimestr, *stopTimestr ;
  3493. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[50];
  3494. int port=0;
  3495. char fname[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  3496. char *str = (char*) data; // ?��?輸入資�?
  3497. int isSuccess = FALSE;
  3498. char ftpbuf[200];
  3499. char temp[100];
  3500. char * pch;
  3501. obj = json_tokener_parse(str);
  3502. printf("handle GetDiagnosticsRequest\n");
  3503. location = json_object_object_get(obj, "location");
  3504. retries = json_object_object_get(obj, "retries");
  3505. retryInterval = json_object_object_get(obj, "retryInterval");
  3506. startTime = json_object_object_get(obj, "startTime");
  3507. stopTime = json_object_object_get(obj, "stopTime");
  3508. locationstr = json_object_get_string(location);
  3509. if(retries != NULL)
  3510. retriesInt = json_object_get_int(retries);
  3511. if(retryInterval != NULL)
  3512. retryIntervalInt = json_object_get_int(retryInterval);
  3513. if(startTime != NULL)
  3514. startTimestr = json_object_get_string(startTime);
  3515. if(stopTime != NULL)
  3516. stopTimestr = json_object_get_string(stopTime);
  3517. printf("handle GetDiagnosticsRequest -1\n");
  3518. memset(protocol, 0, sizeof(protocol));
  3519. memset(user, 0, sizeof(user) );
  3520. memset(password, 0, sizeof(password));
  3521. memset(host, 0, sizeof(host));
  3522. memset(path, 0, sizeof(path));
  3523. memset(ftppath, 0, sizeof(ftppath));
  3524. memset(host1, 0, sizeof(host1));
  3525. memset(path1, 0, sizeof(path1));
  3526. /*location: ftp://user:password@host:port/path*/
  3527. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  3528. // protocol, user, password, host, &port, path);
  3529. //zip files in /Storage
  3530. system("exec /root/logPackTools 'log' 6");
  3531. time_t rawtime;
  3532. struct tm * timeinfo;
  3533. //char buffer [128];
  3534. time (&rawtime);
  3535. //printf("%ld\n", rawtime);
  3536. timeinfo = localtime (&rawtime);
  3537. strftime (fname,sizeof(fname),"/mnt/%4Y_%2m.zip",timeinfo);
  3538. if((access(fname,F_OK))!=-1)
  3539. {
  3540. printf("?‡ä»¶ test.c exist.\n");
  3541. }
  3542. else
  3543. {
  3544. printf("test.c not exist!\n");
  3545. goto end;
  3546. }
  3547. pch=strchr(locationstr,'@');
  3548. if(pch==NULL)
  3549. {
  3550. sscanf(locationstr,
  3551. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  3552. protocol, host, &port, path);
  3553. strcpy(user,"anonymous");
  3554. strcpy(password,"");
  3555. }
  3556. else
  3557. {
  3558. printf("pch=%s\n", pch);
  3559. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  3560. protocol, user, password, host, &port, path);
  3561. }
  3562. sscanf(host,"%[^/]%s",host1, path1);
  3563. sprintf(ftppath,"%s", path1);
  3564. printf("protocol =%s\n",protocol);
  3565. printf("user =%s\n",user);
  3566. printf("password =%s\n",password);
  3567. printf("host1 =%s\n",host1);
  3568. printf("port =%d\n",port);
  3569. printf("path1 =%s\n",path1);
  3570. printf("ftppath=%s\n",ftppath);
  3571. int ftppathlen=strlen(ftppath);
  3572. int i=1;
  3573. char filenametemp[50];
  3574. while(i < ftppathlen)
  3575. {
  3576. printf("ftppath[ftppathlen-i]:%c\n",ftppath[ftppathlen-i]);
  3577. int len=ftppathlen-i;
  3578. if(ftppath[len]== 47) // '/' ascll code: 47
  3579. {
  3580. printf("all right\n");
  3581. break;
  3582. }
  3583. printf("test substr\n");
  3584. i=i+1;
  3585. }
  3586. memset(filenametemp, 0, sizeof(filenametemp));
  3587. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  3588. filenametemp[i+1] = 0;
  3589. printf("filenametemp:%s\n", filenametemp);
  3590. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  3591. //httpDownLoadFile(host, ftppath, fname);
  3592. memset(ftpbuf, 0, sizeof(ftpbuf));
  3593. if(port == 0)
  3594. port = 21;
  3595. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  3596. do{
  3597. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fname);
  3598. sleep(retryIntervalInt);
  3599. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  3600. if(!isSuccess)
  3601. {
  3602. //BulldogUtil.sleepMs(interval*1000);
  3603. printf("Update firmware request and download file fail.\n");
  3604. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  3605. }
  3606. else
  3607. {
  3608. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  3609. isUpdateRequest = TRUE;
  3610. }
  3611. end:
  3612. json_object_put(obj);
  3613. pthread_exit((void *) fname); // ?��?�執行�?
  3614. }
  3615. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  3616. {
  3617. int result = FAIL;
  3618. printf("handle GetLocalListVersionRequest\n");
  3619. if(strcmp(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  3620. {
  3621. localversion = -1;
  3622. }
  3623. else
  3624. {
  3625. OCPP_getListVerion();
  3626. }
  3627. //from db.OCPP_getListVerion
  3628. printf("handle GetLocalListVersionRequest -1\n");
  3629. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  3630. printf("handle GetLocalListVersionRequest -2\n");
  3631. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  3632. sendGetLocalListVersionConfirmation(uuid,"");
  3633. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  3634. return result;
  3635. }
  3636. int handleRemoteStartRequest(char *uuid, char *payload)
  3637. {
  3638. int result = FAIL;
  3639. struct json_object *obj, *connectorId, *idTag, *chargingProfile,
  3640. *chargingProfileId, *transactionId, *stackLevel,
  3641. *chargingProfilePurpose, *chargingProfileKind,
  3642. *recurrencyKind, *validFrom, *validTo, *chargingSchedule,
  3643. *duration, *startSchedule, *chargingRateUnit, *chargingSchedulePeriod,
  3644. *minChargingRate,*limit, *startPeriod, *numberPhases;
  3645. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  3646. durationInt=0, startPeriodInt =0, numberPhasesInt=0;
  3647. char *idTagstr, *chargingProfilePurposestr, *chargingProfileKindstr, *recurrencyKindstr,
  3648. *validFromstr, *validTostr, *startSchedulestr, *chargingRateUnitstr, *chargingSchedulePeriodstr;
  3649. float minChargingRateflaot=0.0, limitflaot=0.0;
  3650. char comfirmstr[20];
  3651. if(server_pending == TRUE)
  3652. {
  3653. return 0;
  3654. }
  3655. obj = json_tokener_parse(payload);
  3656. printf("handleRemoteStartRequest\n");
  3657. connectorId = json_object_object_get(obj, "connectorId");
  3658. idTag = json_object_object_get(obj, "idTag");
  3659. chargingProfile = json_object_object_get(obj, "chargingProfile");
  3660. if(connectorId != NULL)
  3661. {
  3662. connectorIdInt = json_object_get_int(connectorId);
  3663. }
  3664. else
  3665. {
  3666. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3667. goto end;
  3668. }
  3669. idTagstr = (char *)json_object_get_string(idTag);
  3670. if(chargingProfile != NULL)
  3671. {
  3672. chargingProfileId = json_object_object_get(chargingProfile, "chargingProfileId");
  3673. transactionId = json_object_object_get(chargingProfile, "transactionId");
  3674. stackLevel = json_object_object_get(chargingProfile, "stackLevel");
  3675. chargingProfilePurpose = json_object_object_get(chargingProfile, "chargingProfilePurpose");
  3676. chargingProfileKind = json_object_object_get(chargingProfile, "chargingProfileKind");
  3677. recurrencyKind = json_object_object_get(chargingProfile, "recurrencyKind");
  3678. validFrom = json_object_object_get(chargingProfile, "validFrom");
  3679. validTo = json_object_object_get(chargingProfile, "validTo");
  3680. chargingSchedule = json_object_object_get(chargingProfile, "chargingSchedule");
  3681. chargingProfileIdInt = json_object_get_int(chargingProfileId);
  3682. if(transactionId != NULL) // OPTION
  3683. transactionIdInt = json_object_get_int(transactionId);
  3684. stackLevelInt = json_object_get_int(stackLevel);
  3685. chargingProfilePurposestr =(char *)json_object_get_string(chargingProfilePurpose);
  3686. chargingProfileKindstr = (char *)json_object_get_string(chargingProfileKind);
  3687. if(recurrencyKind != NULL) //OPTION
  3688. recurrencyKindstr = (char *)json_object_get_string(recurrencyKind);
  3689. if(validFrom != NULL) // OPTION
  3690. validFromstr = (char *)json_object_get_string(validFrom);
  3691. if(validTo != NULL) //OPTION
  3692. validTostr = (char *)json_object_get_string(validTo);
  3693. duration = json_object_object_get(chargingSchedule, "duration");
  3694. startSchedule = json_object_object_get(chargingSchedule, "startSchedule");
  3695. chargingRateUnit = json_object_object_get(chargingSchedule, "chargingRateUnit");
  3696. chargingSchedulePeriod = json_object_object_get(chargingSchedule, "chargingSchedulePeriod");
  3697. minChargingRate = json_object_object_get(chargingSchedule, "minChargingRate");
  3698. if(duration != NULL) //OPTION
  3699. durationInt = json_object_get_int(duration);
  3700. if(startSchedule != NULL) //OPTION
  3701. startSchedulestr = (char *)json_object_get_string(startSchedule);
  3702. chargingRateUnitstr = (char *)json_object_get_string(chargingRateUnit);
  3703. chargingSchedulePeriodstr = (char *)json_object_get_string(chargingSchedulePeriod);
  3704. if(minChargingRate != NULL) //OPTION
  3705. minChargingRateflaot = (float)json_object_get_double(minChargingRate);
  3706. limit = json_object_object_get(chargingSchedulePeriod, "limit");
  3707. startPeriod = json_object_object_get(chargingSchedulePeriod, "startPeriod");
  3708. numberPhases = json_object_object_get(chargingSchedulePeriod, "numberPhases");
  3709. startPeriodInt = json_object_get_int(startPeriod);
  3710. limitflaot = (float)json_object_get_double(limit);
  3711. if(numberPhases != NULL)
  3712. numberPhasesInt = json_object_get_int(numberPhases);
  3713. }
  3714. /*
  3715. enum _SYSTEM_STATUS
  3716. {
  3717. S_BOOTING = 0,
  3718. S_IDLE, = 1
  3719. S_AUTHORIZING, =2
  3720. S_REASSIGN_CHECK, =3
  3721. S_REASSIGN, =4
  3722. S_PRECHARGE, =5
  3723. S_PREPARING_FOR_EV, =6
  3724. S_PREPARING_FOR_EVSE, =7
  3725. S_CHARGING, =8
  3726. S_TERMINATING, =9
  3727. S_COMPLETE, =10
  3728. S_ALARM, =11
  3729. S_FAULT =12
  3730. }
  3731. */
  3732. if((connectorId != NULL)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)))
  3733. {
  3734. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  3735. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  3736. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  3737. //check Transaction active
  3738. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3739. {
  3740. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  3741. {
  3742. if((1/*?�ç??—æ?*//*ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '8'*/)&&(strcmp(ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  3743. {
  3744. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[connectorIdInt-1].SystemStatus = 8; //S_CHARGING
  3745. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3746. }
  3747. else
  3748. {
  3749. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 1) //S_IDLE
  3750. {
  3751. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3752. goto end;
  3753. }
  3754. }
  3755. }
  3756. }
  3757. for (int index = 0; index < CCS_QUANTITY; index++)
  3758. {
  3759. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  3760. {
  3761. if((1/*?�ç??—æ?*//*ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '8'*/)&&(strcmp(ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  3762. {
  3763. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[connectorIdInt-1].SystemStatus = 8; //S_CHARGING
  3764. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3765. }
  3766. else
  3767. {
  3768. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 1) //S_IDLE
  3769. {
  3770. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3771. goto end;
  3772. }
  3773. }
  3774. }
  3775. }
  3776. for (int index = 0; index < GB_QUANTITY; index++)
  3777. {
  3778. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  3779. {
  3780. if((1/*?�ç??—æ?*//*ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '8'*/)&&(strcmp(ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  3781. {
  3782. //ShmSysConfigAndInfo->SysInfo.GbChargingData[connectorIdInt-1].SystemStatus = 8; //S_CHARGING
  3783. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3784. }
  3785. else
  3786. {
  3787. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 1) //S_IDLE
  3788. {
  3789. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3790. goto end;
  3791. }
  3792. }
  3793. }
  3794. }
  3795. if(chargingProfile != NULL)
  3796. {
  3797. //ChargingProfile
  3798. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  3799. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  3800. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  3801. if(recurrencyKind != NULL) //OPTION
  3802. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  3803. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  3804. if(transactionId != NULL) // OPTION
  3805. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  3806. if(validFrom != NULL) // OPTION
  3807. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  3808. if(validTo != NULL) //OPTION
  3809. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  3810. //ChargingSchedule
  3811. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  3812. if(duration != NULL) //OPTION
  3813. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  3814. if(minChargingRate != NULL) //OPTION
  3815. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  3816. if(startSchedule != NULL) //OPTION
  3817. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  3818. //ChargingSchedulePeriod
  3819. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod->Limit = limitflaot ;
  3820. if(numberPhases != NULL)
  3821. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod->NumberPhases = numberPhasesInt;
  3822. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod->StartPeriod = startPeriodInt;
  3823. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3824. {
  3825. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3826. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  3827. }
  3828. else
  3829. {
  3830. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3831. }
  3832. }
  3833. else
  3834. {
  3835. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3836. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  3837. }
  3838. }
  3839. else
  3840. {
  3841. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3842. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  3843. }
  3844. end:
  3845. if(connectorId != NULL)
  3846. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  3847. strcpy(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  3848. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  3849. json_object_put(obj);
  3850. //OCPP send RemoteStartConfirmation by first.
  3851. sendRemoteStartConfirmation(uuid, comfirmstr);
  3852. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionConf = 1;
  3853. return result;
  3854. }
  3855. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  3856. {
  3857. int result = FAIL;
  3858. int match = FALSE;
  3859. int GunNO = 0;
  3860. struct json_object *obj, *transactionId;
  3861. int transactionIdInt=0;
  3862. char comfirmstr[20];
  3863. printf("handleRemoteStopTransactionRequest\n");
  3864. if(server_pending == TRUE)
  3865. {
  3866. return 0;
  3867. }
  3868. obj = json_tokener_parse(payload);
  3869. transactionId = json_object_object_get(obj, "transactionId");
  3870. transactionIdInt = json_object_get_int(transactionId);
  3871. if(transactionId != NULL)
  3872. {
  3873. for(int gun_index=0;gun_index< (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY);gun_index++)
  3874. {
  3875. if(ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId == transactionIdInt)
  3876. {
  3877. //check Transaction active
  3878. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3879. {
  3880. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  3881. {
  3882. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8) // S_CHARGING
  3883. {
  3884. match = TRUE;
  3885. GunNO = gun_index;
  3886. }
  3887. }
  3888. }
  3889. for (int index = 0; index < CCS_QUANTITY; index++)
  3890. {
  3891. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  3892. {
  3893. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8) // S_CHARGING
  3894. {
  3895. match = TRUE;
  3896. GunNO = gun_index;
  3897. }
  3898. }
  3899. }
  3900. for (int index = 0; index < GB_QUANTITY; index++)
  3901. {
  3902. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  3903. {
  3904. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8) // S_CHARGING
  3905. {
  3906. match = TRUE;
  3907. GunNO = gun_index;
  3908. }
  3909. }
  3910. }
  3911. }
  3912. }
  3913. if( match == TRUE)
  3914. {
  3915. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  3916. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  3917. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  3918. }
  3919. else
  3920. {
  3921. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3922. }
  3923. }
  3924. json_object_put(obj);
  3925. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  3926. //ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionConf = 1;
  3927. return result;
  3928. }
  3929. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  3930. {
  3931. int result = FAIL;
  3932. struct json_object *obj, *connectorId, *expiryDate, *idTag, *parentIdTag, *reservationId;
  3933. int connectorIdInt=0, reservationIdInt=0;
  3934. char *expiryDatestr, *idTagstr, *parentIdTagstr;
  3935. char comfirmstr[20];
  3936. obj = json_tokener_parse(payload);
  3937. printf("handleReserveNowRequest\n");
  3938. connectorId = json_object_object_get(obj, "connectorId");
  3939. expiryDate = json_object_object_get(obj, "expiryDate");
  3940. idTag = json_object_object_get(obj, "idTag");
  3941. parentIdTag = json_object_object_get(obj, "parentIdTag");
  3942. reservationId = json_object_object_get(obj, "reservationId");
  3943. connectorIdInt = json_object_get_int(connectorId);
  3944. expiryDatestr = (char *)json_object_get_string(expiryDate);
  3945. idTagstr = (char *)json_object_get_string(idTag);
  3946. if(parentIdTag != NULL) // option flag
  3947. parentIdTagstr = (char *)json_object_get_string(parentIdTag);
  3948. reservationIdInt = json_object_get_int(reservationId);
  3949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  3950. /*
  3951. enum _SYSTEM_STATUS
  3952. {
  3953. S_BOOTING = 0,
  3954. S_IDLE, = 1
  3955. S_AUTHORIZING, =2
  3956. S_REASSIGN_CHECK, =3
  3957. S_REASSIGN, =4
  3958. S_PRECHARGE, =5
  3959. S_PREPARING_FOR_EV, =6
  3960. S_PREPARING_FOR_EVSE, =7
  3961. S_CHARGING, =8
  3962. S_TERMINATING, =9
  3963. S_COMPLETE, =10
  3964. S_ALARM, =11
  3965. S_FAULT =12
  3966. }
  3967. */
  3968. if((connectorIdInt > 0) && ((connectorIdInt -1) <= (CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)))
  3969. {
  3970. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3971. //check Transaction active
  3972. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3973. {
  3974. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  3975. {
  3976. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  3977. {
  3978. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3979. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 12) //S_FAULT
  3980. {
  3981. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 1) //S_IDLE
  3982. {
  3983. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  3984. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  3985. }
  3986. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) //S_ALARM //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  3987. {
  3988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  3989. }
  3990. else
  3991. {
  3992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  3993. }
  3994. }
  3995. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 12) //S_FAULT
  3996. {
  3997. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  3998. }
  3999. }
  4000. else
  4001. {
  4002. //replace reservation
  4003. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  4004. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  4005. }
  4006. }
  4007. }
  4008. for (int index = 0; index < CCS_QUANTITY; index++)
  4009. {
  4010. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  4011. {
  4012. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  4013. {
  4014. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  4015. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 12) //S_FAULT
  4016. {
  4017. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 1) //S_IDLE
  4018. {
  4019. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  4020. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  4021. }
  4022. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 11) //S_ALARM //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  4023. {
  4024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  4025. }
  4026. else
  4027. {
  4028. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  4029. }
  4030. }
  4031. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==12) //S_FAULT
  4032. {
  4033. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  4034. }
  4035. }
  4036. else
  4037. {
  4038. //replace reservation
  4039. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  4040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  4041. }
  4042. }
  4043. }
  4044. for (int index = 0; index < GB_QUANTITY; index++)
  4045. {
  4046. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  4047. {
  4048. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  4049. {
  4050. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  4051. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 12) //S_FAULT
  4052. {
  4053. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1) //S_IDLE
  4054. {
  4055. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  4056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  4057. }
  4058. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 11) //S_ALARM //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  4059. {
  4060. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  4061. }
  4062. else
  4063. {
  4064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  4065. }
  4066. }
  4067. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==12) //S_FAULT
  4068. {
  4069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  4070. }
  4071. }
  4072. else
  4073. {
  4074. //replace reservation
  4075. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  4076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  4077. }
  4078. }
  4079. }
  4080. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  4081. }
  4082. else
  4083. {
  4084. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  4085. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  4086. }
  4087. if(strcmp(comfirmstr,"Accepted") == 0)
  4088. {
  4089. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  4090. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  4091. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  4092. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  4093. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  4094. strcpy(ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  4095. json_object_put(obj);
  4096. result = TRUE;
  4097. return result;
  4098. }
  4099. json_object_put(obj);
  4100. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  4101. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  4102. return result;
  4103. }
  4104. int handleResetRequest(char *uuid, char *payload)
  4105. {
  4106. int result = FAIL;
  4107. struct json_object *obj, *type;
  4108. char *typestr;
  4109. char comfirmstr[20];
  4110. obj = json_tokener_parse(payload);
  4111. printf("handleResetRequest\n");
  4112. type = json_object_object_get(obj, "type");
  4113. typestr = (char *)json_object_get_string(type);
  4114. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  4115. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  4116. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  4117. {
  4118. //check Transaction active
  4119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4120. {
  4121. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8)
  4122. {
  4123. //0: unplug, 1: Plug-in
  4124. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  4125. }
  4126. }
  4127. for (int index = 0; index < CCS_QUANTITY; index++)
  4128. {
  4129. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8)
  4130. {
  4131. //0: unplug, 1: Plug-in
  4132. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  4133. }
  4134. }
  4135. for (int index = 0; index < GB_QUANTITY; index++)
  4136. {
  4137. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8)
  4138. {
  4139. //0: unplug, 1: Plug-in
  4140. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  4141. }
  4142. }
  4143. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  4144. strcpy(ShmOCPP16Data->Reset.guid, uuid);
  4145. json_object_put(obj);
  4146. result = TRUE;
  4147. return result;
  4148. // strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  4149. // sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  4150. }
  4151. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  4152. {
  4153. //check Transaction active
  4154. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4155. {
  4156. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8)
  4157. {
  4158. //0: unplug, 1: Plug-in
  4159. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  4160. }
  4161. }
  4162. for (int index = 0; index < CCS_QUANTITY; index++)
  4163. {
  4164. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8)
  4165. {
  4166. //0: unplug, 1: Plug-in
  4167. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  4168. }
  4169. }
  4170. for (int index = 0; index < GB_QUANTITY; index++)
  4171. {
  4172. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8)
  4173. {
  4174. //0: unplug, 1: Plug-in
  4175. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  4176. }
  4177. }
  4178. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  4179. strcpy(ShmOCPP16Data->Reset.guid, uuid);
  4180. json_object_put(obj);
  4181. result = TRUE;
  4182. return result;
  4183. // strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  4184. // sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  4185. }
  4186. else
  4187. {
  4188. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  4189. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  4190. goto errorend;
  4191. }
  4192. errorend:
  4193. json_object_put(obj);
  4194. sendResetConfirmation(uuid, comfirmstr);
  4195. //ShmOCPP16Data->MsMsg.bits.ResetConf = 1;
  4196. return result;
  4197. }
  4198. int handleSendLocalListRequest(char *uuid, char *payload)
  4199. {
  4200. int result = FAIL;
  4201. struct json_object *obj, *listVersion , *localAuthorizationList, *updateType, *jsonitem, *idTag, *idTagInfo ,
  4202. *expiryDate, *parentIdTag, *status;
  4203. int listVersionInt;
  4204. char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  4205. char comfirmstr[20];
  4206. int n_localAuthorizations = 0;
  4207. obj = json_tokener_parse(payload);
  4208. printf("handleSendLocalListRequest\n");
  4209. listVersion = json_object_object_get(obj, "listVersion");
  4210. localAuthorizationList = json_object_object_get(obj, "localAuthorizationList");
  4211. updateType = json_object_object_get(obj, "updateType");
  4212. listVersionInt = json_object_get_int(listVersion);
  4213. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  4214. updateTypestr = (char *)json_object_get_string(updateType);
  4215. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  4216. printf("handleSendLocalListRequest -1\n");
  4217. if(localAuthorizationList != NULL)
  4218. n_localAuthorizations = json_object_array_length(localAuthorizationList);
  4219. printf("n_localAuthorizations=%d\n",n_localAuthorizations);
  4220. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  4221. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  4222. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = (struct StructLocalAuthorizationList *)malloc(sizeof(struct StructLocalAuthorizationList)*n_localAuthorizations);
  4223. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 ,sizeof(ShmOCPP16Data->SendLocalList.LocalAuthorizationList));
  4224. //ShmOCPP16Data->MsMsg.bits.SendLocalListReq = 1;
  4225. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  4226. {
  4227. //Local list full update
  4228. printf("Local list full update.\n");
  4229. OCPP_cleanLocalList();
  4230. }
  4231. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  4232. {
  4233. //Local list different update
  4234. printf("Local list different update.\n");
  4235. if(localAuthorizationList == NULL)
  4236. {
  4237. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  4238. goto end;
  4239. }
  4240. OCPP_getListVerion();
  4241. if(listVersionInt <= localversion )
  4242. {
  4243. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  4244. goto end;
  4245. }
  4246. }
  4247. else
  4248. {
  4249. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  4250. goto end;
  4251. }
  4252. for(int i=0;i<n_localAuthorizations;i++)
  4253. {
  4254. printf("handleSendLocalListRequest -2\n");
  4255. jsonitem = json_object_array_get_idx(localAuthorizationList, i);
  4256. printf("handleSendLocalListRequest -2 -0\n");
  4257. idTag = json_object_object_get(jsonitem, "IdToken"/*"idTag"*/);
  4258. printf("handleSendLocalListRequest -2 -0 -0\n");
  4259. idTagInfo = json_object_object_get(jsonitem, "idTagInfo");
  4260. printf("handleSendLocalListRequest -2 -0 -0 -0\n");
  4261. if(idTagInfo != NULL)
  4262. {
  4263. expiryDate = json_object_object_get(idTagInfo, "expiryDate");
  4264. printf("handleSendLocalListRequest -2 -0 -0 -0 -0\n");
  4265. parentIdTag = json_object_object_get(idTagInfo, "parentIdTag");
  4266. printf("handleSendLocalListRequest -2 -0 -0 -0 -0 -0\n");
  4267. status = json_object_object_get(idTagInfo, "status");
  4268. }
  4269. if(idTag != NULL)
  4270. idTagstr = (char *)json_object_get_string(idTag);
  4271. printf("idTagstr=%s\n",idTagstr);
  4272. if(expiryDate != NULL)
  4273. expiryDatestr = (char *)json_object_get_string(expiryDate);
  4274. printf("expiryDatestr=%s\n",expiryDatestr);
  4275. if(parentIdTag != NULL)
  4276. parentIdTagstr = (char *)json_object_get_string(parentIdTag);
  4277. printf("parentIdTagstr=%s\n",parentIdTagstr);
  4278. statusstr = (char *)json_object_get_string(status);
  4279. printf("statusstr=%s\n",statusstr);
  4280. printf("handleSendLocalListRequest -2 -1\n");
  4281. OCPP_getIdTag(idTagstr);
  4282. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  4283. {
  4284. //Local list full update
  4285. printf("Local list full update.\n");
  4286. // update list
  4287. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTagstr, expiryDatestr, statusstr);
  4288. }
  4289. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  4290. {
  4291. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag != NULL))
  4292. {
  4293. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTagstr, expiryDatestr, statusstr);
  4294. }
  4295. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag == NULL))
  4296. {
  4297. OCPP_deleteIdTag(idTagstr);
  4298. }
  4299. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag != NULL))
  4300. {
  4301. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTagstr, expiryDatestr, statusstr);
  4302. }
  4303. }
  4304. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[i].IdTag, idTagstr);
  4305. printf("handleSendLocalListRequest -2 -1 -1\n");
  4306. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[i].IdTagInfo.ExpiryDate, expiryDatestr);
  4307. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[i].IdTagInfo.ParentIdTag, parentIdTagstr);
  4308. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[i].IdTagInfo.Status, statusstr);
  4309. printf("handleSendLocalListRequest -3\n");
  4310. }
  4311. printf("handleSendLocalListRequest -4\n");
  4312. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  4313. end:
  4314. json_object_put(obj);
  4315. sendSendLocalListConfirmation(uuid, comfirmstr);
  4316. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  4317. printf("handleSendLocalListRequest -5\n");
  4318. return result;
  4319. }
  4320. #define MAX 2000
  4321. int handleSetChargingProfileRequest(char *uuid, char *payload)
  4322. {
  4323. int result = FAIL;
  4324. struct json_object *obj, *connectorId, *csChargingProfiles, *chargingProfileId, *stackLevel, *chargingProfilePurpose;
  4325. struct json_object *tempobj, *tempconnectorId, *tempcsChargingProfiles, *tempchargingProfileId, *tempstackLevel, *tempchargingProfilePurpose;
  4326. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  4327. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  4328. const char*chargingProfilePurposeStr;
  4329. char *tempchargingProfilePurposeStr;
  4330. int updateflag = FALSE;
  4331. char comfirmstr[20];
  4332. int meet= FALSE;
  4333. printf("handleSetChargingProfileRequest\n");
  4334. obj = json_tokener_parse(payload);
  4335. connectorId = json_object_object_get(obj, "connectorId");
  4336. csChargingProfiles = json_object_object_get(obj, "csChargingProfiles");
  4337. chargingProfileId = json_object_object_get(csChargingProfiles, "chargingProfileId");
  4338. stackLevel = json_object_object_get(csChargingProfiles, "stackLevel");
  4339. chargingProfilePurpose = json_object_object_get(csChargingProfiles, "chargingProfilePurpose");
  4340. connectorIdInt = json_object_get_int(connectorId);
  4341. chargingProfileIdInt = json_object_get_int(chargingProfileId);
  4342. stackLevelInt = json_object_get_int(stackLevel);
  4343. chargingProfilePurposeStr = json_object_get_string(chargingProfilePurpose);
  4344. #if 1 // get json object from file
  4345. FILE *fptr1, *fptr2;
  4346. int lno, linectr = 0;
  4347. int modifyflag = FALSE;
  4348. char str[MAX],fname[MAX];
  4349. char newln[MAX], temp[] = "temp.json";
  4350. struct json_object *newHeatMap = json_object_new_array();
  4351. printf("\n\n Replace a specific line in a text file with a new text :\n");
  4352. printf("-------------------------------------------------------------\n");
  4353. printf(" Input the file name to be opened : ");
  4354. //fgets(fname, MAX, stdin);
  4355. //fname[strlen(fname) - 1] = '\0';
  4356. switch(connectorIdInt)
  4357. {
  4358. case 0:
  4359. strcpy(fname, ChargingProfile_0_JSON );
  4360. break;
  4361. case 1:
  4362. strcpy(fname, ChargingProfile_1_JSON );
  4363. break;
  4364. case 2:
  4365. strcpy(fname, ChargingProfile_2_JSON );
  4366. break;
  4367. default:
  4368. strcpy(fname, ChargingProfile_0_JSON );
  4369. break;
  4370. }
  4371. fptr1 = fopen(fname, "r");
  4372. if (!fptr1)
  4373. {
  4374. //file not exist
  4375. printf("Unable to open the input file!!\n");
  4376. fptr1 = fopen(fname, "w+");
  4377. }
  4378. fclose(fptr1);
  4379. json_object *test_obj = NULL;
  4380. json_object *tmp_obj = NULL;
  4381. struct array_list *json_list;
  4382. struct json_object *jsonitem;
  4383. size_t n_friends;
  4384. printf("set chargingProfile 1\n");
  4385. //get json object from file
  4386. test_obj = json_object_from_file(fname);
  4387. if(test_obj ==NULL)
  4388. {
  4389. printf("set chargingProfile: test_obj is Null!!!\n");
  4390. //assert(test_obj != NULL);
  4391. }
  4392. tempchargingProfilePurposeStr = NULL;
  4393. printf("set chargingProfile 1-1\n");
  4394. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  4395. {
  4396. printf("set chargingProfile 1-2\n");
  4397. if(connectorIdInt != 0)
  4398. {
  4399. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  4400. goto end;
  4401. }
  4402. }
  4403. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  4404. {
  4405. printf("set chargingProfile 1-3\n");
  4406. if((connectorIdInt != 0) && (connectorIdInt > (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)))
  4407. {
  4408. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  4409. goto end;
  4410. }
  4411. }
  4412. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4413. {
  4414. printf("set chargingProfile 1-4\n");
  4415. //check Transaction active
  4416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4417. {
  4418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == connectorIdInt)
  4419. {
  4420. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '4')
  4421. {
  4422. meet = TRUE;
  4423. }
  4424. }
  4425. }
  4426. for (int index = 0; index < CCS_QUANTITY; index++)
  4427. {
  4428. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == connectorIdInt)
  4429. {
  4430. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '4')
  4431. {
  4432. meet = TRUE;
  4433. }
  4434. }
  4435. }
  4436. for (int index = 0; index < GB_QUANTITY; index++)
  4437. {
  4438. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == connectorIdInt)
  4439. {
  4440. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')
  4441. {
  4442. meet = TRUE;
  4443. }
  4444. }
  4445. }
  4446. if(meet == FALSE)
  4447. {
  4448. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  4449. goto end;
  4450. }
  4451. if((connectorIdInt != 0) && (connectorIdInt > (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)))
  4452. {
  4453. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  4454. goto end;
  4455. }
  4456. }
  4457. printf("set chargingProfile 2\n");
  4458. if((test_obj != NULL) &&(json_object_get_type(test_obj) == json_type_array))
  4459. {
  4460. /* Get array of tests */
  4461. json_list = json_object_get_array(test_obj);
  4462. n_friends = json_object_array_length(test_obj);
  4463. printf("Found %lu friends\n",n_friends);
  4464. for(int i=0;i<n_friends;i++)
  4465. {
  4466. jsonitem = json_object_array_get_idx(test_obj, i);
  4467. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  4468. tempconnectorId = json_object_object_get(jsonitem, "connectorId");
  4469. tempcsChargingProfiles = json_object_object_get(jsonitem, "csChargingProfiles");
  4470. tempchargingProfileId = json_object_object_get(tempcsChargingProfiles, "chargingProfileId");
  4471. tempstackLevel = json_object_object_get(tempcsChargingProfiles, "stackLevel");
  4472. tempchargingProfilePurpose = json_object_object_get(tempcsChargingProfiles, "chargingProfilePurpose");
  4473. tempconnectorIdInt = json_object_get_int(tempconnectorId);
  4474. tempchargingProfileIdInt = json_object_get_int(tempchargingProfileId);
  4475. tempstackLevelInt = json_object_get_int(tempstackLevel);
  4476. tempchargingProfilePurposeStr =(char *)json_object_get_string(tempchargingProfilePurpose);
  4477. printf("s t 1\n");
  4478. if((tempconnectorIdInt == connectorIdInt) && ((tempchargingProfileIdInt == chargingProfileIdInt) || (tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4479. {
  4480. //fprintf(fptr2, "%s", str);
  4481. //fprintf(fptr2, "%s", newln);
  4482. //modifyflag = TRUE;
  4483. //tmp_obj = json_object_new_string(payload);
  4484. //json_object_array_add(newHeatMap, tmp_obj);
  4485. printf("s t 2\n");
  4486. json_object_array_add(newHeatMap, obj);
  4487. printf("s t 3\n");
  4488. //updateflag = TRUE;
  4489. printf("update set chargingProfile to file\n");
  4490. }
  4491. else
  4492. {
  4493. // fprintf(fptr2, "%s", newln);
  4494. //fprintf(fptr2, "%s", str);
  4495. json_object_array_add(newHeatMap, jsonitem);
  4496. printf("add set chargingProfile to file\n");
  4497. }
  4498. }
  4499. #if 0
  4500. if(updateflag == FALSE)
  4501. {
  4502. tmp_obj = json_object_new_string(payload);
  4503. json_object_array_add(newHeatMap, tmp_obj);
  4504. updateflag = TRUE;
  4505. }
  4506. #endif
  4507. remove(fname);
  4508. rename(temp, fname);
  4509. json_object_to_file(fname, newHeatMap);
  4510. json_object_put ( newHeatMap );
  4511. result = TRUE;
  4512. #if 0
  4513. if(errno >=1)
  4514. {
  4515. printf("has errno \n");
  4516. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  4517. }
  4518. else
  4519. #endif
  4520. {
  4521. printf("has no error \n");
  4522. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  4523. }
  4524. }
  4525. else
  4526. {
  4527. printf("set chargingProfile 3\n");
  4528. //write the base object to write.json
  4529. json_object_array_add(newHeatMap, obj);
  4530. json_object_to_file(fname, newHeatMap);
  4531. //sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  4532. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  4533. json_object_put ( newHeatMap );
  4534. printf("set chargingProfile 4\n");
  4535. }
  4536. end:
  4537. printf("set chargingProfile 1-5\n");
  4538. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  4539. return result;
  4540. #endif
  4541. #if 0 // file style handleing
  4542. FILE *fptr1, *fptr2;
  4543. int lno, linectr = 0;
  4544. int modifyflag = FALSE;
  4545. char str[MAX],fname[MAX];
  4546. char newln[MAX], temp[] = "./mnt/temp.json";
  4547. printf("\n\n Replace a specific line in a text file with a new text :\n");
  4548. printf("-------------------------------------------------------------\n");
  4549. printf(" Input the file name to be opened : ");
  4550. //fgets(fname, MAX, stdin);
  4551. //fname[strlen(fname) - 1] = '\0';
  4552. switch(connectorIdInt)
  4553. {
  4554. case 0:
  4555. strcpy(fname, ChargingProfile_0_JSON );
  4556. break;
  4557. case 1:
  4558. strcpy(fname, ChargingProfile_1_JSON );
  4559. break;
  4560. case 2:
  4561. strcpy(fname, ChargingProfile_2_JSON );
  4562. break;
  4563. default:
  4564. strcpy(fname, ChargingProfile_0_JSON );
  4565. break;
  4566. }
  4567. fptr1 = fopen(fname, "r");
  4568. if (!fptr1)
  4569. {
  4570. //file not exist
  4571. printf("Unable to open the input file!!\n");
  4572. fptr1 = fopen(fname, "wb");
  4573. fwrite(newln , 1 , sizeof(newln) , fptr1 );
  4574. fclose(fptr1);
  4575. json_object_put(obj);
  4576. json_object_put(tempobj);
  4577. return result;
  4578. }
  4579. fptr2 = fopen(temp, "w");
  4580. if (!fptr2)
  4581. {
  4582. printf("Unable to open a temporary file to write!!\n");
  4583. fclose(fptr1);
  4584. return 0;
  4585. }
  4586. /* get the new line from the user */
  4587. printf(" Input the content of the new line : ");
  4588. //fgets(newln, MAX, stdin);
  4589. memcpy(newln,payload,strlen(payload));
  4590. /* get the line number to delete the specific line */
  4591. printf(" Input the line no you want to replace : ");
  4592. //scanf("%d", &lno);
  4593. //lno++;
  4594. // copy all contents to the temporary file other except specific line
  4595. while (!feof(fptr1))
  4596. {
  4597. strcpy(str, "\0");
  4598. fgets(str, MAX, fptr1);
  4599. if (!feof(fptr1))
  4600. {
  4601. // linectr++;
  4602. // if (linectr != lno)
  4603. tempobj = json_tokener_parse(str);
  4604. tempconnectorId = json_object_object_get(tempobj, "connectorId");
  4605. tempcsChargingProfiles = json_object_object_get(tempobj, "csChargingProfiles");
  4606. tempchargingProfileId = json_object_object_get(tempcsChargingProfiles, "chargingProfileId");
  4607. tempstackLevel = json_object_object_get(tempcsChargingProfiles, "stackLevel");
  4608. tempchargingProfilePurpose = json_object_object_get(tempcsChargingProfiles, "chargingProfilePurpose");
  4609. tempconnectorIdInt = json_object_get_int(connectorId);
  4610. tempchargingProfileIdInt = json_object_get_int(chargingProfileIdInt);
  4611. tempstackLevelInt = json_object_get_int(stackLevel);
  4612. tempchargingProfilePurposeStr = json_object_get_string(chargingProfilePurpose);
  4613. if((tempconnectorId == connectorId) && ((tempchargingProfileIdInt == chargingProfileIdInt) || (tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4614. {
  4615. //fprintf(fptr2, "%s", str);
  4616. fprintf(fptr2, "%s", newln);
  4617. modifyflag = TRUE;
  4618. }
  4619. else
  4620. {
  4621. // fprintf(fptr2, "%s", newln);
  4622. fprintf(fptr2, "%s", str);
  4623. }
  4624. }
  4625. }
  4626. if(modifyflag == FALSE)
  4627. {
  4628. fwrite(newln , 1 , sizeof(newln) , fptr2 );
  4629. }
  4630. result = TRUE;
  4631. fclose(fptr1);
  4632. fclose(fptr2);
  4633. remove(fname);
  4634. rename(temp, fname);
  4635. printf(" Replacement did successfully..!! \n");
  4636. #endif
  4637. json_object_put(obj);
  4638. json_object_put(tempobj);
  4639. return result;
  4640. }
  4641. int handleTriggerMessageRequest(char *uuid, char *payload)
  4642. {
  4643. int result = FAIL;
  4644. struct json_object *obj, *requestedMessage, *connectorId;
  4645. int connectorIdInt =0;
  4646. char *requestedMessagestr;
  4647. char comfirmstr[20];
  4648. obj = json_tokener_parse(payload);
  4649. printf("handleTriggerMessageRequest\n");
  4650. requestedMessage = json_object_object_get(obj, "requestedMessage");
  4651. connectorId = json_object_object_get(obj, "connectorId");
  4652. requestedMessagestr = (char *)json_object_get_string(requestedMessage);
  4653. if(connectorId != NULL && connectorId > 0)
  4654. {
  4655. connectorIdInt = json_object_get_int(connectorId);
  4656. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  4657. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  4658. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  4659. }
  4660. else if(connectorId != NULL && connectorId <= 0)
  4661. {
  4662. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  4663. goto end;
  4664. }
  4665. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  4666. {
  4667. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  4668. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4669. }
  4670. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  4671. {
  4672. printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  4673. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  4674. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4675. }
  4676. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  4677. {
  4678. sendBootNotificationRequest();
  4679. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4680. }
  4681. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  4682. {
  4683. sendHeartbeatRequest(connectorIdInt);
  4684. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4685. }
  4686. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  4687. {
  4688. if(connectorId != NULL)
  4689. {
  4690. if((connectorIdInt > 0) && ((connectorIdInt -1) < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)))
  4691. {
  4692. sendMeterValuesRequest(connectorIdInt -1);
  4693. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4694. }
  4695. else
  4696. {
  4697. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  4698. }
  4699. }
  4700. else
  4701. {
  4702. for(int idx=0;idx<(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY);idx++)
  4703. sendMeterValuesRequest(idx);
  4704. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4705. }
  4706. }
  4707. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  4708. {
  4709. if(connectorId != NULL)
  4710. {
  4711. if((connectorIdInt > 0) && ((connectorIdInt -1) < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)))
  4712. {
  4713. sendStatusNotificationRequest(connectorIdInt -1);
  4714. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4715. }
  4716. else
  4717. {
  4718. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  4719. }
  4720. }
  4721. else
  4722. {
  4723. for(int idx=0;idx<(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY);idx++)
  4724. sendStatusNotificationRequest(idx);
  4725. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4726. }
  4727. }
  4728. else
  4729. {
  4730. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  4731. }
  4732. end:
  4733. json_object_put(obj);
  4734. sendTriggerMessageConfirmation(uuid,comfirmstr);
  4735. //if(connectorId != NULL)
  4736. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageConf = 1;
  4737. return result;
  4738. }
  4739. int handleUnlockConnectorRequest(char *uuid, char *payload)
  4740. {
  4741. int result = FAIL;
  4742. struct json_object *obj, *connectorId;
  4743. int connectorIdInt =0;
  4744. char comfirmstr[20];
  4745. obj = json_tokener_parse(payload);
  4746. printf("handleUnlockConnectorRequest\n");
  4747. connectorId = json_object_object_get(obj, "connectorId");
  4748. connectorIdInt = json_object_get_int(connectorId);
  4749. if(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY == 0)
  4750. {
  4751. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  4752. goto end;
  4753. }
  4754. else if((connectorIdInt > CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY) || (connectorIdInt <= 0))
  4755. {
  4756. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  4757. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockFailed] );
  4758. goto end;
  4759. }
  4760. else
  4761. {
  4762. //check Transaction active
  4763. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4764. {
  4765. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == connectorIdInt ) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '4') )
  4766. {
  4767. //stop Transaction
  4768. //ShmOCPP16Data->CpMsg.bits[connectorIdInt-1].StopTransactionReq = 1;
  4769. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  4770. }
  4771. }
  4772. for (int index = 0; index < CCS_QUANTITY; index++)
  4773. {
  4774. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == connectorIdInt ) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '4'))
  4775. {
  4776. //stop Transaction
  4777. //ShmOCPP16Data->CpMsg.bits[connectorIdInt-1].StopTransactionReq = 1;
  4778. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  4779. }
  4780. }
  4781. for (int index = 0; index < GB_QUANTITY; index++)
  4782. {
  4783. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == connectorIdInt ) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4'))
  4784. {
  4785. //stop Transaction
  4786. //ShmOCPP16Data->CpMsg.bits[connectorIdInt-1].StopTransactionReq = 1;
  4787. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  4788. }
  4789. }
  4790. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  4791. strcpy(ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  4792. // sprintf(comfirmstr, "%s", UnlockStatusStr[Unlocked] );
  4793. json_object_put(obj);
  4794. result = TRUE;
  4795. return result;
  4796. }
  4797. end:
  4798. json_object_put(obj);
  4799. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  4800. return result;
  4801. }
  4802. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  4803. {
  4804. int result = FAIL;
  4805. pthread_t t;
  4806. pthread_create(&t, NULL, UpdateFirmwareProcess, payload); // 建�?�執行�?
  4807. pthread_join(t, NULL); // 等�?�執行�??��?完�?
  4808. sendUpdateFirmwareConfirmation(uuid);
  4809. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  4810. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  4811. return result;
  4812. }
  4813. void UpdateFirmwareProcess(void* data)
  4814. {
  4815. struct json_object *obj, *location, *retries, *retrieveDate, *retryInterval;
  4816. int retriesInt =0, retryIntervalInt=0;
  4817. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  4818. int port=0;
  4819. char *locationstr, *retrieveDatestr;
  4820. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  4821. char comfirmstr[20];
  4822. int isSuccess = 0;
  4823. char ftpbuf[200];
  4824. char temp[100];
  4825. char * pch;
  4826. char *str = (char*) data; // ?��?輸入資�?
  4827. obj = json_tokener_parse(str);
  4828. printf("handleUpdateFirmwareRequest\n");
  4829. location = json_object_object_get(obj, "location");
  4830. retries = json_object_object_get(obj, "retries");
  4831. retrieveDate = json_object_object_get(obj, "retrieveDate");
  4832. retryInterval = json_object_object_get(obj, "retrieveDate");
  4833. locationstr = (char *)json_object_get_string(location);
  4834. if(retries != NULL)
  4835. retriesInt = json_object_get_int(retries);
  4836. retrieveDatestr = (char *)json_object_get_string(retrieveDate);
  4837. if(retryInterval != NULL)
  4838. retryIntervalInt = json_object_get_int(retryInterval);
  4839. memset(ftppath, 0, sizeof(ftppath));
  4840. memset(path, 0, sizeof(path));
  4841. if(strncmp(locationstr,"http", 4) == 0)
  4842. {
  4843. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  4844. protocol, host, path);
  4845. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  4846. // protocol, user, password, host, path);
  4847. sprintf(ftppath,"/%s", path);
  4848. printf("protocol =%s\n",protocol);
  4849. printf("host =%s\n",host);
  4850. printf("path =%s\n",path);
  4851. printf("ftppath=%s\n",ftppath);
  4852. int ftppathlen=strlen(ftppath);
  4853. int i=1;
  4854. char filenametemp[50];
  4855. while(i < ftppathlen)
  4856. {
  4857. printf("ftppath[ftppathlen-i]:%c\n",ftppath[ftppathlen-i]);
  4858. int len=ftppathlen-i;
  4859. if(ftppath[len]== 47) // '/' ascll code: 47
  4860. {
  4861. printf("compare all right\n");
  4862. break;
  4863. }
  4864. printf("test substr\n");
  4865. i=i+1;
  4866. }
  4867. memset(filenametemp, 0, sizeof(filenametemp));
  4868. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  4869. filenametemp[i+1] = 0;
  4870. printf("filenametemp:%s\n", filenametemp);
  4871. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  4872. do{
  4873. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  4874. sleep(retryIntervalInt);
  4875. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  4876. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  4877. if(!isSuccess)
  4878. {
  4879. //BulldogUtil.sleepMs(interval*1000);
  4880. printf("Update firmware request and download file fail.\n");
  4881. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  4882. }
  4883. else
  4884. {
  4885. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  4886. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  4887. isUpdateRequest = TRUE;
  4888. }
  4889. }
  4890. else // ftp
  4891. {
  4892. memset(ftpbuf, 0, sizeof(ftpbuf));
  4893. memset(temp, 0, sizeof(temp));
  4894. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  4895. int ftppathlen=strlen(ftpbuf);
  4896. int i=1;
  4897. char filenametemp[50];
  4898. while(i < ftppathlen)
  4899. {
  4900. printf("ftppath[ftppathlen-i]:%c\n",ftpbuf[ftppathlen-i]);
  4901. int len=ftppathlen-i;
  4902. if(ftpbuf[len]== 47) // '/' ascll code: 47
  4903. {
  4904. printf("all right\n");
  4905. break;
  4906. }
  4907. printf("test substr\n");
  4908. i=i+1;
  4909. }
  4910. memset(filenametemp, 0, sizeof(filenametemp));
  4911. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  4912. filenametemp[i+1] = 0;
  4913. printf("filenametemp:%s\n", filenametemp);
  4914. strncpy(temp, ftpbuf, ftppathlen-i+1);
  4915. pch=strchr(temp,'@');
  4916. if(pch==NULL)
  4917. {
  4918. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  4919. protocol, host, &port, path);
  4920. strcpy(user,"anonymous");
  4921. strcpy(password,"");
  4922. }
  4923. else
  4924. {
  4925. printf("pch=%s\n", pch);
  4926. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  4927. protocol, user, password, host, &port, path);
  4928. }
  4929. sscanf(host,"%[^/]%s",host1, path1);
  4930. sprintf(ftppath,"%s", path1);
  4931. printf("protocol =%s\n",protocol);
  4932. printf("user =%s\n",user);
  4933. printf("password =%s\n",password);
  4934. printf("host1 =%s\n",host1);
  4935. printf("port =%d\n",port);
  4936. printf("path1 =%s\n",path1);
  4937. printf("ftppath=%s\n",ftppath);
  4938. //ftpFile(host, user, password, port, ftppath, fname);
  4939. //download firmware pthred
  4940. if(port == 0)
  4941. port = 21;
  4942. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  4943. do{
  4944. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp);
  4945. sleep(retryIntervalInt);
  4946. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  4947. if(!isSuccess)
  4948. {
  4949. //BulldogUtil.sleepMs(interval*1000);
  4950. printf("Update firmware request and download file fail.\n");
  4951. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  4952. }
  4953. else
  4954. {
  4955. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  4956. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  4957. isUpdateRequest = TRUE;
  4958. }
  4959. }
  4960. json_object_put(obj);
  4961. pthread_exit(NULL); // ?��?�執行�?
  4962. }
  4963. //==========================================
  4964. // Handle server response routine
  4965. //==========================================
  4966. void handleAuthorizeResponse(char *payload, int gun_index)
  4967. {
  4968. struct json_object *obj, *message, *context;
  4969. struct json_object *root_obj, *temp_obj, *jsonitem, *expiryDateitem, *parentIdTagitem, *statusitem;
  4970. char* filename = AuthorizationCache_JSON;
  4971. char* buffer = NULL;
  4972. FILE *pFile;
  4973. char temp[400];
  4974. obj = json_tokener_parse(payload);
  4975. printf("handleAuthorizeResponse\n");
  4976. #ifdef SystemLogMessage
  4977. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate") != NULL)
  4978. DEBUG_INFO("expiryDate: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate")));
  4979. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag") != NULL)
  4980. DEBUG_INFO("parentIdTag: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag")));
  4981. DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "status")));
  4982. #endif
  4983. printf("handleAuthorizeResponse -1\n");
  4984. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate") != NULL)
  4985. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, (char *)json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate")));
  4986. printf("handleAuthorizeResponse -1-0\n");
  4987. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag") != NULL)
  4988. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (char *)json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag")));
  4989. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, (char *)json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "status")));
  4990. printf("handleAuthorizeResponse -2\n");
  4991. printf("authen reponce 1\n");
  4992. //Update idTag information to authorization cache if supproted
  4993. if((strcmp(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  4994. {
  4995. printf("authen reponce 2\n");
  4996. if((access(filename,F_OK))!=-1)
  4997. {
  4998. printf("authen reponce 3\n");
  4999. printf("AuthorizationCache exist.\n");
  5000. }
  5001. else
  5002. {
  5003. printf("authen reponce 4\n");
  5004. printf("AuthorizationCache not exist\n");
  5005. FILE *log = fopen(filename, "w+");
  5006. printf("authen reponce 4 -1\n");
  5007. //fprintf( log , "" ); --- remove temporally
  5008. printf("authen reponce 4 -2\n");
  5009. if(log == NULL)
  5010. {
  5011. printf("log is NULL\n");
  5012. goto out;
  5013. }
  5014. else
  5015. {
  5016. fclose(log);
  5017. }
  5018. }
  5019. printf("authen reponce 5\n");
  5020. get_file_contents(filename, &buffer);
  5021. printf("%s",buffer);
  5022. root_obj = json_tokener_parse(buffer);
  5023. if(root_obj == NULL)
  5024. {
  5025. message = json_object_new_array();
  5026. context = json_object_new_object();
  5027. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  5028. {
  5029. json_object_object_add(context, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  5030. }
  5031. else
  5032. {
  5033. json_object_object_add(context, "expiryDate", json_object_new_string(""));
  5034. }
  5035. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  5036. {
  5037. json_object_object_add(context, "parentIdTag",json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  5038. }
  5039. else
  5040. {
  5041. //write Authorize IdTag
  5042. json_object_object_add(context, "parentIdTag",json_object_new_string(ShmOCPP16Data->Authorize.IdTag));
  5043. }
  5044. json_object_object_add(context, "status", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
  5045. json_object_array_add(message, context);
  5046. memset(temp,0,sizeof temp);
  5047. sprintf(temp, "%s", json_object_to_json_string(message));
  5048. pFile = fopen( filename,"w" );
  5049. if( NULL == pFile ){
  5050. printf( "open failure" );
  5051. }else{
  5052. fwrite(temp,1,sizeof(temp),pFile);
  5053. fclose(pFile);
  5054. }
  5055. json_object_put(message); // Delete the json object
  5056. }
  5057. else
  5058. {
  5059. struct json_object *newHeatMap = json_object_new_array();
  5060. int n_items = json_object_array_length(root_obj);
  5061. for(int i=0;i<n_items;i++)
  5062. {
  5063. int responseIdTagInfoAsZero= 0;
  5064. jsonitem = json_object_array_get_idx(root_obj, i);
  5065. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  5066. expiryDateitem = json_object_object_get(jsonitem, "expiryDate");
  5067. parentIdTagitem = json_object_object_get(jsonitem, "parentIdTag");
  5068. statusitem = json_object_object_get(jsonitem, "status");
  5069. printf("parentIdTagitem=%s\n",json_object_get_string(parentIdTagitem));
  5070. //printf message
  5071. if((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0)
  5072. {
  5073. printf("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  5074. responseIdTagInfoAsZero = 1;
  5075. }
  5076. else
  5077. {
  5078. printf("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  5079. }
  5080. if((responseIdTagInfoAsZero == 0)&&(strcmp(json_object_get_string(parentIdTagitem), ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0))
  5081. {
  5082. //modify item
  5083. temp_obj = json_object_new_object();
  5084. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  5085. {
  5086. json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  5087. }
  5088. else
  5089. {
  5090. json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  5091. }
  5092. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  5093. {
  5094. json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  5095. }
  5096. else
  5097. {
  5098. json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  5099. }
  5100. json_object_object_add(temp_obj, "status", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
  5101. json_object_array_add(newHeatMap, temp_obj);
  5102. }
  5103. else
  5104. {
  5105. //wrie original item
  5106. json_object_array_add(newHeatMap, jsonitem);
  5107. printf("authen reponce 5-1\n");
  5108. }
  5109. }
  5110. //(1)write to temp file (2)remove original file (3) rename filename of temp file
  5111. char temp[] = "temp.json";
  5112. FILE *fp;
  5113. fp=fopen(temp,"w");
  5114. fclose(fp);
  5115. remove(filename);
  5116. rename(temp, filename);
  5117. json_object_to_file(filename, newHeatMap);
  5118. printf("authen reponce 5-2\n");
  5119. json_object_put(newHeatMap); // Delete the json object
  5120. printf("authen reponce 5-3\n");
  5121. }
  5122. printf("authen reponce 5-4\n");
  5123. free(buffer);
  5124. printf("authen reponce 5-5\n");
  5125. // json_object_put(root_obj); // Delete the json object
  5126. printf("authen reponce 5-6\n");
  5127. }
  5128. out:
  5129. json_object_put(obj);
  5130. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5131. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5132. authorizeRetryTimes = 0;
  5133. //for test
  5134. #if 0
  5135. ShmOCPP16Data->CpMsg.bits[0].StartTransactionReq = 1;
  5136. ShmOCPP16Data->CpMsg.bits[0].StartTransactionConf = 1;
  5137. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus ='3'; //preparing
  5138. teststatus = 0; //for startTransaction
  5139. #endif
  5140. }
  5141. void handleBootNotificationResponse(char *payload, int gun_index)
  5142. {
  5143. struct json_object *obj;
  5144. char *status;
  5145. obj = json_tokener_parse(payload);
  5146. printf("handleBootNotificationResponse\n");
  5147. #ifdef SystemLogMessage
  5148. DEBUG_INFO("currentTime: %s\n", json_object_get_string(json_object_object_get(obj, "currentTime")));
  5149. DEBUG_INFO("interval: %d\n", json_object_get_int(json_object_object_get(obj, "interval")));
  5150. DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(obj, "status")));
  5151. #endif
  5152. //write back to ShmOCPP16Data->BootNotification
  5153. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime,(char *)json_object_get_string(json_object_object_get(obj, "currentTime")));
  5154. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = json_object_get_int(json_object_object_get(obj, "interval"));
  5155. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, (char *)json_object_get_string(json_object_object_get(obj, "status")));
  5156. status = json_object_get_string(json_object_object_get(obj, "status"));
  5157. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  5158. HeartBeatWaitTime = BootNotificationInterval;
  5159. printf("test 1\n");
  5160. if((strcmp(status, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  5161. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  5162. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  5163. {
  5164. server_sign = TRUE;
  5165. server_pending =FALSE;
  5166. }
  5167. else if(strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  5168. {
  5169. server_pending = TRUE;
  5170. }
  5171. double diff_t;
  5172. struct tm tp;
  5173. char buf[28];
  5174. char timebuf[50];
  5175. strptime(ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  5176. tp.tm_isdst = -1;
  5177. time_t utc = mktime(&tp);
  5178. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  5179. memset(timebuf, 0, sizeof timebuf);
  5180. sprintf(timebuf,"date -s '%s'",buf);
  5181. printf("timebuf=%s\n",timebuf);
  5182. system(timebuf);
  5183. //==============================================
  5184. // RTC sync
  5185. //==============================================
  5186. system("/sbin/hwclock -w --systohc");
  5187. printf("test 2\n");
  5188. json_object_put(obj); // Delete the json object
  5189. printf("test 3\n");
  5190. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  5191. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  5192. }
  5193. void handleDataTransferResponse(char *payload, int gun_index)
  5194. {
  5195. struct json_object *obj;
  5196. obj = json_tokener_parse(payload);
  5197. #ifdef SystemLogMessage
  5198. DEBUG_INFO("data: %s\n", json_object_get_string(json_object_object_get(obj, "data")));
  5199. #endif
  5200. }
  5201. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  5202. {
  5203. struct json_object *obj;
  5204. obj = json_tokener_parse(payload);
  5205. // ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5206. // ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  5207. //No fields are defined.
  5208. }
  5209. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  5210. {
  5211. struct json_object *obj;
  5212. obj = json_tokener_parse(payload);
  5213. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5214. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  5215. //No fields are defined.
  5216. }
  5217. void handleHeartbeatResponse(char *payload, int gun_index)
  5218. {
  5219. struct json_object *obj;
  5220. obj = json_tokener_parse(payload);
  5221. printf("handleHeartbeatResponse\n");
  5222. #ifdef SystemLogMessage
  5223. DEBUG_INFO("currentTime: %s\n", json_object_get_string(json_object_object_get(obj, "currentTime")));
  5224. #endif
  5225. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,(char *)json_object_get_string(json_object_object_get(obj, "currentTime")));
  5226. double diff_t;
  5227. struct tm tp;
  5228. char buf[28];
  5229. char timebuf[50];
  5230. strptime(ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  5231. tp.tm_isdst = -1;
  5232. time_t utc = mktime(&tp);
  5233. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  5234. memset(timebuf, 0, sizeof timebuf);
  5235. sprintf(timebuf,"date -s '%s'",buf);
  5236. printf("timebuf=%s\n",timebuf);
  5237. system(timebuf);
  5238. //==============================================
  5239. // RTC sync
  5240. //==============================================
  5241. system("/sbin/hwclock -w --systohc");
  5242. json_object_put(obj); // Delete the json object
  5243. }
  5244. void handleMeterValuesResponse(char *payload, int gun_index)
  5245. {
  5246. struct json_object *obj;
  5247. obj = json_tokener_parse(payload);
  5248. //No fields are defined.
  5249. }
  5250. void handleStartTransactionResponse(char *payload, int gun_index)
  5251. {
  5252. struct json_object *obj;
  5253. obj = json_tokener_parse(payload);
  5254. // gun_index = gun_index-1;
  5255. #ifdef SystemLogMessage
  5256. DEBUG_INFO("idTagInfo-expiryDate: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate")));
  5257. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag")));
  5258. DEBUG_INFO("idTagInfo-status: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "status")));
  5259. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(obj, "transactionId")));
  5260. #endif
  5261. printf("handleStartTransactionResponse\n");
  5262. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate") != NULL) // expiryDate is option
  5263. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate")));
  5264. printf("handleStartTransactionResponse 01\n");
  5265. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag") != NULL) // parentIdTag is option
  5266. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag")));
  5267. printf("handleStartTransactionResponse 02\n");
  5268. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "status")));
  5269. //ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(obj, "transactionId"));
  5270. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(obj, "transactionId"));
  5271. printf("handleStartTransactionResponse 03\n");
  5272. int transactionIdInt = json_object_get_int(json_object_object_get(obj, "transactionId"));
  5273. printf("handleStartTransactionResponse 1\n");
  5274. printf("handleStartTransactionResponse 2\n");
  5275. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  5276. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  5277. //for test
  5278. #if 0
  5279. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5280. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5281. #endif
  5282. if(strcmp(ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  5283. {
  5284. #if 0
  5285. //check Transaction active
  5286. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5287. {
  5288. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  5289. {
  5290. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus = '4';
  5291. }
  5292. }
  5293. for (int index = 0; index < CCS_QUANTITY; index++)
  5294. {
  5295. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  5296. {
  5297. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus = '4';
  5298. }
  5299. }
  5300. for (int index = 0; index < GB_QUANTITY; index++)
  5301. {
  5302. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  5303. {
  5304. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus = '4';
  5305. }
  5306. }
  5307. #endif
  5308. //add Charging Record
  5309. SettingChargingRecord(gun_index, transactionIdInt);
  5310. }
  5311. }
  5312. void handleStatusNotificationResponse(char *payload, int gun_index)
  5313. {
  5314. struct json_object *obj;
  5315. obj = json_tokener_parse(payload);
  5316. printf("handleStatusNotificationResponse\n");
  5317. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5318. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  5319. //for test
  5320. #if 0
  5321. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[gun_index].SystemStatus =='1') // Idle
  5322. {
  5323. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[gun_index].SystemStatus ='3'; //preparing
  5324. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5325. }
  5326. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[gun_index].SystemStatus =='3')//preparing
  5327. {
  5328. printf("preparing UserPlugGun=%d\n",UserPlugGun);
  5329. if(UserPlugGun == 1)
  5330. {
  5331. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[gun_index].SystemStatus ='1';
  5332. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5333. UserPlugGun = 0;
  5334. }
  5335. else
  5336. {
  5337. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 1;
  5338. }
  5339. }
  5340. #endif
  5341. //No fields are defined.
  5342. }
  5343. void handleStopTransactionnResponse(char *payload, int gun_index)
  5344. {
  5345. struct json_object *obj;
  5346. obj = json_tokener_parse(payload);
  5347. printf("handleStopTransactionnResponse\n");
  5348. // gun_index = gun_index - 1;
  5349. if(json_object_object_get(obj, "idTagInfo") != NULL) // option
  5350. {
  5351. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate") != NULL) // option
  5352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate")));
  5353. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag") != NULL) // option
  5354. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag")));
  5355. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "status")));
  5356. #ifdef SystemLogMessage
  5357. DEBUG_INFO("idTagInfo-expiryDate: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate")));
  5358. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag")));
  5359. DEBUG_INFO("idTagInfo-status: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "status")));
  5360. #endif
  5361. }
  5362. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  5363. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5364. json_object_put(obj); // Delete the json object
  5365. //for test
  5366. //UserPlugGun = 0;
  5367. #if 0
  5368. if(strcmp(ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  5369. {
  5370. //check Transaction active
  5371. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5372. {
  5373. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  5374. {
  5375. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus = '3'; //3: preparing
  5376. }
  5377. }
  5378. for (int index = 0; index < CCS_QUANTITY; index++)
  5379. {
  5380. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  5381. {
  5382. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus = '3'; //3: preparing
  5383. }
  5384. }
  5385. for (int index = 0; index < GB_QUANTITY; index++)
  5386. {
  5387. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  5388. {
  5389. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus = '3'; //3: preparing
  5390. }
  5391. }
  5392. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5393. //ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 1;
  5394. }
  5395. #endif
  5396. }
  5397. //==========================================
  5398. // Handle Error routine
  5399. //==========================================
  5400. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  5401. {
  5402. printf("handleError 1\n");
  5403. struct json_object *obj;
  5404. obj = json_tokener_parse(payload);
  5405. printf("handleError 2\n");
  5406. #ifdef SystemLogMessage
  5407. DEBUG_INFO("errorCode: %s\n", errorCode);
  5408. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  5409. if(obj != NULL)
  5410. DEBUG_INFO("errorDetails: %s\n", payload);
  5411. #endif
  5412. }
  5413. //===============================================
  5414. // Common routine
  5415. //===============================================
  5416. int initialConfigurationTable(void)
  5417. {
  5418. printf("initialConfigurationTable \n");
  5419. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  5420. /*Core Profile*/
  5421. //AllowOfflineTxForUnknownId
  5422. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  5423. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  5424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  5425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  5426. printf("initialConfigurationTable -1 \n");
  5427. //AuthorizationCacheEnabled
  5428. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  5429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  5430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  5431. //AuthorizeRemoteTxRequests
  5432. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  5433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  5434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  5435. //BlinkRepeat
  5436. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  5437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  5438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  5439. //ClockAlignedDataInterval
  5440. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  5441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  5442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  5443. //ConnectionTimeOut
  5444. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  5445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  5446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  5447. //GetConfigurationMaxKeys
  5448. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  5449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  5450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  5451. // HeartbeatInterval
  5452. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  5453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  5454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  5455. // LightIntensity
  5456. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  5457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  5458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  5459. // LocalAuthorizeOffline
  5460. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  5461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  5462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  5463. // LocalPreAuthorize
  5464. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  5465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  5466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  5467. // MaxEnergyOnInvalidId
  5468. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  5469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  5470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  5471. // MeterValuesAlignedData
  5472. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  5473. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  5474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "V,A,KW,KWh" );
  5475. // MeterValuesAlignedDataMaxLength
  5476. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  5477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  5478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "4" );
  5479. // MeterValuesSampledData
  5480. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  5481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  5482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "V,A,KW,KWh" );
  5483. // MeterValuesSampledDataMaxLength
  5484. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  5485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  5486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "4" );
  5487. // MeterValueSampleInterval
  5488. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  5489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  5490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  5491. // MinimumStatusDuration
  5492. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  5493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  5494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  5495. // NumberOfConnectors
  5496. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  5497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  5498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  5499. // ResetRetries
  5500. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  5501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  5502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  5503. // ConnectorPhaseRotation
  5504. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  5505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  5506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  5507. // ConnectorPhaseRotationMaxLength
  5508. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  5509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  5510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  5511. // StopTransactionOnEVSideDisconnect
  5512. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  5513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  5514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  5515. // StopTransactionOnInvalidId
  5516. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  5517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  5518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  5519. // StopTxnAlignedData
  5520. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  5521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  5522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  5523. // StopTxnAlignedDataMaxLength
  5524. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  5525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  5526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  5527. // StopTxnSampledData
  5528. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  5529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  5530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  5531. // StopTxnSampledDataMaxLength
  5532. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  5533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  5534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  5535. // SupportedFeatureProfiles
  5536. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  5537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  5538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  5539. // SupportedFeatureProfilesMaxLength
  5540. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  5541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  5542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  5543. // TransactionMessageAttempts
  5544. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  5545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  5546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  5547. // TransactionMessageRetryInterval
  5548. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  5549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  5550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  5551. // UnlockConnectorOnEVSideDisconnect
  5552. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  5553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  5554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  5555. // WebSocketPingInterval
  5556. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  5557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  5558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  5559. /* Local Auth List Management Profile*/
  5560. //LocalAuthListEnabled
  5561. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  5562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  5563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  5564. //LocalAuthListMaxLength
  5565. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  5566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  5567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  5568. //SendLocalListMaxLength
  5569. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  5570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  5571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  5572. //ReserveConnectorZeroSupported
  5573. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  5574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  5575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  5576. /* Smart Charging Profile */
  5577. //ChargeProfileMaxStackLevel
  5578. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  5579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  5580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  5581. // ChargingScheduleAllowedChargingRateUnit
  5582. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  5583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  5584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  5585. // ChargingScheduleMaxPeriods
  5586. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  5587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  5588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  5589. // ConnectorSwitch3to1PhaseSupported
  5590. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  5591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  5592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  5593. // MaxChargingProfilesInstalled
  5594. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  5595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  5596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  5597. #if 0
  5598. //write Configuration to flash
  5599. unsigned int i,Chk;
  5600. unsigned char *ptr;
  5601. int fd,wrd;
  5602. // Save factory default setting value to flash backup setting block
  5603. fd = open("/Storage/OCPP/OCPPConfiguration.txt", O_RDWR);
  5604. if (fd < 0)
  5605. {
  5606. #ifdef SystemLogMessage
  5607. DEBUG_ERROR("open /Storage/OCPP/OCPPConfiguration.txt NG");
  5608. #endif
  5609. free(ptr);
  5610. return 0;
  5611. }
  5612. wrd=write(fd, &ShmOCPP16Data->ConfigurationTable, sizeof(struct OCPP16ConfigurationTable));
  5613. close(fd);
  5614. if(wrd!=(sizeof(struct SysConfigData)))
  5615. {
  5616. #ifdef SystemLogMessage
  5617. DEBUG_ERROR("write /Storage/OCPP/OCPPConfiguration.txt NG");
  5618. #endif
  5619. free(ptr);
  5620. return 0;
  5621. }
  5622. #endif
  5623. return 0;
  5624. }
  5625. void getKeyValue(char *keyReq)
  5626. {
  5627. int isEmpty = FALSE;
  5628. int isKnowKey = FALSE;
  5629. int unKnowIndex = 0;
  5630. printf("enter getKeyValue \n");
  5631. printf("keyReq= %s\n", keyReq);
  5632. if((keyReq == NULL) || (strlen(keyReq) == 0))
  5633. isEmpty = TRUE;
  5634. printf("getkey_1\n");
  5635. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  5636. {
  5637. printf("getkey_1_0_0\n");
  5638. //debug.logout("Request key: " + (isEmpty?"AllowOfflineTxForUnknownId":keyReq[iReq]));
  5639. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  5640. printf("getkey_1_0\n");
  5641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  5642. printf("getkey_1_1\n");
  5643. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  5644. {
  5645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  5646. }
  5647. else
  5648. {
  5649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  5650. }
  5651. printf("getkey_1_2\n");
  5652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  5653. isKnowKey = TRUE;
  5654. }
  5655. printf("getkey_2\n");
  5656. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  5657. {
  5658. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  5659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  5660. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  5661. {
  5662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  5663. }
  5664. else
  5665. {
  5666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  5667. }
  5668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  5669. isKnowKey = TRUE;
  5670. printf("AuthorizationCacheEnabled\n");
  5671. }
  5672. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  5673. {
  5674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  5675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  5676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  5677. {
  5678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  5679. }
  5680. else
  5681. {
  5682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  5683. }
  5684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  5685. isKnowKey = TRUE;
  5686. printf("AuthorizeRemoteTxRequests\n");
  5687. }
  5688. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  5689. {
  5690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  5691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  5692. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  5693. {
  5694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  5695. }
  5696. else
  5697. {
  5698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  5699. }
  5700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  5701. isKnowKey = TRUE;
  5702. printf("BlinkRepeat\n");
  5703. }
  5704. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  5705. {
  5706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  5707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  5708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  5709. {
  5710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  5711. }
  5712. else
  5713. {
  5714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  5715. }
  5716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  5717. isKnowKey = TRUE;
  5718. printf("ClockAlignedDataInterval\n");
  5719. }
  5720. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  5721. {
  5722. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  5723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  5724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  5725. {
  5726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  5727. }
  5728. else
  5729. {
  5730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  5731. }
  5732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  5733. isKnowKey = TRUE;
  5734. printf("ConnectionTimeOut\n");
  5735. }
  5736. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  5737. {
  5738. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  5739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  5740. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  5741. {
  5742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  5743. }
  5744. else
  5745. {
  5746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  5747. }
  5748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  5749. isKnowKey = TRUE;
  5750. printf("GetConfigurationMaxKeys\n");
  5751. }
  5752. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  5753. {
  5754. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  5755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  5756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  5757. {
  5758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  5759. }
  5760. else
  5761. {
  5762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  5763. }
  5764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  5765. isKnowKey = TRUE;
  5766. printf("HeartbeatInterval\n");
  5767. }
  5768. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  5769. {
  5770. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  5771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  5772. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  5773. {
  5774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  5775. }
  5776. else
  5777. {
  5778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  5779. }
  5780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  5781. isKnowKey = TRUE;
  5782. printf("LightIntensity\n");
  5783. }
  5784. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  5785. {
  5786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  5787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  5788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  5789. {
  5790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  5791. }
  5792. else
  5793. {
  5794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  5795. }
  5796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  5797. isKnowKey = TRUE;
  5798. printf("LocalAuthorizeOffline\n");
  5799. }
  5800. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  5801. {
  5802. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  5803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  5804. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  5805. {
  5806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  5807. }
  5808. else
  5809. {
  5810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  5811. }
  5812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  5813. isKnowKey = TRUE;
  5814. printf("LocalPreAuthorize\n");
  5815. }
  5816. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  5817. {
  5818. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  5819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  5820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  5821. {
  5822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  5823. }
  5824. else
  5825. {
  5826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  5827. }
  5828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  5829. isKnowKey = TRUE;
  5830. printf("MaxEnergyOnInvalidId\n");
  5831. }
  5832. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  5833. {
  5834. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  5835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  5836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  5837. {
  5838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  5839. }
  5840. else
  5841. {
  5842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  5843. }
  5844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  5845. isKnowKey = TRUE;
  5846. printf("MeterValuesAlignedData\n");
  5847. }
  5848. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  5849. {
  5850. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  5851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  5852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  5853. {
  5854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  5855. }
  5856. else
  5857. {
  5858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  5859. }
  5860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  5861. isKnowKey = TRUE;
  5862. printf("MeterValuesAlignedDataMaxLength\n");
  5863. }
  5864. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  5865. {
  5866. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  5867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  5868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  5869. {
  5870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  5871. }
  5872. else
  5873. {
  5874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  5875. }
  5876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  5877. isKnowKey = TRUE;
  5878. printf("MeterValuesSampledData\n");
  5879. }
  5880. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  5881. {
  5882. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  5883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  5884. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  5885. {
  5886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  5887. }
  5888. else
  5889. {
  5890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  5891. }
  5892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  5893. isKnowKey = TRUE;
  5894. printf("MeterValuesSampledDataMaxLength\n");
  5895. }
  5896. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  5897. {
  5898. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  5899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  5900. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  5901. {
  5902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  5903. }
  5904. else
  5905. {
  5906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  5907. }
  5908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  5909. isKnowKey = TRUE;
  5910. printf("MeterValueSampleInterval\n");
  5911. }
  5912. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  5913. {
  5914. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  5915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  5916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  5917. {
  5918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  5919. }
  5920. else
  5921. {
  5922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  5923. }
  5924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  5925. isKnowKey = TRUE;
  5926. printf("MinimumStatusDuration\n");
  5927. }
  5928. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  5929. {
  5930. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  5931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  5932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  5933. {
  5934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  5935. }
  5936. else
  5937. {
  5938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  5939. }
  5940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  5941. isKnowKey = TRUE;
  5942. printf("NumberOfConnectors\n");
  5943. }
  5944. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  5945. {
  5946. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  5947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  5948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  5949. {
  5950. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  5951. }
  5952. else
  5953. {
  5954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  5955. }
  5956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  5957. isKnowKey = TRUE;
  5958. printf("ResetRetries\n");
  5959. }
  5960. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  5961. {
  5962. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  5963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  5964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  5965. {
  5966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  5967. }
  5968. else
  5969. {
  5970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  5971. }
  5972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  5973. isKnowKey = TRUE;
  5974. printf("ConnectorPhaseRotation\n");
  5975. }
  5976. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  5977. {
  5978. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  5979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  5980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  5981. {
  5982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  5983. }
  5984. else
  5985. {
  5986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  5987. }
  5988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  5989. isKnowKey = TRUE;
  5990. printf("ConnectorPhaseRotationMaxLength\n");
  5991. }
  5992. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  5993. {
  5994. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  5995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  5996. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  5997. {
  5998. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  5999. }
  6000. else
  6001. {
  6002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  6003. }
  6004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  6005. isKnowKey = TRUE;
  6006. printf("StopTransactionOnEVSideDisconnect\n");
  6007. }
  6008. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  6009. {
  6010. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  6011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  6012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  6013. {
  6014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  6015. }
  6016. else
  6017. {
  6018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  6019. }
  6020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  6021. isKnowKey = TRUE;
  6022. printf("StopTransactionOnInvalidId\n");
  6023. }
  6024. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  6025. {
  6026. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  6027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  6028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  6029. {
  6030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  6031. }
  6032. else
  6033. {
  6034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  6035. }
  6036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  6037. isKnowKey = TRUE;
  6038. printf("StopTxnAlignedData\n");
  6039. }
  6040. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  6041. {
  6042. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  6043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  6044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  6045. {
  6046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  6047. }
  6048. else
  6049. {
  6050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  6051. }
  6052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  6053. isKnowKey = TRUE;
  6054. printf("StopTxnAlignedDataMaxLength\n");
  6055. }
  6056. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  6057. {
  6058. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  6059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  6060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  6061. {
  6062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  6063. }
  6064. else
  6065. {
  6066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  6067. }
  6068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  6069. isKnowKey = TRUE;
  6070. printf("StopTxnSampledData\n");
  6071. }
  6072. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  6073. {
  6074. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  6075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  6076. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  6077. {
  6078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  6079. }
  6080. else
  6081. {
  6082. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  6083. }
  6084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  6085. isKnowKey = TRUE;
  6086. printf("StopTxnSampledDataMaxLength\n");
  6087. }
  6088. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  6089. {
  6090. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  6091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  6092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  6093. {
  6094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  6095. }
  6096. else
  6097. {
  6098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  6099. }
  6100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  6101. isKnowKey = TRUE;
  6102. printf("SupportedFeatureProfiles\n");
  6103. }
  6104. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  6105. {
  6106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  6107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  6108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  6109. {
  6110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  6111. }
  6112. else
  6113. {
  6114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  6115. }
  6116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  6117. isKnowKey = TRUE;
  6118. printf("SupportedFeatureProfilesMaxLength\n");
  6119. }
  6120. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  6121. {
  6122. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  6123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  6124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  6125. {
  6126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  6127. }
  6128. else
  6129. {
  6130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  6131. }
  6132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  6133. isKnowKey = TRUE;
  6134. printf("TransactionMessageAttempts\n");
  6135. }
  6136. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  6137. {
  6138. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  6139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  6140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  6141. {
  6142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  6143. }
  6144. else
  6145. {
  6146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  6147. }
  6148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  6149. isKnowKey = TRUE;
  6150. printf("TransactionMessageRetryInterval\n");
  6151. }
  6152. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  6153. {
  6154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  6155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  6156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  6157. {
  6158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  6159. }
  6160. else
  6161. {
  6162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  6163. }
  6164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  6165. isKnowKey = TRUE;
  6166. printf("UnlockConnectorOnEVSideDisconnect\n");
  6167. }
  6168. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  6169. {
  6170. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  6171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  6172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  6173. {
  6174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  6175. }
  6176. else
  6177. {
  6178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  6179. }
  6180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  6181. isKnowKey = TRUE;
  6182. printf("WebSocketPingInterval\n");
  6183. }
  6184. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  6185. {
  6186. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  6187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  6188. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  6189. {
  6190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  6191. }
  6192. else
  6193. {
  6194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  6195. }
  6196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  6197. isKnowKey = TRUE;
  6198. printf("LocalAuthListEnabled\n");
  6199. }
  6200. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  6201. {
  6202. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  6203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  6204. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  6205. {
  6206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  6207. }
  6208. else
  6209. {
  6210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  6211. }
  6212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  6213. isKnowKey = TRUE;
  6214. printf("LocalAuthListMaxLength\n");
  6215. }
  6216. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  6217. {
  6218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  6219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  6220. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  6221. {
  6222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  6223. }
  6224. else
  6225. {
  6226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  6227. }
  6228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  6229. isKnowKey = TRUE;
  6230. printf("SendLocalListMaxLength\n");
  6231. }
  6232. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  6233. {
  6234. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  6235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  6236. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  6237. {
  6238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  6239. }
  6240. else
  6241. {
  6242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  6243. }
  6244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  6245. isKnowKey = TRUE;
  6246. printf("ReserveConnectorZeroSupported\n");
  6247. }
  6248. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  6249. {
  6250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  6251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  6252. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  6253. {
  6254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  6255. }
  6256. else
  6257. {
  6258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  6259. }
  6260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  6261. isKnowKey = TRUE;
  6262. printf("ChargeProfileMaxStackLevel\n");
  6263. }
  6264. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  6265. {
  6266. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  6267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  6268. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  6269. {
  6270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  6271. }
  6272. else
  6273. {
  6274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  6275. }
  6276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  6277. isKnowKey = TRUE;
  6278. printf("ChargingScheduleAllowedChargingRateUnit\n");
  6279. }
  6280. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  6281. {
  6282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  6283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  6284. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  6285. {
  6286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  6287. }
  6288. else
  6289. {
  6290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  6291. }
  6292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  6293. isKnowKey = TRUE;
  6294. printf("ChargingScheduleMaxPeriods\n");
  6295. }
  6296. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  6297. {
  6298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  6299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  6300. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  6301. {
  6302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  6303. }
  6304. else
  6305. {
  6306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  6307. }
  6308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  6309. isKnowKey = TRUE;
  6310. printf("ConnectorSwitch3to1PhaseSupported\n");
  6311. }
  6312. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  6313. {
  6314. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  6315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  6316. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  6317. {
  6318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  6319. }
  6320. else
  6321. {
  6322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  6323. }
  6324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  6325. isKnowKey = TRUE;
  6326. printf("MaxChargingProfilesInstalled\n");
  6327. }
  6328. //=========================================================
  6329. if(!isEmpty && !isKnowKey)
  6330. {
  6331. printf("unKnowIndex =%d\n", UnknownKeynum);
  6332. strcpy(unknownkey[UnknownKeynum], keyReq);
  6333. UnknownKeynum = UnknownKeynum + 1;
  6334. }
  6335. }
  6336. void processUnkownKey(void)
  6337. {
  6338. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  6339. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  6340. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = (struct StructConfigurationKeyItems *)malloc(sizeof(struct StructConfigurationKeyItems)*UnknownKeynum);
  6341. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* UnknownKeynum);
  6342. printf("processUnkownKey UnknownKeynum =%d\n",UnknownKeynum);
  6343. for(int index=0; index < UnknownKeynum; index++)
  6344. {
  6345. printf("ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[%d].Item[0]=%c\n",index,ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0]);
  6346. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  6347. {
  6348. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  6349. printf("getkeyValue: %s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item);
  6350. }
  6351. }
  6352. }
  6353. int setKeyValue(char *key, char *value)
  6354. {
  6355. int isSuccess = NotSupported;
  6356. printf("setKeyValue : key : %s\n", key);
  6357. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  6358. {
  6359. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  6360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  6361. {
  6362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6363. isSuccess = ConfigurationStatus_Accepted;
  6364. }
  6365. else
  6366. {
  6367. isSuccess = ConfigurationStatus_Rejected;
  6368. }
  6369. }
  6370. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  6371. {
  6372. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  6373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  6374. {
  6375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6376. isSuccess = ConfigurationStatus_Accepted;
  6377. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  6378. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  6379. }
  6380. else
  6381. {
  6382. isSuccess = ConfigurationStatus_Rejected;
  6383. }
  6384. }
  6385. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  6386. {
  6387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  6388. {
  6389. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  6390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6391. isSuccess = ConfigurationStatus_Accepted;
  6392. }
  6393. else
  6394. {
  6395. isSuccess = ConfigurationStatus_Rejected;
  6396. }
  6397. }
  6398. if(strcmp(key, "BlinkRepeat") == 0)
  6399. {
  6400. //Charger.BlinkRepeat = Integer.parseInt(value);
  6401. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  6402. {
  6403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  6404. isSuccess = ConfigurationStatus_Accepted;
  6405. }
  6406. else
  6407. {
  6408. isSuccess = ConfigurationStatus_Rejected;
  6409. }
  6410. }
  6411. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  6412. {
  6413. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  6414. {
  6415. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  6416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  6417. isSuccess = ConfigurationStatus_Accepted;
  6418. }
  6419. else
  6420. {
  6421. isSuccess = ConfigurationStatus_Rejected;
  6422. }
  6423. }
  6424. if(strcmp(key, "ConnectionTimeOut") == 0 )
  6425. {
  6426. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  6427. {
  6428. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  6429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value)*1000 );
  6430. isSuccess = ConfigurationStatus_Accepted;
  6431. }
  6432. else
  6433. {
  6434. isSuccess = ConfigurationStatus_Rejected;
  6435. }
  6436. }
  6437. if(strcmp(key, "HeartbeatInterval") == 0)
  6438. {
  6439. printf("HeartbeatInterval ItemAccessibility: %d\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility);
  6440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  6441. {
  6442. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  6443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  6444. HeartBeatWaitTime = atoi(value);
  6445. printf("set HeartbeatInterval value \n");
  6446. isSuccess = ConfigurationStatus_Accepted;
  6447. }
  6448. else
  6449. {
  6450. isSuccess = ConfigurationStatus_Rejected;
  6451. }
  6452. }
  6453. if(strcmp(key, "LightIntensity") == 0)
  6454. {
  6455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  6456. {
  6457. //Charger.LightIntensity = Integer.parseInt(value);
  6458. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  6459. isSuccess = ConfigurationStatus_Accepted;
  6460. }
  6461. else
  6462. {
  6463. isSuccess = ConfigurationStatus_Rejected;
  6464. }
  6465. }
  6466. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  6467. {
  6468. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  6469. {
  6470. //Charger.LocalAuthorizeOffline = (value.toLowerCase().equals("true")?true:false);
  6471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6472. isSuccess = ConfigurationStatus_Accepted;
  6473. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  6474. }
  6475. else
  6476. {
  6477. isSuccess = ConfigurationStatus_Rejected;
  6478. }
  6479. }
  6480. if(strcmp(key, "LocalPreAuthorize") == 0)
  6481. {
  6482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  6483. {
  6484. //Charger.LocalPreAuthorize = (value.toLowerCase().equals("true")?true:false);
  6485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6486. isSuccess = ConfigurationStatus_Accepted;
  6487. }
  6488. else
  6489. {
  6490. isSuccess = ConfigurationStatus_Rejected;
  6491. }
  6492. }
  6493. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  6494. {
  6495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  6496. {
  6497. //Charger.MaxEnergyOnInvalidId = Integer.parseInt(value);
  6498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  6499. isSuccess = ConfigurationStatus_Accepted;
  6500. }
  6501. else
  6502. {
  6503. isSuccess = ConfigurationStatus_Rejected;
  6504. }
  6505. }
  6506. if(strcmp(key, "MeterValuesAlignedData") == 0)
  6507. {
  6508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  6509. {
  6510. //Charger.MeterValuesAlignedData = value.toLowerCase();
  6511. int valueLength = strlen(value);
  6512. for(int i = 0; value[i]; i++){
  6513. value[i] = tolower(value[i]);
  6514. }
  6515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  6516. isSuccess = ConfigurationStatus_Accepted;
  6517. }
  6518. else
  6519. {
  6520. isSuccess = ConfigurationStatus_Rejected;
  6521. }
  6522. }
  6523. if(strcmp(key, "MeterValuesSampledData") == 0 )
  6524. {
  6525. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  6526. {
  6527. //Charger.MeterValuesSampledData = value.toLowerCase();
  6528. int valueLength = strlen(value);
  6529. for(int i = 0; value[i]; i++){
  6530. value[i] = tolower(value[i]);
  6531. }
  6532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  6533. isSuccess = ConfigurationStatus_Accepted;
  6534. }
  6535. else
  6536. {
  6537. isSuccess = ConfigurationStatus_Rejected;
  6538. }
  6539. }
  6540. if(strcmp(key, "MeterValueSampleInterval") == 0)
  6541. {
  6542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  6543. {
  6544. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  6545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value)*1000 );
  6546. isSuccess = ConfigurationStatus_Accepted;
  6547. }
  6548. else
  6549. {
  6550. isSuccess = ConfigurationStatus_Rejected;
  6551. }
  6552. }
  6553. if(strcmp(key, "MinimumStatusDuration") == 0)
  6554. {
  6555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  6556. {
  6557. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  6558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  6559. isSuccess = ConfigurationStatus_Accepted;
  6560. }
  6561. else
  6562. {
  6563. isSuccess = ConfigurationStatus_Rejected;
  6564. }
  6565. }
  6566. if(strcmp(key, "ResetRetries") == 0)
  6567. {
  6568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  6569. {
  6570. //Charger.ResetRetries = Integer.parseInt(value);
  6571. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  6572. isSuccess = ConfigurationStatus_Accepted;
  6573. }
  6574. else
  6575. {
  6576. isSuccess = ConfigurationStatus_Rejected;
  6577. }
  6578. }
  6579. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  6580. {
  6581. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  6582. {
  6583. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  6584. int valueLength = strlen(value);
  6585. for(int i = 0; value[i]; i++){
  6586. value[i] = tolower(value[i]);
  6587. }
  6588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  6589. isSuccess = ConfigurationStatus_Accepted;
  6590. }
  6591. else
  6592. {
  6593. isSuccess = ConfigurationStatus_Rejected;
  6594. }
  6595. }
  6596. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  6597. {
  6598. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  6599. {
  6600. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  6601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6602. isSuccess = ConfigurationStatus_Accepted;
  6603. }
  6604. else
  6605. {
  6606. isSuccess = ConfigurationStatus_Rejected;
  6607. }
  6608. }
  6609. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  6610. {
  6611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  6612. {
  6613. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  6614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6615. isSuccess = ConfigurationStatus_Accepted;
  6616. }
  6617. else
  6618. {
  6619. isSuccess = ConfigurationStatus_Rejected;
  6620. }
  6621. }
  6622. if(strcmp(key, "StopTxnAlignedData") == 0)
  6623. {
  6624. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  6625. {
  6626. //Charger.StopTxnAlignedData = value.toLowerCase();
  6627. int valueLength = strlen(value);
  6628. for(int i = 0; value[i]; i++){
  6629. value[i] = tolower(value[i]);
  6630. }
  6631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  6632. isSuccess = ConfigurationStatus_Accepted;
  6633. }
  6634. else
  6635. {
  6636. isSuccess = ConfigurationStatus_Rejected;
  6637. }
  6638. }
  6639. if(strcmp(key, "StopTxnSampledData") == 0)
  6640. {
  6641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  6642. {
  6643. //Charger.StopTxnSampledData = value.toLowerCase();
  6644. int valueLength = strlen(value);
  6645. for(int i = 0; value[i]; i++){
  6646. value[i] = tolower(value[i]);
  6647. }
  6648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  6649. isSuccess = ConfigurationStatus_Accepted;
  6650. }
  6651. else
  6652. {
  6653. isSuccess = ConfigurationStatus_Rejected;
  6654. }
  6655. }
  6656. if(strcmp(key, "TransactionMessageAttempts") == 0)
  6657. {
  6658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  6659. {
  6660. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  6661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  6662. isSuccess = ConfigurationStatus_Accepted;
  6663. }
  6664. else
  6665. {
  6666. isSuccess = ConfigurationStatus_Rejected;
  6667. }
  6668. }
  6669. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  6670. {
  6671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  6672. {
  6673. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  6674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value)*1000 );
  6675. isSuccess = ConfigurationStatus_Accepted;
  6676. }
  6677. else
  6678. {
  6679. isSuccess = ConfigurationStatus_Rejected;
  6680. }
  6681. }
  6682. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  6683. {
  6684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  6685. {
  6686. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  6687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6688. isSuccess = ConfigurationStatus_Accepted;
  6689. }
  6690. else
  6691. {
  6692. isSuccess = ConfigurationStatus_Rejected;
  6693. }
  6694. }
  6695. if(strcmp(key, "WebSocketPingInterval") == 0)
  6696. {
  6697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  6698. {
  6699. //Charger.WebSocketPingInterval = Integer.parseInt(value)*1000;
  6700. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value)*1000 );
  6701. isSuccess = ConfigurationStatus_Accepted;
  6702. }
  6703. else
  6704. {
  6705. isSuccess = ConfigurationStatus_Rejected;
  6706. }
  6707. }
  6708. if(strcmp(key, "LocalAuthListEnabled") == 0)
  6709. {
  6710. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  6711. {
  6712. //Charger.LocalAuthListEnabled = (value.toLowerCase().equals("true")?true:false);
  6713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6714. isSuccess = ConfigurationStatus_Accepted;
  6715. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  6716. }
  6717. else
  6718. {
  6719. isSuccess = ConfigurationStatus_Rejected;
  6720. }
  6721. }
  6722. return isSuccess;
  6723. }
  6724. int updateSetting(char *key, char *value)
  6725. {
  6726. int isSuccess = FALSE;
  6727. json_object *json_obj = NULL;
  6728. json_object *tmp_obj = NULL;
  6729. //new a base object
  6730. json_obj = json_object_new_object();
  6731. tmp_obj = json_object_new_string(value);
  6732. json_object_object_add(json_obj, key, tmp_obj);
  6733. json_object_to_file("/var/www/settings", json_obj);
  6734. isSuccess = TRUE;
  6735. return isSuccess;
  6736. }
  6737. json_object * getJSONfromFile(char *filename)
  6738. {
  6739. FILE *fptr;
  6740. char str[] = "{}";
  6741. json_object * obj ;
  6742. fptr = fopen(filename, "rw+");
  6743. if(fptr == NULL) //if file does not exist, create it
  6744. {
  6745. fptr = fopen(filename, "w");
  6746. fwrite(str , 1 , sizeof(str) , fptr );
  6747. }
  6748. fclose(fptr);
  6749. //obj = new JSONObject(new JSONTokener((new URI("file:///" + filename)).toURL().openStream()));
  6750. obj = json_object_from_file(filename);
  6751. return obj;
  6752. }
  6753. #define SA struct sockaddr
  6754. #define MAXBUF 1024
  6755. static char m_send_buffer[1024];
  6756. static char m_recv_buffer[1024];
  6757. static int m_socket_data;
  6758. static int sockfd;
  6759. int ReadHttpStatus(int sock){
  6760. char c;
  6761. char buff[1024]="",*ptr=buff+1;
  6762. int bytes_received, status;
  6763. printf("Begin Response ..\n");
  6764. while(bytes_received = recv(sock, ptr, 1, 0)){
  6765. if(bytes_received==-1){
  6766. perror("ReadHttpStatus");
  6767. exit(1);
  6768. }
  6769. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  6770. ptr++;
  6771. }
  6772. *ptr=0;
  6773. ptr=buff+1;
  6774. sscanf(ptr,"%*s %d ", &status);
  6775. printf("%s\n",ptr);
  6776. printf("status=%d\n",status);
  6777. printf("End Response ..\n");
  6778. return (bytes_received>0)?status:0;
  6779. }
  6780. //the only filed that it parsed is 'Content-Length'
  6781. int ParseHeader(int sock){
  6782. char c;
  6783. char buff[1024]="",*ptr=buff+4;
  6784. int bytes_received, status;
  6785. printf("Begin HEADER ..\n");
  6786. while(bytes_received = recv(sock, ptr, 1, 0)){
  6787. if(bytes_received==-1){
  6788. perror("Parse Header");
  6789. exit(1);
  6790. }
  6791. if(
  6792. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  6793. (ptr[-1]=='\r') && (*ptr=='\n' )
  6794. ) break;
  6795. ptr++;
  6796. }
  6797. *ptr=0;
  6798. ptr=buff+4;
  6799. //printf("%s",ptr);
  6800. if(bytes_received){
  6801. ptr=strstr(ptr,"Content-Length:");
  6802. if(ptr){
  6803. sscanf(ptr,"%*s %d",&bytes_received);
  6804. }else
  6805. bytes_received=-1; //unknown size
  6806. printf("Content-Length: %d\n",bytes_received);
  6807. }
  6808. printf("End HEADER ..\n");
  6809. return bytes_received ;
  6810. }
  6811. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  6812. {
  6813. //char domain[] = "sstatic.net", path[]="stackexchange/img/logos/so/so-logo-med.png";
  6814. int sock, bytes_received;
  6815. char send_data[1024],recv_data[1024], *p;
  6816. struct sockaddr_in server_addr;
  6817. struct hostent *he;
  6818. char ftpbuf[200];
  6819. int systemresult;
  6820. char temp[100];
  6821. memset(ftpbuf, 0, sizeof(ftpbuf));
  6822. sprintf(ftpbuf, "wget --tries=3 -o %s -cb %s ",filename, url);
  6823. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  6824. systemresult = system(ftpbuf);
  6825. printf("systemresult=%d\n",systemresult);
  6826. if(systemresult != 0)
  6827. {
  6828. printf("ftpget error!\n");
  6829. return FALSE;
  6830. }
  6831. return TRUE;
  6832. }
  6833. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename)
  6834. {
  6835. //int sockfd;
  6836. static int ret= 0;
  6837. int reclen=0, off;
  6838. int n, fileSize;
  6839. char fname[40];
  6840. char fileSizeBuffer[256];
  6841. int len;
  6842. int k, size, status;
  6843. struct sockaddr_in servaddr,cliaddr;
  6844. struct sockaddr_in servaddr_data;
  6845. struct hostent* server;
  6846. char bufferTemp[500000];
  6847. char *IPbuffer;
  6848. char ftpbuf[200];
  6849. int systemresult;
  6850. char temp[100];
  6851. server = gethostbyname(location);
  6852. // To convert an Internet network
  6853. // address into ASCII string
  6854. IPbuffer = inet_ntoa(*((struct in_addr*)
  6855. server->h_addr_list[0]));
  6856. memset(ftpbuf, 0, sizeof(ftpbuf));
  6857. sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename);
  6858. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  6859. systemresult = system(ftpbuf);
  6860. printf("systemresult=%d\n",systemresult);
  6861. if(systemresult != 0)
  6862. {
  6863. printf("ftpget error!\n");
  6864. return FALSE;
  6865. }
  6866. return TRUE;
  6867. }
  6868. int ftpFile(char *location, char *user, char *password, int port, char *path, char *filename)
  6869. {
  6870. //int sockfd;
  6871. static int ret= 0;
  6872. int reclen=0, off;
  6873. int n, fileSize;
  6874. char fname[40];
  6875. char fileSizeBuffer[256];
  6876. int len;
  6877. int k, size, status;
  6878. struct sockaddr_in servaddr,cliaddr;
  6879. struct sockaddr_in servaddr_data;
  6880. struct hostent* server;
  6881. char *IPbuffer;
  6882. char ftpbuf[200];
  6883. int systemresult;
  6884. printf("ftpFile -1\n");
  6885. // To retrieve host information
  6886. server = gethostbyname(location);
  6887. // To convert an Internet network
  6888. // address into ASCII string
  6889. IPbuffer = inet_ntoa(*((struct in_addr*)
  6890. server->h_addr_list[0]));
  6891. memset(ftpbuf, 0, sizeof(ftpbuf));
  6892. /* format : ftpput -u username -p passwd IP target source*/
  6893. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,filename);
  6894. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  6895. systemresult = system(ftpbuf);
  6896. printf("systemresult=%d\n",systemresult);
  6897. if(systemresult != 0)
  6898. {
  6899. printf("ftpput error!\n");
  6900. return FALSE;
  6901. }
  6902. return TRUE;
  6903. }
  6904. int SettingChargingRecord(int target, int transactionId)
  6905. {
  6906. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6907. {
  6908. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '4'))
  6909. {
  6910. addBuff(target, transactionId, 0);
  6911. return TRUE;
  6912. }
  6913. }
  6914. for (int index = 0; index < CCS_QUANTITY; index++)
  6915. {
  6916. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '4'))
  6917. {
  6918. addBuff(target, transactionId, 0);
  6919. return TRUE;
  6920. }
  6921. }
  6922. for (int index = 0; index < GB_QUANTITY; index++)
  6923. {
  6924. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4'))
  6925. {
  6926. addBuff(target, transactionId, 0);
  6927. return TRUE;
  6928. }
  6929. }
  6930. return FALSE;
  6931. }
  6932. int addBuff(int gun_idx, int user_id, int cmd_sn)
  6933. {
  6934. int isSuccess = FALSE;
  6935. char *query = NULL;
  6936. sqlite3_stmt *stmt;
  6937. int rc; // return code
  6938. char str[20];
  6939. sprintf(str,"%d",user_id);
  6940. sqlite3_prepare_v2(db, "insert into log_buffer (user_id, cmd_sn, charger_id, gun_type, gun_no, rfid_no, stime, etime, time_len, s_soc, e_soc, stop_reason, power, meter_before, meter_after, charge_price, reserve, surplus_before, surplus_after, service_price, is_pay ,charge_strategy, charge_parameter, vin, vehicle_no, start_method, card_type, is_upload, guid, is_buf2OK) values (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12,?13,?14,?15,?16,?17,?18,?19,?20,?21,?22,?23,?24,?25,?26,?27,?28,?29,?30);", -1, &stmt, NULL); /* 1 */
  6941. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  6942. rc = sqlite3_step(stmt); /* 3 */
  6943. if (rc != SQLITE_DONE) {
  6944. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  6945. goto out;
  6946. }
  6947. sqlite3_finalize(stmt);
  6948. free(query);
  6949. out:
  6950. /*
  6951. * close SQLite database
  6952. */
  6953. sqlite3_close(db);
  6954. printf("database closed.\n");
  6955. return isSuccess;
  6956. }
  6957. /**
  6958. * Place the contents of the specified file into a memory buffer
  6959. *
  6960. * @param[in] filename The path and name of the file to read
  6961. * @param[out] filebuffer A pointer to the contents in memory
  6962. * @return status 0 success, 1 on failure
  6963. */
  6964. int get_file_contents(const char* filename, char** outbuffer) {
  6965. FILE* file = NULL;
  6966. long filesize;
  6967. const int blocksize = 1;
  6968. size_t readsize;
  6969. char* filebuffer;
  6970. // Open the file
  6971. file = fopen(filename, "r");
  6972. if (NULL == file)
  6973. {
  6974. printf("'%s' not opened\n", filename);
  6975. exit(EXIT_FAILURE);
  6976. }
  6977. // Determine the file size
  6978. fseek(file, 0, SEEK_END);
  6979. filesize = ftell(file);
  6980. rewind (file);
  6981. // Allocate memory for the file contents
  6982. filebuffer = (char*) malloc(sizeof(char) * filesize);
  6983. *outbuffer = filebuffer;
  6984. if (filebuffer == NULL)
  6985. {
  6986. fputs ("malloc out-of-memory", stderr);
  6987. exit(EXIT_FAILURE);
  6988. }
  6989. // Read in the file
  6990. readsize = fread(filebuffer, blocksize, filesize, file);
  6991. if (readsize != filesize)
  6992. {
  6993. fputs ("didn't read file completely",stderr);
  6994. exit(EXIT_FAILURE);
  6995. }
  6996. // Clean exit
  6997. fclose(file);
  6998. return EXIT_SUCCESS;
  6999. }
  7000. //Command Port, Receive Answer
  7001. static int ftp_recv_respond(int m_socket_cmd, char *resp, int len)
  7002. {
  7003. int ret;
  7004. int off;
  7005. len -= 1;
  7006. for(off=0; off<len; off+=ret)
  7007. {
  7008. ret = recv(m_socket_cmd, &resp[off], 1 ,0);
  7009. // ret = socket_recv(m_socket_cmd, &resp[off], 1);
  7010. if(ret < 0)
  7011. {
  7012. printf("recv respond error(ret=%d)!\r\n", ret);
  7013. return 0;
  7014. }
  7015. if(resp[off] == '\n')
  7016. {
  7017. break;
  7018. }
  7019. }
  7020. resp[off+1] = 0;
  7021. printf("respond:%s", resp);
  7022. return atoi(resp);
  7023. }
  7024. static int selectSqlCount = 0;
  7025. void getMemory(char** s, int num)
  7026. {
  7027. *s = (char*)malloc(sizeof(char) * num);
  7028. printf("s = %p\n", s);
  7029. printf("*s = %p\n", *s);
  7030. }
  7031. static int callback(void *data, int argc, char **argv, char **azColName){
  7032. int i;
  7033. printf("%s: ", (const char*)data);
  7034. selectSqlCount = argc;
  7035. for(i = 0; i<argc; i++){
  7036. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  7037. }
  7038. printf("\n");
  7039. return 0;
  7040. }
  7041. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  7042. int i;
  7043. //printf("%s:\n", (const char*)data);
  7044. localversion = argv[5] ? atoi(argv[5]) : 0;
  7045. printf("localversion=%d\n", localversion);
  7046. return 0;
  7047. }
  7048. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  7049. int i;
  7050. //printf("%s:\n", (const char*)data);
  7051. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  7052. printf("IdTag=%s\n", idTagAuthorization);
  7053. return 0;
  7054. }
  7055. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  7056. int i;
  7057. //printf("%s:\n", (const char*)data);
  7058. #if 1
  7059. for(i=0; i<argc; i++){
  7060. printf("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  7061. }
  7062. printf("");
  7063. #endif
  7064. // localversion = argv[5] ? atoi(argv[5]) : 0;
  7065. // printf("localversion=%d\n", localversion);
  7066. return 0;
  7067. }
  7068. void OCPP_getListVerion()
  7069. {
  7070. int ver = 0;
  7071. int isSuccess = FALSE;
  7072. int rc = 0;
  7073. // const char* data = "Callback function called";
  7074. char sql[100];
  7075. char zErrMsg[100];
  7076. memset(sql, 0, 100);
  7077. memset(zErrMsg, 0, 100);
  7078. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  7079. /* Execute SQL statement */
  7080. printf("OCPP_getListVerion -1\n");
  7081. rc = sqlite3_exec(db, sql, versioncallback, 0, &zErrMsg);
  7082. printf("OCPP_getListVerion -2\n");
  7083. printf("rc=%d\n",rc);
  7084. if( rc != SQLITE_OK ){
  7085. printf("SQL error: %s", zErrMsg);
  7086. //sqlite3_free(zErrMsg);
  7087. }else{
  7088. printf("Operation done successfully");
  7089. }
  7090. printf("OCPP_getListVerion -3\n");
  7091. //return ver;
  7092. }
  7093. void OCPP_getIdTag(char *idTag)
  7094. {
  7095. int ver = 0;
  7096. int isSuccess = FALSE;
  7097. int rc = 0;
  7098. // const char* data = "Callback function called";
  7099. char sql[100];
  7100. char zErrMsg[100];
  7101. memset(sql, 0, 100);
  7102. memset(zErrMsg, 0, 100);
  7103. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  7104. /* Execute SQL statement */
  7105. printf("OCPP_getIdTag -1\n");
  7106. rc = sqlite3_exec(db, sql, versioncallback, 0, &zErrMsg);
  7107. printf("OCPP_getIdTag -2\n");
  7108. printf("rc=%d\n",rc);
  7109. if( rc != SQLITE_OK ){
  7110. printf("SQL error: %s", zErrMsg);
  7111. //sqlite3_free(zErrMsg);
  7112. }else{
  7113. printf("Operation done successfully");
  7114. }
  7115. printf("OCPP_getIdTag -3\n");
  7116. //return ver;
  7117. }
  7118. int OCPP_cleanLocalList()
  7119. {
  7120. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  7121. char *errMsg = 0;
  7122. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  7123. if (SQLITE_OK != rc)
  7124. {
  7125. printf("%s\n",errMsg);
  7126. return FALSE;
  7127. }
  7128. else
  7129. {
  7130. printf("delete ocpp_auth_local table successfully\n");
  7131. }
  7132. return TRUE;
  7133. }
  7134. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  7135. {
  7136. int isSuccess = FALSE;
  7137. int ret = 0;
  7138. const char* data = "Callback function called";
  7139. char sql[200];
  7140. char zErrMsg[100];
  7141. // char* sql = NULL;
  7142. // char* zErrMsg = NULL;
  7143. // sql = (char*)malloc(sizeof(char)*200); // getMemory(&sql, 200);
  7144. // zErrMsg = (char*)malloc(sizeof(char)*100); // getMemory(&zErrMsg, 100);
  7145. memset(sql, 0, 200);
  7146. memset(zErrMsg, 0, 100);
  7147. 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);
  7148. printf("sql:%s\n", sql);
  7149. printf("OCPP_addLocalList -5\n");
  7150. /* Execute SQL statement */
  7151. //zErrMsg = 0;
  7152. ret = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
  7153. printf("OCPP_addLocalList -6\n");
  7154. if( ret != SQLITE_OK ){
  7155. printf("SQL error: %s\n", zErrMsg);
  7156. // free(zErrMsg);
  7157. // free(sql);
  7158. return isSuccess;
  7159. }
  7160. printf("successfully Insert records created\n");
  7161. isSuccess = TRUE;
  7162. return isSuccess;
  7163. }
  7164. void OCPP_deleteIdTag(char *idTag)
  7165. {
  7166. int ver = 0;
  7167. int isSuccess = FALSE;
  7168. int rc = 0;
  7169. char sql[100];
  7170. char zErrMsg[100];
  7171. memset(sql, 0, 100);
  7172. memset(zErrMsg, 0, 100);
  7173. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  7174. /* Execute SQL statement */
  7175. printf("OCPP_getIdTag -1\n");
  7176. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0, &zErrMsg);
  7177. printf("OCPP_getIdTag -2\n");
  7178. printf("rc=%d\n",rc);
  7179. if( rc != SQLITE_OK ){
  7180. printf("SQL error: %s", zErrMsg);
  7181. //sqlite3_free(zErrMsg);
  7182. }else{
  7183. printf("Operation done successfully");
  7184. }
  7185. printf("OCPP_getIdTag -3\n");
  7186. }
  7187. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  7188. {
  7189. int isSuccess = FALSE;
  7190. int ret = 0;
  7191. const char* data = "Callback function called";
  7192. char sql[200];
  7193. char zErrMsg[100];
  7194. memset(sql, 0, 200);
  7195. memset(zErrMsg, 0, 100);
  7196. /* selectFromTable */
  7197. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  7198. printf("OCPP_addLocalList -1\n");
  7199. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  7200. printf("OCPP_addLocalList -2\n");
  7201. /* Execute SQL statement */
  7202. selectSqlCount = 0;
  7203. ret = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
  7204. printf("OCPP_addLocalList -3\n");
  7205. if( ret != SQLITE_OK ){
  7206. printf("Error SQL: %s\n", zErrMsg);
  7207. }
  7208. printf("successfully select operation done\n");
  7209. memset(sql, 0, 200);
  7210. memset(zErrMsg, 0, 100);
  7211. if(selectSqlCount == 0)
  7212. {
  7213. printf("OCPP_addLocalList -4\n");
  7214. //Insert
  7215. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
  7216. sprintf(sql,"INSERT INTO ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ", idTag, parentTage, expiryDate, status, version);
  7217. printf("sql:%s\n", sql);
  7218. printf("OCPP_addLocalList -5\n");
  7219. /* Execute SQL statement */
  7220. //zErrMsg = 0;
  7221. ret = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
  7222. printf("OCPP_addLocalList -6\n");
  7223. if( ret != SQLITE_OK ){
  7224. printf("SQL error: %s\n", zErrMsg);
  7225. return isSuccess;
  7226. }
  7227. printf("successfully Insert records created\n");
  7228. isSuccess = TRUE;
  7229. }
  7230. else
  7231. {
  7232. printf("OCPP_addLocalList -7\n");
  7233. //Update
  7234. /* Create merged SQL statement */
  7235. sprintf(sql, "UPDATE ocpp_auth_local set parent_idtag = '%s', expir_date = '%s', status ='%s', version =%d where idtag='%s'; " "SELECT * from ocpp_auth_local", parentTage, expiryDate, status, version, idTag);
  7236. printf("OCPP_addLocalList -8\n");
  7237. /* Execute SQL statement */
  7238. ret = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
  7239. printf("OCPP_addLocalList -9\n");
  7240. if( ret != SQLITE_OK ){
  7241. printf("SQL error: %s\n", zErrMsg);
  7242. //sqlite3_free(zErrMsg);
  7243. //sqlite3_free(sql);
  7244. return isSuccess;
  7245. }
  7246. printf("Successfully operation done \n");
  7247. isSuccess = TRUE;
  7248. }
  7249. return isSuccess;
  7250. }
  7251. char *GetOcppServerURL()
  7252. {
  7253. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  7254. memset(OcppHost, 0, sizeof(OcppHost));
  7255. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  7256. sscanf(ShmOCPP16Data->OcppServerURL,
  7257. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7258. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  7259. printf("OcppProtocol =%s\n",OcppProtocol);
  7260. printf("OcppHost =%s\n",OcppHost);
  7261. printf("OcppPort =%d\n",OcppPort);
  7262. printf("OcppTempPath =%s\n",OcppTempPath);
  7263. return OcppHost;
  7264. }
  7265. char *GetOcppPath()
  7266. {
  7267. if(OcppTempPath == NULL)
  7268. {
  7269. sprintf(OcppPath,"/%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  7270. }
  7271. else
  7272. {
  7273. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  7274. }
  7275. printf("OcppPath=%s\n",OcppPath);
  7276. return OcppPath;
  7277. }
  7278. int GetOcppPort()
  7279. {
  7280. return OcppPort;
  7281. }
  7282. void Send(struct json_object *message)
  7283. {
  7284. printf("Send -1 \n");
  7285. printf("message=%s\n",json_object_to_json_string(message));
  7286. LWS_Send(json_object_to_json_string(message));
  7287. }
  7288. void LWS_Send(char * str)
  7289. {
  7290. pthread_mutex_lock(&lock);
  7291. printf("LWS_Send -1-1 \n");
  7292. printf("message=%s\n",str);
  7293. memset(SendBuffer,0,SendBufLen);
  7294. sprintf((char *)SendBuffer, "%s", str);
  7295. printf("LWS_Send -2 \n");
  7296. pthread_mutex_unlock(&lock);
  7297. lws_callback_on_writable(wsi_client);
  7298. lws_service(context, 10000);//timeout_ms
  7299. //usleep(10000); // 等�??��?微�?
  7300. printf("Send message\n");
  7301. }