MessageHandler.c 420 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556
  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 "libwebsockets.h"
  19. #include <lws_config.h>
  20. //#include "./json-c/JsonParser.h"
  21. #include "hashmap.h"
  22. #include "ShareMemory.h"
  23. #include "TransactionQueue.h"
  24. #include "SystemLogMessage.h"
  25. #include "../../Projects/define.h"
  26. #include "ShareMemory.h"
  27. #include "SystemLogMessage.h"
  28. //#include "config.h"
  29. #include <sys/socket.h>
  30. #include <netinet/in.h>
  31. #include <stdlib.h>
  32. /*for sendfile()*/
  33. #include <sys/sendfile.h>
  34. /*for O_RDONLY*/
  35. #include <fcntl.h>
  36. #include "sqlite3.h"
  37. #include <arpa/inet.h>
  38. //#define _GNU_SOURCE
  39. #include <time.h>
  40. #include "MessageHandler.h"
  41. #include <assert.h>
  42. #include <pthread.h>
  43. #include <mcheck.h>
  44. #define PASS 1
  45. #define FAIL -1
  46. #define FALSE 0
  47. #define TRUE 1 // Option 1
  48. //ChargePointMaxProfile
  49. #define ChargePointMaxProfile_JSON "../Storage/OCPP/ChargePointMaxProfile.json"
  50. //TxDefaultProfile
  51. #define TxDefaultProfile_0_JSON "../Storage/OCPP/TxDefaultProfile_0.json"
  52. #define TxDefaultProfile_1_JSON "../Storage/OCPP/TxDefaultProfile_1.json"
  53. #define TxDefaultProfile_2_JSON "../Storage/OCPP/TxDefaultProfile_2.json"
  54. //TxProfile
  55. #define TxProfile_1_JSON "../Storage/OCPP/TxProfile_1.json"
  56. #define TxProfile_2_JSON "../Storage/OCPP/TxProfile_2.json"
  57. #define ChargingProfile_0_JSON "../Storage/OCPP/chargingprofile_0.json"
  58. #define ChargingProfile_1_JSON "../Storage/OCPP/chargingprofile_1.json"
  59. #define ChargingProfile_2_JSON "../Storage/OCPP/chargingprofile_2.json"
  60. #define AuthorizationCache_JSON "../Storage/OCPP/AuthorizationCache.json"
  61. #define LocalAuthorizationList_JSON "../Storage/OCPP/LocalAuthorizationList.json"
  62. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  63. struct StatusCodeData *ShmStatusCodeData;
  64. struct PsuData *ShmPsuData ;
  65. struct OCPP16Data *ShmOCPP16Data;
  66. /* define Macro */
  67. #define SystemLogMessage
  68. /* OCPP Message Type */
  69. #define MESSAGE_TYPE_CALL 2
  70. #define MESSAGE_TYPE_CALLRESULT 3
  71. #define MESSAGE_TYPE_CALLERROR 4
  72. /* */
  73. #define server_cycle_Status 120
  74. #define MACROSTR(k) #k
  75. //ConfigurationMaxKeys
  76. #define GetConfigurationMaxKeysNUM 43
  77. //char guid[37];
  78. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  79. char queuedata[2000]={0};
  80. //===============================
  81. // Configuration: unknownkey
  82. //===============================
  83. static char unknownkey[10][20]={0};
  84. static int UnknownKeynum = 0;
  85. //===============================
  86. // Gun Total Numbers
  87. //===============================
  88. //#define gunTotalNumber (strstr(ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL) ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  89. static int gunTotalNumber=0;
  90. static int localversion=0;
  91. static char idTagAuthorization[32]={0};
  92. char OcppPath[160]={};
  93. char OcppProtocol[10]={0},OcppHost[50]={0}, OcppTempPath[50]={0};
  94. int OcppPort=0;
  95. int server_sign = FALSE;
  96. int server_pending = FALSE;
  97. int authenrequest = FALSE;
  98. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  99. int BootNotificationInterval = 0;
  100. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  101. int authorizeRetryTimes = 0; //number of Retry times
  102. int isUpdateRequest = FALSE;
  103. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY] = {FALSE};
  104. static int HeartBeatWaitTime = 10;
  105. static int GunStatusInterval = 10;
  106. static int FirstHeartBeat = 0;
  107. static int FirmwareStatusNotificationStatus = 3; // Idle
  108. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  109. static struct OCPPAuthLocalElemet
  110. {
  111. int listVersionInt;
  112. char idTagstr[20];
  113. char parentIdTag[20];
  114. char expiryDate[30];
  115. char idTagstatus[16];
  116. }idTagQuery;
  117. extern struct lws *wsi_client;
  118. extern struct lws_context *context;
  119. #if 0
  120. extern unsigned char *SendBuffer;
  121. #endif
  122. extern unsigned char SendBuffer[4096];
  123. extern int SendBufLen;
  124. //extern map_t hashMap;
  125. //extern data_struct_t* mapItem; --- remove for temporally
  126. //extern data_struct_t mapItem[0];
  127. extern char *random_uuid( char buf[37] );
  128. extern void split(char **arr, char *str, const char *del);
  129. extern pthread_mutex_t mutex1;
  130. extern struct Charger_Info Charger;
  131. extern sqlite3 *db;
  132. int updateSetting(char *key, char *value);
  133. int setKeyValue(char *key, char *value);
  134. void OCPP_get_TableAuthlocalAllData(void);
  135. void processUnkownKey(void);
  136. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  137. struct ClientTime
  138. {
  139. unsigned int Heartbeat;
  140. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  141. unsigned int StartTransaction;
  142. unsigned int StopTransaction;
  143. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  144. }clientTime;
  145. typedef union
  146. {
  147. //Operations Initiated by Central System
  148. unsigned char CsMsgValue[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  149. struct
  150. {
  151. //CsMsgValue[0]
  152. unsigned char StatusNotificationReq :1; //bit 0,
  153. unsigned char StatusNotificationConf :1; //bit 0,
  154. unsigned char :6; //bit 2~7
  155. }bits[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  156. }CpinitiateMsg;
  157. CpinitiateMsg cpinitateMsg;
  158. //==========================================
  159. // Init all Enumeration & Mapping String
  160. //==========================================
  161. /*ChargePointErrorCode*/
  162. typedef enum {
  163. ConnectorLockFailure,
  164. EVCommunicationError,
  165. GroundFailure,
  166. HighTemperature,
  167. InternalError,
  168. LocalListConflict,
  169. NoError,
  170. OtherError,
  171. OverCurrentFailure,
  172. OverVoltage,
  173. PowerMeterFailure,
  174. PowerSwitchFailure,
  175. ReaderFailure,
  176. ResetFailure,
  177. UnderVoltage,
  178. WeakSignal
  179. } ChargePointErrorCode;
  180. #if 0
  181. static char *ChargePointErrorCodeStr[] = {
  182. MACROSTR(ConnectorLockFailure),
  183. MACROSTR(EVCommunicationError),
  184. MACROSTR(GroundFailure),
  185. MACROSTR(HighTemperature),
  186. MACROSTR(InternalError),
  187. MACROSTR(LocalListConflict),
  188. MACROSTR(NoError),
  189. MACROSTR(OtherError),
  190. MACROSTR(OverCurrentFailure),
  191. MACROSTR(OverVoltage),
  192. MACROSTR(PowerMeterFailure),
  193. MACROSTR(PowerSwitchFailure),
  194. MACROSTR(ReaderFailure),
  195. MACROSTR(ResetFailure),
  196. MACROSTR(UnderVoltage),
  197. MACROSTR(WeakSignal)
  198. };
  199. #endif
  200. /*ChargePointStatus*/
  201. typedef enum {
  202. Available =0,
  203. Preparing,
  204. Charging,
  205. SuspendedEVSE,
  206. SuspendedEV,
  207. Finishing,
  208. Reserved,
  209. Unavailable,
  210. Faulted
  211. } ChargePointStatus;
  212. static char * ChargePointStatusStr[] = {
  213. MACROSTR(Available),
  214. MACROSTR(Preparing),
  215. MACROSTR(Charging),
  216. MACROSTR(SuspendedEVSE),
  217. MACROSTR(SuspendedEV),
  218. MACROSTR(Finishing),
  219. MACROSTR(Reserved),
  220. MACROSTR(Unavailable),
  221. MACROSTR(Faulted)
  222. };
  223. /*AvailabilityType*/
  224. typedef enum {
  225. RegistrationStatus_Accepted,
  226. RegistrationStatus_Pending,
  227. RegistrationStatus_Rejected
  228. } RegistrationStatus;
  229. static char *RegistrationStatusStr[] = {
  230. MACROSTR(Accepted),
  231. MACROSTR(Pending),
  232. MACROSTR(Rejected)
  233. };
  234. /*AvailabilityType*/
  235. typedef enum {
  236. Inoperative,
  237. Operative
  238. } AvailabilityType;
  239. static char *AvailabilityTypeStr[] = {
  240. MACROSTR(Inoperative),
  241. MACROSTR(Operative)
  242. };
  243. /*AvailabilityStatus*/
  244. typedef enum {
  245. Accepted,
  246. Rejected,
  247. Scheduled
  248. } AvailabilityStatus;
  249. static char *AvailabilityStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(Scheduled)
  253. };
  254. /*ConfigurationStatus*/
  255. typedef enum {
  256. ConfigurationStatus_Accepted,
  257. ConfigurationStatus_Rejected,
  258. RebootRequired,
  259. NotSupported
  260. } ConfigurationStatus;
  261. static char *ConfigurationStatusStr[] = {
  262. MACROSTR(Accepted),
  263. MACROSTR(Rejected),
  264. MACROSTR(RebootRequired),
  265. MACROSTR(NotSupported)
  266. };
  267. /*ClearCacheStatus*/
  268. typedef enum {
  269. ClearCacheStatus_Accepted,
  270. ClearCacheStatus_Rejected
  271. } ClearCacheStatus;
  272. static char *ClearCacheStatusStr[] = {
  273. MACROSTR(Accepted),
  274. MACROSTR(Rejected)
  275. };
  276. /*ChargingProfilePurposeType*/
  277. typedef enum {
  278. ChargePointMaxProfile,
  279. TxDefaultProfile,
  280. TxProfile
  281. } ChargingProfilePurposeType;
  282. static char *ChargingProfilePurposeTypeStr[] = {
  283. MACROSTR(ChargePointMaxProfile),
  284. MACROSTR(TxDefaultProfile),
  285. MACROSTR(TxProfile)
  286. };
  287. /*ChargingProfileStatus*/
  288. typedef enum {
  289. ChargingProfileStatus_Accepted,
  290. ChargingProfileStatus_Rejected,
  291. ChargingProfileStatus_NotSupported
  292. } ChargingProfileStatus;
  293. static char *ChargingProfileStatusStr[] = {
  294. MACROSTR(Accepted),
  295. MACROSTR(Rejected),
  296. MACROSTR(NotSupported)
  297. };
  298. /*ClearChargingProfileStatus*/
  299. typedef enum {
  300. ClearChargingProfileStatus_Accepted,
  301. ClearChargingProfileStatus_Unknown
  302. } ClearChargingProfileStatus;
  303. static char *ClearChargingProfileStatusStr[] = {
  304. MACROSTR(Accepted),
  305. MACROSTR(Unknown)
  306. };
  307. /*GetCompositeScheduleStatus*/
  308. typedef enum {
  309. GetCompositeScheduleStatus_Accepted,
  310. GetCompositeScheduleStatus_Rejected
  311. } GetCompositeScheduleStatus;
  312. static char *GetCompositeScheduleStatusStr[] = {
  313. MACROSTR(Accepted),
  314. MACROSTR(Rejected)
  315. };
  316. /*ChargingRateUnitType*/
  317. typedef enum {
  318. ChargingRateUnitType_W,
  319. ChargingRateUnitType_A
  320. } ChargingRateUnitType;
  321. /*AuthorizationStatus*/
  322. typedef enum {
  323. AuthorizationStatus_Accepted ,
  324. AuthorizationStatus_Blocked ,
  325. AuthorizationStatus_Expired ,
  326. AuthorizationStatus_Invalid ,
  327. AuthorizationStatus_ConcurrentTx
  328. } AuthorizationStatus;
  329. /*UpdateType*/
  330. typedef enum {
  331. Differential ,
  332. Full
  333. } UpdateType;
  334. static char *UpdateTypeStr[] = {
  335. MACROSTR(Differential),
  336. MACROSTR(Full)
  337. };
  338. /*UpdateStatus*/
  339. typedef enum {
  340. UpdateStatus_Accepted ,
  341. UpdateStatus_Failed ,
  342. UpdateStatus_NotSupported ,
  343. UpdateStatus_VersionMismatch
  344. } UpdateStatus;
  345. static char *UpdateStatusStr[] = {
  346. MACROSTR(Accepted),
  347. MACROSTR(Failed),
  348. MACROSTR(NotSupported),
  349. MACROSTR(VersionMismatch)
  350. };
  351. /*RemoteStartStopStatus*/
  352. typedef enum {
  353. RemoteStartStopStatus_Accepted,
  354. RemoteStartStopStatus_Rejected
  355. } RemoteStartStopStatus;
  356. static char *RemoteStartStopStatusStr[] = {
  357. MACROSTR(Accepted),
  358. MACROSTR(Rejected)
  359. };
  360. /*ReservationStatus*/
  361. typedef enum {
  362. ReservationStatus_Accepted,
  363. ReservationStatus_Faulted,
  364. ReservationStatus_Occupied,
  365. ReservationStatus_Rejected,
  366. ReservationStatus_Unavailable
  367. } ReservationStatus;
  368. static char *ReservationStatusStr[] = {
  369. MACROSTR(Accepted),
  370. MACROSTR(Faulted),
  371. MACROSTR(Occupied),
  372. MACROSTR(Rejected),
  373. MACROSTR(Unavailable)
  374. };
  375. /*ResetType*/
  376. typedef enum {
  377. Hard,
  378. Soft
  379. } ResetType;
  380. static char *ResetTypeStr[] = {
  381. MACROSTR(Hard),
  382. MACROSTR(Soft)
  383. };
  384. /*ResetStatus*/
  385. typedef enum {
  386. ResetStatus_Accepted,
  387. ResetStatus_Rejected
  388. } ResetStatus;
  389. static char *ResetStatusStr[] = {
  390. MACROSTR(Accepted),
  391. MACROSTR(Rejected)
  392. };
  393. /*DiagnosticsStatus*/
  394. typedef enum {
  395. DiagnosticsStatus_Idle,
  396. DiagnosticsStatus_Uploaded,
  397. DiagnosticsStatus_UploadFailed,
  398. DiagnosticsStatus_Uploading
  399. } DiagnosticsStatus;
  400. static char * DiagnosticsStatusStr[] = {
  401. MACROSTR(Idle),
  402. MACROSTR(Uploaded),
  403. MACROSTR(UploadFailed),
  404. MACROSTR(Uploading)
  405. };
  406. /*FirmwareStatus*/
  407. typedef enum {
  408. FirmwareStatus_Downloaded,
  409. FirmwareStatus_DownloadFailed,
  410. FirmwareStatus_Downloading,
  411. FirmwareStatus_Idle,
  412. FirmwareStatus_InstallationFailed,
  413. FirmwareStatus_Installing,
  414. FirmwareStatus_Installed
  415. } FirmwareStatus;
  416. static char * FirmwareStatusStr[] = {
  417. MACROSTR(Downloaded),
  418. MACROSTR(DownloadFailed),
  419. MACROSTR(Downloading),
  420. MACROSTR(Idle),
  421. MACROSTR(InstallationFailed),
  422. MACROSTR(Installing),
  423. MACROSTR(Installed)
  424. };
  425. /*MessageTrigger*/
  426. typedef enum {
  427. BootNotification,
  428. DiagnosticsStatusNotification,
  429. FirmwareStatusNotification,
  430. Heartbeat,
  431. MeterValues,
  432. StatusNotification
  433. } MessageTrigger;
  434. static char * MessageTriggerStr[] = {
  435. MACROSTR(BootNotification),
  436. MACROSTR(DiagnosticsStatusNotification),
  437. MACROSTR(FirmwareStatusNotification),
  438. MACROSTR(Heartbeat),
  439. MACROSTR(MeterValues),
  440. MACROSTR(StatusNotification)
  441. };
  442. /*TriggerMessageStatus*/
  443. typedef enum {
  444. TriggerMessageStatus_Accepted ,
  445. TriggerMessageStatus_Rejected ,
  446. TriggerMessageStatus_NotImplemented
  447. } TriggerMessageStatus;
  448. static char * TriggerMessageStatusStr[] = {
  449. MACROSTR(Accepted),
  450. MACROSTR(Rejected),
  451. MACROSTR(NotImplemented)
  452. };
  453. /*UnlockStatus*/
  454. typedef enum {
  455. Unlocked,
  456. UnlockFailed,
  457. UnlockStatus_NotSupported
  458. } UnlockStatus;
  459. static char * UnlockStatusStr[] = {
  460. MACROSTR(Unlocked),
  461. MACROSTR(UnlockFailed),
  462. MACROSTR(NotSupported)
  463. };
  464. /*StopTransactionReason*/
  465. typedef enum {
  466. EmergencyStop,
  467. EVDisconnected,
  468. HardReset,
  469. Local,
  470. Other,
  471. PowerLoss,
  472. Reboot,
  473. Remote,
  474. SoftReset,
  475. UnlockCommand,
  476. DeAuthorized
  477. } StopTransactionReason;
  478. static char * StopTransactionReasonStr[] = {
  479. MACROSTR(EmergencyStop),
  480. MACROSTR(EVDisconnected),
  481. MACROSTR(HardReset),
  482. MACROSTR(Local),
  483. MACROSTR(Other),
  484. MACROSTR(PowerLoss),
  485. MACROSTR(Reboot),
  486. MACROSTR(Remote),
  487. MACROSTR(SoftReset),
  488. MACROSTR(UnlockCommand),
  489. MACROSTR(DeAuthorized)
  490. };
  491. /*CancelReservationStatus*/
  492. typedef enum {
  493. CancelReservationStatus_Accepted,
  494. CancelReservationStatus_Rejected
  495. } CancelReservationStatus;
  496. static char * CancelReservationStatusStr[] = {
  497. MACROSTR(Accepted),
  498. MACROSTR(Rejected)
  499. };
  500. /*ReadingContext*/
  501. typedef enum {
  502. ReadingContext_Interruption_Begin,
  503. ReadingContext_Interruption_End,
  504. ReadingContext_Other,
  505. ReadingContext_Sample_Clock,
  506. ReadingContext_Sample_Periodic ,
  507. ReadingContext_Transaction_Begin ,
  508. ReadingContext_Transaction_End,
  509. ReadingContext_Trigger
  510. } ReadingContext;
  511. static char * ReadingContextStr[] = {
  512. MACROSTR(Interruption.Begin),
  513. MACROSTR(Interruption.End),
  514. MACROSTR(Other),
  515. MACROSTR(Sample.Clock),
  516. MACROSTR(Sample.Periodic),
  517. MACROSTR(Transaction.Begin),
  518. MACROSTR(Transaction.End),
  519. MACROSTR(Trigger)
  520. };
  521. /*ValueFormat*/
  522. typedef enum {
  523. Raw,
  524. SignedData
  525. } ValueFormat;
  526. static char * ValueFormatStr[] = {
  527. MACROSTR(Raw),
  528. MACROSTR(SignedData)
  529. };
  530. /*Measurand*/
  531. typedef enum {
  532. Current_Export ,
  533. Current_Import,
  534. Current_Offered,
  535. Energy_Active_Export_Register,
  536. Energy_Active_Import_Register,
  537. Energy_Reactive_Export_Register,
  538. Energy_Reactive_Import_Register,
  539. Energy_Active_Export_Interval,
  540. Energy_Active_Import_Interval,
  541. Energy_Reactive_Export_Interval,
  542. Energy_Reactive_Import_Interval,
  543. Frequency,
  544. Power_Active_Export ,
  545. Power_Active_Import,
  546. Power_Factor,
  547. Power_Offered,
  548. Power_Reactive_Export,
  549. Power_Reactive_Import,
  550. RPM,
  551. SoC,
  552. Temperature ,
  553. Voltage
  554. } Measurand;
  555. static char * MeasurandStr[] = {
  556. MACROSTR(Current.Export),
  557. MACROSTR(Current.Import),
  558. MACROSTR(Current.Offered),
  559. MACROSTR(Energy.Active.Export.Register),
  560. MACROSTR(Energy.Active.Import.Register),
  561. MACROSTR(Energy.Reactive.Export.Register),
  562. MACROSTR(Energy.Reactive.Import.Register),
  563. MACROSTR(Energy.Active.Export.Interval),
  564. MACROSTR(Energy.Active.Import.Interval),
  565. MACROSTR(Energy.Reactive.Export.Interval),
  566. MACROSTR(Energy.Reactive.Import.Interval),
  567. MACROSTR(Frequency),
  568. MACROSTR(Power.Active.Export),
  569. MACROSTR(Power.Active.Import),
  570. MACROSTR(Power.Factor),
  571. MACROSTR(Power.Offered),
  572. MACROSTR(Power.Reactive.ExportMACROSTR),
  573. MACROSTR(Power.Reactive.Import),
  574. MACROSTR(RPM),
  575. MACROSTR(SoC),
  576. MACROSTR(Temperature),
  577. MACROSTR(Voltage)
  578. };
  579. /*Location*/
  580. typedef enum {
  581. Location_Body,
  582. Location_Cable,
  583. Location_EV,
  584. Location_Inlet ,
  585. Location_Outlet
  586. } Location;
  587. static char * LocationStr[] = {
  588. MACROSTR(Body),
  589. MACROSTR(Cable),
  590. MACROSTR(EV),
  591. MACROSTR(Inlet),
  592. MACROSTR(Outlet)
  593. };
  594. /*Phase*/
  595. typedef enum {
  596. L1,
  597. L2,
  598. L3,
  599. N,
  600. L1_N,
  601. L2_N,
  602. L3_N,
  603. L1_L2,
  604. L2_L3,
  605. L3_L1
  606. } Phase;
  607. static char * PhaseStr[] = {
  608. MACROSTR(L1),
  609. MACROSTR(L2),
  610. MACROSTR(L3),
  611. MACROSTR(N),
  612. MACROSTR(L1-N),
  613. MACROSTR(L2-N),
  614. MACROSTR(L3-N),
  615. MACROSTR(L1-L2),
  616. MACROSTR(L2-L3),
  617. MACROSTR(L3-L1)
  618. };
  619. /*UnitOfMeasure*/
  620. typedef enum {
  621. UnitOfMeasure_Wh,
  622. UnitOfMeasure_kWh ,
  623. UnitOfMeasure_varh ,
  624. UnitOfMeasure_kvarh ,
  625. UnitOfMeasure_W ,
  626. UnitOfMeasure_kW ,
  627. UnitOfMeasure_VA ,
  628. UnitOfMeasure_kVA ,
  629. UnitOfMeasure_var ,
  630. UnitOfMeasure_kvar ,
  631. UnitOfMeasure_A ,
  632. UnitOfMeasure_V ,
  633. UnitOfMeasure_Celsius ,
  634. UnitOfMeasure_Fahrenheit ,
  635. UnitOfMeasure_K ,
  636. UnitOfMeasure_Percent
  637. } UnitOfMeasure;
  638. static char * UnitOfMeasureStr[] = {
  639. MACROSTR(Wh),
  640. MACROSTR(kWh),
  641. MACROSTR(varh),
  642. MACROSTR(kvarh),
  643. MACROSTR(W),
  644. MACROSTR(kW),
  645. MACROSTR(VA),
  646. MACROSTR(kVA),
  647. MACROSTR(var),
  648. MACROSTR(kvar),
  649. MACROSTR(A),
  650. MACROSTR(V),
  651. MACROSTR(Celsius),
  652. MACROSTR(Fahrenheit),
  653. MACROSTR(K),
  654. MACROSTR(Percent)
  655. };
  656. /*Configuration enum*/
  657. enum CoreProfile {
  658. AllowOfflineTxForUnknownId=0,
  659. AuthorizationCacheEnabled,
  660. AuthorizeRemoteTxRequests,
  661. BlinkRepeat,
  662. ClockAlignedDataInterval,
  663. ConnectionTimeOut,
  664. GetConfigurationMaxKeys,
  665. HeartbeatInterval,
  666. LightIntensity,
  667. LocalAuthorizeOffline,
  668. LocalPreAuthorize,
  669. MaxEnergyOnInvalidId,
  670. MeterValuesAlignedData,
  671. MeterValuesAlignedDataMaxLength,
  672. MeterValuesSampledData,
  673. MeterValuesSampledDataMaxLength,
  674. MeterValueSampleInterval,
  675. MinimumStatusDuration,
  676. NumberOfConnectors,
  677. ResetRetries,
  678. ConnectorPhaseRotation,
  679. ConnectorPhaseRotationMaxLength,
  680. StopTransactionOnEVSideDisconnect,
  681. StopTransactionOnInvalidId,
  682. StopTxnAlignedData,
  683. StopTxnAlignedDataMaxLength,
  684. StopTxnSampledData,
  685. StopTxnSampledDataMaxLength,
  686. SupportedFeatureProfiles,
  687. SupportedFeatureProfilesMaxLength,
  688. TransactionMessageAttempts,
  689. TransactionMessageRetryInterval,
  690. UnlockConnectorOnEVSideDisconnect,
  691. WebSocketPingInterval,
  692. _CoreProfile_CNT
  693. };
  694. enum LocalAuthListManagementProfile{
  695. LocalAuthListEnabled=0,
  696. LocalAuthListMaxLength,
  697. SendLocalListMaxLength,
  698. _LocalAuthListManagementProfile_CNT
  699. };
  700. enum ReservationProfile{
  701. ReserveConnectorZeroSupported
  702. };
  703. enum SmartChargingProfile{
  704. ChargeProfileMaxStackLevel,
  705. ChargingScheduleAllowedChargingRateUnit,
  706. ChargingScheduleMaxPeriods,
  707. ConnectorSwitch3to1PhaseSupported,
  708. MaxChargingProfilesInstalled
  709. };
  710. enum ChargerSystemStatus{
  711. ChargerSystemStatus_Booting,
  712. ChargerSystemStatus_Idle,
  713. ChargerSystemStatus_Authorizing,
  714. ChargerSystemStatus_Preparing,
  715. ChargerSystemStatus_Charging,
  716. ChargerSystemStatus_Terminating,
  717. ChargerSystemStatus_Alarm,
  718. ChargerSystemStatus_Fault
  719. };
  720. enum GetConfigurationKey {
  721. GetConfiguration_AllowOfflineTxForUnknownId=0,
  722. GetConfiguration_AuthorizationCacheEnabled,
  723. GetConfiguration_AuthorizeRemoteTxRequests,
  724. GetConfiguration_BlinkRepeat,
  725. GetConfiguration_ClockAlignedDataInterval,
  726. GetConfiguration_ConnectionTimeOut,
  727. GetConfiguration_GetConfigurationMaxKeys,
  728. GetConfiguration_HeartbeatInterval,
  729. GetConfiguration_LightIntensity,
  730. GetConfiguration_LocalAuthorizeOffline,
  731. GetConfiguration_LocalPreAuthorize,
  732. GetConfiguration_MaxEnergyOnInvalidId,
  733. GetConfiguration_MeterValuesAlignedData,
  734. GetConfiguration_MeterValuesAlignedDataMaxLength,
  735. GetConfiguration_MeterValuesSampledData,
  736. GetConfiguration_MeterValuesSampledDataMaxLength,
  737. GetConfiguration_MeterValueSampleInterval,
  738. GetConfiguration_MinimumStatusDuration,
  739. GetConfiguration_NumberOfConnectors,
  740. GetConfiguration_ResetRetries,
  741. GetConfiguration_ConnectorPhaseRotation,
  742. GetConfiguration_ConnectorPhaseRotationMaxLength,
  743. GetConfiguration_StopTransactionOnEVSideDisconnect,
  744. GetConfiguration_StopTransactionOnInvalidId,
  745. GetConfiguration_StopTxnAlignedData,
  746. GetConfiguration_StopTxnAlignedDataMaxLength,
  747. GetConfiguration_StopTxnSampledData,
  748. GetConfiguration_StopTxnSampledDataMaxLength,
  749. GetConfiguration_SupportedFeatureProfiles,
  750. GetConfiguration_SupportedFeatureProfilesMaxLength,
  751. GetConfiguration_TransactionMessageAttempts,
  752. GetConfiguration_TransactionMessageRetryInterval,
  753. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  754. GetConfiguration_WebSocketPingInterval,
  755. GetConfiguration_LocalAuthListEnabled,
  756. GetConfiguration_LocalAuthListMaxLength,
  757. GetConfiguration_SendLocalListMaxLength,
  758. GetConfiguration_ReserveConnectorZeroSupported,
  759. GetConfiguration_ChargeProfileMaxStackLevel,
  760. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  761. GetConfiguration_ChargingScheduleMaxPeriods,
  762. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  763. GetConfiguration_MaxChargingProfilesInstalled,
  764. };
  765. //GetConfiguration Array
  766. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  767. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  768. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  769. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  770. struct StructChargingSchedulePeriod staticCHAdeMOChargingSchedulePeriod[10]={0};
  771. struct StructChargingSchedulePeriod staticCCSChargingSchedulePeriod[10]={0};
  772. struct StructChargingSchedulePeriod staticGBChargingSchedulePeriod[10]={0};
  773. struct StructChargingSchedulePeriod staticACChargingSchedulePeriod[10]={0};
  774. struct StructChargingSchedulePeriod staticCHAdeMOCompositeChargingSchedulePeriod[10]={0};
  775. struct StructChargingSchedulePeriod staticCCSCompositeChargingSchedulePeriod[10]={0};
  776. struct StructChargingSchedulePeriod staticGBCompositeChargingSchedulePeriod[10]={0};
  777. struct StructChargingSchedulePeriod staticACCompositeChargingSchedulePeriod[10]={0};
  778. struct StructChargingSchedulePeriod staticCHAdeMORemoteStartTransactionChargingSchedulePeriod[10]={0};
  779. struct StructChargingSchedulePeriod staticCCSRemoteStartTransactionChargingSchedulePeriod[10]={0};
  780. struct StructChargingSchedulePeriod staticGBRemoteStartTransactionChargingSchedulePeriod[10]={0};
  781. struct StructChargingSchedulePeriod staticACRemoteStartTransactionChargingSchedulePeriod[10]={0};
  782. //==========================================
  783. // Init all share memory
  784. //==========================================
  785. int InitShareMemory()
  786. {
  787. int result = PASS;
  788. int MeterSMId;
  789. //printf("1\n");
  790. //creat ShmSysConfigAndInfo
  791. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  792. {
  793. #ifdef SystemLogMessage
  794. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  795. #endif
  796. result = FAIL;
  797. }
  798. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  799. {
  800. #ifdef SystemLogMessage
  801. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  802. #endif
  803. result = FAIL;
  804. }
  805. else
  806. {}
  807. //printf("2\n");
  808. //creat ShmStatusCodeData
  809. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  810. {
  811. #ifdef SystemLogMessage
  812. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  813. #endif
  814. result = FAIL;
  815. }
  816. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  817. {
  818. #ifdef SystemLogMessage
  819. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  820. #endif
  821. result = FAIL;
  822. }
  823. else
  824. {}
  825. //printf("3\n");
  826. //creat ShmPsuData
  827. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  828. {
  829. #ifdef SystemLogMessage
  830. DEBUG_ERROR("shmget ShmPsuData NG\n");
  831. #endif
  832. result = FAIL;
  833. }
  834. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  835. {
  836. #ifdef SystemLogMessage
  837. DEBUG_ERROR("shmat ShmPsuData NG\n");
  838. #endif
  839. result = FAIL;
  840. }
  841. else
  842. {}
  843. //printf("4\n");
  844. //creat ShmOCPP16Data
  845. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  846. {
  847. #ifdef SystemLogMessage
  848. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  849. #endif
  850. result = FAIL;
  851. }
  852. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  853. {
  854. #ifdef SystemLogMessage
  855. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  856. #endif
  857. result = FAIL;
  858. }
  859. else
  860. {}
  861. /****************************** For TEST ************************************************/
  862. //inital settings
  863. gunTotalNumber = (strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL) ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  864. memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/);
  865. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  866. {
  867. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  868. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  869. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  870. }
  871. // Charger PRE_SYS_MODE
  872. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  873. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  874. clientTime.Heartbeat=time((time_t*)NULL);
  875. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  876. {
  877. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  878. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  879. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  880. }
  881. //HeartBeatWaitTime = 10;
  882. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  883. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  884. // GetConfiguration
  885. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  886. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  887. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  888. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  889. ShmOCPP16Data->OcppConnStatus = 1;
  890. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  891. {
  892. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticCHAdeMOChargingSchedulePeriod;
  893. ShmOCPP16Data->SetChargingProfile[1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticCCSChargingSchedulePeriod;
  894. ShmOCPP16Data->SetChargingProfile[2].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticGBChargingSchedulePeriod;
  895. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = staticCHAdeMOCompositeChargingSchedulePeriod;
  896. ShmOCPP16Data->GetCompositeSchedule[1].ResponseChargingSchedule.ChargingSchedulePeriod = staticCCSCompositeChargingSchedulePeriod;
  897. ShmOCPP16Data->GetCompositeSchedule[2].ResponseChargingSchedule.ChargingSchedulePeriod = staticGBCompositeChargingSchedulePeriod;
  898. ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticCHAdeMORemoteStartTransactionChargingSchedulePeriod;
  899. ShmOCPP16Data->RemoteStartTransaction[1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticCCSRemoteStartTransactionChargingSchedulePeriod;
  900. ShmOCPP16Data->RemoteStartTransaction[2].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticGBRemoteStartTransactionChargingSchedulePeriod;
  901. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  902. DEBUG_INFO("DC ...\n");
  903. }
  904. else
  905. {
  906. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticACChargingSchedulePeriod;
  907. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = staticACCompositeChargingSchedulePeriod;
  908. ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticACRemoteStartTransactionChargingSchedulePeriod;
  909. SystemInitial = AC_QUANTITY;
  910. DEBUG_INFO("AC ...\n");
  911. DEBUG_INFO("gunTotalNumber=%d\n",gunTotalNumber);
  912. }
  913. //memset(unknownkey, 0, 10);
  914. return result;
  915. }
  916. int ProcessShareMemory()
  917. {
  918. if(InitShareMemory() == FAIL)
  919. {
  920. #ifdef SystemLogMessage
  921. DEBUG_ERROR("InitShareMemory NG\n");
  922. #endif
  923. if(ShmStatusCodeData!=NULL)
  924. {
  925. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  926. }
  927. sleep(5);
  928. return FAIL;
  929. }
  930. return PASS;
  931. }
  932. void CheckSystemValue(void)
  933. {
  934. printf("CheckSystemValue \n");
  935. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]={0};
  936. int IdleModeCnt = 0;
  937. //===============================
  938. // send Heartbeat
  939. //===============================
  940. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  941. {
  942. //parameter for test
  943. sendHeartbeatRequest(0);
  944. //==============================================
  945. // Reset Waiting Time
  946. //==============================================
  947. clientTime.Heartbeat=time((time_t*)NULL);
  948. }
  949. //=====================================================
  950. // Check InternetConn 0: disconnected, 1: connected
  951. //====================================================
  952. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0 )
  953. {
  954. ShmOCPP16Data->OcppConnStatus = 0;
  955. }
  956. else
  957. {
  958. ShmOCPP16Data->OcppConnStatus = 1;
  959. }
  960. //==============================================
  961. // Update request
  962. //==============================================
  963. if(isUpdateRequest == TRUE )
  964. {
  965. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  966. {
  967. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  968. {
  969. //check SystemStatus
  970. /*************************DC*******************************/
  971. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  972. {
  973. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 1)) //S_IDLE
  974. {
  975. IdleModeCnt = IdleModeCnt + 1;
  976. }
  977. }
  978. for (int index = 0; index < CCS_QUANTITY; index++)
  979. {
  980. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 1)) //S_IDLE
  981. {
  982. IdleModeCnt = IdleModeCnt + 1;
  983. }
  984. }
  985. for (int index = 0; index < GB_QUANTITY; index++)
  986. {
  987. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  988. {
  989. IdleModeCnt = IdleModeCnt + 1;
  990. }
  991. }
  992. }
  993. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  994. {
  995. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  996. isUpdateRequest = FALSE;
  997. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  998. }
  999. }
  1000. else
  1001. {
  1002. /*************************AC*******************************/
  1003. for (int index = 0; index < AC_QUANTITY; index++)
  1004. {
  1005. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1006. {
  1007. IdleModeCnt = IdleModeCnt + 1;
  1008. }
  1009. }
  1010. if(IdleModeCnt == AC_QUANTITY)
  1011. {
  1012. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1013. isUpdateRequest = FALSE;
  1014. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1015. }
  1016. }
  1017. }
  1018. DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1019. for(int gun_index=0;gun_index < gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY )*/ ;gun_index++)
  1020. {
  1021. //===============================
  1022. // CSU Trigger Reset Conf
  1023. //===============================
  1024. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1025. {
  1026. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1027. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1028. {
  1029. server_sign = FALSE;
  1030. }
  1031. }
  1032. //===============================
  1033. // CSU Trigger Authorize Request
  1034. //===============================
  1035. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1036. {
  1037. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1038. {
  1039. sendAuthorizeRequest(0);
  1040. authorizeRetryTimes = authorizeRetryTimes + 1;
  1041. /* authenrequest = TRUE; */
  1042. if(authorizeRetryTimes < 3)
  1043. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1044. }
  1045. }
  1046. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1047. {
  1048. authorizeRetryTimes = 0;
  1049. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1050. }
  1051. //==============================================
  1052. // Charger start transaction
  1053. //==============================================
  1054. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1055. {
  1056. sendStartTransactionRequest(gun_index);
  1057. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1058. clientTime.StartTransaction = time((time_t*)NULL);
  1059. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1060. }
  1061. //==============================================
  1062. // Charger stop transaction
  1063. //==============================================
  1064. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1065. {
  1066. sendStopTransactionRequest(gun_index);
  1067. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1068. clientTime.StopTransaction = time((time_t*)NULL);
  1069. }
  1070. //==============================================
  1071. // Charger status report
  1072. //==============================================
  1073. /* Check Mode Change */
  1074. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1075. {
  1076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1077. {
  1078. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1079. {
  1080. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus/*PRE_SYS_MODE[gun_index]*/ )
  1081. {
  1082. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1083. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1084. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1085. statusModeChage[gun_index] = TRUE;
  1086. }
  1087. }
  1088. }
  1089. for (int index = 0; index < CCS_QUANTITY; index++)
  1090. {
  1091. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1092. {
  1093. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus/*PRE_SYS_MODE[gun_index]*/ )
  1094. {
  1095. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1096. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1097. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1098. statusModeChage[gun_index] = TRUE;
  1099. }
  1100. }
  1101. }
  1102. for (int index = 0; index < GB_QUANTITY; index++)
  1103. {
  1104. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1105. {
  1106. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus/*PRE_SYS_MODE[gun_index]*/ )
  1107. {
  1108. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1109. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1110. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1111. statusModeChage[gun_index] = TRUE;
  1112. }
  1113. }
  1114. }
  1115. }
  1116. else //AC
  1117. {
  1118. for (int index = 0; index < AC_QUANTITY; index++)
  1119. {
  1120. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1121. {
  1122. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus/*PRE_SYS_MODE[gun_index]*/ )
  1123. {
  1124. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1125. ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1126. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1127. statusModeChage[gun_index] = TRUE;
  1128. }
  1129. }
  1130. }// END OF FOR
  1131. }// END OF ELSE
  1132. if((SystemInitial != 0)||
  1133. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1134. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1135. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1136. {
  1137. if(SystemInitial != 0)
  1138. SystemInitial = SystemInitial -1;
  1139. //GunStatusInterval= GunStatusInterval* gun_index;
  1140. sendStatusNotificationRequest(gun_index);
  1141. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1142. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1143. statusModeChage[gun_index] = FALSE;
  1144. //sleep(30); // sleep for 30 seconds
  1145. }
  1146. printf("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus = %d \n",(int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus));
  1147. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus = %d \n",(int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus));
  1148. //==============================================
  1149. // Meter report
  1150. //==============================================
  1151. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1152. {
  1153. //check Transaction active
  1154. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1155. {
  1156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1157. {
  1158. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1159. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8))
  1160. {
  1161. meterValueSend[gun_index] =1;
  1162. }
  1163. }
  1164. for (int index = 0; index < CCS_QUANTITY; index++)
  1165. {
  1166. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1167. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8))
  1168. {
  1169. meterValueSend[gun_index] =1;
  1170. }
  1171. }
  1172. for (int index = 0; index < GB_QUANTITY; index++)
  1173. {
  1174. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1175. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8))
  1176. {
  1177. meterValueSend[gun_index] =1;
  1178. }
  1179. }
  1180. }
  1181. else
  1182. {
  1183. for (int index = 0; index < AC_QUANTITY; index++)
  1184. {
  1185. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1186. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 8))
  1187. {
  1188. meterValueSend[gun_index] =1;
  1189. }
  1190. }
  1191. }//END OF ELSE
  1192. // sleep(1);
  1193. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1194. if(meterValueSend[gun_index] == 1)
  1195. sendMeterValuesRequest(gun_index);
  1196. }
  1197. //==============================================
  1198. // Check Connector reserved
  1199. //==============================================
  1200. /*
  1201. enum _SYSTEM_STATUS
  1202. {
  1203. S_BOOTING = 0,
  1204. S_IDLE, =1
  1205. S_AUTHORIZING, =2
  1206. S_REASSIGN_CHECK, =3
  1207. S_REASSIGN, =4
  1208. S_PRECHARGE, =5
  1209. S_PREPARING_FOR_EV, =6
  1210. S_PREPARING_FOR_EVSE, =7
  1211. S_CHARGING, =8
  1212. S_TERMINATING, =9
  1213. S_COMPLETE, =10
  1214. S_ALARM, =11
  1215. S_FAULT =12
  1216. };
  1217. */
  1218. //===============================
  1219. // Check if Reserve is expired
  1220. //===============================
  1221. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1222. {
  1223. double diff_t;
  1224. struct tm tp;
  1225. // current time
  1226. time_t t = time(NULL);
  1227. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1228. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1229. tp.tm_isdst = -1;
  1230. time_t utc = mktime(&tp);
  1231. #if 0
  1232. 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 };
  1233. time_t pseudo = mktime(&e0);
  1234. struct tm e1 = *gmtime(&pseudo);
  1235. e0.tm_sec += utc - diff_tm(&e1, &e0);
  1236. time_t local = e0.tm_sec;
  1237. // ?�到��??�起始�???- chargingScedule起�??��?
  1238. diff_t = difftime(t, local);
  1239. #endif
  1240. diff_t = difftime(utc, t);
  1241. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1242. if(diff_t <= 0)
  1243. {
  1244. DEBUG_INFO("reserve expired !!! \n");
  1245. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1246. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1247. }
  1248. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1249. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1250. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1251. {
  1252. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1253. }
  1254. else
  1255. {
  1256. //check Transaction active
  1257. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1258. {
  1259. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1260. {
  1261. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1262. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1263. {
  1264. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1265. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 12) ) // S_ALARM, S_FAULT
  1266. {
  1267. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1268. }
  1269. }
  1270. }
  1271. for (int index = 0; index < CCS_QUANTITY; index++)
  1272. {
  1273. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1274. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1275. {
  1276. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1277. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 12) ) // S_ALARM, S_FAULT
  1278. {
  1279. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1280. }
  1281. }
  1282. }
  1283. for (int index = 0; index < GB_QUANTITY; index++)
  1284. {
  1285. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1286. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1287. {
  1288. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1289. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 12) ) // S_ALARM, S_FAULT
  1290. {
  1291. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1292. }
  1293. }
  1294. }
  1295. }
  1296. else //AC
  1297. {
  1298. for (int index = 0; index < AC_QUANTITY; index++)
  1299. {
  1300. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1301. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1302. {
  1303. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1304. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 12) ) // S_ALARM, S_FAULT
  1305. {
  1306. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1307. }
  1308. }
  1309. }
  1310. }// END OF ELSE
  1311. }// END OF check Transaction active
  1312. }//END OF Check if Reserve is expired
  1313. //==========================================
  1314. // csu trigger FirmwareStatusNotificationReq
  1315. //==========================================
  1316. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1317. {
  1318. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1319. }
  1320. //==========================================
  1321. // csu trigger CancelReservationConf
  1322. //==========================================
  1323. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1324. {
  1325. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1326. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1327. }
  1328. //==========================================
  1329. // csu trigger ChangeAvailabilityConf
  1330. //==========================================
  1331. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1332. {
  1333. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1334. }
  1335. //==========================================
  1336. // csu trigger UnlockConnectorConf
  1337. //==========================================
  1338. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1339. {
  1340. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1341. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1342. }
  1343. //==========================================
  1344. // csu trigger ReserveNowConf
  1345. //==========================================
  1346. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1347. {
  1348. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1349. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1350. }
  1351. }
  1352. }
  1353. //==========================================
  1354. // send request routine
  1355. //==========================================
  1356. int sendAuthorizeRequest(int gun_index)
  1357. {
  1358. mtrace();
  1359. int result = FAIL;
  1360. char message[100]={0};
  1361. char guid[37];
  1362. char tempdata[65]={0};
  1363. DEBUG_ERROR("sendAuthorizeRequest \n");
  1364. //Local Authorize
  1365. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1366. {
  1367. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1368. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1369. {
  1370. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1371. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1372. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1373. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1374. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1375. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1376. authorizeRetryTimes = 0;
  1377. return result;
  1378. }
  1379. else
  1380. {
  1381. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1382. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1383. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1384. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1385. result = PASS;
  1386. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1387. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1388. authorizeRetryTimes = 0;
  1389. return result;
  1390. }
  1391. }
  1392. //initailize struct Authorize
  1393. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1394. //get data from shared memory
  1395. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1396. random_uuid(guid);
  1397. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1398. LWS_Send(message);
  1399. // Put request guid to hash map
  1400. //memset(mapItem, 0, sizeof(data_struct_t));
  1401. // sprintf(mapItem[0].key_string, "%s", guid);
  1402. sprintf(tempdata, "Authorize,%d", gun_index);//sprintf(mapItem->key_value, senstr);//sprintf(mapItem->key_value, "Authorize");
  1403. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid/*mapItem[0].key_string*/, mapItem/*mapItem[0].key_value*//*mapItem*/,tempdata/*(void**)(&mapItem)*/ /*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1404. {
  1405. result = PASS;
  1406. DEBUG_ERROR("Authorize mapItem pass\n");
  1407. }
  1408. #ifdef SystemLogMessage
  1409. DEBUG_INFO(">>>>>Authorize request\n");
  1410. DEBUG_INFO("Message: %s\n", SendBuffer);
  1411. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1412. #endif
  1413. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1414. return result;
  1415. }
  1416. int sendBootNotificationRequest(void)
  1417. {
  1418. mtrace();
  1419. int result = FAIL;
  1420. //int i = 0;
  1421. //struct json_object *message, *payload;
  1422. char message[500]={0}, payload[700]={0};
  1423. //int count = 0;
  1424. //int gun_index = 0;
  1425. char guid[37]={0};
  1426. char tempdata[65]={0};
  1427. int IsGunCharging = FALSE;
  1428. //check Transaction active
  1429. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1430. {
  1431. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1432. {
  1433. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8) //S_CHARGING
  1434. {
  1435. IsGunCharging = TRUE;
  1436. }
  1437. }
  1438. for (int index = 0; index < CCS_QUANTITY; index++)
  1439. {
  1440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8) //S_CHARGING
  1441. {
  1442. IsGunCharging = TRUE;
  1443. }
  1444. }
  1445. for (int index = 0; index < GB_QUANTITY; index++)
  1446. {
  1447. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8) //S_CHARGING
  1448. {
  1449. IsGunCharging = TRUE;
  1450. }
  1451. }
  1452. }
  1453. else
  1454. {
  1455. for (int index = 0; index < AC_QUANTITY; index++)
  1456. {
  1457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 8) //S_CHARGING
  1458. {
  1459. IsGunCharging = TRUE;
  1460. }
  1461. }
  1462. }
  1463. if(IsGunCharging == TRUE)
  1464. {
  1465. server_sign = TRUE;
  1466. return result;
  1467. }
  1468. // Fill BootNotification fields
  1469. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1470. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1471. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1472. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1473. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1474. ShmOCPP16Data->ChargeBoxId
  1475. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1476. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1477. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1478. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1479. ,ShmOCPP16Data->BootNotification.CpIccid
  1480. ,ShmOCPP16Data->BootNotification.CpImsi
  1481. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1482. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1483. random_uuid(guid);
  1484. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1485. LWS_Send(message);
  1486. // memset(mapItem, 0, sizeof(data_struct_t));
  1487. // Put request guid to hash map
  1488. //sprintf(mapItem[0].key_string, "%s", guid);
  1489. sprintf(tempdata, "BootNotification,0");
  1490. // printf("BootNotification mapItem->key_string=%s\n",mapItem[0].key_string);
  1491. // printf("BootNotification mapItem->key_value=%s\n",mapItem[0].key_value);
  1492. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1493. {
  1494. result = PASS;
  1495. }
  1496. memset(queuedata, 0, strlen(queuedata));
  1497. strcpy(queuedata,message);
  1498. //addq(guid, queuedata);
  1499. #ifdef SystemLogMessage
  1500. DEBUG_INFO(">>>>>BootNotification request\n");
  1501. DEBUG_INFO("Message: %s\n", SendBuffer);
  1502. //DEBUG_INFO("After push hash length: %d\n",hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1503. #endif
  1504. //ShmOCPP16Data->SpMsg.bits.BootNotificationReq = 1;
  1505. return result;
  1506. }
  1507. int sendDataTransferRequest(int gun_index)
  1508. {
  1509. mtrace();
  1510. char message[1000]={0};
  1511. char guid[37]={0};
  1512. char tempdata[65]={0};
  1513. int result = FAIL;
  1514. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1515. random_uuid(guid);
  1516. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1517. MESSAGE_TYPE_CALL,
  1518. guid,
  1519. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1520. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1521. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1522. LWS_Send(message);
  1523. // Put request guid to hash map
  1524. //memset(mapItem, 0, sizeof(data_struct_t));
  1525. //sprintf(mapItem[0].key_string, "%s", guid);
  1526. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1527. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1528. {
  1529. result = PASS;
  1530. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1531. }
  1532. #ifdef SystemLogMessage
  1533. DEBUG_INFO(">>>>>DataTransfer request\n");
  1534. DEBUG_INFO("Message: %s\n", SendBuffer);
  1535. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1536. #endif
  1537. return result;
  1538. }
  1539. int sendDiagnosticsStatusNotificationRequest(char *status)
  1540. {
  1541. mtrace();
  1542. int result = FAIL;
  1543. char message[110]={0};
  1544. char guid[37]={0};
  1545. char tempdata[65]={0};
  1546. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1547. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1548. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1549. random_uuid(guid);
  1550. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1551. LWS_Send(message);
  1552. //memset(mapItem, 0, sizeof(data_struct_t));
  1553. // Put request guid to hash map
  1554. //sprintf(mapItem[0].key_string, "%s", guid);
  1555. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1556. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1557. {
  1558. result = PASS;
  1559. printf("DiagnosticsStatusNotification mapItem pass\n");
  1560. }
  1561. #ifdef SystemLogMessage
  1562. DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1563. DEBUG_INFO("Message: %s\n", SendBuffer);
  1564. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1565. #endif
  1566. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1567. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1568. //record status
  1569. if(strcmp(status,"Idle")==0)
  1570. {
  1571. DiagnosticsStatusNotificationStatus = 0;
  1572. }
  1573. else if(strcmp(status,"Uploaded")==0)
  1574. {
  1575. DiagnosticsStatusNotificationStatus = 1;
  1576. }
  1577. else if(strcmp(status,"UploadFailed")==0)
  1578. {
  1579. DiagnosticsStatusNotificationStatus = 2;
  1580. }
  1581. else if(strcmp(status,"Uploading")==0)
  1582. {
  1583. DiagnosticsStatusNotificationStatus = 3;
  1584. }
  1585. return result;
  1586. }
  1587. int sendFirmwareStatusNotificationRequest(char *status)
  1588. {
  1589. mtrace();
  1590. int result = FAIL;
  1591. char message[110]={0};
  1592. char guid[37]={0};
  1593. char tempdata[65]={0};
  1594. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1595. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1596. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1597. random_uuid(guid);
  1598. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1599. LWS_Send(message);
  1600. //memset(mapItem, 0, sizeof(data_struct_t));
  1601. // Put request guid to hash map
  1602. //sprintf(mapItem[0].key_string, "%s", guid);
  1603. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1604. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1605. {
  1606. result = PASS;
  1607. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1608. }
  1609. #ifdef SystemLogMessage
  1610. DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1611. DEBUG_INFO("Message: %s\n", SendBuffer);
  1612. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1613. #endif
  1614. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1615. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1616. //record status
  1617. if(strcmp(status,"Downloaded")==0)
  1618. {
  1619. FirmwareStatusNotificationStatus = 0;
  1620. }
  1621. else if(strcmp(status,"DownloadFailed")==0)
  1622. {
  1623. FirmwareStatusNotificationStatus = 1;
  1624. }
  1625. else if(strcmp(status,"Downloading")==0)
  1626. {
  1627. FirmwareStatusNotificationStatus = 2;
  1628. }
  1629. else if(strcmp(status,"Idle")==0)
  1630. {
  1631. FirmwareStatusNotificationStatus = 3;
  1632. }
  1633. else if(strcmp(status,"InstallationFailed")==0)
  1634. {
  1635. FirmwareStatusNotificationStatus = 4;
  1636. }
  1637. else if(strcmp(status,"Installing")==0)
  1638. {
  1639. FirmwareStatusNotificationStatus = 5;
  1640. }
  1641. else if(strcmp(status,"Installed")==0)
  1642. {
  1643. FirmwareStatusNotificationStatus = 6;
  1644. }
  1645. return result;
  1646. }
  1647. int sendHeartbeatRequest(int gun_index)
  1648. {
  1649. mtrace();
  1650. int result = FAIL;
  1651. char message[80]={0};
  1652. char guid[37]={0};
  1653. char tempdata[65]={0};
  1654. random_uuid(guid);
  1655. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1656. , MESSAGE_TYPE_CALL
  1657. , guid );
  1658. LWS_Send(message);
  1659. //memset(mapItem, 0, sizeof(data_struct_t));
  1660. //sprintf(mapItem[0].key_string, "%s", guid);
  1661. sprintf(tempdata, "Heartbeat,%d", 0);
  1662. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1663. {
  1664. result = PASS;
  1665. DEBUG_ERROR("Heartbeat mapItem pass\n");
  1666. }
  1667. #ifdef SystemLogMessage
  1668. DEBUG_INFO(">>>>>Heartbeat request\n");
  1669. DEBUG_INFO("Message: %s\n", SendBuffer);
  1670. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1671. #endif
  1672. return result;
  1673. }
  1674. int sendStartTransactionRequest(int gun_index)
  1675. {
  1676. mtrace();
  1677. int result = FAIL;
  1678. char message[250]={0};
  1679. char guid[37]={0};
  1680. struct timeval tmnow;
  1681. struct tm *tm;
  1682. char buf[30];//, usec_buf[6];
  1683. char tempdata[65]={0};
  1684. DEBUG_ERROR("sendStartTransactionRequest...");
  1685. gettimeofday(&tmnow, NULL);
  1686. time_t t;
  1687. t = time(NULL);
  1688. /*UTC time and date*/
  1689. tm = gmtime(&t);
  1690. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1691. #if 0 // remove temporally
  1692. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1693. strcat(buf,".");
  1694. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1695. strcat(buf,usec_buf);
  1696. #endif
  1697. printf("Start Charging Time :%s",buf);
  1698. // set value
  1699. memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1700. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1701. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1702. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1703. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1704. {
  1705. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1706. {
  1707. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1708. {
  1709. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1710. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1711. }
  1712. }
  1713. for (int index = 0; index < CCS_QUANTITY; index++)
  1714. {
  1715. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1716. {
  1717. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1718. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1719. }
  1720. }
  1721. for (int index = 0; index < GB_QUANTITY; index++)
  1722. {
  1723. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1724. {
  1725. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1726. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1727. }
  1728. }
  1729. }
  1730. else
  1731. {
  1732. for (int index = 0; index < AC_QUANTITY; index++)
  1733. {
  1734. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1735. {
  1736. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1737. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1738. }
  1739. }
  1740. }//END OF ELSE
  1741. random_uuid(guid);
  1742. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1743. , MESSAGE_TYPE_CALL
  1744. , guid
  1745. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1746. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1747. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1748. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1749. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1750. LWS_Send(message);
  1751. //memset(mapItem, 0, sizeof(data_struct_t));
  1752. // Put request guid to hash map
  1753. //sprintf(mapItem[0].key_string, "%s", guid);
  1754. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1755. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1756. {
  1757. result = PASS;
  1758. }
  1759. strcpy(queuedata, message);
  1760. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1761. #ifdef SystemLogMessage
  1762. DEBUG_INFO(">>>>>StartTransaction request\n");
  1763. DEBUG_INFO("Message: %s\n", SendBuffer);
  1764. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1765. #endif
  1766. return result;
  1767. }
  1768. int sendStatusNotificationRequest(int gun_index)
  1769. {
  1770. mtrace();
  1771. int result = FAIL;
  1772. char message[600]={0};
  1773. char guid[37];
  1774. int currentStatus = 0;
  1775. struct timeval tmnow;
  1776. struct tm *tm;
  1777. char buf[30];//, usec_buf[6];
  1778. char tempdata[65]={0};
  1779. gettimeofday(&tmnow, NULL);
  1780. time_t t;
  1781. t = time(NULL);
  1782. /*UTC time and date*/
  1783. tm = gmtime(&t);
  1784. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1785. #if 0 // remove temporally
  1786. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1787. strcat(buf,".");
  1788. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1789. strcat(buf,usec_buf);
  1790. #endif
  1791. printf("%s",buf);
  1792. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1793. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1794. // it's option
  1795. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1796. /*
  1797. enum _SYSTEM_STATUS
  1798. {
  1799. S_BOOTING = 0,
  1800. S_IDLE, = 1
  1801. S_AUTHORIZING, =2
  1802. S_REASSIGN_CHECK, =3
  1803. S_REASSIGN, =4
  1804. S_PRECHARGE, =5
  1805. S_PREPARING_FOR_EV, =6
  1806. S_PREPARING_FOR_EVSE, =7
  1807. S_CHARGING, =8
  1808. S_TERMINATING, =9
  1809. S_COMPLETE, =10
  1810. S_ALARM, =11
  1811. S_FAULT =12
  1812. }
  1813. */
  1814. //check Transaction active
  1815. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1816. {
  1817. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1818. {
  1819. //printf("gun_index=%d\n",gun_index);
  1820. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1821. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 1)) //S_IDLE
  1822. {
  1823. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1824. currentStatus = 0; //OCPP Status
  1825. }
  1826. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 5)) //S_PRECHARGE
  1827. {
  1828. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1829. currentStatus = 1; //OCPP Status
  1830. }
  1831. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8)) //S_CHARGING
  1832. {
  1833. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1834. currentStatus = 2; //OCPP Status
  1835. }
  1836. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 10)) //S_COMPLETE
  1837. {
  1838. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1839. currentStatus = 5; //OCPP Status
  1840. }
  1841. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11)) //S_ALARM ---> SuspendedEV
  1842. {
  1843. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1844. currentStatus = 4; //OCPP Status
  1845. }
  1846. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 9)) //S_TERMINATING ---> Unavailable
  1847. {
  1848. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1849. currentStatus = 7; //OCPP Status: Unavailable
  1850. }
  1851. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 12)) //S_FAULT ---> Faulted
  1852. {
  1853. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1854. currentStatus = 8; //OCPP Status: Faulted
  1855. }
  1856. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 13)) // ---> Reserved
  1857. {
  1858. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1859. currentStatus = 6; //OCPP Status: Reserved
  1860. }
  1861. }//end of for CHAdeMO_QUANTITY
  1862. for (int index = 0; index < CCS_QUANTITY; index++)
  1863. {
  1864. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1865. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 1)) //S_IDLE
  1866. {
  1867. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1868. currentStatus = 0; //OCPP Status
  1869. }
  1870. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 5)) //S_PRECHARGE
  1871. {
  1872. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1873. currentStatus = 1; //OCPP Status
  1874. }
  1875. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8)) //S_CHARGING
  1876. {
  1877. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1878. currentStatus = 2; //OCPP Status
  1879. }
  1880. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 10)) //S_COMPLETE
  1881. {
  1882. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1883. currentStatus = 5; //OCPP Status
  1884. }
  1885. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 11)) //S_ALARM ---> SuspendedEV
  1886. {
  1887. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1888. currentStatus = 4; //OCPP Status
  1889. }
  1890. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 9)) //S_TERMINATING ---> Unavailable
  1891. {
  1892. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1893. currentStatus = 7; //OCPP Status
  1894. }
  1895. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 12)) //S_FAULT ---> Faulted
  1896. {
  1897. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1898. currentStatus = 8; //OCPP Status
  1899. }
  1900. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 13)) // ---> Reserved
  1901. {
  1902. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1903. currentStatus = 6; //OCPP Status
  1904. }
  1905. }
  1906. for (int index = 0; index < GB_QUANTITY; index++)
  1907. {
  1908. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1909. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1910. {
  1911. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1912. currentStatus = 0; //OCPP Status
  1913. }
  1914. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 5)) //S_PRECHARGE
  1915. {
  1916. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1917. currentStatus = 1; //OCPP Status
  1918. }
  1919. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8)) //S_CHARGING
  1920. {
  1921. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1922. currentStatus = 2; //OCPP Status
  1923. }
  1924. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8)) //S_COMPLETE
  1925. {
  1926. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1927. currentStatus = 5; //OCPP Status
  1928. }
  1929. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 11)) //S_ALARM ---> SuspendedEV
  1930. {
  1931. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1932. currentStatus = 4; //OCPP Status
  1933. }
  1934. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 9)) //S_TERMINATING ---> Unavailable
  1935. {
  1936. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1937. currentStatus = 7; //OCPP Status: Unavailable
  1938. }
  1939. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 12)) //S_FAULT ---> Faulted
  1940. {
  1941. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1942. currentStatus = 8; //OCPP Status: Faulted
  1943. }
  1944. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 13)) // ---> Reserved
  1945. {
  1946. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1947. currentStatus = 6; //OCPP Status: Faulted
  1948. }
  1949. }
  1950. }
  1951. else
  1952. {
  1953. for (int index = 0; index < AC_QUANTITY; index++)
  1954. {
  1955. //printf("gun_index=%d\n",gun_index);
  1956. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1957. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1)) //S_IDLE
  1958. {
  1959. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1960. currentStatus = 0; //OCPP Status
  1961. }
  1962. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 5)) //S_PRECHARGE
  1963. {
  1964. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1965. currentStatus = 1; //OCPP Status
  1966. }
  1967. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 8)) //S_CHARGING
  1968. {
  1969. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1970. currentStatus = 2; //OCPP Status
  1971. }
  1972. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 10)) //S_COMPLETE
  1973. {
  1974. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1975. currentStatus = 5; //OCPP Status
  1976. }
  1977. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 11)) //S_ALARM ---> SuspendedEV
  1978. {
  1979. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1980. currentStatus = 4; //OCPP Status
  1981. }
  1982. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 9)) //S_TERMINATING ---> Unavailable
  1983. {
  1984. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1985. currentStatus = 7; //OCPP Status: Unavailable
  1986. }
  1987. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 12)) //S_FAULT ---> Faulted
  1988. {
  1989. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1990. currentStatus = 8; //OCPP Status: Faulted
  1991. }
  1992. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 13)) // ---> Reserved
  1993. {
  1994. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1995. currentStatus = 6; //OCPP Status: Reserved
  1996. }
  1997. }//end of for AC_QUANTITY
  1998. }//END OF ELSE
  1999. //it's option
  2000. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2001. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2002. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2003. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2004. random_uuid(guid);
  2005. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2006. , MESSAGE_TYPE_CALL
  2007. , guid
  2008. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2009. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2010. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2011. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2012. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2013. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2014. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2015. LWS_Send(message);
  2016. // Put request guid to hash map
  2017. //memset(mapItem, 0, sizeof(data_struct_t));
  2018. //sprintf(mapItem[0].key_string, "%s", guid);
  2019. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2020. //sprintf(mapItem->key_value, "StatusNotification,%d", gun_index + 1);
  2021. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2022. {
  2023. DEBUG_ERROR("statusNotification mapitem pass");
  2024. result = PASS;
  2025. }
  2026. #ifdef SystemLogMessage
  2027. DEBUG_INFO(">>>>>StatusNotification request\n");
  2028. DEBUG_INFO("Message: %s\n", SendBuffer);
  2029. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2030. #endif
  2031. return result;
  2032. }
  2033. int sendStopTransactionRequest(int gun_index)
  2034. {
  2035. mtrace();
  2036. int result = FAIL;
  2037. char message[700]={0};
  2038. char guid[37]={0};
  2039. char tempdata[65]={0};
  2040. int idx_sample=0;
  2041. DEBUG_ERROR("sendStopTransactionRequest \n");
  2042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId/*ShmOCPP16Data->Authorize.IdTag*/);
  2043. //ENERGY_ACTIVE_IMPORT_REGISTER
  2044. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2045. {
  2046. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2047. {
  2048. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2049. {
  2050. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2051. //Check Status
  2052. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) // S_ALARM (Temporally for SuspendedEV )
  2053. {
  2054. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2055. }
  2056. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2057. }
  2058. }// END OF CHAdeMO_QUANTITY
  2059. for (int index = 0; index < CCS_QUANTITY; index++)
  2060. {
  2061. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2062. {
  2063. //for test
  2064. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2065. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2066. //Check Status
  2067. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 11) // S_ALARM (Temporally for SuspendedEV )
  2068. {
  2069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2070. }
  2071. else
  2072. {
  2073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2074. }
  2075. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2076. }
  2077. }// END OF CCS_QUANTITY
  2078. for (int index = 0; index < GB_QUANTITY; index++)
  2079. {
  2080. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2081. {
  2082. // for test
  2083. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2084. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2085. //Check Status
  2086. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 11) // S_ALARM (Temporally for SuspendedEV )
  2087. {
  2088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2089. }
  2090. else
  2091. {
  2092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2093. }
  2094. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2095. }
  2096. }// END OF GB_QUANTITY
  2097. }
  2098. else
  2099. {
  2100. for (int index = 0; index < AC_QUANTITY; index++)
  2101. {
  2102. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2103. {
  2104. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2105. //Check Status
  2106. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 11) // S_ALARM (Temporally for SuspendedEV )
  2107. {
  2108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2109. }
  2110. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2111. }
  2112. }// END OF AC_QUANTITY
  2113. }//END OF ELSE
  2114. //printf("sendStopTransactionRequest 1\n");
  2115. //Stop Transaction Time
  2116. struct timeval tmnow;
  2117. struct tm *tm;
  2118. char buf[30];//, usec_buf[6];
  2119. gettimeofday(&tmnow, NULL);
  2120. time_t t;
  2121. t = time(NULL);
  2122. /*UTC time and date*/
  2123. tm = gmtime(&t);
  2124. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2125. #if 0 // remove temporally
  2126. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2127. strcat(buf,".");
  2128. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2129. strcat(buf,usec_buf);
  2130. #endif
  2131. printf("StopTransaction Time %s\n",buf);
  2132. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2134. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2135. random_uuid(guid);
  2136. sprintf(message,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":"
  2137. ,MESSAGE_TYPE_CALL
  2138. ,guid
  2139. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2140. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2141. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2142. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2143. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
  2144. //printf("sendStopTransactionRequest 2\n");
  2145. /***********************************transactionData******************************************************/
  2146. ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2147. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*3);
  2148. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2149. {
  2150. //transactionData = json_object_new_object();
  2151. //json_object_object_add(transactionData, "timestamp", json_object_new_string("2019-05-04T18:15:33Z"));
  2152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp, buf/*"2019-05-04T18:15:33Z"*/);
  2153. sprintf(message + strlen(message), "[{\"timestamp\":\"%s\",\"sampledValue\":[", (const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp);
  2154. //Transaction_Begin
  2155. idx_sample=0;
  2156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart));
  2157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Reactive_Export_Register]);
  2160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2163. sprintf(message + strlen(message), "{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2164. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2165. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2166. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2167. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2168. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2169. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2170. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2171. );
  2172. //Transaction_End
  2173. idx_sample=1;
  2174. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2175. {
  2176. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2177. {
  2178. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2179. {
  2180. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2181. }
  2182. }
  2183. for (int index = 0; index < CCS_QUANTITY; index++)
  2184. {
  2185. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2186. {
  2187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2188. }
  2189. }
  2190. for (int index = 0; index < GB_QUANTITY; index++)
  2191. {
  2192. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2193. {
  2194. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );
  2195. }
  2196. }
  2197. }
  2198. else
  2199. {
  2200. for (int index = 0; index < AC_QUANTITY; index++)
  2201. {
  2202. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2203. {
  2204. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2205. }
  2206. }
  2207. }// END FOR AC ELSE
  2208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Reactive_Export_Register]);
  2211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2214. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2215. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2216. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2217. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2218. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2219. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2220. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2221. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2222. );
  2223. sprintf(message + strlen(message)," ] } ] } ]");
  2224. free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue);
  2225. free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);
  2226. }
  2227. LWS_Send(message);
  2228. //memset(mapItem, 0, sizeof(data_struct_t));
  2229. // Put request guid to hash map
  2230. //sprintf(mapItem[0].key_string, "%s", guid);
  2231. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2232. //sprintf(mapItem->key_value, senstr);//sprintf(mapItem->key_value, "StopTransaction");
  2233. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2234. {
  2235. result = PASS;
  2236. DEBUG_INFO("StopTransaction mapitem pass\n");
  2237. }
  2238. strcpy(queuedata, message);
  2239. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2240. //addq(guid, (char*)json_object_to_json_string(message));
  2241. #ifdef SystemLogMessage
  2242. DEBUG_INFO(">>>>>StopTransaction request\n");
  2243. DEBUG_INFO("Message: %s\n", SendBuffer);
  2244. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2245. #endif
  2246. //for test
  2247. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2248. return result;
  2249. }
  2250. int sendMeterValuesRequest(int gun_index)
  2251. {
  2252. mtrace();
  2253. int result = FAIL;
  2254. char message[1500]={0};
  2255. char guid[37]={0};
  2256. int idx_sample=0;
  2257. //int length = 0;
  2258. char tempdata[65]={0};
  2259. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2260. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2261. return result;
  2262. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2263. {
  2264. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2265. }
  2266. //set value
  2267. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2268. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2269. random_uuid(guid);
  2270. sprintf(message,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":"
  2271. ,MESSAGE_TYPE_CALL
  2272. ,guid
  2273. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2274. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId);
  2275. //,comfirmpayload);
  2276. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2277. {
  2278. //allocate memory space
  2279. ShmOCPP16Data->MeterValues[gun_index].MeterValue = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2280. //UTC Date time
  2281. struct timeval tmnow;
  2282. struct tm *tm;
  2283. char buf[30];//, usec_buf[6];
  2284. gettimeofday(&tmnow, NULL);
  2285. time_t t;
  2286. t = time(NULL);
  2287. /*UTC time and date*/
  2288. tm = gmtime(&t);
  2289. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2290. #if 0 // remove temporally
  2291. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2292. strcat(buf,".");
  2293. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2294. strcat(buf,usec_buf);
  2295. #endif
  2296. // printf("%s",buf);
  2297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp, buf);
  2298. //allocate memory space
  2299. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*6);
  2300. sprintf(message + strlen(message),"[{\"timestamp\":\"%s\",\"sampledValue\":[",(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp);
  2301. idx_sample=0;
  2302. /********************************(1)Current.Export************************************************/
  2303. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2304. {
  2305. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2306. {
  2307. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2308. {
  2309. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2310. }
  2311. }
  2312. for (int index = 0; index < CCS_QUANTITY; index++)
  2313. {
  2314. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2315. {
  2316. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2317. }
  2318. }
  2319. for (int index = 0; index < GB_QUANTITY; index++)
  2320. {
  2321. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2322. {
  2323. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2324. }
  2325. }
  2326. }
  2327. else
  2328. {
  2329. for (int index = 0; index < AC_QUANTITY; index++)
  2330. {
  2331. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2332. {
  2333. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2334. }
  2335. }
  2336. }// END FOR AC ELSE
  2337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Current_Export]);
  2340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2341. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2342. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2343. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2344. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2345. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2346. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2347. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2348. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2349. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2350. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2351. );
  2352. idx_sample=1;
  2353. /****************************************************(2)Energy.Active.Export.Register*********************************************/
  2354. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2355. {
  2356. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2357. {
  2358. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2359. {
  2360. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2361. }
  2362. }
  2363. for (int index = 0; index < CCS_QUANTITY; index++)
  2364. {
  2365. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2366. {
  2367. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2368. }
  2369. }
  2370. for (int index = 0; index < GB_QUANTITY; index++)
  2371. {
  2372. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2373. {
  2374. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2375. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2376. }
  2377. }
  2378. }
  2379. else
  2380. {
  2381. for (int index = 0; index < AC_QUANTITY; index++)
  2382. {
  2383. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2384. {
  2385. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2386. }
  2387. }
  2388. }// END FOR AC ELSE
  2389. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2390. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2391. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Register]);
  2392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2395. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2396. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2397. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2398. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2399. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2400. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2401. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2402. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2403. );
  2404. idx_sample=2;
  2405. /****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2406. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2407. {
  2408. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2409. {
  2410. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2411. {
  2412. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2413. }
  2414. }
  2415. for (int index = 0; index < CCS_QUANTITY; index++)
  2416. {
  2417. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2418. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2419. {
  2420. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2421. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2422. }
  2423. }
  2424. for (int index = 0; index < GB_QUANTITY; index++)
  2425. {
  2426. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2427. {
  2428. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2429. }
  2430. }
  2431. }
  2432. else
  2433. {
  2434. for (int index = 0; index < AC_QUANTITY; index++)
  2435. {
  2436. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2437. {
  2438. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2439. }
  2440. }
  2441. }//END FOR AC ELSE
  2442. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2448. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2449. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2450. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2451. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2452. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2453. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2454. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2455. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2456. );
  2457. idx_sample=3;
  2458. /********************************(4)Power.Active.Export************************************************/
  2459. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2460. {
  2461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2462. {
  2463. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2464. {
  2465. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2466. }
  2467. }
  2468. for (int index = 0; index < CCS_QUANTITY; index++)
  2469. {
  2470. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2471. {
  2472. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2473. }
  2474. }
  2475. for (int index = 0; index < GB_QUANTITY; index++)
  2476. {
  2477. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2478. {
  2479. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2480. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2481. }
  2482. }
  2483. }
  2484. else
  2485. {
  2486. for (int index = 0; index < AC_QUANTITY; index++)
  2487. {
  2488. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2489. {
  2490. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2491. }
  2492. }
  2493. }// END FOR AC ELSE
  2494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Power_Active_Export]);
  2497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2500. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2501. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2502. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2503. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2504. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2505. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2506. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2507. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2508. );
  2509. idx_sample=4;
  2510. /***********************************************(5)VOLTAGE******************************************************/
  2511. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2512. {
  2513. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2514. {
  2515. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2516. {
  2517. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2518. }
  2519. }
  2520. for (int index = 0; index < CCS_QUANTITY; index++)
  2521. {
  2522. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2523. {
  2524. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2525. }
  2526. }
  2527. for (int index = 0; index < GB_QUANTITY; index++)
  2528. {
  2529. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2530. {
  2531. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2532. }
  2533. }
  2534. }
  2535. else
  2536. {
  2537. for (int index = 0; index < AC_QUANTITY; index++)
  2538. {
  2539. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2540. {
  2541. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2542. }
  2543. }
  2544. }//END FOR AC ELSE
  2545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2547. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Voltage]);
  2548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2551. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2552. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2553. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2554. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2555. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2556. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2557. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2558. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2559. );
  2560. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2561. {
  2562. idx_sample=5;
  2563. //sampledValue = NULL;
  2564. /***********************************************(6)SOC******************************************************/
  2565. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2566. {
  2567. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2568. {
  2569. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2570. {
  2571. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2572. }
  2573. }
  2574. for (int index = 0; index < CCS_QUANTITY; index++)
  2575. {
  2576. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2577. {
  2578. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2579. }
  2580. }
  2581. for (int index = 0; index < GB_QUANTITY; index++)
  2582. {
  2583. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2584. {
  2585. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2586. }
  2587. }
  2588. }
  2589. else
  2590. {
  2591. for (int index = 0; index < AC_QUANTITY; index++)
  2592. {
  2593. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2594. {
  2595. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2596. }
  2597. }
  2598. }//END FOR AC ELSE
  2599. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2600. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2601. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[SoC]);
  2602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2603. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2604. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2605. sprintf(message + strlen(message),",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2606. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2607. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2608. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2609. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2610. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2611. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2612. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2613. );
  2614. }
  2615. //}
  2616. sprintf(message + strlen(message)," ] } ] } ]");
  2617. free(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue);
  2618. }
  2619. LWS_Send(message);
  2620. //memset(mapItem, 0, sizeof(data_struct_t));
  2621. // Put request guid to hash map
  2622. //sprintf(mapItem[0].key_string, "%s", guid);
  2623. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2624. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2625. {
  2626. result = PASS;
  2627. DEBUG_INFO("MeterValues mapitem pass\n");
  2628. }
  2629. strcpy(queuedata, message);
  2630. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2631. #ifdef SystemLogMessage
  2632. DEBUG_INFO(">>>>>MeerValues request\n");
  2633. DEBUG_INFO("Message: %s\n", SendBuffer);
  2634. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2635. #endif
  2636. return result;
  2637. }
  2638. //==========================================
  2639. // send confirm routine
  2640. //==========================================
  2641. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2642. {
  2643. mtrace();
  2644. int result = FAIL;
  2645. char message[100]={0};
  2646. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2647. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2648. LWS_Send(message);
  2649. result = TRUE;
  2650. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2651. return result;
  2652. }
  2653. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2654. {
  2655. mtrace();
  2656. int result = FAIL;
  2657. char message[100]={0};
  2658. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2659. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2660. LWS_Send(message);
  2661. result = TRUE;
  2662. return result;
  2663. }
  2664. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2665. {
  2666. mtrace();
  2667. int result = FAIL;
  2668. char message[100]={0};
  2669. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2670. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2671. LWS_Send(message);
  2672. result = TRUE;
  2673. return result;
  2674. }
  2675. int sendClearCacheConfirmation(char *uuid,char *payload)
  2676. {
  2677. mtrace();
  2678. int result = FAIL;
  2679. char message[500]={0};
  2680. // int count = 0;
  2681. // int gun_index = 0;
  2682. // char guid[37];
  2683. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2684. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2685. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2686. LWS_Send(message);
  2687. return result;
  2688. }
  2689. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2690. {
  2691. mtrace();
  2692. int result = FAIL;
  2693. char message[500]={0};
  2694. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2695. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2696. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2697. LWS_Send(message);
  2698. return result;
  2699. }
  2700. int sendDataTransferConfirmation(char *uuid,char *payload)
  2701. {
  2702. mtrace();
  2703. char statusStr[20]={0};
  2704. char dataStr[10]={0};
  2705. char sstr[20]={0};
  2706. int c = 0;
  2707. char *loc;
  2708. int result = FAIL;
  2709. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2710. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2711. /**********************status**************************/
  2712. loc = strstr(payload, "status");
  2713. memset(sstr ,0, sizeof(sstr) );
  2714. c = 0;
  2715. while (loc[3+strlen("status")+c] != '\"')
  2716. {
  2717. sstr[c] = loc[3+strlen("status")+c];
  2718. c++;
  2719. }
  2720. sstr[c] = '\0';
  2721. strcpy(statusStr, sstr);
  2722. /**********************data**************************/
  2723. loc = strstr(payload, "data");
  2724. memset(sstr ,0, sizeof(sstr) );
  2725. c = 0;
  2726. while (loc[3+strlen("data")+c] != '\"')
  2727. {
  2728. sstr[c] = loc[3+strlen("data")+c];
  2729. c++;
  2730. }
  2731. sstr[c] = '\0';
  2732. strcpy(dataStr, sstr);
  2733. return result;
  2734. }
  2735. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2736. {
  2737. mtrace();
  2738. int result = FAIL;
  2739. char message[1000]={0};
  2740. double diff_f = 0.0;
  2741. int diff_i = 0;
  2742. struct tm tp;
  2743. DEBUG_ERROR("handle sendGetCompositeScheduleConfirmation ...\n");
  2744. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2745. tp.tm_isdst = -1;
  2746. time_t utc = mktime(&tp);
  2747. time_t t = time(NULL);
  2748. diff_f = difftime(t, utc);
  2749. diff_i = (int)diff_f;
  2750. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2751. #if 0 //remove temporally
  2752. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":6.0,\"numberPhases\":3},{\"startPeriod\":40,\"limit\":10.0,\"numberPhases\":3},{\"startPeriod\":100,\"limit\":8.0,\"numberPhases\":3}"
  2753. ,MESSAGE_TYPE_CALLRESULT
  2754. ,uuid
  2755. ,payload
  2756. ,connectorIdInt
  2757. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2758. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2759. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2760. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2761. #endif
  2762. if(nPeriod == 0)
  2763. {
  2764. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2765. ,MESSAGE_TYPE_CALLRESULT
  2766. ,uuid
  2767. ,payload
  2768. ,connectorIdInt
  2769. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule);
  2770. }
  2771. else
  2772. {
  2773. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2774. ,MESSAGE_TYPE_CALLRESULT
  2775. ,uuid
  2776. ,payload
  2777. ,connectorIdInt
  2778. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2779. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2780. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2781. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2782. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  2783. #if 1 // remove temporally
  2784. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  2785. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2786. {
  2787. if (idx_sample == 0)
  2788. {
  2789. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2790. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  2791. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2792. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2793. }
  2794. else
  2795. {
  2796. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2797. , (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diff_i /*-1*/)
  2798. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2799. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2800. }
  2801. }
  2802. #endif
  2803. sprintf(message + strlen(message), "]}}]");
  2804. }
  2805. LWS_Send(message);
  2806. result = TRUE;
  2807. return result;
  2808. }
  2809. int sendGetConfigurationConfirmation(char *uuid)
  2810. {
  2811. mtrace();
  2812. int result = FAIL;
  2813. int MaxKeySupported = 0;
  2814. int sentConfigurationNumber= 0;
  2815. int sentunConfigurationNumber= 0;
  2816. char message[4000]={0};
  2817. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  2818. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2819. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  2820. ,MESSAGE_TYPE_CALLRESULT
  2821. ,uuid );
  2822. //configuration key
  2823. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2824. {
  2825. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2826. {
  2827. if (sentConfigurationNumber == 0)
  2828. {
  2829. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  2830. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2831. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2832. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2833. }
  2834. else
  2835. {
  2836. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  2837. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  2838. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  2839. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  2840. }
  2841. sentConfigurationNumber = sentConfigurationNumber + 1;
  2842. }
  2843. }
  2844. sprintf(message + strlen(message), "]");
  2845. if(UnknownKeynum != 0)
  2846. {
  2847. sprintf(message + strlen(message), ",\"unknownKey\":[");
  2848. //unkown key
  2849. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  2850. {
  2851. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  2852. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  2853. if(sentunConfigurationNumber == 0)
  2854. {
  2855. sprintf(message + strlen(message), "\"%s\""
  2856. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2857. }
  2858. else
  2859. {
  2860. sprintf(message + strlen(message), ",\"%s\""
  2861. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  2862. }
  2863. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  2864. }
  2865. sprintf(message + strlen(message), "]");
  2866. }
  2867. sprintf(message + strlen(message), "} ]");
  2868. LWS_Send(message);
  2869. #if 0
  2870. printf("error 1-0\n");
  2871. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  2872. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  2873. #endif
  2874. return result;
  2875. }
  2876. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  2877. {
  2878. mtrace();
  2879. int result = FAIL;
  2880. char message[400]={0};
  2881. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  2882. if(strcmp(payload,"")==0)
  2883. {
  2884. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  2885. }
  2886. else
  2887. {
  2888. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  2889. }
  2890. LWS_Send(message);
  2891. result = TRUE;
  2892. return result;
  2893. }
  2894. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  2895. {
  2896. mtrace();
  2897. int result = FAIL;
  2898. char message[80]={0};
  2899. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  2900. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  2901. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  2902. LWS_Send(message);
  2903. result = TRUE;
  2904. return result;
  2905. }
  2906. int sendRemoteStartConfirmation(char *uuid,char *payload)
  2907. {
  2908. mtrace();
  2909. int result = FAIL;
  2910. char message[80]={0};
  2911. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  2912. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  2913. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  2914. LWS_Send(message);
  2915. result = TRUE;
  2916. return result;
  2917. }
  2918. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  2919. {
  2920. mtrace();
  2921. int result = FAIL;
  2922. char message[80]={0};
  2923. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  2924. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  2925. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  2926. LWS_Send(message);
  2927. result = TRUE;
  2928. return result;
  2929. }
  2930. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  2931. {
  2932. mtrace();
  2933. int result = FAIL;
  2934. char message[80]={0};
  2935. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  2936. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  2937. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  2938. LWS_Send(message);
  2939. result = TRUE;
  2940. return result;
  2941. }
  2942. int sendResetConfirmation(char *uuid,char *payload)
  2943. {
  2944. mtrace();
  2945. int result = FAIL;
  2946. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  2947. char message[80]={0};
  2948. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  2949. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  2950. LWS_Send(message);
  2951. result = TRUE;
  2952. return result;
  2953. }
  2954. int sendSendLocalListConfirmation(char *uuid,char *payload)
  2955. {
  2956. mtrace();
  2957. int result = FAIL;
  2958. char message[500]={0};
  2959. // [ 3, "1571284266109", { "status": "Accepted" } ]
  2960. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2961. LWS_Send(message);
  2962. result = TRUE;
  2963. return result;
  2964. }
  2965. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  2966. {
  2967. mtrace();
  2968. int result = FAIL;
  2969. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  2970. char message[80]={0};
  2971. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  2972. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  2973. LWS_Send(message);
  2974. result = TRUE;
  2975. return result;
  2976. }
  2977. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  2978. {
  2979. mtrace();
  2980. int result = FAIL;
  2981. char message[80]={0};
  2982. DEBUG_ERROR("sendTriggerMessageConfirmation\n");
  2983. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  2984. LWS_Send(message);
  2985. result = TRUE;
  2986. return result;
  2987. }
  2988. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  2989. {
  2990. mtrace();
  2991. int result = FAIL;
  2992. char message[80]={0};
  2993. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  2994. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  2995. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  2996. LWS_Send(message);
  2997. result = TRUE;
  2998. return result;
  2999. }
  3000. int sendUpdateFirmwareConfirmation(char *uuid)
  3001. {
  3002. mtrace();
  3003. int result = FAIL;
  3004. char message[60]={0};
  3005. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3006. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3007. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3008. LWS_Send(message);
  3009. result = TRUE;
  3010. return result;
  3011. }
  3012. //==========================================
  3013. // send CallError routine
  3014. //==========================================
  3015. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3016. {
  3017. mtrace();
  3018. //int result = FAIL;
  3019. char message[220]={0};
  3020. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3021. #ifdef SystemLogMessage
  3022. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3023. uniqueId, action, errorCode, errorDescription);
  3024. #endif
  3025. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3026. LWS_Send(message);
  3027. //result = TRUE;
  3028. }
  3029. //==========================================
  3030. // Handle server request routine Start
  3031. //==========================================
  3032. #define GUN_NUM 1
  3033. int handleCancelReservationRequest(char *uuid, char *payload)
  3034. {
  3035. mtrace();
  3036. int result = FAIL;
  3037. int gunNO = 0;
  3038. int reservationIdInt =0;
  3039. char comfirmstr[20];
  3040. int c = 0;
  3041. char *loc;
  3042. char sstr[100]={0};
  3043. DEBUG_INFO("handle CancelReservationRequest\n");
  3044. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3045. c = 0;
  3046. loc = strstr(payload, "reservationId");
  3047. memset(sstr ,0, sizeof(sstr) );
  3048. while (loc[strlen("reservationId")+2+c] != '}')
  3049. {
  3050. sstr[c] = loc[strlen("reservationId")+2+c];
  3051. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3052. c++;
  3053. }
  3054. sstr[c] = '\0';
  3055. reservationIdInt = atoi(sstr);
  3056. memset(comfirmstr, 0, sizeof comfirmstr);
  3057. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3058. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3059. //check Transaction active
  3060. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3061. {
  3062. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3063. {
  3064. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3065. {
  3066. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3067. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3068. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3069. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3070. goto end;
  3071. }
  3072. }
  3073. for (int index = 0; index < CCS_QUANTITY; index++)
  3074. {
  3075. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3076. {
  3077. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3078. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3079. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3080. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3081. goto end;
  3082. }
  3083. }
  3084. for (int index = 0; index < GB_QUANTITY; index++)
  3085. {
  3086. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3087. {
  3088. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3089. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3090. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3091. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3092. goto end;
  3093. }
  3094. }
  3095. }
  3096. else
  3097. {
  3098. for (int index = 0; index < AC_QUANTITY; index++)
  3099. {
  3100. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3101. {
  3102. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3103. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3104. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3105. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3106. goto end;
  3107. }
  3108. }
  3109. }// END FOR AC ELSE
  3110. //The reservationId does NOT match the reservationId
  3111. sendCancelReservationConfirmation(uuid, comfirmstr);
  3112. end:
  3113. // Fill in ocpp packet uuid
  3114. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3115. return result;
  3116. }
  3117. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3118. {
  3119. mtrace();
  3120. int result = FAIL;
  3121. int gunIndex = 0;
  3122. char sstr[90]={0};
  3123. char typeStr[16]={0};
  3124. char comfirmstr[20];
  3125. int specificId = FALSE;
  3126. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3127. char *loc;
  3128. //int intervalInt = 0;
  3129. int c = 0;
  3130. /*** connectorId ****/
  3131. c = 0;
  3132. loc = strstr(payload, "connectorId");
  3133. memset(sstr ,0, sizeof(sstr) );
  3134. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3135. {
  3136. sstr[c] = loc[strlen("connectorId")+2+c];
  3137. c++;
  3138. }
  3139. sstr[c] = '\0';
  3140. gunIndex = atoi(sstr);
  3141. /***type ****/
  3142. loc = strstr(payload, "type");
  3143. memset(sstr ,0, sizeof(sstr) );
  3144. c = 0;
  3145. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3146. {
  3147. sstr[c] = loc[3+strlen("type")+c];
  3148. c++;
  3149. }
  3150. sstr[c] = '\0';
  3151. strcpy(typeStr, sstr);
  3152. if(gunIndex != 0)
  3153. {
  3154. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3155. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3156. }
  3157. else
  3158. {
  3159. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3160. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3161. }
  3162. memset(comfirmstr, 0, sizeof comfirmstr);
  3163. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3164. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3165. {
  3166. specificId = TRUE;
  3167. }
  3168. if(specificId == FALSE)
  3169. goto end;
  3170. if(gunIndex != 0)
  3171. {
  3172. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3173. }
  3174. else
  3175. {
  3176. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3177. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3178. }
  3179. /*
  3180. enum _SYSTEM_STATUS
  3181. {
  3182. S_BOOTING = 0,
  3183. S_IDLE, = 1
  3184. S_AUTHORIZING, =2
  3185. S_REASSIGN_CHECK, =3
  3186. S_REASSIGN, =4
  3187. S_PRECHARGE, =5
  3188. S_PREPARING_FOR_EV, =6
  3189. S_PREPARING_FOR_EVSE, =7
  3190. S_CHARGING, =8
  3191. S_TERMINATING, =9
  3192. S_COMPLETE, =10
  3193. S_ALARM, =11
  3194. S_FAULT =12
  3195. }
  3196. */
  3197. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3198. {
  3199. //check Transaction active
  3200. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3201. {
  3202. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3203. {
  3204. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3205. {
  3206. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 5) // S_PRECHARGE
  3207. {
  3208. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3209. }
  3210. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8) // S_CHARGING
  3211. {
  3212. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3213. }
  3214. else
  3215. {
  3216. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3217. }
  3218. goto end;
  3219. }
  3220. }//END FOR CHAdeMO_QUANTITY
  3221. for (int index = 0; index < CCS_QUANTITY; index++)
  3222. {
  3223. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3224. {
  3225. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 5)// S_PRECHARGE
  3226. {
  3227. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3228. }
  3229. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8) // S_CHARGING
  3230. {
  3231. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3232. }
  3233. else
  3234. {
  3235. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3236. }
  3237. goto end;
  3238. }
  3239. }//END FOR CCS_QUANTITY
  3240. for (int index = 0; index < GB_QUANTITY; index++)
  3241. {
  3242. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3243. {
  3244. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 5) // S_PRECHARGE
  3245. {
  3246. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3247. }
  3248. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8) // S_CHARGING
  3249. {
  3250. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3251. }
  3252. else
  3253. {
  3254. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3255. }
  3256. goto end;
  3257. }
  3258. }// END FOR GB_QUANTITY
  3259. }
  3260. else
  3261. {
  3262. for (int index = 0; index < AC_QUANTITY; index++)
  3263. {
  3264. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3265. {
  3266. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 5) // S_PRECHARGE
  3267. {
  3268. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3269. }
  3270. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 8) // S_CHARGING
  3271. {
  3272. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3273. }
  3274. else
  3275. {
  3276. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3277. }
  3278. goto end;
  3279. }
  3280. }//END FOR AC_QUANTITY
  3281. }// END FOR AC ELSE
  3282. }//END FOR AvailabilityTypeStr[Inoperative]
  3283. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3284. {
  3285. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3286. //check Transaction active
  3287. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3288. {
  3289. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3290. {
  3291. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 12)) //S_FAULT
  3292. {
  3293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3294. goto end;
  3295. }
  3296. }//END FOR CHAdeMO_QUANTITY
  3297. for (int index = 0; index < CCS_QUANTITY; index++)
  3298. {
  3299. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 12)) //S_FAULT
  3300. {
  3301. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3302. goto end;
  3303. }
  3304. }//END FOR CCS_QUANTITY
  3305. for (int index = 0; index < GB_QUANTITY; index++)
  3306. {
  3307. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 12)) //S_FAULT
  3308. {
  3309. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3310. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3311. goto end;
  3312. }
  3313. }// END FOR GB_QUANTITY
  3314. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3315. }
  3316. else
  3317. {
  3318. for (int index = 0; index < AC_QUANTITY; index++)
  3319. {
  3320. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != 12)) //S_FAULT
  3321. {
  3322. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3323. goto end;
  3324. }
  3325. }//END FOR CHAdeMO_QUANTITY
  3326. }//END FOR AC ELSE
  3327. }//END FOR AvailabilityTypeStr[Operative]
  3328. end:
  3329. if(gunIndex != 0)
  3330. {
  3331. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3332. }
  3333. else
  3334. {
  3335. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3336. }
  3337. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3338. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3339. return result;
  3340. }
  3341. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3342. {
  3343. mtrace();
  3344. int result = FAIL;
  3345. char sstr[100]={0};
  3346. char keystr[40]={0};
  3347. char valuestr[16]={0};
  3348. char *loc;
  3349. int c = 0;
  3350. char comfirmstr[20];
  3351. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3352. /***key ****/
  3353. loc = strstr(payload, "key");
  3354. memset(sstr ,0, sizeof(sstr) );
  3355. c = 0;
  3356. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3357. {
  3358. sstr[c] = loc[3+strlen("key")+c];
  3359. c++;
  3360. }
  3361. sstr[c] = '\0';
  3362. strcpy(keystr, sstr);
  3363. /***value ****/
  3364. loc = strstr(payload, "value");
  3365. memset(sstr ,0, sizeof(sstr) );
  3366. c = 0;
  3367. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3368. {
  3369. sstr[c] = loc[3+strlen("value")+c];
  3370. c++;
  3371. }
  3372. sstr[c] = '\0';
  3373. strcpy(valuestr, sstr);
  3374. if((uuid==NULL) || (payload ==NULL) )
  3375. {
  3376. #ifdef Debug
  3377. DEBUG_INFO("payload is null\n");
  3378. #endif
  3379. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3380. }
  3381. else
  3382. {
  3383. int status = setKeyValue(keystr, valuestr);
  3384. switch(status)
  3385. {
  3386. case ConfigurationStatus_Accepted:
  3387. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3388. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3389. break;
  3390. case ConfigurationStatus_Rejected:
  3391. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3392. break;
  3393. case RebootRequired:
  3394. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3395. break;
  3396. case NotSupported:
  3397. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3398. break;
  3399. default:
  3400. break;
  3401. }
  3402. }
  3403. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3404. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3405. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3406. return result;
  3407. }
  3408. int handleClearCacheRequest(char *uuid, char *payload)
  3409. {
  3410. mtrace();
  3411. int result = FAIL;
  3412. char comfirmstr[20];
  3413. int fd;
  3414. char rmFileCmd[100]={0};
  3415. struct stat stats;
  3416. DEBUG_ERROR("handle ClearCacheRequest\n");
  3417. stat("../Storage/OCPP", &stats);
  3418. // Check for directory existence
  3419. if (S_ISDIR(stats.st_mode) == 1)
  3420. {
  3421. DEBUG_ERROR("\n OCPP directory exist \n");
  3422. }
  3423. else
  3424. {
  3425. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3426. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3427. system(rmFileCmd);
  3428. }
  3429. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  3430. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3431. {
  3432. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3433. }
  3434. else
  3435. {
  3436. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3437. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3438. if(log == NULL)
  3439. {
  3440. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3441. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3442. goto end;
  3443. }
  3444. else
  3445. {
  3446. fclose(log);
  3447. }
  3448. }
  3449. fd = open(AuthorizationCache_JSON,O_RDWR);
  3450. if(fd < 0)
  3451. {
  3452. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3453. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3454. }
  3455. else
  3456. {
  3457. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3458. /* 清空?�件 */
  3459. ftruncate(fd,0);
  3460. /* ?�新设置?�件?�移??*/
  3461. lseek(fd,0,SEEK_SET);
  3462. close(fd);
  3463. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3464. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3465. }
  3466. end:
  3467. sendClearCacheConfirmation(uuid, comfirmstr);
  3468. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3469. return result;
  3470. }
  3471. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3472. {
  3473. mtrace();
  3474. int result = FAIL;
  3475. int resultRename;
  3476. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3477. char chargingProfilePurposeStr[26]={0};
  3478. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3479. char tempchargingProfilePurposeStr[26]={0};
  3480. char sstr[160]={0};//sstr[200]={ 0 };
  3481. char str[100]={0};
  3482. int c = 0;
  3483. //int i = 0;
  3484. //char * pch;
  3485. char *loc;
  3486. char fname[200];
  3487. char comfirmstr[20]={0};
  3488. char word[1000]={0};
  3489. int clearflag = FALSE;
  3490. int chargingProfileIdIsNULL = FALSE;
  3491. int connectorIsNULL = FALSE;
  3492. FILE *fptr1, *fptr2;
  3493. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3494. int n_chargingProfile=0;
  3495. char sLineWord[1060]={0};
  3496. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3497. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3498. /***id ****/
  3499. c = 0;
  3500. loc = strstr(payload, "id");
  3501. memset(sstr ,0, sizeof(sstr) );
  3502. if(loc == NULL)
  3503. {
  3504. chargingProfileIdIsNULL = TRUE;
  3505. }
  3506. while ((loc != NULL) &&(loc[strlen("id")+2+c] != ',') )
  3507. {
  3508. sstr[c] = loc[strlen("id")+2+c];
  3509. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3510. c++;
  3511. }
  3512. sstr[c] = '\0';
  3513. chargingProfileIdInt = atoi(sstr);
  3514. /***connectorId ****/
  3515. c=0;
  3516. loc = strstr(payload, "connectorId");
  3517. memset(sstr ,0, sizeof(sstr) );
  3518. if(loc == NULL)
  3519. {
  3520. connectorIsNULL = TRUE;
  3521. }
  3522. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  3523. {
  3524. sstr[c] = loc[strlen("connectorId")+2+c];
  3525. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3526. c++;
  3527. }
  3528. sstr[c] = '\0';
  3529. connectorIdInt = atoi(sstr);
  3530. /***chargingProfilePurpose ****/
  3531. loc = strstr(payload, "chargingProfilePurpose");
  3532. memset(sstr ,0, sizeof(sstr) );
  3533. c = 0;
  3534. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3535. {
  3536. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3537. c++;
  3538. }
  3539. sstr[c] = '\0';
  3540. strcpy(chargingProfilePurposeStr, sstr);
  3541. /***stackLevel ****/
  3542. c=0;
  3543. loc = strstr(payload, "stackLevel");
  3544. memset(sstr ,0, sizeof(sstr) );
  3545. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3546. {
  3547. sstr[c] = loc[strlen("stackLevel")+2+c];
  3548. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3549. c++;
  3550. }
  3551. sstr[c] = '\0';
  3552. stackLevelInt = atoi(sstr);
  3553. if(connectorIsNULL == FALSE)
  3554. {
  3555. switch(connectorIdInt)
  3556. {
  3557. case 0:
  3558. if(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)
  3559. {
  3560. strcpy(fname, ChargePointMaxProfile_JSON);
  3561. }
  3562. else
  3563. {
  3564. strcpy(fname, TxDefaultProfile_0_JSON);
  3565. }
  3566. break;
  3567. case 1:
  3568. if(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)
  3569. {
  3570. strcpy(fname, TxDefaultProfile_1_JSON);
  3571. }
  3572. else
  3573. {
  3574. strcpy(fname, TxProfile_1_JSON);
  3575. }
  3576. break;
  3577. case 2:
  3578. if(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)
  3579. {
  3580. strcpy(fname, TxDefaultProfile_2_JSON);
  3581. }
  3582. else
  3583. {
  3584. strcpy(fname, TxProfile_2_JSON);
  3585. }
  3586. break;
  3587. default:
  3588. strcpy(fname, ChargePointMaxProfile_JSON );
  3589. break;
  3590. }
  3591. }
  3592. else
  3593. {
  3594. strcpy(fname, ChargePointMaxProfile_JSON );
  3595. }
  3596. fptr1 = fopen(fname, "r");
  3597. if (!fptr1)
  3598. {
  3599. //file not exist
  3600. DEBUG_ERROR("Unable to open the input file!!\n");
  3601. fptr1 = fopen(fname, "w+");
  3602. }
  3603. fclose(fptr1);
  3604. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3605. {
  3606. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3607. goto end;
  3608. }
  3609. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3610. {
  3611. //clear the whole contents of a file in C
  3612. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3613. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3614. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3615. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3616. fclose(fopen(TxProfile_1_JSON, "w"));
  3617. fclose(fopen(TxProfile_2_JSON, "w"));
  3618. #if 0
  3619. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3620. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3621. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3622. #endif
  3623. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3624. }
  3625. else
  3626. {
  3627. fptr1 = fopen(fname, "r");
  3628. fptr2 = fopen(temp, "w+");
  3629. while(fscanf(fptr1, "%s", word) != EOF)
  3630. {
  3631. DEBUG_INFO("word=%s\n",word);
  3632. if(strcmp(word, "chargingProfileId") == 0)
  3633. {
  3634. n_chargingProfile = n_chargingProfile + 1;
  3635. printf("Found\n");
  3636. }
  3637. }
  3638. rewind(fptr1);
  3639. //search Charging Profile Element
  3640. //int i= 0;
  3641. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3642. {
  3643. /*************************tempconnectorIdInt*********************************/
  3644. loc = strstr(sLineWord, "connectorId");
  3645. c = 0;
  3646. memset(sstr ,0, sizeof(sstr) );
  3647. while (loc[strlen("connectorId")+2+c] != ',')
  3648. {
  3649. sstr[c] = loc[strlen("connectorId")+2+c];
  3650. c++;
  3651. }
  3652. sstr[c] = '\0';
  3653. tempconnectorIdInt = atoi(sstr);
  3654. //chargingProfileId
  3655. c = 0;
  3656. loc = strstr(sLineWord, "chargingProfileId");
  3657. memset(sstr ,0, sizeof(sstr) );
  3658. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3659. {
  3660. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3661. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3662. c++;
  3663. }
  3664. sstr[c] = '\0';
  3665. tempchargingProfileIdInt = atoi(sstr);
  3666. //stackLevel
  3667. c = 0;
  3668. loc = strstr(sLineWord, "stackLevel");
  3669. memset(sstr ,0, sizeof(sstr) );
  3670. while (loc[strlen("stackLevel")+2+c] != ',')
  3671. {
  3672. sstr[c] = loc[strlen("stackLevel")+2+c];
  3673. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3674. c++;
  3675. }
  3676. sstr[c] = '\0';
  3677. tempstackLevelInt = atoi(sstr);
  3678. c = 0;
  3679. loc = strstr(sLineWord, "chargingProfilePurpose");
  3680. memset(sstr ,0, sizeof(sstr) );
  3681. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3682. {
  3683. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3684. c++;
  3685. }
  3686. sstr[c] = '\0';
  3687. strcpy(tempchargingProfilePurposeStr, sstr);
  3688. if(chargingProfileIdIsNULL == FALSE)
  3689. {
  3690. DEBUG_INFO("\n OCPP clear 0 !!!\n");
  3691. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3692. {
  3693. DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3694. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3695. clearflag = TRUE;
  3696. break;//continue;
  3697. }
  3698. else
  3699. {
  3700. DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3701. //json_object_array_add(newHeatMap, jsonitem);
  3702. fprintf(fptr2, sLineWord);//writing data into file
  3703. }
  3704. }
  3705. else
  3706. {
  3707. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt) && (tempstackLevelInt == stackLevelInt))
  3708. {
  3709. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3710. clearflag = TRUE;
  3711. break;//continue;
  3712. }
  3713. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3714. {
  3715. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3716. clearflag = TRUE;
  3717. break;//continue;
  3718. }
  3719. else
  3720. {
  3721. //json_object_array_add(newHeatMap, jsonitem);
  3722. fprintf(fptr2, sLineWord);//writing data into file
  3723. }
  3724. }
  3725. memset(sLineWord, 0, sizeof sLineWord);
  3726. }
  3727. if(clearflag == FALSE)
  3728. {
  3729. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3730. goto end;
  3731. }
  3732. fclose(fptr1);
  3733. fclose(fptr2);
  3734. sprintf(str,"rm -f %s",fname);
  3735. system(str);
  3736. resultRename = rename(temp, fname);
  3737. if(resultRename == 0)
  3738. {
  3739. DEBUG_ERROR("File ChargingProfile renamed successfully");
  3740. }
  3741. else
  3742. {
  3743. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  3744. }
  3745. }
  3746. end:
  3747. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3748. return result;
  3749. }
  3750. int handleDataTransferRequest(char *uuid, char *payload)
  3751. {
  3752. mtrace();
  3753. int result = FAIL;
  3754. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  3755. char tempvendorId[255]={0};
  3756. char tempmessageId[50]={0};
  3757. char tempdata[50]={0};
  3758. char sstr[160]={0};//sstr[200]={ 0 };
  3759. char message[80]={0};
  3760. int c = 0;
  3761. char *loc;
  3762. DEBUG_INFO("handle DataTransferRequest\n");
  3763. //===============================
  3764. // vendorId
  3765. //===============================
  3766. c = 0;
  3767. loc = strstr(payload, "vendorId");
  3768. while (loc[strlen("vendorId")+3+c] != '\"')
  3769. {
  3770. sstr[c] = loc[strlen("vendorId")+3+c];
  3771. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3772. c++;
  3773. }
  3774. sstr[c] = '\0';
  3775. strcpy(tempvendorId,sstr);
  3776. //===============================
  3777. // messageId
  3778. //===============================
  3779. memset(sstr ,0, sizeof(sstr) );
  3780. c = 0;
  3781. loc = strstr(payload, "messageId");
  3782. while (loc[strlen("messageId")+3+c] != '\"')
  3783. {
  3784. sstr[c] = loc[strlen("messageId")+3+c];
  3785. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3786. c++;
  3787. }
  3788. sstr[c] = '\0';
  3789. strcpy(tempmessageId,sstr);
  3790. //===============================
  3791. // data
  3792. //===============================
  3793. memset(sstr ,0, sizeof(sstr) );
  3794. c = 0;
  3795. loc = strstr(payload, "data");
  3796. printf("loc=%s\n",loc);
  3797. while (loc[strlen("data")+3+c] != '\"')
  3798. {
  3799. sstr[c] = loc[strlen("data")+3+c];
  3800. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3801. c++;
  3802. }
  3803. sstr[c] = '\0';
  3804. strcpy(tempdata,sstr);
  3805. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  3806. LWS_Send(message);
  3807. return result;
  3808. }
  3809. #if 0
  3810. long long diff_tm(struct tm *a, struct tm *b) {
  3811. return a->tm_sec - b->tm_sec
  3812. + 60LL * (a->tm_min - b->tm_min)
  3813. + 3600LL * (a->tm_hour - b->tm_hour)
  3814. + 86400LL * (a->tm_yday - b->tm_yday)
  3815. + (a->tm_year - 70) * 31536000LL
  3816. - (a->tm_year - 69) / 4 * 86400LL
  3817. + (a->tm_year - 1) / 100 * 86400LL
  3818. - (a->tm_year + 299) / 400 * 86400LL
  3819. - (b->tm_year - 70) * 31536000LL
  3820. + (b->tm_year - 69) / 4 * 86400LL
  3821. - (b->tm_year - 1) / 100 * 86400LL
  3822. + (b->tm_year + 299) /400 * 86400LL;
  3823. }
  3824. #endif
  3825. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  3826. {
  3827. mtrace();
  3828. int result = FAIL;
  3829. int connectorIdInt, durationInt;
  3830. char chargingRateUnitStr[4]={0};
  3831. //int tempconnectorIdInt,
  3832. int tempdurationInt;
  3833. float tempminChargingRateFloat = 0.0;
  3834. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  3835. int tempStartPeriodInt=0;
  3836. float tempLimitInt=0.0;//0.1;
  3837. int tempNumberPhasesInt=0;
  3838. char fname[200];
  3839. char comfirmstr[20];
  3840. //float totallimit =0.0;
  3841. float MinChargingRate =0.0;
  3842. double diff_t;
  3843. struct tm tp;
  3844. //int clearflag = FALSE;
  3845. FILE *fptr1;//, *fptr2;
  3846. //char temp[] = "../Storage/OCPP/temp.json";
  3847. int c = 0;
  3848. //int i = 0;
  3849. char * pch;
  3850. char *loc;
  3851. char sstr[200]={ 0 };
  3852. int n_chargingProfile = 0;
  3853. int n_SchedulePeriods = 0;
  3854. char SchedulePeriodList[10][200]={0};
  3855. char sLineWord[800]={0};
  3856. //int n_periods = 0;
  3857. char word[1000]={0};
  3858. int confirmPeriods = 0;
  3859. struct StructProfile ChargePointMaxProfile;
  3860. struct StructProfile TxDefaultProfile;
  3861. struct StructProfile TxProfile;
  3862. struct StructProfile TxDefaultProfiletemp[2]={0};
  3863. int TxDefaultProfileFileIsNull=FALSE;
  3864. int ChargePointMaxProfileIsNull=FALSE;
  3865. int TxProfileIsNull=FALSE;
  3866. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  3867. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  3868. memset(&TxProfile,0,sizeof(struct StructProfile));
  3869. c=0;
  3870. loc = strstr(payload, "connectorId");
  3871. memset(sstr ,0, sizeof(sstr) );
  3872. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  3873. {
  3874. sstr[c] = loc[strlen("connectorId")+2+c];
  3875. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3876. c++;
  3877. }
  3878. sstr[c] = '\0';
  3879. connectorIdInt = atoi(sstr);
  3880. c=0;
  3881. loc = strstr(payload, "duration");
  3882. memset(sstr ,0, sizeof(sstr) );
  3883. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  3884. {
  3885. sstr[c] = loc[strlen("duration")+2+c];
  3886. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3887. c++;
  3888. }
  3889. sstr[c] = '\0';
  3890. durationInt = atoi(sstr);
  3891. c = 0;
  3892. loc = strstr(payload, "chargingRateUnit");
  3893. memset(sstr ,0, sizeof(sstr) );
  3894. if(loc == NULL)
  3895. {
  3896. }
  3897. else
  3898. {
  3899. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  3900. {
  3901. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  3902. c++;
  3903. }
  3904. sstr[c] = '\0';
  3905. strcpy(chargingRateUnitStr, sstr);
  3906. }
  3907. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  3908. if(connectorIdInt==0) // connectorId is 0
  3909. {
  3910. /******************************ChargePointMaxProfile*****************************************************/
  3911. strcpy(fname, ChargePointMaxProfile_JSON );
  3912. char word[30]={0};
  3913. char sLineWord[1060]={0};
  3914. int n_chargingProfile=0;
  3915. ChargePointMaxProfileIsNull=TRUE;
  3916. if((access(fname,F_OK))!=-1)
  3917. {
  3918. fptr1 = fopen(fname, "r");
  3919. int c;
  3920. c = fgetc(fptr1);
  3921. DEBUG_INFO("c:%d\n",c);
  3922. rewind(fptr1);
  3923. if(c == EOF)
  3924. {
  3925. DEBUG_INFO("\n End of file ChargingProfile reached.");
  3926. ChargePointMaxProfileIsNull=TRUE;
  3927. fclose(fptr1);
  3928. }
  3929. else
  3930. {
  3931. ChargePointMaxProfileIsNull=FALSE;
  3932. while(fscanf(fptr1, "%s", word) != EOF)
  3933. {
  3934. if(strcmp(word, "chargingProfileId") == 0)
  3935. {
  3936. n_chargingProfile = n_chargingProfile + 1;
  3937. printf("Found\n");
  3938. }
  3939. }
  3940. rewind(fptr1);
  3941. //search Charging Profile Element
  3942. int i= 0;
  3943. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  3944. #if 0
  3945. /***********connectorId****************/
  3946. c = 0;
  3947. loc = strstr(sLineWord, "connectorId");
  3948. // printf("loc=%s\n",loc);
  3949. memset(sstr ,0, sizeof(sstr) );
  3950. while (loc[strlen("connectorId")+2+c] != ',')
  3951. {
  3952. sstr[c] = loc[strlen("connectorId")+2+c];
  3953. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3954. c++;
  3955. }
  3956. sstr[c] = '\0';
  3957. tempconnectorIdInt = atoi(sstr);
  3958. #endif
  3959. /***********validFrom**************/
  3960. c = 0;
  3961. loc = strstr(sLineWord, "validFrom");
  3962. //DEBUG_INFO("loc=%s\n",loc);
  3963. memset(sstr ,0, sizeof(sstr) );
  3964. if(loc != NULL)
  3965. {
  3966. while (loc[3+strlen("validFrom")+c] != '\"')
  3967. {
  3968. sstr[c] = loc[3+strlen("validFrom")+c];
  3969. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3970. c++;
  3971. }
  3972. sstr[c] = '\0';
  3973. DEBUG_INFO("validFrom=%s\n",sstr);
  3974. strcpy(tempvalidFromStr,sstr);
  3975. }
  3976. else
  3977. {
  3978. strcpy(tempvalidFromStr,"");
  3979. }
  3980. /**********startSchedule**********/
  3981. c = 0;
  3982. loc = strstr(sLineWord, "startSchedule");
  3983. //DEBUG_INFO("loc=%s\n",loc);
  3984. memset(sstr ,0, sizeof(sstr) );
  3985. while (loc[3+strlen("startSchedule")+c] != '\"')
  3986. {
  3987. sstr[c] = loc[3+strlen("startSchedule")+c];
  3988. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3989. c++;
  3990. }
  3991. sstr[c] = '\0';
  3992. strcpy(tempstartScheduleStr, sstr);
  3993. /**********startSchedule**********/
  3994. c = 0;
  3995. loc = strstr(sLineWord, "chargingRateUnit");
  3996. memset(sstr ,0, sizeof(sstr) );
  3997. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  3998. {
  3999. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4000. c++;
  4001. }
  4002. sstr[c] = '\0';
  4003. strcpy(tempchargingRateUnitStr, sstr);
  4004. /**********minChargingRate*******/
  4005. c = 0;
  4006. loc = strstr(sLineWord, "minChargingRate");
  4007. //printf("loc=%s\n",loc);
  4008. if(loc != NULL)
  4009. {
  4010. memset(sstr ,0, sizeof(sstr) );
  4011. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4012. {
  4013. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4014. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4015. c++;
  4016. }
  4017. sstr[c] = '\0';
  4018. tempminChargingRateFloat = atof(sstr);
  4019. }
  4020. else
  4021. {
  4022. tempminChargingRateFloat = 0.0;
  4023. }
  4024. //
  4025. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4026. tp.tm_isdst = -1;
  4027. time_t utc = mktime(&tp);
  4028. // current time
  4029. time_t t = time(NULL);
  4030. diff_t = difftime(t, utc);
  4031. //parsing strings to words
  4032. i = 0;
  4033. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4034. loc = loc+3+strlen("chargingSchedulePeriod");
  4035. pch = strtok(loc ,"{");
  4036. while (pch != NULL)
  4037. {
  4038. strcpy(SchedulePeriodList[i], pch);
  4039. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4040. //printf ("%s\n",pch);
  4041. pch = strtok (NULL, "{");
  4042. i = i + 1;
  4043. }
  4044. n_SchedulePeriods = i;
  4045. for(int i=0;i<n_SchedulePeriods;i++)
  4046. {
  4047. /*************startPeriod****************/
  4048. c = 0;
  4049. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4050. memset(sstr ,0, sizeof(sstr) );
  4051. while (loc[strlen("startPeriod")+2+c] != ',')
  4052. {
  4053. sstr[c] = loc[strlen("startPeriod")+2+c];
  4054. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4055. c++;
  4056. }
  4057. sstr[c] = '\0';
  4058. tempStartPeriodInt = atoi(sstr);
  4059. /*************limit****************/
  4060. c = 0;
  4061. loc = strstr(SchedulePeriodList[i], "limit");
  4062. memset(sstr ,0, sizeof(sstr) );
  4063. while (loc[strlen("limit")+2+c] != ',')
  4064. {
  4065. sstr[c] = loc[strlen("limit")+2+c];
  4066. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4067. c++;
  4068. }
  4069. sstr[c] = '\0';
  4070. tempLimitInt = atof(sstr);
  4071. /*************numberPhases****************/
  4072. c = 0;
  4073. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4074. memset(sstr ,0, sizeof(sstr) );
  4075. while (loc[strlen("numberPhases")+2+c] != ',')
  4076. {
  4077. sstr[c] = loc[strlen("numberPhases")+2+c];
  4078. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4079. c++;
  4080. }
  4081. sstr[c] = '\0';
  4082. tempNumberPhasesInt = atoi(sstr);
  4083. ChargePointMaxProfile.Duration = durationInt;
  4084. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4085. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4086. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4087. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4088. }
  4089. if(MinChargingRate < tempminChargingRateFloat)
  4090. MinChargingRate = tempminChargingRateFloat;
  4091. }
  4092. }// End of file ChargingProfile
  4093. } //THE END OF ACCESS ChargePointMaxProfile
  4094. /******************************TxDefaultProfile***********************************************/
  4095. strcpy(fname, TxDefaultProfile_0_JSON);
  4096. memset(word, 0, 30);
  4097. memset(sLineWord, 0, 1060);
  4098. //char word[30]={0};
  4099. //char sLineWord[1060]={0};
  4100. n_chargingProfile=0;
  4101. TxDefaultProfileFileIsNull=TRUE;
  4102. if((access(fname,F_OK))!=-1)
  4103. {
  4104. fptr1 = fopen(fname, "r");
  4105. c = 0;
  4106. c = fgetc(fptr1);
  4107. DEBUG_INFO("c:%d\n",c);
  4108. rewind(fptr1);
  4109. if(c == EOF)
  4110. {
  4111. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4112. TxDefaultProfileFileIsNull=TRUE;
  4113. fclose(fptr1);
  4114. }
  4115. else
  4116. {
  4117. TxDefaultProfileFileIsNull=FALSE;
  4118. while(fscanf(fptr1, "%s", word) != EOF)
  4119. {
  4120. if(strcmp(word, "chargingProfileId") == 0)
  4121. {
  4122. n_chargingProfile = n_chargingProfile + 1;
  4123. printf("Found\n");
  4124. }
  4125. }
  4126. rewind(fptr1);
  4127. //search Charging Profile Element
  4128. int i= 0;
  4129. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4130. #if 0
  4131. /***********connectorId****************/
  4132. c = 0;
  4133. loc = strstr(sLineWord, "connectorId");
  4134. // printf("loc=%s\n",loc);
  4135. memset(sstr ,0, sizeof(sstr) );
  4136. while (loc[strlen("connectorId")+2+c] != ',')
  4137. {
  4138. sstr[c] = loc[strlen("connectorId")+2+c];
  4139. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4140. c++;
  4141. }
  4142. sstr[c] = '\0';
  4143. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4144. tempconnectorIdInt = atoi(sstr);
  4145. #endif
  4146. /***********validFrom**************/
  4147. c = 0;
  4148. loc = strstr(sLineWord, "validFrom");
  4149. //DEBUG_INFO("loc=%s\n",loc);
  4150. memset(sstr ,0, sizeof(sstr) );
  4151. if(loc != NULL)
  4152. {
  4153. while (loc[3+strlen("validFrom")+c] != '\"')
  4154. {
  4155. sstr[c] = loc[3+strlen("validFrom")+c];
  4156. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4157. c++;
  4158. }
  4159. sstr[c] = '\0';
  4160. DEBUG_INFO("validFrom=%s\n",sstr);
  4161. strcpy(tempvalidFromStr,sstr);
  4162. }
  4163. else
  4164. {
  4165. strcpy(tempvalidFromStr,"");
  4166. }
  4167. /**********startSchedule**********/
  4168. c = 0;
  4169. loc = strstr(sLineWord, "startSchedule");
  4170. //DEBUG_INFO("loc=%s\n",loc);
  4171. memset(sstr ,0, sizeof(sstr) );
  4172. while (loc[3+strlen("startSchedule")+c] != '\"')
  4173. {
  4174. sstr[c] = loc[3+strlen("startSchedule")+c];
  4175. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4176. c++;
  4177. }
  4178. sstr[c] = '\0';
  4179. strcpy(tempstartScheduleStr, sstr);
  4180. DEBUG_INFO(" debug 3-1\n");
  4181. /**********startSchedule**********/
  4182. c = 0;
  4183. loc = strstr(sLineWord, "chargingRateUnit");
  4184. memset(sstr ,0, sizeof(sstr) );
  4185. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4186. {
  4187. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4188. c++;
  4189. }
  4190. sstr[c] = '\0';
  4191. strcpy(tempchargingRateUnitStr, sstr);
  4192. /**********minChargingRate*******/
  4193. c = 0;
  4194. loc = strstr(sLineWord, "minChargingRate");
  4195. //printf("loc=%s\n",loc);
  4196. if(loc != NULL)
  4197. {
  4198. memset(sstr ,0, sizeof(sstr) );
  4199. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4200. {
  4201. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4202. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4203. c++;
  4204. }
  4205. sstr[c] = '\0';
  4206. tempminChargingRateFloat = atof(sstr);
  4207. }
  4208. else
  4209. {
  4210. tempminChargingRateFloat = 0.0;
  4211. }
  4212. //
  4213. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4214. tp.tm_isdst = -1;
  4215. time_t utc = mktime(&tp);
  4216. // current time
  4217. time_t t = time(NULL);
  4218. diff_t = difftime(t, utc);
  4219. //parsing strings to words
  4220. i = 0;
  4221. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4222. loc = loc+3+strlen("chargingSchedulePeriod");
  4223. pch = strtok(loc ,"{");
  4224. while (pch != NULL)
  4225. {
  4226. strcpy(SchedulePeriodList[i], pch);
  4227. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4228. //printf ("%s\n",pch);
  4229. pch = strtok (NULL, "{");
  4230. i = i + 1;
  4231. }
  4232. n_SchedulePeriods = i;
  4233. for(int i=0;i<n_SchedulePeriods;i++)
  4234. {
  4235. /*************startPeriod****************/
  4236. c = 0;
  4237. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4238. memset(sstr ,0, sizeof(sstr) );
  4239. while (loc[strlen("startPeriod")+2+c] != ',')
  4240. {
  4241. sstr[c] = loc[strlen("startPeriod")+2+c];
  4242. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4243. c++;
  4244. }
  4245. sstr[c] = '\0';
  4246. tempStartPeriodInt = atoi(sstr);
  4247. /*************limit****************/
  4248. c = 0;
  4249. loc = strstr(SchedulePeriodList[i], "limit");
  4250. memset(sstr ,0, sizeof(sstr) );
  4251. while (loc[strlen("limit")+2+c] != ',')
  4252. {
  4253. sstr[c] = loc[strlen("limit")+2+c];
  4254. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4255. c++;
  4256. }
  4257. sstr[c] = '\0';
  4258. tempLimitInt = atof(sstr);
  4259. /*************numberPhases****************/
  4260. c = 0;
  4261. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4262. memset(sstr ,0, sizeof(sstr) );
  4263. while (loc[strlen("numberPhases")+2+c] != ',')
  4264. {
  4265. sstr[c] = loc[strlen("numberPhases")+2+c];
  4266. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4267. c++;
  4268. }
  4269. sstr[c] = '\0';
  4270. tempNumberPhasesInt = atoi(sstr);
  4271. TxDefaultProfile.Duration = durationInt;
  4272. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4273. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4274. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4275. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4276. }
  4277. if(MinChargingRate < tempminChargingRateFloat)
  4278. MinChargingRate = tempminChargingRateFloat;
  4279. }
  4280. }
  4281. }// the end of ACCESS TxDefaultProfile
  4282. // Composite Schedule
  4283. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4284. {
  4285. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4286. {
  4287. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4288. {
  4289. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4290. }
  4291. else
  4292. {
  4293. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4294. }
  4295. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4296. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4297. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4298. }
  4299. }
  4300. /* Define temporary variables */
  4301. struct tm *gtime;
  4302. time_t now;
  4303. char buf[28];
  4304. /* Read the current system time */
  4305. time(&now);
  4306. /* Convert the system time to GMT (now UTC) */
  4307. gtime = gmtime(&now);
  4308. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4309. // make .conf
  4310. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  4311. //MaxChargingProfilesInstalled is 10
  4312. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4313. memset(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4314. //nPeriod = 1;
  4315. if(chargingRateUnitStr[0] != 0)
  4316. {
  4317. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4318. }
  4319. else
  4320. {
  4321. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, "" );
  4322. }
  4323. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4324. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4325. confirmPeriods = 1;
  4326. }
  4327. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4328. {
  4329. /*****************************ChargePointMaxProfile******************************************/
  4330. strcpy(fname, ChargePointMaxProfile_JSON);
  4331. ChargePointMaxProfileIsNull=TRUE;
  4332. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4333. {
  4334. fptr1 = fopen(fname, "r");
  4335. int c;
  4336. c = fgetc(fptr1);
  4337. DEBUG_INFO("c:%d\n",c);
  4338. rewind(fptr1);
  4339. if(c == EOF)
  4340. {
  4341. DEBUG_INFO("\n End of file reached.");
  4342. ChargePointMaxProfileIsNull=TRUE;
  4343. fclose(fptr1);
  4344. }
  4345. else
  4346. {
  4347. ChargePointMaxProfileIsNull=FALSE;
  4348. while(fscanf(fptr1, "%s", word) != EOF)
  4349. {
  4350. if(strcmp(word, "chargingProfileId") == 0)
  4351. {
  4352. n_chargingProfile = n_chargingProfile + 1;
  4353. }
  4354. }
  4355. rewind(fptr1);
  4356. //search Charging Profile Element
  4357. int i = 0;
  4358. int j = 0;
  4359. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4360. #if 0
  4361. /***********connectorId****************/
  4362. c = 0;
  4363. loc = strstr(sLineWord, "connectorId");
  4364. memset(sstr ,0, sizeof(sstr) );
  4365. while (loc[strlen("connectorId")+2+c] != ',')
  4366. {
  4367. sstr[c] = loc[strlen("connectorId")+2+c];
  4368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4369. c++;
  4370. }
  4371. sstr[c] = '\0';
  4372. tempconnectorIdInt = atoi(sstr);
  4373. #endif
  4374. /***********validFrom**************/
  4375. c = 0;
  4376. loc = strstr(sLineWord, "validFrom");
  4377. if(loc != NULL)
  4378. {
  4379. memset(sstr ,0, sizeof(sstr) );
  4380. while (loc[3+strlen("validFrom")+c] != '\"')
  4381. {
  4382. sstr[c] = loc[3+strlen("validFrom")+c];
  4383. c++;
  4384. }
  4385. sstr[c] = '\0';
  4386. strcpy(tempvalidFromStr,sstr);
  4387. }
  4388. else
  4389. {
  4390. strcpy(tempvalidFromStr,"");
  4391. }
  4392. /***********validFrom**************/
  4393. c = 0;
  4394. loc = strstr(sLineWord, "duration");
  4395. if(loc != NULL)
  4396. {
  4397. memset(sstr ,0, sizeof(sstr) );
  4398. while (loc[2+strlen("duration")+c] != ',')
  4399. {
  4400. sstr[c] = loc[2+strlen("duration")+c];
  4401. c++;
  4402. }
  4403. sstr[c] = '\0';
  4404. tempdurationInt = atoi(sstr);
  4405. }
  4406. else
  4407. {
  4408. tempdurationInt = 0;
  4409. }
  4410. /**********startSchedule**********/
  4411. c = 0;
  4412. loc = strstr(sLineWord, "startSchedule");
  4413. memset(sstr ,0, sizeof(sstr) );
  4414. while (loc[3+strlen("startSchedule")+c] != '\"')
  4415. {
  4416. sstr[c] = loc[3+strlen("startSchedule")+c];
  4417. c++;
  4418. }
  4419. sstr[c] = '\0';
  4420. strcpy(tempstartScheduleStr, sstr);
  4421. /**********startSchedule**********/
  4422. c = 0;
  4423. loc = strstr(sLineWord, "chargingRateUnit");
  4424. memset(sstr ,0, sizeof(sstr) );
  4425. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4426. {
  4427. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4428. c++;
  4429. }
  4430. sstr[c] = '\0';
  4431. strcpy(tempchargingRateUnitStr, sstr);
  4432. /**********minChargingRate*******/
  4433. c = 0;
  4434. loc = strstr(sLineWord, "minChargingRate");
  4435. if(loc != NULL)
  4436. {
  4437. memset(sstr ,0, sizeof(sstr) );
  4438. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4439. {
  4440. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4441. c++;
  4442. }
  4443. sstr[c] = '\0';
  4444. tempminChargingRateFloat = atof(sstr);
  4445. }
  4446. else
  4447. {
  4448. tempminChargingRateFloat = 0.0;
  4449. }
  4450. //
  4451. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4452. tp.tm_isdst = -1;
  4453. time_t utc = mktime(&tp);
  4454. time_t t = time(NULL);
  4455. diff_t = difftime(t, utc);
  4456. DEBUG_INFO("diff_t=%f\n",diff_t);
  4457. DEBUG_INFO(" debug 5 -1\n");
  4458. //parsing strings to words
  4459. i = 0;
  4460. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4461. loc = loc+3+strlen("chargingSchedulePeriod");
  4462. pch = strtok(loc ,"{");
  4463. while (pch != NULL)
  4464. {
  4465. strcpy(SchedulePeriodList[i], pch);
  4466. pch = strtok (NULL, "{");
  4467. i = i + 1;
  4468. }
  4469. n_SchedulePeriods = i;
  4470. for(int i=0;i<n_SchedulePeriods;i++)
  4471. {
  4472. /*************startPeriod****************/
  4473. c = 0;
  4474. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4475. memset(sstr ,0, sizeof(sstr) );
  4476. while (loc[strlen("startPeriod")+2+c] != ',')
  4477. {
  4478. sstr[c] = loc[strlen("startPeriod")+2+c];
  4479. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4480. c++;
  4481. }
  4482. sstr[c] = '\0';
  4483. tempStartPeriodInt = atoi(sstr);
  4484. /*************limit****************/
  4485. c = 0;
  4486. loc = strstr(SchedulePeriodList[i], "limit");
  4487. memset(sstr ,0, sizeof(sstr) );
  4488. while (loc[strlen("limit")+2+c] != ',')
  4489. {
  4490. sstr[c] = loc[strlen("limit")+2+c];
  4491. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4492. c++;
  4493. }
  4494. sstr[c] = '\0';
  4495. tempLimitInt = atof(sstr);
  4496. /*************numberPhases****************/
  4497. c = 0;
  4498. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4499. memset(sstr ,0, sizeof(sstr) );
  4500. while (loc[strlen("numberPhases")+2+c] != '}')
  4501. {
  4502. sstr[c] = loc[strlen("numberPhases")+2+c];
  4503. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4504. c++;
  4505. }
  4506. sstr[c] = '\0';
  4507. tempNumberPhasesInt = atoi(sstr);
  4508. if(j == 0)
  4509. {
  4510. ChargePointMaxProfile.Duration = tempdurationInt;
  4511. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4512. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4513. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4514. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4515. }
  4516. }
  4517. if(MinChargingRate < tempminChargingRateFloat)
  4518. {
  4519. MinChargingRate = tempminChargingRateFloat;
  4520. }
  4521. if(confirmPeriods < n_SchedulePeriods)
  4522. {
  4523. confirmPeriods = n_SchedulePeriods;
  4524. }
  4525. j = j + 1;
  4526. }
  4527. fclose(fptr1);
  4528. }
  4529. }// the end of access file ChargePointMaxProfile
  4530. /****************************TxDefaultProfile************************************************/
  4531. switch(connectorIdInt)
  4532. {
  4533. case 0:
  4534. break;
  4535. case 1:
  4536. strcpy(fname, TxDefaultProfile_1_JSON );
  4537. break;
  4538. case 2:
  4539. strcpy(fname, TxDefaultProfile_2_JSON );
  4540. break;
  4541. default:
  4542. strcpy(fname, TxDefaultProfile_1_JSON );
  4543. break;
  4544. }
  4545. TxDefaultProfileFileIsNull=TRUE;
  4546. if((access(fname,F_OK))!=-1)
  4547. {
  4548. fptr1 = fopen(fname, "r");
  4549. c = 0;
  4550. c = fgetc(fptr1);
  4551. DEBUG_INFO("c:%d\n",c);
  4552. rewind(fptr1);
  4553. if(c == EOF)
  4554. {
  4555. DEBUG_INFO("\n End of file reached.");
  4556. TxDefaultProfileFileIsNull=TRUE;
  4557. fclose(fptr1);
  4558. }
  4559. else
  4560. {
  4561. TxDefaultProfileFileIsNull=FALSE;
  4562. while(fscanf(fptr1, "%s", word) != EOF)
  4563. {
  4564. if(strcmp(word, "chargingProfileId") == 0)
  4565. {
  4566. n_chargingProfile = n_chargingProfile + 1;
  4567. }
  4568. }
  4569. rewind(fptr1);
  4570. //search Charging Profile Element
  4571. int i = 0;
  4572. int j = 0;
  4573. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4574. #if 0
  4575. /***********connectorId****************/
  4576. c = 0;
  4577. loc = strstr(sLineWord, "connectorId");
  4578. memset(sstr ,0, sizeof(sstr) );
  4579. while (loc[strlen("connectorId")+2+c] != ',')
  4580. {
  4581. sstr[c] = loc[strlen("connectorId")+2+c];
  4582. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4583. c++;
  4584. }
  4585. sstr[c] = '\0';
  4586. tempconnectorIdInt = atoi(sstr);
  4587. #endif
  4588. /***********validFrom**************/
  4589. c = 0;
  4590. loc = strstr(sLineWord, "validFrom");
  4591. if(loc != NULL)
  4592. {
  4593. memset(sstr ,0, sizeof(sstr) );
  4594. while (loc[3+strlen("validFrom")+c] != '\"')
  4595. {
  4596. sstr[c] = loc[3+strlen("validFrom")+c];
  4597. c++;
  4598. }
  4599. sstr[c] = '\0';
  4600. strcpy(tempvalidFromStr,sstr);
  4601. }
  4602. else
  4603. {
  4604. strcpy(tempvalidFromStr,"");
  4605. }
  4606. /***********validFrom**************/
  4607. c = 0;
  4608. loc = strstr(sLineWord, "duration");
  4609. if(loc != NULL)
  4610. {
  4611. memset(sstr ,0, sizeof(sstr) );
  4612. while (loc[2+strlen("duration")+c] != ',')
  4613. {
  4614. sstr[c] = loc[2+strlen("duration")+c];
  4615. c++;
  4616. }
  4617. sstr[c] = '\0';
  4618. tempdurationInt = atoi(sstr);
  4619. }
  4620. else
  4621. {
  4622. tempdurationInt = 0;
  4623. }
  4624. /**********startSchedule**********/
  4625. c = 0;
  4626. loc = strstr(sLineWord, "startSchedule");
  4627. memset(sstr ,0, sizeof(sstr) );
  4628. while (loc[3+strlen("startSchedule")+c] != '\"')
  4629. {
  4630. sstr[c] = loc[3+strlen("startSchedule")+c];
  4631. c++;
  4632. }
  4633. sstr[c] = '\0';
  4634. strcpy(tempstartScheduleStr, sstr);
  4635. /**********startSchedule**********/
  4636. c = 0;
  4637. loc = strstr(sLineWord, "chargingRateUnit");
  4638. memset(sstr ,0, sizeof(sstr) );
  4639. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4640. {
  4641. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4642. c++;
  4643. }
  4644. sstr[c] = '\0';
  4645. strcpy(tempchargingRateUnitStr, sstr);
  4646. /**********minChargingRate*******/
  4647. c = 0;
  4648. loc = strstr(sLineWord, "minChargingRate");
  4649. if(loc != NULL)
  4650. {
  4651. memset(sstr ,0, sizeof(sstr) );
  4652. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4653. {
  4654. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4655. c++;
  4656. }
  4657. sstr[c] = '\0';
  4658. tempminChargingRateFloat = atof(sstr);
  4659. }
  4660. else
  4661. {
  4662. tempminChargingRateFloat = 0.0;
  4663. }
  4664. //
  4665. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4666. tp.tm_isdst = -1;
  4667. time_t utc = mktime(&tp);
  4668. time_t t = time(NULL);
  4669. diff_t = difftime(t, utc);
  4670. DEBUG_INFO("diff_t=%f\n",diff_t);
  4671. DEBUG_INFO(" debug 5 -1\n");
  4672. //parsing strings to words
  4673. i = 0;
  4674. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4675. loc = loc+3+strlen("chargingSchedulePeriod");
  4676. pch = strtok(loc ,"{");
  4677. while (pch != NULL)
  4678. {
  4679. strcpy(SchedulePeriodList[i], pch);
  4680. pch = strtok (NULL, "{");
  4681. i = i + 1;
  4682. }
  4683. n_SchedulePeriods = i;
  4684. for(int i=0;i<n_SchedulePeriods;i++)
  4685. {
  4686. /*************startPeriod****************/
  4687. c = 0;
  4688. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4689. memset(sstr ,0, sizeof(sstr) );
  4690. while (loc[strlen("startPeriod")+2+c] != ',')
  4691. {
  4692. sstr[c] = loc[strlen("startPeriod")+2+c];
  4693. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4694. c++;
  4695. }
  4696. sstr[c] = '\0';
  4697. tempStartPeriodInt = atoi(sstr);
  4698. /*************limit****************/
  4699. c = 0;
  4700. loc = strstr(SchedulePeriodList[i], "limit");
  4701. memset(sstr ,0, sizeof(sstr) );
  4702. while (loc[strlen("limit")+2+c] != ',')
  4703. {
  4704. sstr[c] = loc[strlen("limit")+2+c];
  4705. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4706. c++;
  4707. }
  4708. sstr[c] = '\0';
  4709. tempLimitInt = atof(sstr);
  4710. /*************numberPhases****************/
  4711. c = 0;
  4712. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4713. memset(sstr ,0, sizeof(sstr) );
  4714. while (loc[strlen("numberPhases")+2+c] != '}')
  4715. {
  4716. sstr[c] = loc[strlen("numberPhases")+2+c];
  4717. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4718. c++;
  4719. }
  4720. sstr[c] = '\0';
  4721. tempNumberPhasesInt = atoi(sstr);
  4722. if(j == 0)
  4723. {
  4724. TxDefaultProfile.Duration = tempdurationInt;
  4725. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4726. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4727. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4728. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4729. }
  4730. else
  4731. {
  4732. //other stack level charging Profile
  4733. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  4734. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  4735. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  4736. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  4737. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  4738. }
  4739. }
  4740. if(MinChargingRate < tempminChargingRateFloat)
  4741. MinChargingRate = tempminChargingRateFloat;
  4742. if(confirmPeriods < n_SchedulePeriods)
  4743. confirmPeriods = n_SchedulePeriods;
  4744. j = j + 1;
  4745. }
  4746. fclose(fptr1);
  4747. //Stacking Charging Profiles
  4748. for(int l=0; l <(j-1) ;l++)
  4749. {
  4750. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  4751. {
  4752. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  4753. {
  4754. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  4755. {
  4756. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  4757. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  4758. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  4759. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4760. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4761. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4762. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4763. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4764. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4765. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4766. }
  4767. else
  4768. {
  4769. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4770. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4771. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4772. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4773. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4774. }
  4775. }
  4776. }
  4777. }
  4778. //end of Stacking Charging Profiles
  4779. }
  4780. }// the end of ACCESS TxDefaultProfile
  4781. /****************************TxProfile************************************************/
  4782. switch(connectorIdInt)
  4783. {
  4784. case 0:
  4785. break;
  4786. case 1:
  4787. strcpy(fname, TxProfile_1_JSON );
  4788. break;
  4789. case 2:
  4790. strcpy(fname, TxProfile_2_JSON );
  4791. break;
  4792. default:
  4793. strcpy(fname, TxProfile_1_JSON );
  4794. break;
  4795. }
  4796. TxProfileIsNull=TRUE;
  4797. if((access(fname,F_OK))!=-1)
  4798. {
  4799. fptr1 = fopen(fname, "r");
  4800. c = 0;
  4801. c = fgetc(fptr1);
  4802. DEBUG_INFO("c:%d\n",c);
  4803. rewind(fptr1);
  4804. if(c == EOF)
  4805. {
  4806. DEBUG_INFO("\n End of file reached.");
  4807. TxProfileIsNull=TRUE;
  4808. fclose(fptr1);
  4809. }
  4810. else
  4811. {
  4812. TxProfileIsNull=FALSE;
  4813. while(fscanf(fptr1, "%s", word) != EOF)
  4814. {
  4815. if(strcmp(word, "chargingProfileId") == 0)
  4816. {
  4817. n_chargingProfile = n_chargingProfile + 1;
  4818. }
  4819. }
  4820. rewind(fptr1);
  4821. //search Charging Profile Element
  4822. int i= 0;
  4823. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4824. #if 0
  4825. /***********connectorId****************/
  4826. c = 0;
  4827. loc = strstr(sLineWord, "connectorId");
  4828. memset(sstr ,0, sizeof(sstr) );
  4829. while (loc[strlen("connectorId")+2+c] != ',')
  4830. {
  4831. sstr[c] = loc[strlen("connectorId")+2+c];
  4832. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4833. c++;
  4834. }
  4835. sstr[c] = '\0';
  4836. tempconnectorIdInt = atoi(sstr);
  4837. #endif
  4838. /***********validFrom**************/
  4839. c = 0;
  4840. loc = strstr(sLineWord, "validFrom");
  4841. if(loc != NULL)
  4842. {
  4843. memset(sstr ,0, sizeof(sstr) );
  4844. while (loc[3+strlen("validFrom")+c] != '\"')
  4845. {
  4846. sstr[c] = loc[3+strlen("validFrom")+c];
  4847. c++;
  4848. }
  4849. sstr[c] = '\0';
  4850. strcpy(tempvalidFromStr,sstr);
  4851. }
  4852. else
  4853. {
  4854. strcpy(tempvalidFromStr,"");
  4855. }
  4856. /**********startSchedule**********/
  4857. c = 0;
  4858. loc = strstr(sLineWord, "startSchedule");
  4859. memset(sstr ,0, sizeof(sstr) );
  4860. while (loc[3+strlen("startSchedule")+c] != '\"')
  4861. {
  4862. sstr[c] = loc[3+strlen("startSchedule")+c];
  4863. c++;
  4864. }
  4865. sstr[c] = '\0';
  4866. strcpy(tempstartScheduleStr, sstr);
  4867. /**********startSchedule**********/
  4868. c = 0;
  4869. loc = strstr(sLineWord, "chargingRateUnit");
  4870. memset(sstr ,0, sizeof(sstr) );
  4871. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4872. {
  4873. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4874. c++;
  4875. }
  4876. sstr[c] = '\0';
  4877. strcpy(tempchargingRateUnitStr, sstr);
  4878. /**********minChargingRate*******/
  4879. c = 0;
  4880. loc = strstr(sLineWord, "minChargingRate");
  4881. if(loc != NULL)
  4882. {
  4883. memset(sstr ,0, sizeof(sstr) );
  4884. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4885. {
  4886. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4887. c++;
  4888. }
  4889. sstr[c] = '\0';
  4890. tempminChargingRateFloat = atof(sstr);
  4891. }
  4892. else
  4893. {
  4894. tempminChargingRateFloat = 0.0;
  4895. }
  4896. //
  4897. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4898. tp.tm_isdst = -1;
  4899. time_t utc = mktime(&tp);
  4900. time_t t = time(NULL);
  4901. diff_t = difftime(t, utc);
  4902. DEBUG_INFO("diff_t=%f\n",diff_t);
  4903. //parsing strings to words
  4904. i = 0;
  4905. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4906. loc = loc+3+strlen("chargingSchedulePeriod");
  4907. pch = strtok(loc ,"{");
  4908. while (pch != NULL)
  4909. {
  4910. strcpy(SchedulePeriodList[i], pch);
  4911. pch = strtok (NULL, "{");
  4912. i = i + 1;
  4913. }
  4914. n_SchedulePeriods = i;
  4915. for(int i=0;i<n_SchedulePeriods;i++)
  4916. {
  4917. /*************startPeriod****************/
  4918. c = 0;
  4919. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4920. memset(sstr ,0, sizeof(sstr) );
  4921. while (loc[strlen("startPeriod")+2+c] != ',')
  4922. {
  4923. sstr[c] = loc[strlen("startPeriod")+2+c];
  4924. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4925. c++;
  4926. }
  4927. sstr[c] = '\0';
  4928. tempStartPeriodInt = atoi(sstr);
  4929. /*************limit****************/
  4930. c = 0;
  4931. loc = strstr(SchedulePeriodList[i], "limit");
  4932. memset(sstr ,0, sizeof(sstr) );
  4933. while (loc[strlen("limit")+2+c] != ',')
  4934. {
  4935. sstr[c] = loc[strlen("limit")+2+c];
  4936. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4937. c++;
  4938. }
  4939. sstr[c] = '\0';
  4940. tempLimitInt = atof(sstr);
  4941. /*************numberPhases****************/
  4942. c = 0;
  4943. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4944. memset(sstr ,0, sizeof(sstr) );
  4945. while (loc[strlen("numberPhases")+2+c] != '}')
  4946. {
  4947. sstr[c] = loc[strlen("numberPhases")+2+c];
  4948. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4949. c++;
  4950. }
  4951. sstr[c] = '\0';
  4952. tempNumberPhasesInt = atoi(sstr);
  4953. TxProfile.Duration = durationInt;
  4954. TxProfile.TotalPeriod = n_SchedulePeriods;
  4955. TxProfile.Period[i].Limit = tempLimitInt;
  4956. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4957. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4958. }
  4959. if(MinChargingRate < tempminChargingRateFloat)
  4960. MinChargingRate = tempminChargingRateFloat;
  4961. if(confirmPeriods < n_SchedulePeriods)
  4962. confirmPeriods = n_SchedulePeriods;
  4963. }
  4964. fclose(fptr1);
  4965. }
  4966. }// the end of ACCESS TxProfile
  4967. //CompositeSchedule
  4968. int period=0;
  4969. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  4970. {
  4971. for(int k=0; k < TxProfile.TotalPeriod;k++)
  4972. {
  4973. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  4974. {
  4975. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  4976. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  4977. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  4978. period = period + 1;
  4979. }
  4980. else
  4981. {
  4982. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  4983. {
  4984. }
  4985. else
  4986. {
  4987. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  4988. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  4989. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  4990. period = period + 1;
  4991. }
  4992. }
  4993. }
  4994. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  4995. {
  4996. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  4997. {
  4998. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  4999. {
  5000. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5001. }
  5002. else
  5003. {
  5004. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5005. }
  5006. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5007. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5008. period = period + 1;
  5009. }
  5010. }
  5011. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5012. {
  5013. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5014. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5015. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5016. period = period + 1;
  5017. }
  5018. }
  5019. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5020. {
  5021. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5022. {
  5023. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5024. {
  5025. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5026. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5027. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5028. period = period + 1;
  5029. }
  5030. else
  5031. {
  5032. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5033. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5034. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5035. period = period + 1;
  5036. }
  5037. }
  5038. }
  5039. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5040. {
  5041. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5042. {
  5043. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5044. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5045. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5046. period = period + 1;
  5047. }
  5048. }
  5049. confirmPeriods = period;
  5050. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5051. /* Define temporary variables */
  5052. struct tm *gtime;
  5053. time_t now;
  5054. char buf[28];
  5055. /* Read the current system time */
  5056. time(&now);
  5057. /* Convert the system time to GMT (now UTC) */
  5058. gtime = gmtime(&now);
  5059. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5060. // make .conf
  5061. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  5062. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = durationInt;
  5063. //DEBUG_INFO(" debug 11\n");
  5064. // if(chargingRateUnitStr[0] != 0)
  5065. // {
  5066. // strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  5067. // }
  5068. // else
  5069. {
  5070. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5071. }
  5072. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5073. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5074. }
  5075. else
  5076. {
  5077. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5078. }
  5079. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5080. return result;
  5081. }
  5082. int handleGetConfigurationRequest(char *uuid, char *payload)
  5083. {
  5084. mtrace();
  5085. int result = FAIL;
  5086. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5087. //struct json_object *jsonitem;
  5088. int MaxKeySupported = 0;
  5089. int n_keys = 0;
  5090. char requestKey[43][50]={0};
  5091. char search[]="[";
  5092. char sstr[500]={ 0 };
  5093. //int pos;
  5094. int l, c = 0;
  5095. int i = 0;
  5096. char *delim = "\",\"";
  5097. char * pch;
  5098. char *loc = strstr(payload, search);
  5099. /********************* Parsing String ***********************************/
  5100. if(loc == NULL) {
  5101. DEBUG_INFO("no key match in Configuration \n");
  5102. }
  5103. else {
  5104. //pos = loc - payload;
  5105. l = strlen(loc)-4;
  5106. while (c < l)
  5107. {
  5108. sstr[c] = loc[c+2];
  5109. c++;
  5110. }
  5111. sstr[c] = '\0';
  5112. //parsing strings to words
  5113. pch = strtok(sstr,delim);
  5114. if(pch == NULL)
  5115. {
  5116. strcpy(requestKey[0], sstr);
  5117. }
  5118. else
  5119. {
  5120. while (pch != NULL)
  5121. {
  5122. strcpy(requestKey[i], pch);
  5123. pch = strtok (NULL, delim);
  5124. i = i + 1;
  5125. }
  5126. n_keys = i;
  5127. }
  5128. }
  5129. UnknownKeynum = 0;
  5130. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5131. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5132. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5133. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5134. if(n_keys != 0)
  5135. {
  5136. for(int i=0;i<n_keys;i++)
  5137. {
  5138. getKeyValue(requestKey[i]);
  5139. //json_object_put(jsonitem);
  5140. }
  5141. }
  5142. else
  5143. {
  5144. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5145. getKeyValue("");
  5146. }
  5147. processUnkownKey();
  5148. sendGetConfigurationConfirmation(uuid);
  5149. return result;
  5150. }
  5151. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5152. {
  5153. mtrace();
  5154. int result = FAIL;
  5155. //void *ret; //
  5156. char fnamePlusPath[50]="";
  5157. char fname[16]="";
  5158. pthread_t t; // pthread 變數
  5159. time_t rawtime;
  5160. struct tm * timeinfo;
  5161. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5162. system("exec /root/logPackTools 'log' 6");
  5163. //char buffer [128];
  5164. time (&rawtime);
  5165. //printf("%ld\n", rawtime);
  5166. timeinfo = localtime (&rawtime);
  5167. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5168. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5169. if((access(fnamePlusPath,F_OK))!=-1)
  5170. {
  5171. DEBUG_INFO("fnamePlusPath exist.\n");
  5172. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5173. }
  5174. else
  5175. {
  5176. DEBUG_INFO("fnamePlusPath not exist!\n");
  5177. }
  5178. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5179. pthread_create(&t, NULL, GetDiagnosticsProcess, payload); // 建�?�執行�?
  5180. pthread_join(t, NULL/*&ret*/);
  5181. // ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = 1;
  5182. //sendGetDiagnosticsConfirmation(uuid,fname);
  5183. // sendGetDiagnosticsConfirmation(uuid,(char*) ret);
  5184. // ShmOCPP16Data->MsMsg.bits.GetDiagnosticsConf = 1;
  5185. return result;
  5186. }
  5187. void* GetDiagnosticsProcess(void* data)
  5188. {
  5189. mtrace();
  5190. int retriesInt=0, retryIntervalInt=0;
  5191. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5192. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5193. char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
  5194. int port=0;
  5195. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5196. char fname[16]="";
  5197. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5198. int c = 0;
  5199. char *loc;
  5200. int isSuccess = FALSE;
  5201. char ftpbuf[200]={0};
  5202. //char temp[100]={0};
  5203. char * pch;
  5204. // [2,"137d88c7-a403-4ead-bb2d-fc6ec90531c1","GetDiagnostics",{"location":"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/","retries":0,"retryInterval":0,"startTime":"0001-01-01T00:00:00.000Z","stopTime":"0001-01-01T00:00:00.000Z"}]
  5205. char *str = (char*) data; // ?��?輸入資�?
  5206. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5207. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5208. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5209. /****************location*******************/
  5210. c = 0;
  5211. memset(sstr ,0, sizeof(sstr) );
  5212. loc = strstr(str, "location");
  5213. while (loc[3+strlen("location")+c] != '\"')
  5214. {
  5215. sstr[c] = loc[3+strlen("location")+c];
  5216. c++;
  5217. }
  5218. sstr[c] = '\0';
  5219. strcpy(locationstr,sstr);
  5220. if(strcmp(locationstr,"")==0)
  5221. {
  5222. DEBUG_INFO("location is <Empty>!\n");
  5223. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5224. goto end;
  5225. }
  5226. /****************retries*******************/
  5227. c = 0;
  5228. loc = strstr(str, "retries");
  5229. if(loc == NULL)
  5230. {
  5231. retriesIsNULL = TRUE;
  5232. }
  5233. else
  5234. {
  5235. while (loc[strlen("retries")+2+c] != ',')
  5236. {
  5237. sstr[c] = loc[strlen("retries")+2+c];
  5238. c++;
  5239. }
  5240. sstr[c] = '\0';
  5241. retriesInt = atoi(sstr);
  5242. }
  5243. if(retriesIsNULL == TRUE)
  5244. {
  5245. retriesInt = 0;
  5246. }
  5247. /****************retryInterval*******************/
  5248. c = 0;
  5249. loc = strstr(str, "retryInterval");
  5250. if(loc == NULL)
  5251. {
  5252. retryIntervalIsNULL = TRUE;
  5253. }
  5254. else
  5255. {
  5256. while (loc[strlen("retryInterval")+2+c] != ',')
  5257. {
  5258. sstr[c] = loc[strlen("retryInterval")+2+c];
  5259. c++;
  5260. }
  5261. sstr[c] = '\0';
  5262. retryIntervalInt = atoi(sstr);
  5263. }
  5264. /****************startTime*******************/
  5265. c = 0;
  5266. memset(sstr ,0, sizeof(sstr) );
  5267. loc = strstr(str, "startTime");
  5268. if(loc == NULL)
  5269. {
  5270. startTimeIsNULL = TRUE;
  5271. }
  5272. else
  5273. {
  5274. while (loc[3+strlen("startTime")+c] != '\"')
  5275. {
  5276. sstr[c] = loc[3+strlen("startTime")+c];
  5277. c++;
  5278. }
  5279. sstr[c] = '\0';
  5280. strcpy(startTimestr,sstr);
  5281. }
  5282. /****************stopTime*******************/
  5283. c = 0;
  5284. memset(sstr ,0, sizeof(sstr) );
  5285. loc = strstr(str, "stopTime");
  5286. if(loc == NULL)
  5287. {
  5288. stopTimeIsNULL = TRUE;
  5289. }
  5290. else
  5291. {
  5292. while (loc[3+strlen("stopTime")+c] != '\"')
  5293. {
  5294. sstr[c] = loc[3+strlen("stopTime")+c];
  5295. c++;
  5296. }
  5297. sstr[c] = '\0';
  5298. strcpy(stopTimestr,sstr);
  5299. }
  5300. memset(protocol, 0, sizeof(protocol));
  5301. memset(user, 0, sizeof(user) );
  5302. memset(password, 0, sizeof(password));
  5303. memset(host, 0, sizeof(host));
  5304. memset(path, 0, sizeof(path));
  5305. memset(ftppath, 0, sizeof(ftppath));
  5306. memset(host1, 0, sizeof(host1));
  5307. memset(path1, 0, sizeof(path1));
  5308. /*location: ftp://user:password@host:port/path*/
  5309. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5310. // protocol, user, password, host, &port, path);
  5311. #if 0 // remove for temporally
  5312. //zip files in /Storage
  5313. system("exec /root/logPackTools 'log' 6");
  5314. #endif
  5315. // system("exec /root/Module_WebService 'log' 6");
  5316. time_t rawtime;
  5317. struct tm * timeinfo;
  5318. //char buffer [128];
  5319. time (&rawtime);
  5320. //printf("%ld\n", rawtime);
  5321. timeinfo = localtime (&rawtime);
  5322. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5323. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5324. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5325. if((access(fnamePlusPath,F_OK))!=-1)
  5326. {
  5327. DEBUG_INFO("fnamePlusPath exist.\n");
  5328. }
  5329. else
  5330. {
  5331. DEBUG_INFO("fnamePlusPath not exist!\n");
  5332. goto end;
  5333. }
  5334. pch=strchr(locationstr,'@');
  5335. if(pch==NULL)
  5336. {
  5337. sscanf(locationstr,
  5338. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5339. protocol, host, &port, path);
  5340. strcpy(user,"anonymous");
  5341. strcpy(password,"");
  5342. }
  5343. else
  5344. {
  5345. DEBUG_INFO("pch=%s\n", pch);
  5346. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5347. protocol, user, password, host, &port, path);
  5348. }
  5349. if(strcmp(protocol,"ftp")!=0)
  5350. {
  5351. DEBUG_INFO("protocol is not ftp!\n");
  5352. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5353. goto end;
  5354. }
  5355. sscanf(host,"%[^/]%s",host1, path1);
  5356. sprintf(ftppath,"%s", path1);
  5357. DEBUG_INFO("protocol =%s\n",protocol);
  5358. DEBUG_INFO("user =%s\n",user);
  5359. DEBUG_INFO("password =%s\n",password);
  5360. DEBUG_INFO("host1 =%s\n",host1);
  5361. DEBUG_INFO("port =%d\n",port);
  5362. DEBUG_INFO("path1 =%s\n",path1);
  5363. DEBUG_INFO("ftppath=%s\n",ftppath);
  5364. int ftppathlen=strlen(ftppath);
  5365. int i=1;
  5366. char filenametemp[50];
  5367. while(i < ftppathlen)
  5368. {
  5369. int len=ftppathlen-i;
  5370. if(ftppath[len]== 47) // '/' ascll code: 47
  5371. {
  5372. DEBUG_INFO("find '/' all right\n");
  5373. break;
  5374. }
  5375. i=i+1;
  5376. }
  5377. memset(filenametemp, 0, sizeof(filenametemp));
  5378. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5379. filenametemp[i+1] = 0;
  5380. //httpDownLoadFile(host, ftppath, fname);
  5381. memset(ftpbuf, 0, sizeof(ftpbuf));
  5382. if(port == 0)
  5383. port = 21;
  5384. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5385. do{
  5386. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5387. sleep(retryIntervalInt);
  5388. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5389. if(!isSuccess)
  5390. {
  5391. //BulldogUtil.sleepMs(interval*1000);
  5392. DEBUG_INFO("Diagnostics fail.\n");
  5393. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5394. }
  5395. else
  5396. {
  5397. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5398. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5399. //isUpdateRequest = TRUE;
  5400. }
  5401. end:
  5402. // json_object_put(obj);
  5403. DiagnosticsStatusNotificationStatus = 0; //Idle
  5404. pthread_exit(NULL/*(void *) fname*/); // ?��?�執行�?
  5405. }
  5406. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5407. {
  5408. mtrace();
  5409. int result = FAIL;
  5410. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5411. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5412. {
  5413. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5414. localversion = -1;
  5415. }
  5416. else
  5417. {
  5418. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5419. OCPP_getListVerion();
  5420. }
  5421. //from db.OCPP_getListVerion
  5422. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5423. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5424. sendGetLocalListVersionConfirmation(uuid,"");
  5425. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5426. return result;
  5427. }
  5428. int handleRemoteStartRequest(char *uuid, char *payload)
  5429. {
  5430. mtrace();
  5431. int result = FAIL;
  5432. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5433. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5434. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5435. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5436. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5437. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5438. int chargingSchedulePeriodCount = 0;
  5439. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5440. int c = 0;
  5441. char *loc;
  5442. char comfirmstr[20]={0};
  5443. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5444. if(server_pending == TRUE)
  5445. {
  5446. return 0;
  5447. }
  5448. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5449. /**********connectorId****************/
  5450. c = 0;
  5451. memset(sstr ,0, sizeof(sstr) );
  5452. loc = strstr(payload, "connectorId");
  5453. if(loc == NULL)
  5454. {
  5455. connectorIdIsNULL = TRUE;
  5456. }
  5457. else
  5458. {
  5459. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5460. {
  5461. sstr[c] = loc[strlen("connectorId")+2+c];
  5462. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5463. c++;
  5464. }
  5465. sstr[c] = '\0';
  5466. connectorIdInt = atoi(sstr);
  5467. }
  5468. if(connectorIdIsNULL == TRUE) // need to discussion
  5469. {
  5470. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5471. goto end;
  5472. }
  5473. /****************idTag*******************/
  5474. c = 0;
  5475. memset(sstr ,0, sizeof(sstr) );
  5476. loc = strstr(payload, "idTag");
  5477. while (loc[3+strlen("idTag")+c] != '\"')
  5478. {
  5479. sstr[c] = loc[3+strlen("idTag")+c];
  5480. c++;
  5481. }
  5482. sstr[c] = '\0';
  5483. strcpy(idTagstr,sstr);
  5484. /****************chargingProfile*******************/
  5485. c = 0;
  5486. memset(sstr ,0, sizeof(sstr) );
  5487. loc = strstr(payload, "chargingProfile");
  5488. if(loc == NULL)
  5489. {
  5490. chargingProfileIsNULL = TRUE;
  5491. }
  5492. else
  5493. {
  5494. /****************chargingProfileId*******************/
  5495. c=0;
  5496. loc = strstr(payload, "chargingProfileId");
  5497. memset(sstr ,0, sizeof(sstr) );
  5498. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5499. {
  5500. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5501. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5502. c++;
  5503. }
  5504. sstr[c] = '\0';
  5505. chargingProfileIdInt = atoi(sstr);
  5506. /****************transactionId*******************/
  5507. loc = strstr(payload, "transactionId");
  5508. if(loc == NULL)
  5509. {
  5510. transactionIdIsNULL = TRUE;
  5511. }
  5512. else
  5513. {
  5514. c=0;
  5515. memset(sstr ,0, sizeof(sstr) );
  5516. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5517. {
  5518. sstr[c] = loc[strlen("transactionId")+2+c];
  5519. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5520. c++;
  5521. }
  5522. sstr[c] = '\0';
  5523. transactionIdInt = atoi(sstr);
  5524. }
  5525. /****************stackLevel*******************/
  5526. c=0;
  5527. loc = strstr(payload, "stackLevel");
  5528. memset(sstr ,0, sizeof(sstr) );
  5529. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5530. {
  5531. sstr[c] = loc[strlen("stackLevel")+2+c];
  5532. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5533. c++;
  5534. }
  5535. sstr[c] = '\0';
  5536. stackLevelInt = atoi(sstr);
  5537. /****************chargingProfilePurpose*******************/
  5538. c = 0;
  5539. memset(sstr ,0, sizeof(sstr) );
  5540. loc = strstr(payload, "chargingProfilePurpose");
  5541. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5542. {
  5543. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5544. c++;
  5545. }
  5546. sstr[c] = '\0';
  5547. strcpy(chargingProfilePurposestr,sstr);
  5548. /****************chargingProfileKind*******************/
  5549. c = 0;
  5550. memset(sstr ,0, sizeof(sstr) );
  5551. loc = strstr(payload, "chargingProfileKind");
  5552. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5553. {
  5554. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5555. c++;
  5556. }
  5557. sstr[c] = '\0';
  5558. strcpy(chargingProfileKindstr,sstr);
  5559. /****************recurrencyKind*******************/
  5560. loc = strstr(payload, "recurrencyKind");
  5561. if(loc == NULL)
  5562. {
  5563. recurrencyKindIsNULL = TRUE;
  5564. }
  5565. else
  5566. {
  5567. c = 0;
  5568. memset(sstr ,0, sizeof(sstr) );
  5569. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5570. {
  5571. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5572. c++;
  5573. }
  5574. sstr[c] = '\0';
  5575. strcpy(recurrencyKindstr,sstr);
  5576. }
  5577. /****************validFrom*******************/
  5578. loc = strstr(payload, "validFrom");
  5579. if(loc == NULL)
  5580. {
  5581. validFromIsNULL = TRUE;
  5582. }
  5583. else
  5584. {
  5585. c = 0;
  5586. memset(sstr ,0, sizeof(sstr) );
  5587. while (loc[3+strlen("validFrom")+c] != '\"')
  5588. {
  5589. sstr[c] = loc[3+strlen("validFrom")+c];
  5590. c++;
  5591. }
  5592. sstr[c] = '\0';
  5593. strcpy(validFromstr,sstr);
  5594. }
  5595. /****************validTo*******************/
  5596. loc = strstr(payload, "validTo");
  5597. if(loc == NULL)
  5598. {
  5599. validToIsNULL = TRUE;
  5600. }
  5601. else
  5602. {
  5603. c = 0;
  5604. memset(sstr ,0, sizeof(sstr) );
  5605. while (loc[3+strlen("validTo")+c] != '\"')
  5606. {
  5607. sstr[c] = loc[3+strlen("validTo")+c];
  5608. c++;
  5609. }
  5610. sstr[c] = '\0';
  5611. strcpy(validTostr,sstr);
  5612. }
  5613. /****************chargingSchedule*******************/
  5614. loc = strstr(payload, "chargingSchedule");
  5615. if(loc != NULL)
  5616. {
  5617. /****************duration*******************/
  5618. loc = strstr(payload, "duration");
  5619. if(loc == NULL)
  5620. {
  5621. durationIsNULL = TRUE;
  5622. }
  5623. else
  5624. {
  5625. c=0;
  5626. memset(sstr ,0, sizeof(sstr) );
  5627. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5628. {
  5629. sstr[c] = loc[strlen("duration")+2+c];
  5630. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5631. c++;
  5632. }
  5633. sstr[c] = '\0';
  5634. durationInt = atoi(sstr);
  5635. }
  5636. /****************startSchedule******************/
  5637. loc = strstr(payload, "startSchedule");
  5638. if(loc == NULL)
  5639. {
  5640. startScheduleIsNULL = TRUE;
  5641. }
  5642. else
  5643. {
  5644. c = 0;
  5645. memset(sstr ,0, sizeof(sstr) );
  5646. while (loc[3+strlen("startSchedule")+c] != '\"')
  5647. {
  5648. sstr[c] = loc[3+strlen("startSchedule")+c];
  5649. c++;
  5650. }
  5651. sstr[c] = '\0';
  5652. strcpy(startSchedulestr,sstr);
  5653. }
  5654. /****************chargingRateUnit*******************/
  5655. c = 0;
  5656. memset(sstr ,0, sizeof(sstr) );
  5657. loc = strstr(payload, "chargingRateUnit");
  5658. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5659. {
  5660. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5661. c++;
  5662. }
  5663. sstr[c] = '\0';
  5664. strcpy(chargingRateUnitstr,sstr);
  5665. /****************minChargingRate*******************/
  5666. loc = strstr(payload, "minChargingRate");
  5667. if(loc == NULL)
  5668. {
  5669. minChargingRateIsNULL = TRUE;
  5670. }
  5671. else
  5672. {
  5673. c=0;
  5674. memset(sstr ,0, sizeof(sstr) );
  5675. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5676. {
  5677. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5678. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5679. c++;
  5680. }
  5681. sstr[c] = '\0';
  5682. minChargingRateflaot = atof(sstr);
  5683. }
  5684. /****************chargingSchedulePeriod count*******************/
  5685. int what_len = strlen("startPeriod");
  5686. char *where = payload;
  5687. while ((where = strstr(where, "startPeriod"))) {
  5688. where += what_len;
  5689. chargingSchedulePeriodCount++;
  5690. }
  5691. where = payload;
  5692. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5693. {
  5694. /****************startPeriod*******************/
  5695. c=0;
  5696. loc = strstr(where, "startPeriod");
  5697. memset(sstr ,0, sizeof(sstr) );
  5698. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5699. {
  5700. sstr[c] = loc[strlen("startPeriod")+2+c];
  5701. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5702. c++;
  5703. }
  5704. sstr[c] = '\0';
  5705. startPeriodInt[periodNums] = atoi(sstr);
  5706. /****************limit*******************/
  5707. c=0;
  5708. loc = strstr(where, "limit");
  5709. memset(sstr ,0, sizeof(sstr) );
  5710. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5711. {
  5712. sstr[c] = loc[strlen("limit")+2+c];
  5713. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5714. c++;
  5715. }
  5716. sstr[c] = '\0';
  5717. limitflaot[periodNums] = atof(sstr);
  5718. /****************numberPhases*******************/
  5719. loc = strstr(where, "numberPhases");
  5720. if(loc == NULL)
  5721. {
  5722. numberPhasesIsNULL = TRUE;
  5723. }
  5724. else
  5725. {
  5726. c=0;
  5727. memset(sstr ,0, sizeof(sstr) );
  5728. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  5729. {
  5730. sstr[c] = loc[strlen("numberPhases")+2+c];
  5731. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5732. c++;
  5733. }
  5734. sstr[c] = '\0';
  5735. numberPhasesInt[periodNums] = atoi(sstr);
  5736. }
  5737. where = loc;
  5738. }
  5739. }
  5740. }
  5741. /*
  5742. enum _SYSTEM_STATUS
  5743. {
  5744. S_BOOTING = 0,
  5745. S_IDLE, = 1
  5746. S_AUTHORIZING, =2
  5747. S_REASSIGN_CHECK, =3
  5748. S_REASSIGN, =4
  5749. S_PRECHARGE, =5
  5750. S_PREPARING_FOR_EV, =6
  5751. S_PREPARING_FOR_EVSE, =7
  5752. S_CHARGING, =8
  5753. S_TERMINATING, =9
  5754. S_COMPLETE, =10
  5755. S_ALARM, =11
  5756. S_FAULT =12
  5757. }
  5758. */
  5759. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  5760. {
  5761. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  5762. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  5763. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  5764. //check Transaction active
  5765. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  5766. {
  5767. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5768. {
  5769. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  5770. {
  5771. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  5772. {
  5773. //Reserved
  5774. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  5775. }
  5776. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  5777. {
  5778. //Reserved
  5779. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  5780. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5781. goto end;
  5782. }
  5783. else
  5784. {
  5785. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 1) //S_IDLE
  5786. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 5 ) //S_PRECHARGE
  5787. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 6 ) //S_PREPARING_FOR_EV
  5788. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 7 )) // S_PREPARING_FOR_EVSE
  5789. {
  5790. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5791. goto end;
  5792. }
  5793. }//END FOR ELSE
  5794. }
  5795. }// END FOR CHAdeMO_QUANTITY
  5796. for (int index = 0; index < CCS_QUANTITY; index++)
  5797. {
  5798. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  5799. {
  5800. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  5801. {
  5802. //Reserved
  5803. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  5804. }
  5805. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  5806. {
  5807. //Reserved
  5808. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  5809. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5810. goto end;
  5811. }
  5812. else
  5813. {
  5814. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 1) //S_IDLE
  5815. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 5) //S_PRECHARGE
  5816. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 6) //S_PREPARING_FOR_EV
  5817. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 7)) // S_PREPARING_FOR_EVSE
  5818. {
  5819. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5820. goto end;
  5821. }
  5822. }// END FOR ELSE
  5823. }
  5824. }// END FOR CCS_QUANTITY
  5825. for (int index = 0; index < GB_QUANTITY; index++)
  5826. {
  5827. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  5828. {
  5829. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  5830. {
  5831. //Reserved
  5832. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  5833. }
  5834. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  5835. {
  5836. //Reserved
  5837. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  5838. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5839. goto end;
  5840. }
  5841. else
  5842. {
  5843. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 1) //S_IDLE
  5844. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 5) //S_PRECHARGE
  5845. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 6) //S_PREPARING_FOR_EV
  5846. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 7)) // S_PREPARING_FOR_EVSE
  5847. {
  5848. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5849. goto end;
  5850. }
  5851. }// END FOR ELSE
  5852. }
  5853. } // END FOR GB_QUANTITY
  5854. }
  5855. else
  5856. {
  5857. for (int index = 0; index < AC_QUANTITY; index++)
  5858. {
  5859. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  5860. {
  5861. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  5862. {
  5863. //Reserved
  5864. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  5865. }
  5866. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  5867. {
  5868. //Reserved
  5869. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  5870. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5871. goto end;
  5872. }
  5873. else
  5874. {
  5875. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != 1) //S_IDLE
  5876. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != 5 ) //S_PRECHARGE
  5877. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != 6 ) //S_PREPARING_FOR_EV
  5878. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != 7 )) // S_PREPARING_FOR_EVSE
  5879. {
  5880. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5881. goto end;
  5882. }
  5883. }//END FOR ELSE
  5884. }
  5885. }// END FOR AC_QUANTITY
  5886. }
  5887. if(chargingProfileIsNULL == FALSE)
  5888. {
  5889. //ChargingProfile
  5890. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  5891. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  5892. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  5893. if(recurrencyKindIsNULL == FALSE) //OPTION
  5894. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  5895. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  5896. if(transactionIdIsNULL == FALSE) // OPTION
  5897. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  5898. if(validFromIsNULL == FALSE) // OPTION
  5899. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  5900. if(validToIsNULL == FALSE) //OPTION
  5901. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  5902. //ChargingSchedule
  5903. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  5904. if(durationIsNULL == FALSE) //OPTION
  5905. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  5906. if(minChargingRateIsNULL == FALSE) //OPTION
  5907. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  5908. if(startScheduleIsNULL == FALSE) //OPTION
  5909. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  5910. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5911. {
  5912. //ChargingSchedulePeriod
  5913. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  5914. if(numberPhasesIsNULL == FALSE)
  5915. {
  5916. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  5917. }
  5918. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  5919. }
  5920. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  5921. {
  5922. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  5923. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  5924. }
  5925. else
  5926. {
  5927. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5928. }
  5929. }
  5930. else
  5931. {
  5932. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  5933. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  5934. }
  5935. }
  5936. else
  5937. {
  5938. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5939. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  5940. }
  5941. end:
  5942. if(connectorIdIsNULL == FALSE)
  5943. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  5944. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  5945. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  5946. //json_object_put(obj); -- remove temporally
  5947. //OCPP send RemoteStartConfirmation by first.
  5948. sendRemoteStartConfirmation(uuid, comfirmstr);
  5949. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionConf = 1;
  5950. return result;
  5951. }
  5952. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  5953. {
  5954. mtrace();
  5955. int result = FAIL;
  5956. int match = FALSE;
  5957. int GunNO = 0;
  5958. int transactionIdInt=0;
  5959. int transactionIdIsNULL= FALSE;
  5960. char sstr[16]={ 0 };//sstr[200]={ 0 };
  5961. int c = 0;
  5962. char *loc;
  5963. char comfirmstr[20];
  5964. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  5965. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  5966. if(server_pending == TRUE)
  5967. {
  5968. return 0;
  5969. }
  5970. c=0;
  5971. loc = strstr(payload, "transactionId");
  5972. if(loc == NULL)
  5973. {
  5974. transactionIdIsNULL= TRUE;
  5975. }
  5976. else
  5977. {
  5978. memset(sstr ,0, sizeof(sstr) );
  5979. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5980. {
  5981. sstr[c] = loc[strlen("transactionId")+2+c];
  5982. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5983. c++;
  5984. }
  5985. sstr[c] = '\0';
  5986. transactionIdInt = atoi(sstr);
  5987. }
  5988. if(transactionIdIsNULL == FALSE)
  5989. {
  5990. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  5991. {
  5992. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  5993. {
  5994. //check Transaction active
  5995. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  5996. {
  5997. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5998. {
  5999. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6000. {
  6001. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8) // S_CHARGING
  6002. {
  6003. match = TRUE;
  6004. GunNO = gun_index;
  6005. }
  6006. }
  6007. }// END FOR CHAdeMO_QUANTITY
  6008. for (int index = 0; index < CCS_QUANTITY; index++)
  6009. {
  6010. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6011. {
  6012. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8) // S_CHARGING
  6013. {
  6014. match = TRUE;
  6015. GunNO = gun_index;
  6016. }
  6017. }
  6018. }// END FOR CCS_QUANTITY
  6019. for (int index = 0; index < GB_QUANTITY; index++)
  6020. {
  6021. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6022. {
  6023. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8) // S_CHARGING
  6024. {
  6025. match = TRUE;
  6026. GunNO = gun_index;
  6027. }
  6028. }
  6029. }// END FOR GB_QUANTITY
  6030. }
  6031. else
  6032. {
  6033. for (int index = 0; index < AC_QUANTITY; index++)
  6034. {
  6035. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6036. {
  6037. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 8) // S_CHARGING
  6038. {
  6039. match = TRUE;
  6040. GunNO = gun_index;
  6041. }
  6042. }
  6043. }// END FOR CHAdeMO_QUANTITY
  6044. }// END FOR AC ELSE
  6045. }// CHECK IF ResponseTransactionId == transactionIdInt
  6046. }//END FOR
  6047. if( match == TRUE)
  6048. {
  6049. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6050. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6051. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6052. }
  6053. else
  6054. {
  6055. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6056. }
  6057. }
  6058. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6059. return result;
  6060. }
  6061. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6062. {
  6063. mtrace();
  6064. int result = FAIL;
  6065. int connectorIdInt=0, reservationIdInt=0;
  6066. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6067. char comfirmstr[20]={0};
  6068. char sstr[180]={ 0 };
  6069. int c = 0;
  6070. char *loc;
  6071. //char *ptr;
  6072. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6073. /***(1)connectorId ****/
  6074. c=0;
  6075. loc = strstr(payload, "connectorId");
  6076. memset(sstr ,0, sizeof(sstr) );
  6077. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6078. {
  6079. sstr[c] = loc[strlen("connectorId")+2+c];
  6080. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6081. c++;
  6082. }
  6083. sstr[c] = '\0';
  6084. connectorIdInt = atoi(sstr);
  6085. /***(2)expiryDate ****/
  6086. loc = strstr(payload, "expiryDate");
  6087. memset(sstr ,0, sizeof(sstr) );
  6088. c = 0;
  6089. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6090. {
  6091. sstr[c] = loc[3+strlen("expiryDate")+c];
  6092. c++;
  6093. }
  6094. sstr[c] = '\0';
  6095. strcpy(expiryDatestr, sstr);
  6096. /***(3)idTag ****/
  6097. loc = strstr(payload, "idTag");
  6098. memset(sstr ,0, sizeof(sstr) );
  6099. c = 0;
  6100. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6101. {
  6102. sstr[c] = loc[3+strlen("idTag")+c];
  6103. c++;
  6104. }
  6105. sstr[c] = '\0';
  6106. strcpy(idTagstr, sstr);
  6107. /***(4)parentIdTag ****/
  6108. loc = strstr(payload, "parentIdTag");
  6109. memset(sstr ,0, sizeof(sstr) );
  6110. c = 0;
  6111. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6112. {
  6113. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6114. c++;
  6115. }
  6116. sstr[c] = '\0';
  6117. strcpy(parentIdTagstr, sstr);
  6118. /***(5)reservationId ****/
  6119. c=0;
  6120. loc = strstr(payload, "reservationId");
  6121. memset(sstr ,0, sizeof(sstr) );
  6122. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6123. {
  6124. sstr[c] = loc[strlen("reservationId")+2+c];
  6125. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6126. c++;
  6127. }
  6128. sstr[c] = '\0';
  6129. reservationIdInt = atoi(sstr);
  6130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6131. /*
  6132. enum _SYSTEM_STATUS
  6133. {
  6134. S_BOOTING = 0,
  6135. S_IDLE, = 1
  6136. S_AUTHORIZING, =2
  6137. S_REASSIGN_CHECK, =3
  6138. S_REASSIGN, =4
  6139. S_PRECHARGE, =5
  6140. S_PREPARING_FOR_EV, =6
  6141. S_PREPARING_FOR_EVSE, =7
  6142. S_CHARGING, =8
  6143. S_TERMINATING, =9
  6144. S_COMPLETE, =10
  6145. S_ALARM, =11
  6146. S_FAULT =12
  6147. }
  6148. */
  6149. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6150. {
  6151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6152. goto end;
  6153. }
  6154. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6155. {
  6156. //check Transaction active
  6157. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6158. {
  6159. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6160. {
  6161. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6162. {
  6163. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6164. {
  6165. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6166. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 12) //S_FAULT
  6167. {
  6168. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 1) //S_IDLE
  6169. {
  6170. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6171. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6172. }
  6173. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 9) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6174. {
  6175. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6176. }
  6177. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 5) //S_PRECHARGE
  6178. {
  6179. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6180. }
  6181. else
  6182. {
  6183. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6184. }
  6185. }
  6186. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 12) //S_FAULT
  6187. {
  6188. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6189. }
  6190. }
  6191. else
  6192. {
  6193. //replace reservation
  6194. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6195. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6196. }
  6197. }
  6198. } // END FOR CHAdeMO_QUANTITY
  6199. for (int index = 0; index < CCS_QUANTITY; index++)
  6200. {
  6201. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6202. {
  6203. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6204. {
  6205. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6206. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 12) //S_FAULT
  6207. {
  6208. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 1) //S_IDLE
  6209. {
  6210. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6211. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6212. }
  6213. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 9) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6214. {
  6215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6216. }
  6217. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 5) //S_PRECHARGE
  6218. {
  6219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6220. }
  6221. else
  6222. {
  6223. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6224. }
  6225. }
  6226. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==12) //S_FAULT
  6227. {
  6228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6229. }
  6230. }
  6231. else
  6232. {
  6233. //replace reservation
  6234. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6236. }
  6237. }
  6238. } // END FOR CCS_QUANTITY
  6239. for (int index = 0; index < GB_QUANTITY; index++)
  6240. {
  6241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6242. {
  6243. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6244. {
  6245. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6246. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 12) //S_FAULT
  6247. {
  6248. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1) //S_IDLE
  6249. {
  6250. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6251. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6252. }
  6253. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 9) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6254. {
  6255. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6256. }
  6257. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 5) //S_PRECHARGE
  6258. {
  6259. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6260. }
  6261. else
  6262. {
  6263. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6264. }
  6265. }
  6266. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==12) //S_FAULT
  6267. {
  6268. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6269. }
  6270. }
  6271. else
  6272. {
  6273. //replace reservation
  6274. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6276. }
  6277. }
  6278. }// END FOR GB_QUANTITY
  6279. }
  6280. else
  6281. {
  6282. for (int index = 0; index < AC_QUANTITY; index++)
  6283. {
  6284. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6285. {
  6286. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6287. {
  6288. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6289. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != 12) //S_FAULT
  6290. {
  6291. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  6292. {
  6293. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6294. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6295. }
  6296. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 9) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6297. {
  6298. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6299. }
  6300. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 5) //S_PRECHARGE
  6301. {
  6302. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6303. }
  6304. else
  6305. {
  6306. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6307. }
  6308. }
  6309. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 12) //S_FAULT
  6310. {
  6311. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6312. }
  6313. }
  6314. else
  6315. {
  6316. //replace reservation
  6317. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6318. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6319. }
  6320. }
  6321. } // END FOR AC_QUANTITY
  6322. }//END FOR AC ELSE
  6323. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6324. }
  6325. else if(connectorIdInt == 0)
  6326. {
  6327. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6328. {
  6329. //check Transaction active
  6330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6331. {
  6332. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6333. {
  6334. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 9) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6335. {
  6336. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6337. goto end;
  6338. }
  6339. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 5) //S_PRECHARGE
  6340. {
  6341. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6342. goto end;
  6343. }
  6344. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 12) //S_FAULT
  6345. {
  6346. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6347. goto end;
  6348. }
  6349. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 1) //S_IDLE
  6350. {
  6351. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6352. goto end;
  6353. }
  6354. }
  6355. }// END FOR CHAdeMO_QUANTITY
  6356. for (int index = 0; index < CCS_QUANTITY; index++)
  6357. {
  6358. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6359. {
  6360. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 9) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6361. {
  6362. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6363. }
  6364. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 5) //S_PRECHARGE
  6365. {
  6366. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6367. }
  6368. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==12) //S_FAULT
  6369. {
  6370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6371. }
  6372. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 1) //S_IDLE
  6373. {
  6374. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6375. }
  6376. }
  6377. } // END FOR CCS_QUANTITY
  6378. for (int index = 0; index < GB_QUANTITY; index++)
  6379. {
  6380. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6381. {
  6382. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 9) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6383. {
  6384. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6385. }
  6386. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 5) //S_PRECHARGE
  6387. {
  6388. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6389. }
  6390. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==12) //S_FAULT
  6391. {
  6392. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6393. }
  6394. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 1) //S_IDLE
  6395. {
  6396. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6397. }
  6398. }
  6399. } // END FOR GB_QUANTITY
  6400. }
  6401. else
  6402. {
  6403. for (int index = 0; index < AC_QUANTITY; index++)
  6404. {
  6405. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6406. {
  6407. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 9) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6408. {
  6409. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6410. goto end;
  6411. }
  6412. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 5) //S_PRECHARGE
  6413. {
  6414. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6415. goto end;
  6416. }
  6417. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 12) //S_FAULT
  6418. {
  6419. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6420. goto end;
  6421. }
  6422. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != 1) //S_IDLE
  6423. {
  6424. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6425. goto end;
  6426. }
  6427. }
  6428. }// END FOR AC_QUANTITY
  6429. }
  6430. //The connectorId is 0
  6431. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6433. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6434. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6435. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6436. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6437. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6438. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6439. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6440. result = TRUE;
  6441. return result;
  6442. }
  6443. else
  6444. {
  6445. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6446. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6447. }
  6448. if(strcmp(comfirmstr,"Accepted") == 0)
  6449. {
  6450. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6451. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6452. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6453. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6454. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6455. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6456. result = TRUE;
  6457. return result;
  6458. }
  6459. end:
  6460. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6461. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6462. return result;
  6463. }
  6464. int handleResetRequest(char *uuid, char *payload)
  6465. {
  6466. mtrace();
  6467. int result = FAIL;
  6468. char sstr[10]={0};
  6469. char typestr[10]={0};
  6470. char comfirmstr[20]={0};
  6471. int c = 0;
  6472. char *loc;
  6473. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6474. DEBUG_INFO("handleResetRequest ...\n");
  6475. loc = strstr(payload, "type");
  6476. memset(sstr ,0, sizeof(sstr) );
  6477. c = 0;
  6478. while (loc[3+strlen("type")+c] != '\"')
  6479. {
  6480. sstr[c] = loc[3+strlen("type")+c];
  6481. c++;
  6482. }
  6483. sstr[c] = '\0';
  6484. strcpy(typestr,sstr);
  6485. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6486. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6487. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6488. {
  6489. //check Transaction active
  6490. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6491. {
  6492. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6493. {
  6494. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8)
  6495. {
  6496. //0: unplug, 1: Plug-in
  6497. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6498. }
  6499. }
  6500. for (int index = 0; index < CCS_QUANTITY; index++)
  6501. {
  6502. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8)
  6503. {
  6504. //0: unplug, 1: Plug-in
  6505. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6506. }
  6507. }
  6508. for (int index = 0; index < GB_QUANTITY; index++)
  6509. {
  6510. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8)
  6511. {
  6512. //0: unplug, 1: Plug-in
  6513. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6514. }
  6515. }
  6516. }
  6517. else
  6518. {
  6519. for (int index = 0; index < AC_QUANTITY; index++)
  6520. {
  6521. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 8)
  6522. {
  6523. //0: unplug, 1: Plug-in
  6524. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6525. }
  6526. }
  6527. }// END FOR AC ELSE
  6528. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6529. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6530. result = TRUE;
  6531. return result;
  6532. }
  6533. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6534. {
  6535. //check Transaction active
  6536. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6537. {
  6538. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6539. {
  6540. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8)
  6541. {
  6542. //0: unplug, 1: Plug-in
  6543. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6544. }
  6545. }
  6546. for (int index = 0; index < CCS_QUANTITY; index++)
  6547. {
  6548. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8)
  6549. {
  6550. //0: unplug, 1: Plug-in
  6551. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6552. }
  6553. }
  6554. for (int index = 0; index < GB_QUANTITY; index++)
  6555. {
  6556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8)
  6557. {
  6558. //0: unplug, 1: Plug-in
  6559. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6560. }
  6561. }
  6562. }
  6563. else
  6564. {
  6565. for (int index = 0; index < AC_QUANTITY; index++)
  6566. {
  6567. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 8)
  6568. {
  6569. //0: unplug, 1: Plug-in
  6570. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6571. }
  6572. }
  6573. }// END FOR AC ELSE
  6574. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6575. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6576. result = TRUE;
  6577. return result;
  6578. }
  6579. else
  6580. {
  6581. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6582. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6583. goto errorend;
  6584. }
  6585. errorend:
  6586. sendResetConfirmation(uuid, comfirmstr);
  6587. return result;
  6588. }
  6589. int handleSendLocalListRequest(char *uuid, char *payload)
  6590. {
  6591. mtrace();
  6592. int result = FAIL;
  6593. int listVersionInt;
  6594. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6595. char listsearch[]="listVersion";
  6596. char updateTypesearch[]="updateType";
  6597. char localAuthorizationListsearch[]="localAuthorizationList";
  6598. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6599. char CardList[500][160]={0};
  6600. char updateTypestr[15]={0};
  6601. char idTagstr[20]={0};
  6602. char parentIdTag[20]={0};
  6603. char expiryDate[30]={0};
  6604. char idTagstatus[16]={0};
  6605. int c = 0;
  6606. int i = 0;
  6607. char *delim1 = "}";
  6608. char * pch;
  6609. char *loc;
  6610. //char *ptr;
  6611. char comfirmstr[20];
  6612. //int n_localAuthorizations = 0;
  6613. int checkState_Faulted = FALSE;
  6614. DEBUG_INFO("handleSendLocalListRequest\n");
  6615. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6616. {
  6617. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6618. goto end;
  6619. }
  6620. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6621. {
  6622. //check Charge Point state
  6623. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6624. {
  6625. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 12) //S_FAULT ---> Faulted
  6626. {
  6627. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6628. }
  6629. }
  6630. for (int index = 0; index < CCS_QUANTITY; index++)
  6631. {
  6632. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 12) //S_FAULT ---> Faulted
  6633. {
  6634. checkState_Faulted = TRUE; //OCPP Status
  6635. }
  6636. }
  6637. for (int index = 0; index < GB_QUANTITY; index++)
  6638. {
  6639. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 12) //S_FAULT ---> Faulted
  6640. {
  6641. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6642. }
  6643. }
  6644. }
  6645. else
  6646. {
  6647. //check Charge Point state
  6648. for (int index = 0; index < AC_QUANTITY; index++)
  6649. {
  6650. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 12) //S_FAULT ---> Faulted
  6651. {
  6652. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6653. }
  6654. }
  6655. }// END FOR AC ELSE
  6656. if(checkState_Faulted == TRUE)
  6657. {
  6658. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6659. goto end;
  6660. }
  6661. //listVersion
  6662. c = 0;
  6663. loc = strstr(payload, listsearch);
  6664. while (loc[strlen("listVersion")+2+c] != ',')
  6665. {
  6666. sstr[c] = loc[strlen("listVersion")+2+c];
  6667. c++;
  6668. }
  6669. sstr[c] = '\0';
  6670. listVersionInt = atoi(sstr);
  6671. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6672. //updateType
  6673. loc = strstr(payload, updateTypesearch);
  6674. c = 0;
  6675. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6676. {
  6677. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6678. c++;
  6679. }
  6680. sstr[c] = '\0';
  6681. strcpy(updateTypestr, sstr);
  6682. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6683. //localAuthorizationList
  6684. memset(sstr ,0, sizeof(sstr) );
  6685. loc = strstr(payload, localAuthorizationListsearch);
  6686. if(loc != NULL) // localAuthorizationList is not NULL
  6687. {
  6688. //Check UpdateType
  6689. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6690. {
  6691. //Local list full update
  6692. printf("Local list full update.\n");
  6693. OCPP_cleanLocalList();
  6694. }
  6695. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6696. {
  6697. //Local list different update
  6698. printf("Local list different update.\n");
  6699. OCPP_getListVerion();
  6700. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6701. {
  6702. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6703. goto end;
  6704. }
  6705. }
  6706. else
  6707. {
  6708. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6709. goto end;
  6710. }
  6711. c = 0;
  6712. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6713. {
  6714. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6715. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6716. c++;
  6717. }
  6718. sstr[c] = '\0';
  6719. //parsing strings to words
  6720. i = 0;
  6721. pch = strtok(sstr,delim1);
  6722. while (pch != NULL)
  6723. {
  6724. strcpy(CardList[i], pch);
  6725. pch = strtok (NULL, delim1);
  6726. i = i + 1;
  6727. }
  6728. //local Authorizations List Numbers
  6729. //n_localAuthorizations = i;
  6730. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6731. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  6732. #if 0
  6733. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  6734. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  6735. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = (struct StructLocalAuthorizationList *)malloc(sizeof(struct StructLocalAuthorizationList)*n_localAuthorizations);
  6736. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 ,sizeof(ShmOCPP16Data->SendLocalList.LocalAuthorizationList));
  6737. #endif
  6738. c= 0;
  6739. while(c < i)
  6740. {
  6741. //Search "IdToken"
  6742. memset(sstr ,0, sizeof(sstr) );
  6743. loc = strstr(CardList[c], "idTag");
  6744. int j = 0;
  6745. while (loc[3+strlen("idTag")+j] != '\"')
  6746. {
  6747. sstr[j] = loc[3+strlen("idTag")+j];
  6748. //printf("i=%d sstr=%c\n",c, sstr[j]);
  6749. j++;
  6750. }
  6751. sstr[j] = '\0';
  6752. strcpy(idTagstr, sstr);
  6753. //Search "expiryDate"
  6754. memset(sstr ,0, sizeof(sstr) );
  6755. loc = strstr(CardList[c], "expiryDate");
  6756. j = 0;
  6757. while (loc[3+strlen("expiryDate")+j] != '\"')
  6758. {
  6759. sstr[j] = loc[3+strlen("expiryDate")+j];
  6760. //printf("i=%d sstr=%c\n",c, sstr[j]);
  6761. j++;
  6762. }
  6763. sstr[j] = '\0';
  6764. strcpy(expiryDate, sstr);
  6765. //Search "parentIdTag"
  6766. memset(sstr ,0, sizeof(sstr) );
  6767. loc = strstr(CardList[c], "parentIdTag");
  6768. j = 0;
  6769. while (loc[3+strlen("parentIdTag")+j] != '\"')
  6770. {
  6771. sstr[j] = loc[3+strlen("parentIdTag")+j];
  6772. //printf("i=%d sstr=%c\n",c, sstr[j]);
  6773. j++;
  6774. }
  6775. sstr[j] = '\0';
  6776. strcpy(parentIdTag, sstr);
  6777. //Search "status"
  6778. memset(sstr ,0, sizeof(sstr) );
  6779. loc = strstr(CardList[c], "status");
  6780. j = 0;
  6781. while (loc[3+strlen("status")+j] != '\"')
  6782. {
  6783. sstr[j] = loc[3+strlen("status")+j];
  6784. //printf("i=%d sstr=%c\n",c, sstr[j]);
  6785. j++;
  6786. }
  6787. sstr[j] = '\0';
  6788. strcpy(idTagstatus, sstr);
  6789. OCPP_getIdTag(idTagstr);
  6790. //OCPP_getIdTag("test"); For Test
  6791. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  6792. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6793. {
  6794. //Local list full update
  6795. DEBUG_INFO("Local list full update.\n");
  6796. // update list
  6797. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  6798. OCPP_get_TableAuthlocalAllData();
  6799. }
  6800. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6801. {
  6802. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  6803. {
  6804. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  6805. }
  6806. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  6807. {
  6808. OCPP_deleteIdTag(idTagstr);
  6809. }
  6810. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  6811. {
  6812. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  6813. }
  6814. }
  6815. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  6816. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  6817. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  6818. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  6819. c++;
  6820. }
  6821. }
  6822. else
  6823. {
  6824. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6825. {
  6826. //Local list different update
  6827. DEBUG_INFO("Local list different update.\n");
  6828. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  6829. goto end;
  6830. }
  6831. }
  6832. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  6833. end:
  6834. sendSendLocalListConfirmation(uuid, comfirmstr);
  6835. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  6836. #if 0
  6837. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  6838. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  6839. #endif
  6840. return result;
  6841. }
  6842. /*
  6843. enum _SYSTEM_STATUS
  6844. {
  6845. S_BOOTING = 0,
  6846. S_IDLE, =1
  6847. S_AUTHORIZING, =2
  6848. S_REASSIGN_CHECK, =3
  6849. S_REASSIGN, =4
  6850. S_PRECHARGE, =5
  6851. S_PREPARING_FOR_EV, =6
  6852. S_PREPARING_FOR_EVSE, =7
  6853. S_CHARGING, =8
  6854. S_TERMINATING, =9
  6855. S_COMPLETE, =10
  6856. S_ALARM, =11
  6857. S_FAULT =12
  6858. };
  6859. */
  6860. #define MAX 200
  6861. int handleSetChargingProfileRequest(char *uuid, char *payload)
  6862. {
  6863. mtrace();
  6864. int result = FAIL;
  6865. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6866. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  6867. char chargingProfilePurposeStr[30]={0};
  6868. char chargingProfileKindStr[16]={0};
  6869. char recurrencyKindStr[10]={0};
  6870. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  6871. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  6872. int chargingSchedulePeriodCount = 0;
  6873. //int updateflag = FALSE;
  6874. char comfirmstr[20]={0};
  6875. int meet= FALSE;
  6876. char sstr[10]={0};
  6877. int c = 0;
  6878. char *loc;
  6879. FILE *fptr1;//, *fptr2;
  6880. //int lno=0;//, linectr = 0;
  6881. //int modifyflag = FALSE;
  6882. char filename[MAX]={0};
  6883. char tempfile[] = "../Storage/OCPP/temp.json";
  6884. int resultRename=0;
  6885. char rmFileCmd[50]={0};
  6886. char tempchargingProfilePurposeStr[30]={0};
  6887. //[2,"d65bcbca-0b07-49c1-b679-e6c6ff9f5627","SetChargingProfile",{"connectorId":0,"csChargingProfiles":{"chargingProfileId":1,"transactionId":0,"stackLevel":0,"chargingProfilePurpose":"TxDefaultProfile","chargingProfileKind":"Absolute","recurrencyKind":"Daily","validFrom":"2019-07-01T02:39:55.000Z","validTo":"2019-07-04T02:39:55.000Z","chargingSchedule":{"duration":86400,"startSchedule":"2019-07-01T02:39:55.000Z","chargingRateUnit":"A","chargingSchedulePeriod":[{"startPeriod":0,"limit":20.0,"numberPhases":3},{"startPeriod":300,"limit":10.0,"numberPhases":3},{"startPeriod":600,"limit":20.0,"numberPhases":3},{"startPeriod":1200,"limit":10.0,"numberPhases":3},{"startPeriod":1800,"limit":20.0,"numberPhases":3},{"startPeriod":2400,"limit":10.0,"numberPhases":3},{"startPeriod":3000,"limit":20.0,"numberPhases":3}],"minChargingRate":20.1}}}]
  6888. DEBUG_INFO("handleSetChargingProfileRequest\n");
  6889. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  6890. /*********************connectorId***************************/
  6891. loc = strstr(payload, "connectorId");
  6892. c = 0;
  6893. memset(sstr ,0, sizeof(sstr) );
  6894. while (loc[strlen("connectorId")+2+c] != ',')
  6895. {
  6896. sstr[c] = loc[strlen("connectorId")+2+c];
  6897. c++;
  6898. }
  6899. sstr[c] = '\0';
  6900. connectorIdInt = atoi(sstr);
  6901. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  6902. {
  6903. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  6904. }
  6905. else
  6906. {
  6907. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  6908. }
  6909. DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  6910. /*********************chargingProfileId***************************/
  6911. loc = strstr(payload, "chargingProfileId");
  6912. c = 0;
  6913. memset(sstr ,0, sizeof(sstr) );
  6914. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6915. {
  6916. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6917. c++;
  6918. }
  6919. sstr[c] = '\0';
  6920. chargingProfileIdInt = atoi(sstr);
  6921. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  6922. {
  6923. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6924. }
  6925. else
  6926. {
  6927. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6928. }
  6929. DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  6930. /*********************transactionId***************************/
  6931. loc = strstr(payload, "transactionId");
  6932. if(loc != NULL)
  6933. {
  6934. c = 0;
  6935. memset(sstr ,0, sizeof(sstr) );
  6936. while (loc[strlen("transactionId")+2+c] != ',')
  6937. {
  6938. sstr[c] = loc[strlen("transactionId")+2+c];
  6939. c++;
  6940. }
  6941. sstr[c] = '\0';
  6942. transactionIdInt = atoi(sstr);
  6943. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  6944. {
  6945. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  6946. }
  6947. else
  6948. {
  6949. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6950. }
  6951. }
  6952. DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  6953. /*********************stackLevel***************************/
  6954. loc = strstr(payload, "stackLevel");
  6955. c = 0;
  6956. memset(sstr ,0, sizeof(sstr) );
  6957. while (loc[strlen("stackLevel")+2+c] != ',')
  6958. {
  6959. sstr[c] = loc[strlen("stackLevel")+2+c];
  6960. c++;
  6961. }
  6962. sstr[c] = '\0';
  6963. stackLevelInt = atoi(sstr);
  6964. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  6965. {
  6966. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  6967. }
  6968. else
  6969. {
  6970. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6971. }
  6972. DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  6973. /*********************chargingProfilePurpose***************************/
  6974. loc = strstr(payload, "chargingProfilePurpose");
  6975. c = 0;
  6976. memset(sstr ,0, sizeof(sstr) );
  6977. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6978. {
  6979. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6980. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6981. c++;
  6982. }
  6983. sstr[c] = '\0';
  6984. strcpy(chargingProfilePurposeStr,sstr);
  6985. DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  6986. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  6987. {
  6988. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  6989. }
  6990. else
  6991. {
  6992. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  6993. }
  6994. DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  6995. /*********************chargingProfileKind***************************/
  6996. loc = strstr(payload, "chargingProfileKind");
  6997. c = 0;
  6998. memset(sstr ,0, sizeof(sstr) );
  6999. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7000. {
  7001. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7002. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7003. c++;
  7004. }
  7005. sstr[c] = '\0';
  7006. strcpy(chargingProfileKindStr,sstr);
  7007. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7008. {
  7009. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7010. }
  7011. else
  7012. {
  7013. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7014. }
  7015. DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7016. /*********************recurrencyKind***************************/
  7017. loc = strstr(payload, "recurrencyKind");
  7018. if(loc != NULL)
  7019. {
  7020. c = 0;
  7021. memset(sstr ,0, sizeof(sstr) );
  7022. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7023. {
  7024. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7025. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7026. c++;
  7027. }
  7028. sstr[c] = '\0';
  7029. strcpy(recurrencyKindStr,sstr);
  7030. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7031. {
  7032. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7033. }
  7034. else
  7035. {
  7036. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7037. }
  7038. }
  7039. DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7040. /*********************validFrom***************************/
  7041. loc = strstr(payload, "validFrom");
  7042. if(loc != NULL)
  7043. {
  7044. c = 0;
  7045. memset(sstr ,0, sizeof(sstr) );
  7046. while (loc[3+strlen("validFrom")+c] != '\"')
  7047. {
  7048. sstr[c] = loc[3+strlen("validFrom")+c];
  7049. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7050. c++;
  7051. }
  7052. sstr[c] = '\0';
  7053. strcpy(validFromStr,sstr);
  7054. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7055. {
  7056. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7057. }
  7058. else
  7059. {
  7060. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7061. }
  7062. }
  7063. DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7064. /*********************validTo***************************/
  7065. loc = strstr(payload, "validTo");
  7066. if(loc != NULL)
  7067. {
  7068. c = 0;
  7069. memset(sstr ,0, sizeof(sstr) );
  7070. while (loc[3+strlen("validTo")+c] != '\"')
  7071. {
  7072. sstr[c] = loc[3+strlen("validTo")+c];
  7073. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7074. c++;
  7075. }
  7076. sstr[c] = '\0';
  7077. strcpy(validToStr,sstr);
  7078. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7079. {
  7080. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7081. }
  7082. else
  7083. {
  7084. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7085. }
  7086. }
  7087. DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7088. /*********************duration***************************/
  7089. loc = strstr(payload, "duration");
  7090. if(loc != NULL)
  7091. {
  7092. c = 0;
  7093. memset(sstr ,0, sizeof(sstr) );
  7094. while (loc[strlen("duration")+2+c] != ',')
  7095. {
  7096. sstr[c] = loc[strlen("duration")+2+c];
  7097. c++;
  7098. }
  7099. sstr[c] = '\0';
  7100. durationInt = atoi(sstr);
  7101. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7102. {
  7103. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7104. }
  7105. else
  7106. {
  7107. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7108. }
  7109. }
  7110. DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7111. /*********************startSchedule***************************/
  7112. loc = strstr(payload, "startSchedule");
  7113. if(loc != NULL)
  7114. {
  7115. c = 0;
  7116. memset(sstr ,0, sizeof(sstr) );
  7117. while (loc[3+strlen("startSchedule")+c] != '\"')
  7118. {
  7119. sstr[c] = loc[3+strlen("startSchedule")+c];
  7120. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7121. c++;
  7122. }
  7123. sstr[c] = '\0';
  7124. strcpy(startScheduleStr,sstr);
  7125. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7126. {
  7127. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7128. }
  7129. else
  7130. {
  7131. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7132. }
  7133. }
  7134. DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7135. /*********************chargingRateUnit***************************/
  7136. loc = strstr(payload, "chargingRateUnit");
  7137. if(loc != NULL)
  7138. {
  7139. c = 0;
  7140. memset(sstr ,0, sizeof(sstr) );
  7141. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7142. {
  7143. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7144. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7145. c++;
  7146. }
  7147. sstr[c] = '\0';
  7148. strcpy(chargingRateUnitStr,sstr);
  7149. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7150. {
  7151. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7152. }
  7153. else
  7154. {
  7155. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7156. }
  7157. }
  7158. DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7159. /****************chargingSchedulePeriod count start*******************/
  7160. int what_len = strlen("startPeriod");
  7161. char *where = payload;
  7162. if (what_len)
  7163. while ((where = strstr(where, "startPeriod"))) {
  7164. where += what_len;
  7165. chargingSchedulePeriodCount++;
  7166. }
  7167. DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7168. DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7169. where = payload;
  7170. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7171. {
  7172. /****************startPeriod*******************/
  7173. c=0;
  7174. loc = strstr(where, "startPeriod");
  7175. memset(sstr ,0, sizeof(sstr) );
  7176. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7177. {
  7178. sstr[c] = loc[strlen("startPeriod")+2+c];
  7179. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7180. c++;
  7181. }
  7182. sstr[c] = '\0';
  7183. startPeriodInt[periodNums] = atoi(sstr);
  7184. DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7185. DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7186. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7187. {
  7188. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7189. }
  7190. else
  7191. {
  7192. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7193. }
  7194. DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7195. /****************limit*******************/
  7196. c=0;
  7197. loc = strstr(where, "limit");
  7198. memset(sstr ,0, sizeof(sstr) );
  7199. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7200. {
  7201. sstr[c] = loc[strlen("limit")+2+c];
  7202. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7203. c++;
  7204. }
  7205. sstr[c] = '\0';
  7206. limitflaot[periodNums] = atof(sstr);
  7207. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7208. {
  7209. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7210. }
  7211. else
  7212. {
  7213. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7214. }
  7215. DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7216. /****************numberPhases*******************/
  7217. loc = strstr(where, "numberPhases");
  7218. if(loc != NULL)
  7219. {
  7220. c=0;
  7221. memset(sstr ,0, sizeof(sstr) );
  7222. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7223. {
  7224. sstr[c] = loc[strlen("numberPhases")+2+c];
  7225. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7226. c++;
  7227. }
  7228. sstr[c] = '\0';
  7229. numberPhasesInt[periodNums] = atoi(sstr);
  7230. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7231. {
  7232. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7233. }
  7234. else
  7235. {
  7236. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7237. }
  7238. }
  7239. where = loc;
  7240. }
  7241. DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7242. /****************chargingSchedulePeriod count end*******************/
  7243. /*********************minChargingRate***************************/
  7244. loc = strstr(payload, "minChargingRate");
  7245. if(loc != NULL)
  7246. {
  7247. c = 0;
  7248. memset(sstr ,0, sizeof(sstr) );
  7249. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7250. {
  7251. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7252. c++;
  7253. }
  7254. sstr[c] = '\0';
  7255. minChargingRateFloat = atof(sstr);
  7256. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7257. {
  7258. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7259. }
  7260. else
  7261. {
  7262. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7263. }
  7264. }
  7265. DEBUG_INFO("\n\n Replace a specific line in a text file with a new text :\n");
  7266. DEBUG_INFO("-------------------------------------------------------------\n");
  7267. DEBUG_INFO(" Input the file name to be opened : ");
  7268. //fgets(fname, MAX, stdin);
  7269. //fname[strlen(fname) - 1] = '\0';
  7270. #if 0
  7271. switch(connectorIdInt)
  7272. {
  7273. case 0:
  7274. strcpy(filename, ChargingProfile_0_JSON );
  7275. break;
  7276. case 1:
  7277. strcpy(filename, ChargingProfile_1_JSON );
  7278. break;
  7279. case 2:
  7280. strcpy(filename, ChargingProfile_2_JSON );
  7281. break;
  7282. default:
  7283. strcpy(filename, ChargingProfile_0_JSON );
  7284. break;
  7285. }
  7286. fptr1 = fopen(filename, "r");
  7287. if (!fptr1)
  7288. {
  7289. //file not exist
  7290. DEBUG_INFO("Unable to open the input file!!\n");
  7291. fptr1 = fopen(filename, "w+");
  7292. }
  7293. fclose(fptr1);
  7294. #endif
  7295. DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7296. DEBUG_INFO(" ChargingProfilePurposeTypeStr[TxProfile]=%s\n", ChargingProfilePurposeTypeStr[TxProfile]);
  7297. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7298. {
  7299. //printf("set chargingProfile 1-2\n");
  7300. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7301. if(connectorIdInt != 0)
  7302. {
  7303. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7304. goto end;
  7305. }
  7306. strcpy(filename, ChargePointMaxProfile_JSON );
  7307. fptr1 = fopen(filename, "r");
  7308. if (!fptr1)
  7309. {
  7310. //file not exist
  7311. DEBUG_INFO("Unable to open the input file!!\n");
  7312. fptr1 = fopen(filename, "w+");
  7313. }
  7314. fclose(fptr1);
  7315. }
  7316. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7317. {
  7318. //printf("set chargingProfile 1-3\n");
  7319. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7320. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7321. {
  7322. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7323. goto end;
  7324. }
  7325. switch(connectorIdInt)
  7326. {
  7327. case 0:
  7328. strcpy(filename, TxDefaultProfile_0_JSON );
  7329. break;
  7330. case 1:
  7331. strcpy(filename, TxDefaultProfile_1_JSON );
  7332. break;
  7333. case 2:
  7334. strcpy(filename, TxDefaultProfile_2_JSON );
  7335. break;
  7336. default:
  7337. strcpy(filename, TxDefaultProfile_0_JSON );
  7338. break;
  7339. }
  7340. fptr1 = fopen(filename, "r");
  7341. if (!fptr1)
  7342. {
  7343. //file not exist
  7344. DEBUG_INFO("Unable to open the input file!!\n");
  7345. fptr1 = fopen(filename, "w+");
  7346. }
  7347. fclose(fptr1);
  7348. }
  7349. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7350. {
  7351. //printf("set chargingProfile 1-4\n");
  7352. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7353. //check Transaction active
  7354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7355. {
  7356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7357. {
  7358. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8) // S_CHARGING
  7359. {
  7360. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7361. {
  7362. meet = TRUE;
  7363. break;
  7364. }
  7365. }
  7366. }
  7367. }
  7368. for (int index = 0; index < CCS_QUANTITY; index++)
  7369. {
  7370. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7371. {
  7372. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8) // S_CHARGING
  7373. {
  7374. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7375. {
  7376. meet = TRUE;
  7377. break;
  7378. }
  7379. }
  7380. }
  7381. }
  7382. for (int index = 0; index < GB_QUANTITY; index++)
  7383. {
  7384. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7385. {
  7386. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8) // S_CHARGING
  7387. {
  7388. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7389. {
  7390. meet = TRUE;
  7391. break;
  7392. }
  7393. }
  7394. }
  7395. }
  7396. if(meet == FALSE)
  7397. {
  7398. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7399. goto end;
  7400. }
  7401. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7402. {
  7403. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7404. goto end;
  7405. }
  7406. switch(connectorIdInt)
  7407. {
  7408. case 0:
  7409. break;
  7410. case 1:
  7411. strcpy(filename, TxProfile_1_JSON);
  7412. break;
  7413. case 2:
  7414. strcpy(filename, TxProfile_2_JSON);
  7415. break;
  7416. default:
  7417. strcpy(filename, TxProfile_1_JSON);
  7418. break;
  7419. }
  7420. fptr1 = fopen(filename, "r");
  7421. if (!fptr1)
  7422. {
  7423. //file not exist
  7424. DEBUG_INFO("Unable to open the input file!!\n");
  7425. fptr1 = fopen(filename, "w+");
  7426. }
  7427. fclose(fptr1);
  7428. }
  7429. /**********************************Write to File********************************************************/
  7430. FILE *infile;
  7431. FILE *outfile;
  7432. // open file for writing
  7433. infile = fopen (filename, "r");
  7434. outfile = fopen (tempfile, "w");
  7435. int d =0;
  7436. d = fgetc(infile);
  7437. DEBUG_INFO("d:%d\n",d);
  7438. rewind(infile);
  7439. if(d == EOF)
  7440. {
  7441. DEBUG_INFO("ChargingProfile content is NULL\n");
  7442. fprintf(outfile,"[%s]\n",payload);
  7443. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7444. fclose(infile);
  7445. fclose(outfile);
  7446. sprintf(rmFileCmd,"rm -f %s",filename);
  7447. system(rmFileCmd);
  7448. resultRename = rename(tempfile, filename);
  7449. if(resultRename == 0)
  7450. {
  7451. DEBUG_INFO("File chargingProfile renamed successfully");
  7452. }
  7453. else
  7454. {
  7455. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7456. }
  7457. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7458. //system(rmFileCmd);
  7459. }
  7460. else
  7461. {
  7462. char buf[1000]={0};
  7463. while (fgets(buf, sizeof(buf), infile) != NULL)
  7464. {
  7465. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7466. /*************************tempconnectorIdInt*********************************/
  7467. loc = strstr(buf, "connectorId");
  7468. c = 0;
  7469. memset(sstr ,0, sizeof(sstr) );
  7470. while (loc[strlen("connectorId")+2+c] != ',')
  7471. {
  7472. sstr[c] = loc[strlen("connectorId")+2+c];
  7473. c++;
  7474. }
  7475. sstr[c] = '\0';
  7476. tempconnectorIdInt = atoi(sstr);
  7477. /*************************tempchargingProfileIdInt*********************************/
  7478. loc = strstr(buf, "chargingProfileId");
  7479. c = 0;
  7480. memset(sstr ,0, sizeof(sstr) );
  7481. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7482. {
  7483. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7484. c++;
  7485. }
  7486. sstr[c] = '\0';
  7487. tempchargingProfileIdInt = atoi(sstr);
  7488. /*************************tempstackLevelInt*********************************/
  7489. loc = strstr(buf, "stackLevel");
  7490. c = 0;
  7491. memset(sstr ,0, sizeof(sstr) );
  7492. while (loc[strlen("stackLevel")+2+c] != ',')
  7493. {
  7494. sstr[c] = loc[strlen("stackLevel")+2+c];
  7495. c++;
  7496. }
  7497. sstr[c] = '\0';
  7498. tempstackLevelInt = atoi(sstr);
  7499. /*************************tempchargingProfilePurposeStr*********************************/
  7500. loc = strstr(payload, "chargingProfilePurpose");
  7501. c = 0;
  7502. memset(sstr ,0, sizeof(sstr) );
  7503. while ((loc[3+strlen("chargingProfilePurpose")+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != ']'))
  7504. {
  7505. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7506. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7507. c++;
  7508. }
  7509. sstr[c] = '\0';
  7510. strcpy(tempchargingProfilePurposeStr,sstr);
  7511. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7512. {
  7513. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7514. {
  7515. DEBUG_INFO("update set chargingProfile to file -0\n");
  7516. fprintf(outfile,"[%s]\n",payload);
  7517. }
  7518. else
  7519. {
  7520. DEBUG_INFO("update set chargingProfile to file -1\n");
  7521. if(tempstackLevelInt < stackLevelInt)
  7522. {
  7523. DEBUG_INFO("update set chargingProfile to file -2\n");
  7524. fprintf(outfile,"[%s]\n",payload);
  7525. fprintf(outfile,"[%s]\n",buf);
  7526. }
  7527. }
  7528. DEBUG_INFO("update set chargingProfile to file\n");
  7529. }
  7530. else
  7531. {
  7532. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7533. {
  7534. fprintf(outfile,"[%s]\n",payload);
  7535. fprintf(outfile,"[%s]\n",buf);
  7536. }
  7537. else if(tempstackLevelInt < stackLevelInt)
  7538. {
  7539. fprintf(outfile,"[%s]\n",payload);
  7540. fprintf(outfile,"[%s]\n",buf);
  7541. }
  7542. else
  7543. {
  7544. fprintf(outfile,"[%s]\n",buf);
  7545. fprintf(outfile,"[%s]\n",payload);
  7546. }
  7547. fprintf(outfile,"[%s]\n",buf);
  7548. DEBUG_INFO("add set chargingProfile to file\n");
  7549. }
  7550. } // end of while loop
  7551. fclose(infile);
  7552. fclose(outfile);
  7553. sprintf(rmFileCmd,"rm -f %s",filename);
  7554. system(rmFileCmd);
  7555. resultRename = rename(tempfile, filename);
  7556. if(resultRename == 0)
  7557. {
  7558. DEBUG_INFO("File chargingProfile renamed successfully");
  7559. }
  7560. else
  7561. {
  7562. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7563. }
  7564. result = TRUE;
  7565. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7566. }
  7567. end:
  7568. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7569. return result;
  7570. return result;
  7571. }
  7572. int handleTriggerMessageRequest(char *uuid, char *payload)
  7573. {
  7574. mtrace();
  7575. int result = FAIL;
  7576. int connectorIdIsNULL = FALSE;
  7577. int connectorIdInt =0;
  7578. char sstr[40]={0};
  7579. char requestedMessagestr[40]={0};
  7580. char comfirmstr[20]={0};
  7581. int c = 0;
  7582. char *loc;
  7583. DEBUG_INFO("handleTriggerMessageRequest\n");
  7584. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7585. c = 0;
  7586. loc = strstr(payload, "requestedMessage");
  7587. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7588. {
  7589. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7590. c++;
  7591. }
  7592. sstr[c] = '\0';
  7593. strcpy(requestedMessagestr, sstr);
  7594. c = 0;
  7595. loc = strstr(payload, "connectorId");
  7596. if(loc == NULL)
  7597. {
  7598. connectorIdIsNULL = TRUE;
  7599. }
  7600. else
  7601. {
  7602. memset(sstr ,0, sizeof(sstr) );
  7603. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7604. {
  7605. sstr[c] = loc[strlen("connectorId")+2+c];
  7606. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7607. c++;
  7608. }
  7609. sstr[c] = '\0';
  7610. connectorIdInt = atoi(sstr);
  7611. }
  7612. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7613. {
  7614. //connectorIdInt = json_object_get_int(connectorId);
  7615. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7616. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7617. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7618. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7619. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7620. }
  7621. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7622. {
  7623. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7624. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7625. return TRUE;
  7626. }
  7627. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7628. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7629. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7630. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7631. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7632. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7633. {
  7634. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7635. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7636. return TRUE;
  7637. }
  7638. else
  7639. {
  7640. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7641. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7642. }
  7643. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7644. {
  7645. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7646. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7647. }
  7648. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7649. {
  7650. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7651. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7652. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7653. }
  7654. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7655. {
  7656. sendBootNotificationRequest();
  7657. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7658. }
  7659. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7660. {
  7661. sendHeartbeatRequest(connectorIdInt);
  7662. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7663. }
  7664. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7665. {
  7666. if(connectorIdIsNULL == FALSE)
  7667. {
  7668. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7669. {
  7670. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7671. sendMeterValuesRequest(connectorIdInt -1);
  7672. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7673. }
  7674. //else
  7675. //{
  7676. // sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7677. //}
  7678. }
  7679. else
  7680. {
  7681. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7682. {
  7683. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  7684. sendMeterValuesRequest(idx);
  7685. }
  7686. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7687. }
  7688. }
  7689. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  7690. {
  7691. if(connectorIdIsNULL == FALSE)
  7692. {
  7693. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7694. {
  7695. sendStatusNotificationRequest(connectorIdInt -1);
  7696. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7697. }
  7698. // else
  7699. // {
  7700. // sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7701. // }
  7702. }
  7703. else
  7704. {
  7705. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7706. sendStatusNotificationRequest(idx);
  7707. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7708. }
  7709. }
  7710. // else
  7711. // {
  7712. // sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7713. // }
  7714. //end:
  7715. //sendTriggerMessageConfirmation(uuid,comfirmstr);
  7716. return result;
  7717. }
  7718. int handleUnlockConnectorRequest(char *uuid, char *payload)
  7719. {
  7720. mtrace();
  7721. int result = FAIL;
  7722. char sstr[6]={0};
  7723. int connectorIdInt =0;
  7724. char comfirmstr[20]={0};
  7725. int c = 0;
  7726. char *loc;
  7727. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  7728. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  7729. c = 0;
  7730. loc = strstr(payload, "connectorId");
  7731. memset(sstr ,0, sizeof(sstr) );
  7732. while (loc[strlen("connectorId")+2+c] != '}')
  7733. {
  7734. sstr[c] = loc[strlen("connectorId")+2+c];
  7735. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7736. c++;
  7737. }
  7738. sstr[c] = '\0';
  7739. connectorIdInt = atoi(sstr);
  7740. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  7741. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  7742. {
  7743. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  7744. goto end;
  7745. }
  7746. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  7747. {
  7748. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  7749. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  7750. goto end;
  7751. }
  7752. else
  7753. {
  7754. //check Transaction active
  7755. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  7756. {
  7757. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7758. {
  7759. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 1) ))
  7760. {
  7761. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  7762. }
  7763. }
  7764. for (int index = 0; index < CCS_QUANTITY; index++)
  7765. {
  7766. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 1) ))
  7767. {
  7768. //stop Transaction
  7769. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  7770. }
  7771. }
  7772. for (int index = 0; index < GB_QUANTITY; index++)
  7773. {
  7774. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)))
  7775. {
  7776. //stop Transaction
  7777. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  7778. }
  7779. }
  7780. }
  7781. else
  7782. {
  7783. for (int index = 0; index < AC_QUANTITY; index++)
  7784. {
  7785. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 8) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) ))
  7786. {
  7787. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  7788. }
  7789. }
  7790. }// END FOR AC ELSE
  7791. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  7792. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  7793. result = TRUE;
  7794. return result;
  7795. }
  7796. end:
  7797. //json_object_put(obj); --- remove temporally
  7798. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  7799. return result;
  7800. }
  7801. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  7802. {
  7803. mtrace();
  7804. int result = FAIL;
  7805. pthread_t t;
  7806. sendUpdateFirmwareConfirmation(uuid);
  7807. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  7808. pthread_join(t, NULL); // 等�?�執行�??��?完�?
  7809. //sendUpdateFirmwareConfirmation(uuid);
  7810. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  7811. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  7812. return result;
  7813. }
  7814. void *UpdateFirmwareProcess(void *data)
  7815. {
  7816. mtrace();
  7817. int retriesInt =0, retryIntervalInt=0;
  7818. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  7819. int port=0;
  7820. char locationstr[160]={0}, retrieveDatestr[30]={0};
  7821. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  7822. //char comfirmstr[20];
  7823. int isSuccess = 0;
  7824. char ftpbuf[200];
  7825. char temp[100];
  7826. char * pch;
  7827. int retriesISNULL=FALSE;
  7828. int retryInterval=FALSE;
  7829. int c = 0;
  7830. //int i = 0;
  7831. char *loc;
  7832. char sstr[300]={ 0 };
  7833. char *str = (char*) data; // ?��?輸入資�?
  7834. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  7835. /***************location **************/
  7836. loc = strstr(str, "location");
  7837. memset(sstr ,0, sizeof(sstr) );
  7838. c = 0;
  7839. while (loc[3+strlen("location")+c] != '\"')
  7840. {
  7841. sstr[c] = loc[3+strlen("location")+c];
  7842. c++;
  7843. }
  7844. sstr[c] = '\0';
  7845. strcpy(locationstr, sstr);
  7846. /***************retries**************/
  7847. c = 0;
  7848. loc = strstr(str, "retries");
  7849. if(loc == NULL)
  7850. {
  7851. retriesISNULL=TRUE;
  7852. }
  7853. else
  7854. {
  7855. memset(sstr ,0, sizeof(sstr) );
  7856. while (loc[strlen("retries")+2+c] != ',')
  7857. {
  7858. sstr[c] = loc[strlen("retries")+2+c];
  7859. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7860. c++;
  7861. }
  7862. sstr[c] = '\0';
  7863. }
  7864. if(retriesISNULL == FALSE)
  7865. {
  7866. retriesInt = atoi(sstr);
  7867. }
  7868. /***************retrieveDate **************/
  7869. loc = strstr(str, "retrieveDate");
  7870. memset(sstr ,0, sizeof(sstr) );
  7871. c = 0;
  7872. while (loc[3+strlen("retrieveDate")+c] != '\"')
  7873. {
  7874. sstr[c] = loc[3+strlen("retrieveDate")+c];
  7875. c++;
  7876. }
  7877. sstr[c] = '\0';
  7878. strcpy(retrieveDatestr, sstr);
  7879. /***************retryInterval **************/
  7880. c = 0;
  7881. loc = strstr(str, "retryInterval");
  7882. memset(sstr ,0, sizeof(sstr) );
  7883. if(loc == NULL)
  7884. {
  7885. retryInterval=TRUE;
  7886. }
  7887. else
  7888. {
  7889. while (loc[strlen("retryInterval")+2+c] != ',')
  7890. {
  7891. sstr[c] = loc[strlen("retryInterval")+2+c];
  7892. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7893. c++;
  7894. }
  7895. sstr[c] = '\0';
  7896. }
  7897. if(retryInterval==FALSE)
  7898. {
  7899. retryIntervalInt = atoi(sstr);
  7900. }
  7901. memset(ftppath, 0, sizeof(ftppath));
  7902. memset(path, 0, sizeof(path));
  7903. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  7904. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  7905. if(strncmp(locationstr,"http", 4) == 0)
  7906. {
  7907. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  7908. protocol, host, path);
  7909. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  7910. // protocol, user, password, host, path);
  7911. sprintf(ftppath,"/%s", path);
  7912. DEBUG_INFO("protocol =%s\n",protocol);
  7913. DEBUG_INFO("host =%s\n",host);
  7914. DEBUG_INFO("path =%s\n",path);
  7915. DEBUG_INFO("ftppath=%s\n",ftppath);
  7916. int ftppathlen=strlen(ftppath);
  7917. int i=1;
  7918. char filenametemp[50];
  7919. while(i < ftppathlen)
  7920. {
  7921. int len=ftppathlen-i;
  7922. if(ftppath[len]== 47) // '/' ascll code: 47
  7923. {
  7924. DEBUG_INFO("compare '/' all right\n");
  7925. break;
  7926. }
  7927. i=i+1;
  7928. }
  7929. memset(filenametemp, 0, sizeof(filenametemp));
  7930. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7931. filenametemp[i+1] = 0;
  7932. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  7933. do{
  7934. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  7935. sleep(retryIntervalInt);
  7936. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7937. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  7938. if(!isSuccess)
  7939. {
  7940. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  7941. }
  7942. else
  7943. {
  7944. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  7945. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  7946. isUpdateRequest = TRUE;
  7947. }
  7948. }
  7949. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  7950. {
  7951. memset(ftpbuf, 0, sizeof(ftpbuf));
  7952. memset(temp, 0, sizeof(temp));
  7953. DEBUG_INFO("locationstr=%s\n",locationstr);
  7954. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  7955. int ftppathlen=strlen(ftpbuf);
  7956. int i=1;
  7957. char filenametemp[50];
  7958. while(i < ftppathlen)
  7959. {
  7960. int len=ftppathlen-i;
  7961. if(ftpbuf[len]== 47) // '/' ascll code: 47
  7962. {
  7963. DEBUG_INFO(" compare '/' all right\n");
  7964. break;
  7965. }
  7966. i=i+1;
  7967. }
  7968. memset(filenametemp, 0, sizeof(filenametemp));
  7969. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  7970. filenametemp[i+1] = 0;
  7971. strncpy(temp, ftpbuf, ftppathlen-i+1);
  7972. pch=strchr(temp,'@');
  7973. if(pch==NULL)
  7974. {
  7975. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7976. protocol, host, &port, path);
  7977. strcpy(user,"anonymous");
  7978. strcpy(password,"");
  7979. }
  7980. else
  7981. {
  7982. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  7983. protocol, user, password, host, &port, path);
  7984. }
  7985. sscanf(host,"%[^/]%s",host1, path1);
  7986. sprintf(ftppath,"%s", path1);
  7987. DEBUG_INFO("protocol =%s\n",protocol);
  7988. DEBUG_INFO("user =%s\n",user);
  7989. DEBUG_INFO("password =%s\n",password);
  7990. DEBUG_INFO("host1 =%s\n",host1);
  7991. DEBUG_INFO("port =%d\n",port);
  7992. DEBUG_INFO("path1 =%s\n",path1);
  7993. DEBUG_INFO("ftppath=%s\n",ftppath);
  7994. //ftpFile(host, user, password, port, ftppath, fname);
  7995. //download firmware pthred
  7996. if(port == 0)
  7997. {
  7998. port = 21;
  7999. }
  8000. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8001. do{
  8002. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8003. sleep(retryIntervalInt);
  8004. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8005. if(!isSuccess)
  8006. {
  8007. //BulldogUtil.sleepMs(interval*1000);
  8008. DEBUG_INFO("Update firmware request and download file fail.\n");
  8009. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8010. }
  8011. else
  8012. {
  8013. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8014. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8015. isUpdateRequest = TRUE;
  8016. }
  8017. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8018. }
  8019. else
  8020. {
  8021. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8022. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8023. }
  8024. pthread_exit(NULL);
  8025. }
  8026. //==========================================
  8027. // Handle server response routine
  8028. //==========================================
  8029. void handleAuthorizeResponse(char *payload, int gun_index)
  8030. {
  8031. mtrace();
  8032. char expiryDatestr[30]={0};
  8033. char parentIdTagstr[20]={0};
  8034. char statusstr[20]={0};
  8035. char expiryDatestrtemp[30]={0};
  8036. char parentIdTagstrtemp[20]={0};
  8037. char statusstrtemp[20]={0};
  8038. int expiryDateISNULL=FALSE;
  8039. int parentIdTagISNULL=FALSE;
  8040. char sstr[160]={ 0 };
  8041. char* filename = AuthorizationCache_JSON;
  8042. char tempfile[] = "temp.json";
  8043. //char* buffer = NULL;
  8044. //FILE *pFile;
  8045. //char temp[400];
  8046. int c = 0;
  8047. char *loc;
  8048. int resultRename=0;
  8049. int responseIdTagInfoAsZero= 0;
  8050. char rmFileCmd[50]={0};
  8051. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8052. /***********expiryDate*************/
  8053. loc = strstr(payload, "expiryDate");
  8054. memset(sstr ,0, sizeof(sstr) );
  8055. c = 0;
  8056. if(loc == NULL)
  8057. {
  8058. expiryDateISNULL = TRUE;
  8059. }
  8060. else
  8061. {
  8062. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8063. {
  8064. sstr[c] = loc[3+strlen("expiryDate")+c];
  8065. c++;
  8066. }
  8067. sstr[c] = '\0';
  8068. strcpy(expiryDatestr, sstr);
  8069. }
  8070. /***********parentIdTag*************/
  8071. loc = strstr(payload, "parentIdTag");
  8072. memset(sstr ,0, sizeof(sstr) );
  8073. c = 0;
  8074. if(loc == NULL)
  8075. {
  8076. parentIdTagISNULL = TRUE;
  8077. }
  8078. else
  8079. {
  8080. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8081. {
  8082. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8083. c++;
  8084. }
  8085. sstr[c] = '\0';
  8086. strcpy(parentIdTagstr, sstr);
  8087. }
  8088. /***********status*************/
  8089. loc = strstr(payload, "status");
  8090. memset(sstr ,0, sizeof(sstr) );
  8091. c = 0;
  8092. while (loc[3+strlen("status")+c] != '\"')
  8093. {
  8094. sstr[c] = loc[3+strlen("status")+c];
  8095. c++;
  8096. }
  8097. sstr[c] = '\0';
  8098. strcpy(statusstr, sstr);
  8099. #ifdef SystemLogMessage
  8100. if(expiryDateISNULL == FALSE)
  8101. DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8102. if(parentIdTagISNULL == FALSE)
  8103. DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8104. DEBUG_INFO("status: %s\n", statusstr);
  8105. #endif
  8106. if(expiryDateISNULL == FALSE)
  8107. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8108. if(parentIdTagISNULL == FALSE)
  8109. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8110. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8111. //Update idTag information to authorization cache if supproted
  8112. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8113. {
  8114. if((access(filename,F_OK))!=-1)
  8115. {
  8116. DEBUG_INFO("AuthorizationCache exist.\n");
  8117. }
  8118. else
  8119. {
  8120. DEBUG_INFO("AuthorizationCache not exist\n");
  8121. FILE *log = fopen(filename, "w+");
  8122. if(log == NULL)
  8123. {
  8124. DEBUG_INFO("log is NULL\n");
  8125. goto out;
  8126. }
  8127. else
  8128. {
  8129. fclose(log);
  8130. }
  8131. }
  8132. FILE *infile;
  8133. FILE *outfile;
  8134. // open file for writing
  8135. infile = fopen (filename, "r");
  8136. outfile = fopen (tempfile, "w");
  8137. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8138. int c;
  8139. c = fgetc(infile);
  8140. DEBUG_INFO("c:%d\n",c);
  8141. rewind(infile);
  8142. if(c == EOF)
  8143. {
  8144. DEBUG_INFO("Orignal File is NULL\n");
  8145. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8146. {
  8147. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8148. }
  8149. else
  8150. {
  8151. strcpy(expiryDatestrtemp, "");
  8152. }
  8153. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8154. {
  8155. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8156. }
  8157. else
  8158. {
  8159. //write Authorize IdTag
  8160. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8161. }
  8162. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8163. fprintf(outfile,"[{\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n", expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8164. fclose(infile);
  8165. fclose(outfile);
  8166. sprintf(rmFileCmd,"rm -f %s",filename);
  8167. system(rmFileCmd);
  8168. resultRename = rename(tempfile, filename);
  8169. if(resultRename == 0)
  8170. {
  8171. DEBUG_INFO("File renamed successfully");
  8172. }
  8173. else
  8174. {
  8175. DEBUG_INFO("Error: unable to rename the file");
  8176. }
  8177. }
  8178. else
  8179. {
  8180. char buf[160]={0};
  8181. DEBUG_INFO("Orignal File is not NULL\n");
  8182. while (fgets(buf, sizeof(buf), infile) != NULL)
  8183. {
  8184. DEBUG_INFO("Orignal File is not NULL-1\n");
  8185. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8186. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8187. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8188. memset(statusstr, 0, sizeof(statusstrtemp));
  8189. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8190. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8191. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8192. /*********************expiryDate***************/
  8193. loc = strstr(buf, "expiryDate");
  8194. memset(sstr ,0, sizeof(sstr) );
  8195. c = 0;
  8196. while (loc[3+strlen("expiryDate")+c] != '\"')
  8197. {
  8198. sstr[c] = loc[3+strlen("expiryDate")+c];
  8199. c++;
  8200. }
  8201. sstr[c] = '\0';
  8202. strcpy(expiryDatestr,sstr);
  8203. /*********************parentIdTag***************/
  8204. loc = strstr(buf, "parentIdTag");
  8205. memset(sstr ,0, sizeof(sstr) );
  8206. c = 0;
  8207. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8208. {
  8209. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8210. c++;
  8211. }
  8212. sstr[c] = '\0';
  8213. strcpy(parentIdTagstr,sstr);
  8214. /*********************status***************/
  8215. loc = strstr(buf, "status");
  8216. memset(sstr ,0, sizeof(sstr) );
  8217. c = 0;
  8218. while (loc[3+strlen("status")+c] != '\"')
  8219. {
  8220. sstr[c] = loc[3+strlen("status")+c];
  8221. c++;
  8222. }
  8223. sstr[c] = '\0';
  8224. strcpy(statusstr,sstr);
  8225. if((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0)
  8226. {
  8227. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8228. responseIdTagInfoAsZero = 1;
  8229. }
  8230. else
  8231. {
  8232. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8233. }
  8234. if((responseIdTagInfoAsZero == 0)&&(strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0))
  8235. {
  8236. //modify item
  8237. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8238. {
  8239. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8240. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8241. }
  8242. else
  8243. {
  8244. strcpy(expiryDatestrtemp, "");
  8245. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8246. }
  8247. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8248. {
  8249. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8250. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8251. }
  8252. else
  8253. {
  8254. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8255. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8256. }
  8257. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8258. }
  8259. else
  8260. {
  8261. //wrie original item
  8262. strcpy(expiryDatestrtemp, expiryDatestr);
  8263. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8264. strcpy(statusstrtemp, statusstr);
  8265. }
  8266. fprintf(outfile,"[{\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n", expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8267. }
  8268. fclose(infile);
  8269. fclose(outfile);
  8270. sprintf(rmFileCmd,"rm -f %s",filename);
  8271. system(rmFileCmd);
  8272. resultRename = rename(tempfile, filename);
  8273. if(resultRename == 0)
  8274. {
  8275. DEBUG_INFO("File renamed successfully");
  8276. }
  8277. else
  8278. {
  8279. DEBUG_INFO("Error: unable to rename the file");
  8280. }
  8281. }
  8282. }
  8283. out:
  8284. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8285. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8286. authorizeRetryTimes = 0;
  8287. }
  8288. void handleBootNotificationResponse(char *payload, int gun_index)
  8289. {
  8290. mtrace();
  8291. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8292. char statusStr[12]={0};
  8293. char currentTimeStr[30]={0};
  8294. char *loc;
  8295. int intervalInt = 0;
  8296. int c = 0;
  8297. //double diff_t;
  8298. struct tm tp;
  8299. char buf[28]={0};
  8300. char timebuf[50]={0};
  8301. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8302. /*** interval ****/
  8303. c = 0;
  8304. loc = strstr(payload, "interval");
  8305. printf("loc=%s\n",loc);
  8306. memset(sstr ,0, sizeof(sstr) );
  8307. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8308. {
  8309. sstr[c] = loc[strlen("interval")+2+c];
  8310. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8311. c++;
  8312. }
  8313. sstr[c] = '\0';
  8314. DEBUG_INFO("id=%d\n",atoi(sstr));
  8315. intervalInt = atoi(sstr);
  8316. /***status ****/
  8317. loc = strstr(payload, "status");
  8318. memset(sstr ,0, sizeof(sstr) );
  8319. c = 0;
  8320. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8321. {
  8322. sstr[c] = loc[3+strlen("status")+c];
  8323. c++;
  8324. }
  8325. sstr[c] = '\0';
  8326. strcpy(statusStr, sstr);
  8327. /***currentTime ****/
  8328. loc = strstr(payload, "currentTime");
  8329. //printf("loc=%s\n",loc);
  8330. memset(sstr ,0, sizeof(sstr) );
  8331. c = 0;
  8332. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8333. {
  8334. sstr[c] = loc[3+strlen("currentTime")+c];
  8335. c++;
  8336. }
  8337. sstr[c] = '\0';
  8338. strcpy(currentTimeStr, sstr);
  8339. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8340. HeartBeatWaitTime = BootNotificationInterval;
  8341. #ifdef SystemLogMessage
  8342. DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8343. DEBUG_INFO("interval: %d\n", intervalInt);
  8344. DEBUG_INFO("status: %s\n", statusStr);
  8345. #endif
  8346. //write back to ShmOCPP16Data->BootNotification
  8347. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8348. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8349. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8350. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8351. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8352. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8353. {
  8354. server_sign = TRUE;
  8355. server_pending =FALSE;
  8356. }
  8357. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8358. {
  8359. server_pending = TRUE;
  8360. }
  8361. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8362. tp.tm_isdst = -1;
  8363. //time_t utc = mktime(&tp);
  8364. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8365. memset(timebuf, 0, sizeof timebuf);
  8366. sprintf(timebuf,"date -s '%s'",buf);
  8367. DEBUG_INFO("timebuf=%s\n",timebuf);
  8368. system(timebuf);
  8369. //==============================================
  8370. // RTC sync
  8371. //==============================================
  8372. system("/sbin/hwclock -w --systohc");
  8373. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8374. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8375. }
  8376. void handleDataTransferResponse(char *payload, int gun_index)
  8377. {
  8378. char sstr[160]={0};//sstr[200]={ 0 };
  8379. int c = 0;
  8380. char *loc;
  8381. DEBUG_INFO("handleDataTransferResponse ...\n");
  8382. loc = strstr(payload, "status");
  8383. printf("loc=%s\n",loc);
  8384. c = 0;
  8385. while (loc[3+strlen("status")+c] != '\"')
  8386. {
  8387. sstr[c] = loc[3+strlen("status")+c];
  8388. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8389. c++;
  8390. }
  8391. sstr[c] = '\0';
  8392. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8393. #ifdef SystemLogMessage
  8394. DEBUG_INFO("data: %s\n", payload);
  8395. #endif
  8396. }
  8397. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8398. {
  8399. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8400. //struct json_object *obj;
  8401. // obj = json_tokener_parse(payload);
  8402. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8403. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8404. //No fields are defined.
  8405. }
  8406. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8407. {
  8408. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8409. //struct json_object *obj;
  8410. // obj = json_tokener_parse(payload);
  8411. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8412. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8413. //No fields are defined.
  8414. }
  8415. void handleHeartbeatResponse(char *payload, int gun_index)
  8416. {
  8417. mtrace();
  8418. //double diff_t;
  8419. struct tm tp;
  8420. char buf[28]={0};
  8421. char timebuf[50]={0};
  8422. char sstr[30]={ 0 };
  8423. int c = 0;
  8424. char *loc;
  8425. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8426. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8427. c = 0;
  8428. loc = strstr(payload, "currentTime");
  8429. memset(sstr ,0, sizeof(sstr) );
  8430. while (loc[3+strlen("currentTime")+c] != '\"')
  8431. {
  8432. sstr[c] = loc[3+strlen("currentTime")+c];
  8433. c++;
  8434. }
  8435. sstr[c] = '\0';
  8436. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8437. #ifdef SystemLogMessage
  8438. DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8439. #endif
  8440. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8441. tp.tm_isdst = -1;
  8442. //time_t utc = mktime(&tp);
  8443. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8444. memset(timebuf, 0, sizeof timebuf);
  8445. sprintf(timebuf,"date -s '%s'",buf);
  8446. system(timebuf);
  8447. //==============================================
  8448. // RTC sync
  8449. //==============================================
  8450. system("/sbin/hwclock -w --systohc");
  8451. if(FirstHeartBeat == 0)
  8452. {
  8453. FirstHeartBeat = 1;
  8454. }
  8455. }
  8456. void handleMeterValuesResponse(char *payload, int gun_index)
  8457. {
  8458. mtrace();
  8459. //struct json_object *obj;
  8460. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8461. //No fields are defined.
  8462. }
  8463. void handleStartTransactionResponse(char *payload, int gun_index)
  8464. {
  8465. mtrace();
  8466. char sstr[30]={ 0 };
  8467. int c = 0;
  8468. char *loc;
  8469. int transactionIdInt = 0;
  8470. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8471. DEBUG_INFO("handleStartTransactionResponse\n");
  8472. /****************expiryDate********************/
  8473. loc = strstr(payload, "expiryDate");
  8474. if(loc == NULL)
  8475. {
  8476. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8477. }
  8478. else
  8479. {
  8480. c = 0;
  8481. memset(sstr ,0, sizeof(sstr) );
  8482. while (loc[3+strlen("expiryDate")+c] != '\"')
  8483. {
  8484. sstr[c] = loc[3+strlen("expiryDate")+c];
  8485. c++;
  8486. }
  8487. sstr[c] = '\0';
  8488. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8489. }
  8490. /****************parentIdTag********************/
  8491. loc = strstr(payload, "parentIdTag");
  8492. if(loc == NULL)
  8493. {
  8494. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8495. }
  8496. else
  8497. {
  8498. c = 0;
  8499. memset(sstr ,0, sizeof(sstr) );
  8500. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8501. {
  8502. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8503. c++;
  8504. }
  8505. sstr[c] = '\0';
  8506. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8507. }
  8508. /****************status********************/
  8509. loc = strstr(payload, "status");
  8510. if(loc == NULL)
  8511. {
  8512. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8513. }
  8514. else
  8515. {
  8516. c = 0;
  8517. memset(sstr ,0, sizeof(sstr) );
  8518. while (loc[3+strlen("status")+c] != '\"')
  8519. {
  8520. sstr[c] = loc[3+strlen("status")+c];
  8521. c++;
  8522. }
  8523. sstr[c] = '\0';
  8524. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8525. }
  8526. /****************transactionId********************/
  8527. c=0;
  8528. loc = strstr(payload, "transactionId");
  8529. memset(sstr ,0, sizeof(sstr) );
  8530. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8531. {
  8532. sstr[c] = loc[strlen("transactionId")+2+c];
  8533. c++;
  8534. }
  8535. sstr[c] = '\0';
  8536. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8537. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8538. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8539. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8540. #ifdef SystemLogMessage
  8541. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8542. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8543. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8544. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8545. #endif
  8546. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8547. {
  8548. //add Charging Record
  8549. SettingChargingRecord(gun_index, transactionIdInt);
  8550. }
  8551. }
  8552. void handleStatusNotificationResponse(char *payload, int gun_index)
  8553. {
  8554. mtrace();
  8555. printf("handleStatusNotificationResponse\n");
  8556. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8557. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8558. }
  8559. void handleStopTransactionnResponse(char *payload, int gun_index)
  8560. {
  8561. mtrace();
  8562. char sstr[30]={ 0 };
  8563. int c = 0;
  8564. char *loc;
  8565. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8566. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8567. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8568. loc = strstr(payload, "idTagInfo");
  8569. /***********************idTagInfo************************/
  8570. if(loc != NULL)
  8571. {
  8572. /***********************expiryDate************************/
  8573. loc = strstr(payload, "expiryDate");
  8574. if(loc != NULL)
  8575. {
  8576. memset(sstr ,0, sizeof(sstr) );
  8577. c = 0;
  8578. while (loc[3+strlen("expiryDate")+c] != '\"')
  8579. {
  8580. sstr[c] = loc[3+strlen("expiryDate")+c];
  8581. c++;
  8582. }
  8583. sstr[c] = '\0';
  8584. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8585. }
  8586. /***********************parentIdTag************************/
  8587. loc = strstr(payload, "parentIdTag");
  8588. if(loc != NULL)
  8589. {
  8590. memset(sstr ,0, sizeof(sstr) );
  8591. c = 0;
  8592. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8593. {
  8594. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8595. c++;
  8596. }
  8597. sstr[c] = '\0';
  8598. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8599. }
  8600. /***********************status************************/
  8601. loc = strstr(payload, "status");
  8602. memset(sstr ,0, sizeof(sstr) );
  8603. c = 0;
  8604. while (loc[3+strlen("status")+c] != '\"')
  8605. {
  8606. sstr[c] = loc[3+strlen("status")+c];
  8607. c++;
  8608. }
  8609. sstr[c] = '\0';
  8610. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8611. }
  8612. #ifdef SystemLogMessage
  8613. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8614. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8615. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8616. #endif
  8617. }
  8618. //==========================================
  8619. // Handle Error routine
  8620. //==========================================
  8621. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8622. {
  8623. mtrace();
  8624. #ifdef SystemLogMessage
  8625. DEBUG_INFO("errorCode: %s\n", errorCode);
  8626. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8627. DEBUG_INFO("errorDetails: %s\n", payload);
  8628. #endif
  8629. }
  8630. //===============================================
  8631. // Common routine
  8632. //===============================================
  8633. int initialConfigurationTable(void)
  8634. {
  8635. printf("initialConfigurationTable \n");
  8636. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8637. /*Core Profile*/
  8638. //AllowOfflineTxForUnknownId
  8639. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8640. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8643. //AuthorizationCacheEnabled
  8644. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE" /*"FALSE"*/ );
  8647. //AuthorizeRemoteTxRequests
  8648. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8651. //BlinkRepeat
  8652. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8655. //ClockAlignedDataInterval
  8656. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8659. //ConnectionTimeOut
  8660. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8663. //GetConfigurationMaxKeys
  8664. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  8667. // HeartbeatInterval
  8668. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  8669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  8670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  8671. // LightIntensity
  8672. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  8673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  8674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  8675. // LocalAuthorizeOffline
  8676. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;//0; --- for OCTT Test case
  8677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  8678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  8679. // LocalPreAuthorize
  8680. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1; //0; --- for OCTT Test case
  8681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  8682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  8683. // MaxEnergyOnInvalidId
  8684. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  8685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  8686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  8687. // MeterValuesAlignedData
  8688. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  8689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  8690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "V,A,KW,KWh" );
  8691. // MeterValuesAlignedDataMaxLength
  8692. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  8693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  8694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "4" );
  8695. // MeterValuesSampledData
  8696. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  8697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  8698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "V,A,KW,KWh" );
  8699. // MeterValuesSampledDataMaxLength
  8700. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  8701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  8702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "4" );
  8703. // MeterValueSampleInterval
  8704. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  8705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  8706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  8707. // MinimumStatusDuration
  8708. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  8709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  8710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  8711. // NumberOfConnectors
  8712. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  8713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  8714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  8715. // ResetRetries
  8716. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  8717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  8718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  8719. // ConnectorPhaseRotation
  8720. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  8721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  8722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  8723. // ConnectorPhaseRotationMaxLength
  8724. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  8725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  8726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  8727. // StopTransactionOnEVSideDisconnect
  8728. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 1;// 0; // --- for OCTT Test case
  8729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  8730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  8731. // StopTransactionOnInvalidId
  8732. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  8733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  8734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  8735. // StopTxnAlignedData
  8736. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  8737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  8738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  8739. // StopTxnAlignedDataMaxLength
  8740. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  8741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  8742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  8743. // StopTxnSampledData
  8744. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  8745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  8746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  8747. // StopTxnSampledDataMaxLength
  8748. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  8749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  8750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  8751. // SupportedFeatureProfiles
  8752. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  8753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  8754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  8755. // SupportedFeatureProfilesMaxLength
  8756. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  8757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  8758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  8759. // TransactionMessageAttempts
  8760. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  8761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  8762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  8763. // TransactionMessageRetryInterval
  8764. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  8765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  8766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  8767. // UnlockConnectorOnEVSideDisconnect
  8768. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 1;//0; --- for OCTT Test case
  8769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  8770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  8771. // WebSocketPingInterval
  8772. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  8773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  8774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  8775. /* Local Auth List Management Profile*/
  8776. #if 1
  8777. //For OCTT Test Case
  8778. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  8779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  8780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  8781. #endif
  8782. #if 0 // remove temporally
  8783. //LocalAuthListEnabled
  8784. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  8785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  8786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  8787. #endif
  8788. //LocalAuthListMaxLength
  8789. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  8790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  8791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  8792. //SendLocalListMaxLength
  8793. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  8794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  8795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  8796. //ReserveConnectorZeroSupported
  8797. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  8798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  8799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "TRUE"/*"FALSE"*/ ); //For OCTT Test Case
  8800. /* Smart Charging Profile */
  8801. //ChargeProfileMaxStackLevel
  8802. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  8803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  8804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  8805. // ChargingScheduleAllowedChargingRateUnit
  8806. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  8807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  8808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  8809. // ChargingScheduleMaxPeriods
  8810. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  8811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  8812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  8813. // ConnectorSwitch3to1PhaseSupported
  8814. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  8815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  8816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  8817. // MaxChargingProfilesInstalled
  8818. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  8819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  8820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  8821. return 0;
  8822. }
  8823. void getKeyValue(char *keyReq)
  8824. {
  8825. int isEmpty = FALSE;
  8826. int isKnowKey = FALSE;
  8827. //int unKnowIndex = 0;
  8828. DEBUG_INFO("getKeyValue \n");
  8829. if((keyReq == NULL) || (strlen(keyReq) == 0))
  8830. isEmpty = TRUE;
  8831. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  8832. {
  8833. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  8834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  8835. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  8836. {
  8837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  8838. }
  8839. else
  8840. {
  8841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  8842. }
  8843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  8844. isKnowKey = TRUE;
  8845. }
  8846. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  8847. {
  8848. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  8849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  8850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  8851. {
  8852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  8853. }
  8854. else
  8855. {
  8856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  8857. }
  8858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  8859. isKnowKey = TRUE;
  8860. }
  8861. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  8862. {
  8863. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  8864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  8865. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  8866. {
  8867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  8868. }
  8869. else
  8870. {
  8871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  8872. }
  8873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  8874. isKnowKey = TRUE;
  8875. }
  8876. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  8877. {
  8878. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  8879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  8880. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  8881. {
  8882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  8883. }
  8884. else
  8885. {
  8886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  8887. }
  8888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  8889. isKnowKey = TRUE;
  8890. }
  8891. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  8892. {
  8893. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  8894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  8895. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  8896. {
  8897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  8898. }
  8899. else
  8900. {
  8901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  8902. }
  8903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  8904. isKnowKey = TRUE;
  8905. }
  8906. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  8907. {
  8908. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  8909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  8910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  8911. {
  8912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  8913. }
  8914. else
  8915. {
  8916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  8917. }
  8918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  8919. isKnowKey = TRUE;
  8920. }
  8921. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  8922. {
  8923. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  8924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  8925. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  8926. {
  8927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  8928. }
  8929. else
  8930. {
  8931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  8932. }
  8933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  8934. isKnowKey = TRUE;
  8935. }
  8936. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  8937. {
  8938. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  8939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  8940. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  8941. {
  8942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  8943. }
  8944. else
  8945. {
  8946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  8947. }
  8948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  8949. isKnowKey = TRUE;
  8950. }
  8951. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  8952. {
  8953. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  8954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  8955. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  8956. {
  8957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  8958. }
  8959. else
  8960. {
  8961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  8962. }
  8963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  8964. isKnowKey = TRUE;
  8965. }
  8966. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  8967. {
  8968. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  8969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  8970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  8971. {
  8972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  8973. }
  8974. else
  8975. {
  8976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  8977. }
  8978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  8979. isKnowKey = TRUE;
  8980. }
  8981. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  8982. {
  8983. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  8984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  8985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  8986. {
  8987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  8988. }
  8989. else
  8990. {
  8991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  8992. }
  8993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  8994. isKnowKey = TRUE;
  8995. }
  8996. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  8997. {
  8998. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  8999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9001. {
  9002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9003. }
  9004. else
  9005. {
  9006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9007. }
  9008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9009. isKnowKey = TRUE;
  9010. }
  9011. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9012. {
  9013. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9016. {
  9017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9018. }
  9019. else
  9020. {
  9021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9022. }
  9023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9024. isKnowKey = TRUE;
  9025. }
  9026. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9027. {
  9028. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9030. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9031. {
  9032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9033. }
  9034. else
  9035. {
  9036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9037. }
  9038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9039. isKnowKey = TRUE;
  9040. }
  9041. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9042. {
  9043. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9046. {
  9047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9048. }
  9049. else
  9050. {
  9051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9052. }
  9053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9054. isKnowKey = TRUE;
  9055. }
  9056. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9057. {
  9058. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9061. {
  9062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9063. }
  9064. else
  9065. {
  9066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9067. }
  9068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9069. isKnowKey = TRUE;
  9070. }
  9071. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9072. {
  9073. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9076. {
  9077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9078. }
  9079. else
  9080. {
  9081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9082. }
  9083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9084. isKnowKey = TRUE;
  9085. }
  9086. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9087. {
  9088. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9091. {
  9092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9093. }
  9094. else
  9095. {
  9096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9097. }
  9098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9099. isKnowKey = TRUE;
  9100. }
  9101. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9102. {
  9103. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9106. {
  9107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9108. }
  9109. else
  9110. {
  9111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9112. }
  9113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9114. isKnowKey = TRUE;
  9115. }
  9116. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9117. {
  9118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9121. {
  9122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9123. }
  9124. else
  9125. {
  9126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9127. }
  9128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9129. isKnowKey = TRUE;
  9130. }
  9131. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9132. {
  9133. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9136. {
  9137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9138. }
  9139. else
  9140. {
  9141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9142. }
  9143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9144. isKnowKey = TRUE;
  9145. }
  9146. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9147. {
  9148. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9151. {
  9152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9153. }
  9154. else
  9155. {
  9156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9157. }
  9158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9159. isKnowKey = TRUE;
  9160. }
  9161. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9162. {
  9163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9166. {
  9167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9168. }
  9169. else
  9170. {
  9171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9172. }
  9173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9174. isKnowKey = TRUE;
  9175. }
  9176. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9177. {
  9178. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9181. {
  9182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9183. }
  9184. else
  9185. {
  9186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9187. }
  9188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9189. isKnowKey = TRUE;
  9190. }
  9191. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9192. {
  9193. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9196. {
  9197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9198. }
  9199. else
  9200. {
  9201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9202. }
  9203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9204. isKnowKey = TRUE;
  9205. }
  9206. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9207. {
  9208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9211. {
  9212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9213. }
  9214. else
  9215. {
  9216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9217. }
  9218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9219. isKnowKey = TRUE;
  9220. }
  9221. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9222. {
  9223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9226. {
  9227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9228. }
  9229. else
  9230. {
  9231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9232. }
  9233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9234. isKnowKey = TRUE;
  9235. }
  9236. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9237. {
  9238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9241. {
  9242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9243. }
  9244. else
  9245. {
  9246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9247. }
  9248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9249. isKnowKey = TRUE;
  9250. }
  9251. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9252. {
  9253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9256. {
  9257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9258. }
  9259. else
  9260. {
  9261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9262. }
  9263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9264. isKnowKey = TRUE;
  9265. }
  9266. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9267. {
  9268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9271. {
  9272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9273. }
  9274. else
  9275. {
  9276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9277. }
  9278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9279. isKnowKey = TRUE;
  9280. }
  9281. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9282. {
  9283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9286. {
  9287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9288. }
  9289. else
  9290. {
  9291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9292. }
  9293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9294. isKnowKey = TRUE;
  9295. }
  9296. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9297. {
  9298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9301. {
  9302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9303. }
  9304. else
  9305. {
  9306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9307. }
  9308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9309. isKnowKey = TRUE;
  9310. }
  9311. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9312. {
  9313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9316. {
  9317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9318. }
  9319. else
  9320. {
  9321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9322. }
  9323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9324. isKnowKey = TRUE;
  9325. }
  9326. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9327. {
  9328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9331. {
  9332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9333. }
  9334. else
  9335. {
  9336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9337. }
  9338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9339. isKnowKey = TRUE;
  9340. }
  9341. #if 1
  9342. //For OCTT Test Case
  9343. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9344. {
  9345. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9347. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9348. {
  9349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9350. }
  9351. else
  9352. {
  9353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9354. }
  9355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9356. isKnowKey = TRUE;
  9357. }
  9358. #endif
  9359. #if 0 // remove temporally
  9360. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9361. {
  9362. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9364. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9365. {
  9366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9367. }
  9368. else
  9369. {
  9370. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9371. }
  9372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9373. isKnowKey = TRUE;
  9374. }
  9375. #endif
  9376. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9377. {
  9378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9380. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9381. {
  9382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9383. }
  9384. else
  9385. {
  9386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9387. }
  9388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9389. isKnowKey = TRUE;
  9390. }
  9391. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9392. {
  9393. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9395. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9396. {
  9397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9398. }
  9399. else
  9400. {
  9401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9402. }
  9403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9404. isKnowKey = TRUE;
  9405. }
  9406. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9407. {
  9408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9410. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9411. {
  9412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9413. }
  9414. else
  9415. {
  9416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9417. }
  9418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9419. isKnowKey = TRUE;
  9420. }
  9421. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9422. {
  9423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9425. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9426. {
  9427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9428. }
  9429. else
  9430. {
  9431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9432. }
  9433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9434. isKnowKey = TRUE;
  9435. }
  9436. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9437. {
  9438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9440. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9441. {
  9442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9443. }
  9444. else
  9445. {
  9446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9447. }
  9448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9449. isKnowKey = TRUE;
  9450. }
  9451. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9452. {
  9453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9455. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9456. {
  9457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9458. }
  9459. else
  9460. {
  9461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9462. }
  9463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9464. isKnowKey = TRUE;
  9465. }
  9466. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9467. {
  9468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9470. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9471. {
  9472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9473. }
  9474. else
  9475. {
  9476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9477. }
  9478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9479. isKnowKey = TRUE;
  9480. }
  9481. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9482. {
  9483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9485. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9486. {
  9487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9488. }
  9489. else
  9490. {
  9491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9492. }
  9493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9494. isKnowKey = TRUE;
  9495. }
  9496. //=========================================================
  9497. if(!isEmpty && !isKnowKey)
  9498. {
  9499. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9500. strcpy(unknownkey[UnknownKeynum], keyReq);
  9501. UnknownKeynum = UnknownKeynum + 1;
  9502. }
  9503. }
  9504. void processUnkownKey(void)
  9505. {
  9506. DEBUG_INFO("processUnkownKey\n");
  9507. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9508. for(int index=0; index < UnknownKeynum; index++)
  9509. {
  9510. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9511. {
  9512. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9513. }
  9514. }
  9515. }
  9516. int setKeyValue(char *key, char *value)
  9517. {
  9518. int isSuccess = NotSupported;
  9519. int check_ascii=0;
  9520. #ifdef Debug
  9521. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9522. #endif
  9523. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9524. {
  9525. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9527. {
  9528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9529. isSuccess = ConfigurationStatus_Accepted;
  9530. }
  9531. else
  9532. {
  9533. isSuccess = ConfigurationStatus_Rejected;
  9534. }
  9535. }
  9536. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9537. {
  9538. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9539. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9540. {
  9541. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9542. isSuccess = ConfigurationStatus_Accepted;
  9543. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9544. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9545. }
  9546. else
  9547. {
  9548. isSuccess = ConfigurationStatus_Rejected;
  9549. }
  9550. }
  9551. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9552. {
  9553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9554. {
  9555. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9557. isSuccess = ConfigurationStatus_Accepted;
  9558. }
  9559. else
  9560. {
  9561. isSuccess = ConfigurationStatus_Rejected;
  9562. }
  9563. }
  9564. if(strcmp(key, "BlinkRepeat") == 0)
  9565. {
  9566. //Charger.BlinkRepeat = Integer.parseInt(value);
  9567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9568. {
  9569. check_ascii = value[0];
  9570. if( (check_ascii < 48) || (check_ascii > 57) )
  9571. {
  9572. isSuccess = ConfigurationStatus_Rejected;
  9573. }
  9574. else
  9575. {
  9576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9577. isSuccess = ConfigurationStatus_Accepted;
  9578. }
  9579. }
  9580. else
  9581. {
  9582. isSuccess = ConfigurationStatus_Rejected;
  9583. }
  9584. }
  9585. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9586. {
  9587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9588. {
  9589. check_ascii = value[0];
  9590. if( (check_ascii < 48) || (check_ascii > 57) )
  9591. {
  9592. isSuccess = ConfigurationStatus_Rejected;
  9593. }
  9594. else
  9595. {
  9596. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9598. isSuccess = ConfigurationStatus_Accepted;
  9599. }
  9600. }
  9601. else
  9602. {
  9603. isSuccess = ConfigurationStatus_Rejected;
  9604. }
  9605. }
  9606. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9607. {
  9608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9609. {
  9610. check_ascii = value[0];
  9611. if( (check_ascii < 48) || (check_ascii > 57) )
  9612. {
  9613. isSuccess = ConfigurationStatus_Rejected;
  9614. }
  9615. else
  9616. {
  9617. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value)*1000 );
  9619. isSuccess = ConfigurationStatus_Accepted;
  9620. }
  9621. }
  9622. else
  9623. {
  9624. isSuccess = ConfigurationStatus_Rejected;
  9625. }
  9626. }
  9627. if(strcmp(key, "HeartbeatInterval") == 0)
  9628. {
  9629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9630. {
  9631. check_ascii = value[0];
  9632. if( (check_ascii < 48) || (check_ascii > 57) )
  9633. {
  9634. isSuccess = ConfigurationStatus_Rejected;
  9635. }
  9636. else
  9637. {
  9638. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9640. HeartBeatWaitTime = atoi(value);
  9641. isSuccess = ConfigurationStatus_Accepted;
  9642. }
  9643. }
  9644. else
  9645. {
  9646. isSuccess = ConfigurationStatus_Rejected;
  9647. }
  9648. }
  9649. if(strcmp(key, "LightIntensity") == 0)
  9650. {
  9651. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9652. {
  9653. check_ascii = value[0];
  9654. if( (check_ascii < 48) || (check_ascii > 57) )
  9655. {
  9656. isSuccess = ConfigurationStatus_Rejected;
  9657. }
  9658. else
  9659. {
  9660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9661. isSuccess = ConfigurationStatus_Accepted;
  9662. }
  9663. }
  9664. else
  9665. {
  9666. isSuccess = ConfigurationStatus_Rejected;
  9667. }
  9668. }
  9669. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  9670. {
  9671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9672. {
  9673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9674. isSuccess = ConfigurationStatus_Accepted;
  9675. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9676. }
  9677. else
  9678. {
  9679. isSuccess = ConfigurationStatus_Rejected;
  9680. }
  9681. }
  9682. if(strcmp(key, "LocalPreAuthorize") == 0)
  9683. {
  9684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9685. {
  9686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9687. isSuccess = ConfigurationStatus_Accepted;
  9688. }
  9689. else
  9690. {
  9691. isSuccess = ConfigurationStatus_Rejected;
  9692. }
  9693. }
  9694. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  9695. {
  9696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9697. {
  9698. check_ascii = value[0];
  9699. if( (check_ascii < 48) || (check_ascii > 57) )
  9700. {
  9701. isSuccess = ConfigurationStatus_Rejected;
  9702. }
  9703. else
  9704. {
  9705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  9706. isSuccess = ConfigurationStatus_Accepted;
  9707. }
  9708. }
  9709. else
  9710. {
  9711. isSuccess = ConfigurationStatus_Rejected;
  9712. }
  9713. }
  9714. if(strcmp(key, "MeterValuesAlignedData") == 0)
  9715. {
  9716. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9717. {
  9718. //int valueLength = strlen(value);
  9719. for(int i = 0; value[i]; i++){
  9720. value[i] = tolower(value[i]);
  9721. }
  9722. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  9723. isSuccess = ConfigurationStatus_Accepted;
  9724. }
  9725. else
  9726. {
  9727. isSuccess = ConfigurationStatus_Rejected;
  9728. }
  9729. }
  9730. if(strcmp(key, "MeterValuesSampledData") == 0 )
  9731. {
  9732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9733. {
  9734. //int valueLength = strlen(value);
  9735. for(int i = 0; value[i]; i++){
  9736. value[i] = tolower(value[i]);
  9737. }
  9738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  9739. isSuccess = ConfigurationStatus_Accepted;
  9740. }
  9741. else
  9742. {
  9743. isSuccess = ConfigurationStatus_Rejected;
  9744. }
  9745. }
  9746. if(strcmp(key, "MeterValueSampleInterval") == 0)
  9747. {
  9748. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9749. {
  9750. check_ascii = value[0];
  9751. if( (check_ascii < 48) || (check_ascii > 57) )
  9752. {
  9753. isSuccess = ConfigurationStatus_Rejected;
  9754. }
  9755. else
  9756. {
  9757. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  9758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  9759. isSuccess = ConfigurationStatus_Accepted;
  9760. }
  9761. #ifdef Debug
  9762. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  9763. #endif
  9764. }
  9765. else
  9766. {
  9767. isSuccess = ConfigurationStatus_Rejected;
  9768. #ifdef Debug
  9769. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  9770. #endif
  9771. }
  9772. }
  9773. if(strcmp(key, "MinimumStatusDuration") == 0)
  9774. {
  9775. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9776. {
  9777. check_ascii = value[0];
  9778. if( (check_ascii < 48) || (check_ascii > 57) )
  9779. {
  9780. isSuccess = ConfigurationStatus_Rejected;
  9781. }
  9782. else
  9783. {
  9784. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  9785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  9786. isSuccess = ConfigurationStatus_Accepted;
  9787. }
  9788. }
  9789. else
  9790. {
  9791. isSuccess = ConfigurationStatus_Rejected;
  9792. }
  9793. }
  9794. if(strcmp(key, "ResetRetries") == 0)
  9795. {
  9796. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9797. {
  9798. check_ascii = value[0];
  9799. if( (check_ascii < 48) || (check_ascii > 57) )
  9800. {
  9801. isSuccess = ConfigurationStatus_Rejected;
  9802. }
  9803. else
  9804. {
  9805. //Charger.ResetRetries = Integer.parseInt(value);
  9806. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  9807. isSuccess = ConfigurationStatus_Accepted;
  9808. }
  9809. }
  9810. else
  9811. {
  9812. isSuccess = ConfigurationStatus_Rejected;
  9813. }
  9814. }
  9815. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  9816. {
  9817. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9818. {
  9819. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  9820. //int valueLength = strlen(value);
  9821. for(int i = 0; value[i]; i++){
  9822. value[i] = tolower(value[i]);
  9823. }
  9824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  9825. isSuccess = ConfigurationStatus_Accepted;
  9826. }
  9827. else
  9828. {
  9829. isSuccess = ConfigurationStatus_Rejected;
  9830. }
  9831. }
  9832. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  9833. {
  9834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9835. {
  9836. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  9837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9838. isSuccess = ConfigurationStatus_Accepted;
  9839. }
  9840. else
  9841. {
  9842. isSuccess = ConfigurationStatus_Rejected;
  9843. }
  9844. }
  9845. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  9846. {
  9847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9848. {
  9849. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  9850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9851. isSuccess = ConfigurationStatus_Accepted;
  9852. }
  9853. else
  9854. {
  9855. isSuccess = ConfigurationStatus_Rejected;
  9856. }
  9857. }
  9858. if(strcmp(key, "StopTxnAlignedData") == 0)
  9859. {
  9860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9861. {
  9862. //Charger.StopTxnAlignedData = value.toLowerCase();
  9863. //int valueLength = strlen(value);
  9864. for(int i = 0; value[i]; i++){
  9865. value[i] = tolower(value[i]);
  9866. }
  9867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  9868. isSuccess = ConfigurationStatus_Accepted;
  9869. }
  9870. else
  9871. {
  9872. isSuccess = ConfigurationStatus_Rejected;
  9873. }
  9874. }
  9875. if(strcmp(key, "StopTxnSampledData") == 0)
  9876. {
  9877. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9878. {
  9879. //Charger.StopTxnSampledData = value.toLowerCase();
  9880. //int valueLength = strlen(value);
  9881. for(int i = 0; value[i]; i++){
  9882. value[i] = tolower(value[i]);
  9883. }
  9884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  9885. isSuccess = ConfigurationStatus_Accepted;
  9886. }
  9887. else
  9888. {
  9889. isSuccess = ConfigurationStatus_Rejected;
  9890. }
  9891. }
  9892. if(strcmp(key, "TransactionMessageAttempts") == 0)
  9893. {
  9894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9895. {
  9896. check_ascii = value[0];
  9897. if( (check_ascii < 48) || (check_ascii > 57) )
  9898. {
  9899. isSuccess = ConfigurationStatus_Rejected;
  9900. }
  9901. else
  9902. {
  9903. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  9904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  9905. isSuccess = ConfigurationStatus_Accepted;
  9906. }
  9907. }
  9908. else
  9909. {
  9910. isSuccess = ConfigurationStatus_Rejected;
  9911. }
  9912. }
  9913. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  9914. {
  9915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9916. {
  9917. check_ascii = value[0];
  9918. if( (check_ascii < 48) || (check_ascii > 57) )
  9919. {
  9920. isSuccess = ConfigurationStatus_Rejected;
  9921. }
  9922. else
  9923. {
  9924. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  9925. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  9926. isSuccess = ConfigurationStatus_Accepted;
  9927. }
  9928. }
  9929. else
  9930. {
  9931. isSuccess = ConfigurationStatus_Rejected;
  9932. }
  9933. }
  9934. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  9935. {
  9936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9937. {
  9938. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  9939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9940. isSuccess = ConfigurationStatus_Accepted;
  9941. }
  9942. else
  9943. {
  9944. isSuccess = ConfigurationStatus_Rejected;
  9945. }
  9946. }
  9947. if(strcmp(key, "WebSocketPingInterval") == 0)
  9948. {
  9949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9950. {
  9951. check_ascii = value[0];
  9952. if( (check_ascii < 48) || (check_ascii > 57) )
  9953. {
  9954. isSuccess = ConfigurationStatus_Rejected;
  9955. }
  9956. else
  9957. {
  9958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  9959. isSuccess = ConfigurationStatus_Accepted;
  9960. }
  9961. }
  9962. else
  9963. {
  9964. isSuccess = ConfigurationStatus_Rejected;
  9965. }
  9966. }
  9967. #if 1
  9968. //For OCPP Test Case
  9969. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  9970. {
  9971. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9972. {
  9973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9974. isSuccess = ConfigurationStatus_Accepted;
  9975. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9976. }
  9977. else
  9978. {
  9979. isSuccess = ConfigurationStatus_Rejected;
  9980. }
  9981. }
  9982. #endif
  9983. #if 0 // rmove temporally
  9984. if(strcmp(key, "LocalAuthListEnabled") == 0)
  9985. {
  9986. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9987. {
  9988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9989. isSuccess = ConfigurationStatus_Accepted;
  9990. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9991. }
  9992. else
  9993. {
  9994. isSuccess = ConfigurationStatus_Rejected;
  9995. }
  9996. }
  9997. #endif
  9998. return isSuccess;
  9999. }
  10000. int updateSetting(char *key, char *value)
  10001. {
  10002. mtrace();
  10003. int isSuccess = FALSE;
  10004. char string[1000]={0}, buffer[1000]={0};
  10005. char strtemp[50]={0};
  10006. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10007. int pos, c = 0;
  10008. char *loc;
  10009. int pos1=0;
  10010. FILE *f = fopen("/var/www/settings1", "r");
  10011. if(f == NULL)
  10012. {
  10013. #ifdef Debug
  10014. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10015. #endif
  10016. return isSuccess;
  10017. }
  10018. fseek(f, 0, SEEK_END);
  10019. long fsize = ftell(f);
  10020. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10021. fread(string, 1, fsize, f);
  10022. fclose(f);
  10023. string[fsize] = 0;
  10024. loc = strstr(string, key/*"LocalAuthListEnabled"*/);
  10025. if(loc != NULL)
  10026. {
  10027. DEBUG_INFO("key exist!\n");
  10028. pos = loc - string-1;
  10029. f = fopen("/var/www/settings1", "w");
  10030. strncpy(buffer, string, pos);
  10031. fprintf(f, "%s", buffer);
  10032. memset(sstr ,0, sizeof(sstr) );
  10033. c = 0;
  10034. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10035. {
  10036. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10037. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10038. c++;
  10039. }
  10040. sstr[c] = '\0';
  10041. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10042. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10043. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10044. memset(buffer ,0, sizeof(buffer) );
  10045. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10046. //printf("buffer=%s",buffer);
  10047. fprintf(f, "%s", buffer);
  10048. fclose(f);
  10049. }
  10050. else
  10051. {
  10052. printf("key not exist!\n");
  10053. f = fopen("/var/www/settings1", "w+");
  10054. fputs(string, f);
  10055. fseek(f, -1, SEEK_CUR);
  10056. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10057. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10058. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10059. fclose(f);
  10060. }
  10061. isSuccess = TRUE;
  10062. return isSuccess;
  10063. }
  10064. #if 0
  10065. json_object * getJSONfromFile(char *filename)
  10066. {
  10067. mtrace();
  10068. FILE *fptr;
  10069. char str[] = "{}";
  10070. json_object * obj ;
  10071. fptr = fopen(filename, "rw+");
  10072. if(fptr == NULL) //if file does not exist, create it
  10073. {
  10074. fptr = fopen(filename, "w");
  10075. fwrite(str , 1 , sizeof(str) , fptr );
  10076. }
  10077. fclose(fptr);
  10078. //obj = new JSONObject(new JSONTokener((new URI("file:///" + filename)).toURL().openStream()));
  10079. obj = json_object_from_file(filename);
  10080. return obj;
  10081. }
  10082. #endif
  10083. int TransactionMessageAttemptsGet(void)
  10084. {
  10085. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10086. }
  10087. int FirstHeartBeatResponse(void)
  10088. {
  10089. return FirstHeartBeat;
  10090. }
  10091. #define SA struct sockaddr
  10092. #define MAXBUF 1024
  10093. //static int m_socket_data;
  10094. //static int sockfd;
  10095. int ReadHttpStatus(int sock){
  10096. //char c;
  10097. char buff[1024]="",*ptr=buff+1;
  10098. int bytes_received, status;
  10099. DEBUG_INFO("Begin Response ..\n");
  10100. while((bytes_received = recv(sock, ptr, 1, 0))){
  10101. if(bytes_received==-1){
  10102. perror("ReadHttpStatus");
  10103. exit(1);
  10104. }
  10105. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10106. ptr++;
  10107. }
  10108. *ptr=0;
  10109. ptr=buff+1;
  10110. sscanf(ptr,"%*s %d ", &status);
  10111. DEBUG_INFO("%s\n",ptr);
  10112. DEBUG_INFO("status=%d\n",status);
  10113. DEBUG_INFO("End Response ..\n");
  10114. return (bytes_received>0)?status:0;
  10115. }
  10116. //the only filed that it parsed is 'Content-Length'
  10117. int ParseHeader(int sock){
  10118. //char c;
  10119. char buff[1024]="",*ptr=buff+4;
  10120. int bytes_received;
  10121. DEBUG_INFO("Begin HEADER ..\n");
  10122. while((bytes_received = recv(sock, ptr, 1, 0))){
  10123. if(bytes_received==-1){
  10124. perror("Parse Header");
  10125. exit(1);
  10126. }
  10127. if(
  10128. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10129. (ptr[-1]=='\r') && (*ptr=='\n' )
  10130. ) break;
  10131. ptr++;
  10132. }
  10133. *ptr=0;
  10134. ptr=buff+4;
  10135. //printf("%s",ptr);
  10136. if(bytes_received){
  10137. ptr=strstr(ptr,"Content-Length:");
  10138. if(ptr){
  10139. sscanf(ptr,"%*s %d",&bytes_received);
  10140. }else
  10141. bytes_received=-1; //unknown size
  10142. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10143. }
  10144. DEBUG_INFO("End HEADER ..\n");
  10145. return bytes_received ;
  10146. }
  10147. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10148. {
  10149. //char domain[] = "sstatic.net", path[]="stackexchange/img/logos/so/so-logo-med.png";
  10150. //int sock;//, bytes_received;
  10151. char ftpbuf[200];
  10152. int systemresult;
  10153. //char temp[100];
  10154. DEBUG_INFO("filename=%s\n",filename);
  10155. DEBUG_INFO("url=%s\n",url);
  10156. memset(ftpbuf, 0, sizeof(ftpbuf));
  10157. sprintf(ftpbuf, "wget --tries=3 -O %s -c %s",filename, url);
  10158. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10159. systemresult = system(ftpbuf);
  10160. DEBUG_INFO("systemresult=%d\n",systemresult);
  10161. if(systemresult != 0)
  10162. {
  10163. DEBUG_INFO("http DownLoad error!\n");
  10164. return FALSE;
  10165. }
  10166. return TRUE;
  10167. }
  10168. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10169. {
  10170. char ftpbuf[200];
  10171. int systemresult;
  10172. //char temp[100];
  10173. #if 0
  10174. struct hostent* server;
  10175. char *IPbuffer;
  10176. server = gethostbyname(location);
  10177. // To convert an Internet network
  10178. // address into ASCII string
  10179. IPbuffer = inet_ntoa(*((struct in_addr*)
  10180. server->h_addr_list[0]));
  10181. #endif
  10182. memset(ftpbuf, 0, sizeof(ftpbuf));
  10183. sprintf(ftpbuf, "wget --tries=3 -O %s -c %s",filename, url);
  10184. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10185. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10186. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10187. systemresult = system(ftpbuf);
  10188. DEBUG_INFO("systemresult=%d\n",systemresult);
  10189. if(systemresult != 0)
  10190. {
  10191. printf("ftpget error!\n");
  10192. return FALSE;
  10193. }
  10194. return TRUE;
  10195. }
  10196. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10197. {
  10198. struct hostent* server;
  10199. char *IPbuffer;
  10200. char ftpbuf[200];
  10201. int systemresult;
  10202. // To retrieve host information
  10203. server = gethostbyname(location);
  10204. // To convert an Internet network
  10205. // address into ASCII string
  10206. IPbuffer = inet_ntoa(*((struct in_addr*)
  10207. server->h_addr_list[0]));
  10208. memset(ftpbuf, 0, sizeof(ftpbuf));
  10209. /* format : ftpput -u username -p passwd IP target source*/
  10210. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10211. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10212. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10213. systemresult = system(ftpbuf);
  10214. DEBUG_INFO("systemresult=%d\n",systemresult);
  10215. if(systemresult != 0)
  10216. {
  10217. DEBUG_INFO("ftpput error!\n");
  10218. return FALSE;
  10219. }
  10220. return TRUE;
  10221. }
  10222. int SettingChargingRecord(int target, int transactionId)
  10223. {
  10224. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  10225. {
  10226. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10227. {
  10228. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8))
  10229. {
  10230. addBuff(target, transactionId, 0);
  10231. return TRUE;
  10232. }
  10233. }
  10234. for (int index = 0; index < CCS_QUANTITY; index++)
  10235. {
  10236. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8))
  10237. {
  10238. addBuff(target, transactionId, 0);
  10239. return TRUE;
  10240. }
  10241. }
  10242. for (int index = 0; index < GB_QUANTITY; index++)
  10243. {
  10244. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8))
  10245. {
  10246. addBuff(target, transactionId, 0);
  10247. return TRUE;
  10248. }
  10249. }
  10250. }
  10251. else
  10252. {
  10253. for (int index = 0; index < AC_QUANTITY; index++)
  10254. {
  10255. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 8))
  10256. {
  10257. addBuff(target, transactionId, 0);
  10258. return TRUE;
  10259. }
  10260. }
  10261. }
  10262. return FALSE;
  10263. }
  10264. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10265. {
  10266. int isSuccess = FALSE;
  10267. //char *query = NULL;
  10268. sqlite3_stmt *stmt;
  10269. int rc; // return code
  10270. char str[20];
  10271. sprintf(str,"%d",user_id);
  10272. 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 */
  10273. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10274. rc = sqlite3_step(stmt); /* 3 */
  10275. if (rc != SQLITE_DONE) {
  10276. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10277. goto out;
  10278. }
  10279. sqlite3_finalize(stmt);
  10280. // free(query);
  10281. out:
  10282. /*
  10283. * close SQLite database
  10284. */
  10285. sqlite3_close(db);
  10286. printf("database closed.\n");
  10287. return isSuccess;
  10288. }
  10289. /**
  10290. * Place the contents of the specified file into a memory buffer
  10291. *
  10292. * @param[in] filename The path and name of the file to read
  10293. * @param[out] filebuffer A pointer to the contents in memory
  10294. * @return status 0 success, 1 on failure
  10295. */
  10296. int get_file_contents(const char* filename, char** outbuffer) {
  10297. FILE* file = NULL;
  10298. long filesize;
  10299. const int blocksize = 1;
  10300. size_t readsize;
  10301. char* filebuffer;
  10302. // Open the file
  10303. file = fopen(filename, "r");
  10304. if (NULL == file)
  10305. {
  10306. printf("'%s' not opened\n", filename);
  10307. exit(EXIT_FAILURE);
  10308. }
  10309. // Determine the file size
  10310. fseek(file, 0, SEEK_END);
  10311. filesize = ftell(file);
  10312. rewind (file);
  10313. // Allocate memory for the file contents
  10314. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10315. *outbuffer = filebuffer;
  10316. if (filebuffer == NULL)
  10317. {
  10318. fputs ("malloc out-of-memory", stderr);
  10319. exit(EXIT_FAILURE);
  10320. }
  10321. // Read in the file
  10322. readsize = fread(filebuffer, blocksize, filesize, file);
  10323. if (readsize != filesize)
  10324. {
  10325. fputs ("didn't read file completely",stderr);
  10326. exit(EXIT_FAILURE);
  10327. }
  10328. // Clean exit
  10329. fclose(file);
  10330. return EXIT_SUCCESS;
  10331. }
  10332. static int selectSqlCount = 0;
  10333. static int callback(void *data, int argc, char **argv, char **azColName){
  10334. int i;
  10335. printf("%s: ", (const char*)data);
  10336. selectSqlCount = argc;
  10337. for(i = 0; i<argc; i++){
  10338. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10339. }
  10340. printf("\n");
  10341. return 0;
  10342. }
  10343. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10344. //int i;
  10345. //printf("%s:\n", (const char*)data);
  10346. localversion = argv[5] ? atoi(argv[5]) : 0;
  10347. printf("localversion=%d\n", localversion);
  10348. return 0;
  10349. }
  10350. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10351. //int i;
  10352. //printf("%s:\n", (const char*)data);
  10353. //idTag
  10354. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10355. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10356. //parentIdTag
  10357. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10358. //expir_date
  10359. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10360. //status
  10361. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10362. //version
  10363. idTagQuery.listVersionInt = atoi(argv[5]);
  10364. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10365. return 0;
  10366. }
  10367. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10368. int i;
  10369. //printf("%s:\n", (const char*)data);
  10370. #if 1
  10371. for(i=0; i<argc; i++){
  10372. printf("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10373. }
  10374. //printf("");
  10375. #endif
  10376. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10377. // printf("localversion=%d\n", localversion);
  10378. return 0;
  10379. }
  10380. /** sqlite3_exec?„å?è°ƒã€?
  10381. *
  10382. * ?‘控?¶å�°?“å�°?¥è¯¢?„ç??œã€?
  10383. *
  10384. * @param in data 传递ç??žè??½æ•°?„æ•°?®ã€?
  10385. * @param in n_columns sqlite3_exec?§è?结æ??†ä¸­?—ç??°é???
  10386. * @param in col_values sqlite3_exec?§è?结æ??†ä¸­æ¯�ä??—ç??°æ�®??
  10387. * @param in col_names sqlite3_exec?§è?结æ??†ä¸­æ¯�ä??—ç??�称??
  10388. * @return ?¶æ€�ç???
  10389. */
  10390. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10391. {
  10392. for (int i = 0; i < n_columns; i++)
  10393. {
  10394. DEBUG_INFO("%s/t", col_values[i]);
  10395. }
  10396. DEBUG_INFO("/n");
  10397. return 0;
  10398. }
  10399. void OCPP_getListVerion()
  10400. {
  10401. int rc = 0;
  10402. // const char* data = "Callback function called";
  10403. char sql[100];
  10404. char zErrMsg[100];
  10405. memset(sql, 0, 100);
  10406. memset(zErrMsg, 0, 100);
  10407. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10408. /* Execute SQL statement */
  10409. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10410. printf("rc=%d\n",rc);
  10411. if( rc != SQLITE_OK ){
  10412. printf("SQL error: %s", zErrMsg);
  10413. //sqlite3_free(zErrMsg);
  10414. }else{
  10415. printf("Operation done successfully");
  10416. }
  10417. }
  10418. void OCPP_getIdTag(char *idTag)
  10419. {
  10420. int rc = 0;
  10421. // const char* data = "Callback function called";
  10422. char sql[100];
  10423. char zErrMsg[100];
  10424. memset(sql, 0, 100);
  10425. memset(zErrMsg, 0, 100);
  10426. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10427. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10428. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10429. /* Execute SQL statement */
  10430. printf("OCPP_getIdTag -1\n");
  10431. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10432. printf("OCPP_getIdTag -2\n");
  10433. printf("rc=%d\n",rc);
  10434. if( rc != SQLITE_OK ){
  10435. printf("SQL error: %s", zErrMsg);
  10436. //sqlite3_free(zErrMsg);
  10437. }else{
  10438. printf("Operation done successfully");
  10439. }
  10440. printf("OCPP_getIdTag -3\n");
  10441. //return ver;
  10442. }
  10443. void OCPP_get_TableAuthlocalAllData(void)
  10444. {
  10445. int rc = 0;
  10446. // const char* data = "Callback function called";
  10447. char sql[100];
  10448. char zErrMsg[100];
  10449. memset(sql, 0, 100);
  10450. memset(zErrMsg, 0, 100);
  10451. sprintf(sql,"select * from ocpp_auth_local ");
  10452. /* Execute SQL statement */
  10453. printf("OCPP_get_TableAuthlocalAllData -1\n");
  10454. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10455. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10456. printf("OCPP_get_TableAuthlocalAllData -2\n");
  10457. printf("rc=%d\n",rc);
  10458. if( rc != SQLITE_OK ){
  10459. printf("SQL error: %s", zErrMsg);
  10460. //sqlite3_free(zErrMsg);
  10461. }else{
  10462. printf("Operation done successfully");
  10463. }
  10464. printf("OCPP_get_TableAuthlocalAllData -3\n");
  10465. //return ver;
  10466. }
  10467. int OCPP_cleanLocalList()
  10468. {
  10469. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10470. char *errMsg = 0;
  10471. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10472. if (SQLITE_OK != rc)
  10473. {
  10474. printf("%s\n",errMsg);
  10475. return FALSE;
  10476. }
  10477. else
  10478. {
  10479. printf("delete ocpp_auth_local table successfully\n");
  10480. }
  10481. return TRUE;
  10482. }
  10483. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10484. {
  10485. int isSuccess = FALSE;
  10486. int ret = 0;
  10487. //const char* data = "Callback function called";
  10488. char sql[200];
  10489. char zErrMsg[100];
  10490. memset(sql, 0, 200);
  10491. memset(zErrMsg, 0, 100);
  10492. 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);
  10493. printf("sql:%s\n", sql);
  10494. printf("OCPP_addLocalList -5\n");
  10495. /* Execute SQL statement */
  10496. //zErrMsg = 0;
  10497. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10498. printf("OCPP_addLocalList -6\n");
  10499. if( ret != SQLITE_OK ){
  10500. printf("SQL error: %s\n", zErrMsg);
  10501. // free(zErrMsg);
  10502. // free(sql);
  10503. return isSuccess;
  10504. }
  10505. printf("successfully Insert records created\n");
  10506. isSuccess = TRUE;
  10507. return isSuccess;
  10508. }
  10509. void OCPP_deleteIdTag(char *idTag)
  10510. {
  10511. //int ver = 0;
  10512. //int isSuccess = FALSE;
  10513. int rc = 0;
  10514. char sql[100];
  10515. char zErrMsg[100];
  10516. memset(sql, 0, 100);
  10517. memset(zErrMsg, 0, 100);
  10518. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10519. /* Execute SQL statement */
  10520. printf("OCPP_getIdTag -1\n");
  10521. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10522. printf("OCPP_getIdTag -2\n");
  10523. printf("rc=%d\n",rc);
  10524. if( rc != SQLITE_OK ){
  10525. printf("SQL error: %s", zErrMsg);
  10526. //sqlite3_free(zErrMsg);
  10527. }else{
  10528. printf("Operation done successfully");
  10529. }
  10530. printf("OCPP_getIdTag -3\n");
  10531. }
  10532. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10533. {
  10534. int isSuccess = FALSE;
  10535. int ret = 0;
  10536. const char* data = "Callback function called";
  10537. char sql[200];
  10538. char zErrMsg[100];
  10539. memset(sql, 0, 200);
  10540. memset(zErrMsg, 0, 100);
  10541. /* selectFromTable */
  10542. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10543. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10544. /* Execute SQL statement */
  10545. selectSqlCount = 0;
  10546. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10547. if( ret != SQLITE_OK ){
  10548. printf("Error SQL: %s\n", zErrMsg);
  10549. }
  10550. printf("successfully select operation done\n");
  10551. memset(sql, 0, 200);
  10552. memset(zErrMsg, 0, 100);
  10553. if(selectSqlCount == 0)
  10554. {
  10555. //Insert
  10556. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
  10557. 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);
  10558. printf("sql:%s\n", sql);
  10559. /* Execute SQL statement */
  10560. //zErrMsg = 0;
  10561. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10562. if( ret != SQLITE_OK ){
  10563. printf("SQL error: %s\n", zErrMsg);
  10564. return isSuccess;
  10565. }
  10566. printf("successfully Insert records created\n");
  10567. isSuccess = TRUE;
  10568. }
  10569. else
  10570. {
  10571. //Update
  10572. /* Create merged SQL statement */
  10573. 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);
  10574. /* Execute SQL statement */
  10575. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10576. if( ret != SQLITE_OK ){
  10577. printf("SQL error: %s\n", zErrMsg);
  10578. //sqlite3_free(zErrMsg);
  10579. //sqlite3_free(sql);
  10580. return isSuccess;
  10581. }
  10582. printf("Successfully operation done \n");
  10583. isSuccess = TRUE;
  10584. }
  10585. return isSuccess;
  10586. }
  10587. char *GetOcppServerURL()
  10588. {
  10589. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10590. memset(OcppHost, 0, sizeof(OcppHost));
  10591. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10592. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10593. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10594. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10595. printf("OcppProtocol =%s\n",OcppProtocol);
  10596. printf("OcppHost =%s\n",OcppHost);
  10597. printf("OcppPort =%d\n",OcppPort);
  10598. printf("OcppTempPath =%s\n",OcppTempPath);
  10599. return OcppHost;
  10600. }
  10601. char *GetOcppPath()
  10602. {
  10603. if(OcppTempPath == NULL)
  10604. {
  10605. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10606. }
  10607. else
  10608. {
  10609. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10610. }
  10611. printf("OcppPath=%s\n",OcppPath);
  10612. return OcppPath;
  10613. }
  10614. int GetOcppPort()
  10615. {
  10616. return OcppPort;
  10617. }
  10618. #if 0
  10619. void Send(struct json_object *message)
  10620. {
  10621. printf("Send -1 \n");
  10622. printf("message=%s\n",json_object_to_json_string(message));
  10623. LWS_Send(json_object_to_json_string(message));
  10624. }
  10625. #endif
  10626. void LWS_Send(char * str)
  10627. {
  10628. #if 1
  10629. if(ShmOCPP16Data->OcppConnStatus == 0)
  10630. {
  10631. DEBUG_INFO("\n offline now !!!\n");
  10632. return;
  10633. }
  10634. #endif
  10635. pthread_mutex_lock(&lock);
  10636. memset(SendBuffer,0,SendBufLen);
  10637. sprintf((char *)SendBuffer, "%s", str);
  10638. pthread_mutex_unlock(&lock);
  10639. lws_callback_on_writable(wsi_client);
  10640. lws_service(context, 10000);//timeout_ms
  10641. //usleep(10000); // 等�??��?微�?
  10642. DEBUG_INFO("Send message end\n");
  10643. }