MessageHandler.c 451 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928
  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 "hashmap.h"
  21. #include "ShareMemory.h"
  22. #include "TransactionQueue.h"
  23. #include "SystemLogMessage.h"
  24. #include "define.h"
  25. #include "ShareMemory.h"
  26. #include "SystemLogMessage.h"
  27. //#include "config.h"
  28. #include <sys/socket.h>
  29. #include <netinet/in.h>
  30. #include <stdlib.h>
  31. /*for sendfile()*/
  32. #include <sys/sendfile.h>
  33. /*for O_RDONLY*/
  34. #include <fcntl.h>
  35. #include "sqlite3.h"
  36. #include <arpa/inet.h>
  37. //#define _GNU_SOURCE
  38. #include <time.h>
  39. #include "MessageHandler.h"
  40. #include <assert.h>
  41. #include <pthread.h>
  42. #include <mcheck.h>
  43. #define PASS 1
  44. #define FAIL -1
  45. #define FALSE 0
  46. #define TRUE 1 // Option 1
  47. //ChargePointMaxProfile
  48. #define ChargePointMaxProfile_JSON "../Storage/OCPP/ChargePointMaxProfile.json"
  49. //TxDefaultProfile
  50. #define TxDefaultProfile_0_JSON "../Storage/OCPP/TxDefaultProfile_0.json"
  51. #define TxDefaultProfile_1_JSON "../Storage/OCPP/TxDefaultProfile_1.json"
  52. #define TxDefaultProfile_2_JSON "../Storage/OCPP/TxDefaultProfile_2.json"
  53. //TxProfile
  54. #define TxProfile_1_JSON "../Storage/OCPP/TxProfile_1.json"
  55. #define TxProfile_2_JSON "../Storage/OCPP/TxProfile_2.json"
  56. #define ChargingProfile_0_JSON "../Storage/OCPP/chargingprofile_0.json"
  57. #define ChargingProfile_1_JSON "../Storage/OCPP/chargingprofile_1.json"
  58. #define ChargingProfile_2_JSON "../Storage/OCPP/chargingprofile_2.json"
  59. #define AuthorizationCache_JSON "../Storage/OCPP/AuthorizationCache.json"
  60. #define LocalAuthorizationList_JSON "../Storage/OCPP/LocalAuthorizationList.json"
  61. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  62. struct StatusCodeData *ShmStatusCodeData;
  63. struct PsuData *ShmPsuData ;
  64. struct OCPP16Data *ShmOCPP16Data;
  65. // define Macro
  66. #define SystemLogMessage
  67. // OCPP Message Type
  68. #define MESSAGE_TYPE_CALL 2
  69. #define MESSAGE_TYPE_CALLRESULT 3
  70. #define MESSAGE_TYPE_CALLERROR 4
  71. //
  72. #define server_cycle_Status 120
  73. #define MACROSTR(k) #k
  74. //ConfigurationMaxKeys
  75. #define GetConfigurationMaxKeysNUM 43
  76. //char guid[37];
  77. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  78. char queuedata[2000]={0};
  79. //===============================
  80. // Configuration: unknownkey
  81. //===============================
  82. static char unknownkey[10][20]={0};
  83. static int UnknownKeynum = 0;
  84. //===============================
  85. // Gun Total Numbers
  86. //===============================
  87. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  88. static int gunTotalNumber=0;
  89. //===============================
  90. // Local List Version
  91. //===============================
  92. static int localversion=0;
  93. static char idTagAuthorization[32]={0};
  94. //===============================
  95. // OCPP Path
  96. //===============================
  97. char OcppPath[160]={};
  98. char OcppProtocol[10]={0},OcppHost[50]={0}, OcppTempPath[50]={0};
  99. int OcppPort=0;
  100. //===============================
  101. // OCPP sign variable
  102. //===============================
  103. int server_sign = FALSE;
  104. int server_pending = FALSE;
  105. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  106. int BootNotificationInterval = 0;
  107. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  108. //===============================
  109. // OCPP auth variable
  110. //===============================
  111. int authenrequest = FALSE;
  112. int authorizeRetryTimes = 0; //number of Retry times
  113. //===============================
  114. // OCPP other variables
  115. //===============================
  116. int isUpdateRequest = FALSE;
  117. static int HeartBeatWaitTime = 10;
  118. static int FirstHeartBeat = 0;
  119. static int FirmwareStatusNotificationStatus = 3; // Idle
  120. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  121. //========================================
  122. // OCPP status/previous related variables
  123. //========================================
  124. static int GunStatusInterval = 10;
  125. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  126. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  127. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  128. static int GbPreviousSystemStatus[GB_QUANTITY];
  129. static int AcPreviousSystemStatus[AC_QUANTITY];
  130. int TransactionMessageAttemptsValue = 0;
  131. int TransactionMessageRetryIntervalValue = 0;
  132. static struct OCPPAuthLocalElemet
  133. {
  134. int listVersionInt;
  135. char idTagstr[20];
  136. char parentIdTag[20];
  137. char expiryDate[30];
  138. char idTagstatus[16];
  139. }idTagQuery;
  140. //=============================================
  141. // OCPP HeartBeat Response Not Receive Counts
  142. //============================================
  143. static int HeartBeatWithNOResponse = 0;
  144. extern struct lws *wsi_client;
  145. extern struct lws_context *context;
  146. #if 0
  147. extern unsigned char *SendBuffer;
  148. #endif
  149. extern unsigned char SendBuffer[4096];
  150. extern int SendBufLen;
  151. //extern map_t hashMap;
  152. //extern data_struct_t* mapItem; --- remove for temporally
  153. //extern data_struct_t mapItem[0];
  154. extern char *random_uuid( char buf[37] );
  155. extern void split(char **arr, char *str, const char *del);
  156. extern pthread_mutex_t mutex1;
  157. extern struct Charger_Info Charger;
  158. extern sqlite3 *db;
  159. int TransactionMessageAttemptsGet(void);
  160. int TransactionMessageRetryIntervalGet(void);
  161. int GetOcppConnStatus(void);
  162. void SetOcppConnStatus(uint8_t status);
  163. int updateSetting(char *key, char *value);
  164. int setKeyValue(char *key, char *value);
  165. void OCPP_get_TableAuthlocalAllData(void);
  166. void processUnkownKey(void);
  167. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  168. struct StructOCPPMeterValue
  169. {
  170. unsigned char TimeStamp[28];
  171. struct StructSampledValue SampledValue[10];
  172. };
  173. struct ClientTime
  174. {
  175. unsigned int Heartbeat;
  176. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  177. unsigned int StartTransaction;
  178. unsigned int StopTransaction;
  179. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  180. }clientTime;
  181. typedef union
  182. {
  183. //Operations Initiated by Central System
  184. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  185. struct
  186. {
  187. //CsMsgValue[0]
  188. unsigned char StatusNotificationReq :1; //bit 0,
  189. unsigned char StatusNotificationConf :1; //bit 0,
  190. unsigned char :6; //bit 2~7
  191. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  192. }CpinitiateMsg;
  193. CpinitiateMsg cpinitateMsg;
  194. //==========================================
  195. // Init all Enumeration & Mapping String
  196. //==========================================
  197. /*ChargePointErrorCode*/
  198. typedef enum {
  199. ConnectorLockFailure,
  200. EVCommunicationError,
  201. GroundFailure,
  202. HighTemperature,
  203. InternalError,
  204. LocalListConflict,
  205. NoError,
  206. OtherError,
  207. OverCurrentFailure,
  208. OverVoltage,
  209. PowerMeterFailure,
  210. PowerSwitchFailure,
  211. ReaderFailure,
  212. ResetFailure,
  213. UnderVoltage,
  214. WeakSignal
  215. } ChargePointErrorCode;
  216. #if 0
  217. static char *ChargePointErrorCodeStr[] = {
  218. MACROSTR(ConnectorLockFailure),
  219. MACROSTR(EVCommunicationError),
  220. MACROSTR(GroundFailure),
  221. MACROSTR(HighTemperature),
  222. MACROSTR(InternalError),
  223. MACROSTR(LocalListConflict),
  224. MACROSTR(NoError),
  225. MACROSTR(OtherError),
  226. MACROSTR(OverCurrentFailure),
  227. MACROSTR(OverVoltage),
  228. MACROSTR(PowerMeterFailure),
  229. MACROSTR(PowerSwitchFailure),
  230. MACROSTR(ReaderFailure),
  231. MACROSTR(ResetFailure),
  232. MACROSTR(UnderVoltage),
  233. MACROSTR(WeakSignal)
  234. };
  235. #endif
  236. /*ChargePointStatus*/
  237. typedef enum {
  238. Available =0,
  239. Preparing,
  240. Charging,
  241. SuspendedEVSE,
  242. SuspendedEV,
  243. Finishing,
  244. Reserved,
  245. Unavailable,
  246. Faulted
  247. } ChargePointStatus;
  248. static char * ChargePointStatusStr[] = {
  249. MACROSTR(Available),
  250. MACROSTR(Preparing),
  251. MACROSTR(Charging),
  252. MACROSTR(SuspendedEVSE),
  253. MACROSTR(SuspendedEV),
  254. MACROSTR(Finishing),
  255. MACROSTR(Reserved),
  256. MACROSTR(Unavailable),
  257. MACROSTR(Faulted)
  258. };
  259. /*AvailabilityType*/
  260. typedef enum {
  261. RegistrationStatus_Accepted,
  262. RegistrationStatus_Pending,
  263. RegistrationStatus_Rejected
  264. } RegistrationStatus;
  265. static char *RegistrationStatusStr[] = {
  266. MACROSTR(Accepted),
  267. MACROSTR(Pending),
  268. MACROSTR(Rejected)
  269. };
  270. /*AvailabilityType*/
  271. typedef enum {
  272. Inoperative,
  273. Operative
  274. } AvailabilityType;
  275. static char *AvailabilityTypeStr[] = {
  276. MACROSTR(Inoperative),
  277. MACROSTR(Operative)
  278. };
  279. /*AvailabilityStatus*/
  280. typedef enum {
  281. Accepted,
  282. Rejected,
  283. Scheduled
  284. } AvailabilityStatus;
  285. static char *AvailabilityStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected),
  288. MACROSTR(Scheduled)
  289. };
  290. /*ConfigurationStatus*/
  291. typedef enum {
  292. ConfigurationStatus_Accepted,
  293. ConfigurationStatus_Rejected,
  294. RebootRequired,
  295. NotSupported
  296. } ConfigurationStatus;
  297. static char *ConfigurationStatusStr[] = {
  298. MACROSTR(Accepted),
  299. MACROSTR(Rejected),
  300. MACROSTR(RebootRequired),
  301. MACROSTR(NotSupported)
  302. };
  303. /*ClearCacheStatus*/
  304. typedef enum {
  305. ClearCacheStatus_Accepted,
  306. ClearCacheStatus_Rejected
  307. } ClearCacheStatus;
  308. static char *ClearCacheStatusStr[] = {
  309. MACROSTR(Accepted),
  310. MACROSTR(Rejected)
  311. };
  312. /*ChargingProfilePurposeType*/
  313. typedef enum {
  314. ChargePointMaxProfile,
  315. TxDefaultProfile,
  316. TxProfile
  317. } ChargingProfilePurposeType;
  318. static char *ChargingProfilePurposeTypeStr[] = {
  319. MACROSTR(ChargePointMaxProfile),
  320. MACROSTR(TxDefaultProfile),
  321. MACROSTR(TxProfile)
  322. };
  323. /*ChargingProfileStatus*/
  324. typedef enum {
  325. ChargingProfileStatus_Accepted,
  326. ChargingProfileStatus_Rejected,
  327. ChargingProfileStatus_NotSupported
  328. } ChargingProfileStatus;
  329. static char *ChargingProfileStatusStr[] = {
  330. MACROSTR(Accepted),
  331. MACROSTR(Rejected),
  332. MACROSTR(NotSupported)
  333. };
  334. /*ClearChargingProfileStatus*/
  335. typedef enum {
  336. ClearChargingProfileStatus_Accepted,
  337. ClearChargingProfileStatus_Unknown
  338. } ClearChargingProfileStatus;
  339. static char *ClearChargingProfileStatusStr[] = {
  340. MACROSTR(Accepted),
  341. MACROSTR(Unknown)
  342. };
  343. /*GetCompositeScheduleStatus*/
  344. typedef enum {
  345. GetCompositeScheduleStatus_Accepted,
  346. GetCompositeScheduleStatus_Rejected
  347. } GetCompositeScheduleStatus;
  348. static char *GetCompositeScheduleStatusStr[] = {
  349. MACROSTR(Accepted),
  350. MACROSTR(Rejected)
  351. };
  352. /*ChargingRateUnitType*/
  353. typedef enum {
  354. ChargingRateUnitType_W,
  355. ChargingRateUnitType_A
  356. } ChargingRateUnitType;
  357. /*AuthorizationStatus*/
  358. typedef enum {
  359. AuthorizationStatus_Accepted ,
  360. AuthorizationStatus_Blocked ,
  361. AuthorizationStatus_Expired ,
  362. AuthorizationStatus_Invalid ,
  363. AuthorizationStatus_ConcurrentTx
  364. } AuthorizationStatus;
  365. /*UpdateType*/
  366. typedef enum {
  367. Differential ,
  368. Full
  369. } UpdateType;
  370. static char *UpdateTypeStr[] = {
  371. MACROSTR(Differential),
  372. MACROSTR(Full)
  373. };
  374. /*UpdateStatus*/
  375. typedef enum {
  376. UpdateStatus_Accepted ,
  377. UpdateStatus_Failed ,
  378. UpdateStatus_NotSupported ,
  379. UpdateStatus_VersionMismatch
  380. } UpdateStatus;
  381. static char *UpdateStatusStr[] = {
  382. MACROSTR(Accepted),
  383. MACROSTR(Failed),
  384. MACROSTR(NotSupported),
  385. MACROSTR(VersionMismatch)
  386. };
  387. /*RemoteStartStopStatus*/
  388. typedef enum {
  389. RemoteStartStopStatus_Accepted,
  390. RemoteStartStopStatus_Rejected
  391. } RemoteStartStopStatus;
  392. static char *RemoteStartStopStatusStr[] = {
  393. MACROSTR(Accepted),
  394. MACROSTR(Rejected)
  395. };
  396. /*ReservationStatus*/
  397. typedef enum {
  398. ReservationStatus_Accepted,
  399. ReservationStatus_Faulted,
  400. ReservationStatus_Occupied,
  401. ReservationStatus_Rejected,
  402. ReservationStatus_Unavailable
  403. } ReservationStatus;
  404. static char *ReservationStatusStr[] = {
  405. MACROSTR(Accepted),
  406. MACROSTR(Faulted),
  407. MACROSTR(Occupied),
  408. MACROSTR(Rejected),
  409. MACROSTR(Unavailable)
  410. };
  411. /*ResetType*/
  412. typedef enum {
  413. Hard,
  414. Soft
  415. } ResetType;
  416. static char *ResetTypeStr[] = {
  417. MACROSTR(Hard),
  418. MACROSTR(Soft)
  419. };
  420. /*ResetStatus*/
  421. typedef enum {
  422. ResetStatus_Accepted,
  423. ResetStatus_Rejected
  424. } ResetStatus;
  425. static char *ResetStatusStr[] = {
  426. MACROSTR(Accepted),
  427. MACROSTR(Rejected)
  428. };
  429. /*DiagnosticsStatus*/
  430. typedef enum {
  431. DiagnosticsStatus_Idle,
  432. DiagnosticsStatus_Uploaded,
  433. DiagnosticsStatus_UploadFailed,
  434. DiagnosticsStatus_Uploading
  435. } DiagnosticsStatus;
  436. static char * DiagnosticsStatusStr[] = {
  437. MACROSTR(Idle),
  438. MACROSTR(Uploaded),
  439. MACROSTR(UploadFailed),
  440. MACROSTR(Uploading)
  441. };
  442. /*FirmwareStatus*/
  443. typedef enum {
  444. FirmwareStatus_Downloaded,
  445. FirmwareStatus_DownloadFailed,
  446. FirmwareStatus_Downloading,
  447. FirmwareStatus_Idle,
  448. FirmwareStatus_InstallationFailed,
  449. FirmwareStatus_Installing,
  450. FirmwareStatus_Installed
  451. } FirmwareStatus;
  452. static char * FirmwareStatusStr[] = {
  453. MACROSTR(Downloaded),
  454. MACROSTR(DownloadFailed),
  455. MACROSTR(Downloading),
  456. MACROSTR(Idle),
  457. MACROSTR(InstallationFailed),
  458. MACROSTR(Installing),
  459. MACROSTR(Installed)
  460. };
  461. /*MessageTrigger*/
  462. typedef enum {
  463. BootNotification,
  464. DiagnosticsStatusNotification,
  465. FirmwareStatusNotification,
  466. Heartbeat,
  467. MeterValues,
  468. StatusNotification
  469. } MessageTrigger;
  470. static char * MessageTriggerStr[] = {
  471. MACROSTR(BootNotification),
  472. MACROSTR(DiagnosticsStatusNotification),
  473. MACROSTR(FirmwareStatusNotification),
  474. MACROSTR(Heartbeat),
  475. MACROSTR(MeterValues),
  476. MACROSTR(StatusNotification)
  477. };
  478. /*TriggerMessageStatus*/
  479. typedef enum {
  480. TriggerMessageStatus_Accepted ,
  481. TriggerMessageStatus_Rejected ,
  482. TriggerMessageStatus_NotImplemented
  483. } TriggerMessageStatus;
  484. static char * TriggerMessageStatusStr[] = {
  485. MACROSTR(Accepted),
  486. MACROSTR(Rejected),
  487. MACROSTR(NotImplemented)
  488. };
  489. /*UnlockStatus*/
  490. typedef enum {
  491. Unlocked,
  492. UnlockFailed,
  493. UnlockStatus_NotSupported
  494. } UnlockStatus;
  495. static char * UnlockStatusStr[] = {
  496. MACROSTR(Unlocked),
  497. MACROSTR(UnlockFailed),
  498. MACROSTR(NotSupported)
  499. };
  500. /*StopTransactionReason*/
  501. typedef enum {
  502. EmergencyStop,
  503. EVDisconnected,
  504. HardReset,
  505. Local,
  506. Other,
  507. PowerLoss,
  508. Reboot,
  509. Remote,
  510. SoftReset,
  511. UnlockCommand,
  512. DeAuthorized
  513. } StopTransactionReason;
  514. static char * StopTransactionReasonStr[] = {
  515. MACROSTR(EmergencyStop),
  516. MACROSTR(EVDisconnected),
  517. MACROSTR(HardReset),
  518. MACROSTR(Local),
  519. MACROSTR(Other),
  520. MACROSTR(PowerLoss),
  521. MACROSTR(Reboot),
  522. MACROSTR(Remote),
  523. MACROSTR(SoftReset),
  524. MACROSTR(UnlockCommand),
  525. MACROSTR(DeAuthorized)
  526. };
  527. /*CancelReservationStatus*/
  528. typedef enum {
  529. CancelReservationStatus_Accepted,
  530. CancelReservationStatus_Rejected
  531. } CancelReservationStatus;
  532. static char * CancelReservationStatusStr[] = {
  533. MACROSTR(Accepted),
  534. MACROSTR(Rejected)
  535. };
  536. /*ReadingContext*/
  537. typedef enum {
  538. ReadingContext_Interruption_Begin,
  539. ReadingContext_Interruption_End,
  540. ReadingContext_Other,
  541. ReadingContext_Sample_Clock,
  542. ReadingContext_Sample_Periodic ,
  543. ReadingContext_Transaction_Begin ,
  544. ReadingContext_Transaction_End,
  545. ReadingContext_Trigger
  546. } ReadingContext;
  547. static char * ReadingContextStr[] = {
  548. MACROSTR(Interruption.Begin),
  549. MACROSTR(Interruption.End),
  550. MACROSTR(Other),
  551. MACROSTR(Sample.Clock),
  552. MACROSTR(Sample.Periodic),
  553. MACROSTR(Transaction.Begin),
  554. MACROSTR(Transaction.End),
  555. MACROSTR(Trigger)
  556. };
  557. /*ValueFormat*/
  558. typedef enum {
  559. Raw,
  560. SignedData
  561. } ValueFormat;
  562. static char * ValueFormatStr[] = {
  563. MACROSTR(Raw),
  564. MACROSTR(SignedData)
  565. };
  566. /*Measurand*/
  567. typedef enum {
  568. Current_Export ,
  569. Current_Import,
  570. Current_Offered,
  571. Energy_Active_Export_Register,
  572. Energy_Active_Import_Register,
  573. Energy_Reactive_Export_Register,
  574. Energy_Reactive_Import_Register,
  575. Energy_Active_Export_Interval,
  576. Energy_Active_Import_Interval,
  577. Energy_Reactive_Export_Interval,
  578. Energy_Reactive_Import_Interval,
  579. Frequency,
  580. Power_Active_Export ,
  581. Power_Active_Import,
  582. Power_Factor,
  583. Power_Offered,
  584. Power_Reactive_Export,
  585. Power_Reactive_Import,
  586. RPM,
  587. SoC,
  588. Temperature ,
  589. Voltage
  590. } Measurand;
  591. static char * MeasurandStr[] = {
  592. MACROSTR(Current.Export),
  593. MACROSTR(Current.Import),
  594. MACROSTR(Current.Offered),
  595. MACROSTR(Energy.Active.Export.Register),
  596. MACROSTR(Energy.Active.Import.Register),
  597. MACROSTR(Energy.Reactive.Export.Register),
  598. MACROSTR(Energy.Reactive.Import.Register),
  599. MACROSTR(Energy.Active.Export.Interval),
  600. MACROSTR(Energy.Active.Import.Interval),
  601. MACROSTR(Energy.Reactive.Export.Interval),
  602. MACROSTR(Energy.Reactive.Import.Interval),
  603. MACROSTR(Frequency),
  604. MACROSTR(Power.Active.Export),
  605. MACROSTR(Power.Active.Import),
  606. MACROSTR(Power.Factor),
  607. MACROSTR(Power.Offered),
  608. MACROSTR(Power.Reactive.ExportMACROSTR),
  609. MACROSTR(Power.Reactive.Import),
  610. MACROSTR(RPM),
  611. MACROSTR(SoC),
  612. MACROSTR(Temperature),
  613. MACROSTR(Voltage)
  614. };
  615. /*Location*/
  616. typedef enum {
  617. Location_Body,
  618. Location_Cable,
  619. Location_EV,
  620. Location_Inlet ,
  621. Location_Outlet
  622. } Location;
  623. static char * LocationStr[] = {
  624. MACROSTR(Body),
  625. MACROSTR(Cable),
  626. MACROSTR(EV),
  627. MACROSTR(Inlet),
  628. MACROSTR(Outlet)
  629. };
  630. /*Phase*/
  631. typedef enum {
  632. L1,
  633. L2,
  634. L3,
  635. N,
  636. L1_N,
  637. L2_N,
  638. L3_N,
  639. L1_L2,
  640. L2_L3,
  641. L3_L1
  642. } Phase;
  643. static char * PhaseStr[] = {
  644. MACROSTR(L1),
  645. MACROSTR(L2),
  646. MACROSTR(L3),
  647. MACROSTR(N),
  648. MACROSTR(L1-N),
  649. MACROSTR(L2-N),
  650. MACROSTR(L3-N),
  651. MACROSTR(L1-L2),
  652. MACROSTR(L2-L3),
  653. MACROSTR(L3-L1)
  654. };
  655. /*UnitOfMeasure*/
  656. typedef enum {
  657. UnitOfMeasure_Wh,
  658. UnitOfMeasure_kWh ,
  659. UnitOfMeasure_varh ,
  660. UnitOfMeasure_kvarh ,
  661. UnitOfMeasure_W ,
  662. UnitOfMeasure_kW ,
  663. UnitOfMeasure_VA ,
  664. UnitOfMeasure_kVA ,
  665. UnitOfMeasure_var ,
  666. UnitOfMeasure_kvar ,
  667. UnitOfMeasure_A ,
  668. UnitOfMeasure_V ,
  669. UnitOfMeasure_Celsius ,
  670. UnitOfMeasure_Fahrenheit ,
  671. UnitOfMeasure_K ,
  672. UnitOfMeasure_Percent
  673. } UnitOfMeasure;
  674. static char * UnitOfMeasureStr[] = {
  675. MACROSTR(Wh),
  676. MACROSTR(kWh),
  677. MACROSTR(varh),
  678. MACROSTR(kvarh),
  679. MACROSTR(W),
  680. MACROSTR(kW),
  681. MACROSTR(VA),
  682. MACROSTR(kVA),
  683. MACROSTR(var),
  684. MACROSTR(kvar),
  685. MACROSTR(A),
  686. MACROSTR(V),
  687. MACROSTR(Celsius),
  688. MACROSTR(Fahrenheit),
  689. MACROSTR(K),
  690. MACROSTR(Percent)
  691. };
  692. /*Configuration enum*/
  693. enum CoreProfile {
  694. AllowOfflineTxForUnknownId=0,
  695. AuthorizationCacheEnabled,
  696. AuthorizeRemoteTxRequests,
  697. BlinkRepeat,
  698. ClockAlignedDataInterval,
  699. ConnectionTimeOut,
  700. GetConfigurationMaxKeys,
  701. HeartbeatInterval,
  702. LightIntensity,
  703. LocalAuthorizeOffline,
  704. LocalPreAuthorize,
  705. MaxEnergyOnInvalidId,
  706. MeterValuesAlignedData,
  707. MeterValuesAlignedDataMaxLength,
  708. MeterValuesSampledData,
  709. MeterValuesSampledDataMaxLength,
  710. MeterValueSampleInterval,
  711. MinimumStatusDuration,
  712. NumberOfConnectors,
  713. ResetRetries,
  714. ConnectorPhaseRotation,
  715. ConnectorPhaseRotationMaxLength,
  716. StopTransactionOnEVSideDisconnect,
  717. StopTransactionOnInvalidId,
  718. StopTxnAlignedData,
  719. StopTxnAlignedDataMaxLength,
  720. StopTxnSampledData,
  721. StopTxnSampledDataMaxLength,
  722. SupportedFeatureProfiles,
  723. SupportedFeatureProfilesMaxLength,
  724. TransactionMessageAttempts,
  725. TransactionMessageRetryInterval,
  726. UnlockConnectorOnEVSideDisconnect,
  727. WebSocketPingInterval,
  728. _CoreProfile_CNT
  729. };
  730. enum LocalAuthListManagementProfile{
  731. LocalAuthListEnabled=0,
  732. LocalAuthListMaxLength,
  733. SendLocalListMaxLength,
  734. _LocalAuthListManagementProfile_CNT
  735. };
  736. enum ReservationProfile{
  737. ReserveConnectorZeroSupported
  738. };
  739. enum SmartChargingProfile{
  740. ChargeProfileMaxStackLevel,
  741. ChargingScheduleAllowedChargingRateUnit,
  742. ChargingScheduleMaxPeriods,
  743. ConnectorSwitch3to1PhaseSupported,
  744. MaxChargingProfilesInstalled
  745. };
  746. enum ChargerSystemStatus{
  747. ChargerSystemStatus_Booting,
  748. ChargerSystemStatus_Idle,
  749. ChargerSystemStatus_Authorizing,
  750. ChargerSystemStatus_Preparing,
  751. ChargerSystemStatus_Charging,
  752. ChargerSystemStatus_Terminating,
  753. ChargerSystemStatus_Alarm,
  754. ChargerSystemStatus_Fault
  755. };
  756. enum GetConfigurationKey {
  757. GetConfiguration_AllowOfflineTxForUnknownId=0,
  758. GetConfiguration_AuthorizationCacheEnabled,
  759. GetConfiguration_AuthorizeRemoteTxRequests,
  760. GetConfiguration_BlinkRepeat,
  761. GetConfiguration_ClockAlignedDataInterval,
  762. GetConfiguration_ConnectionTimeOut,
  763. GetConfiguration_GetConfigurationMaxKeys,
  764. GetConfiguration_HeartbeatInterval,
  765. GetConfiguration_LightIntensity,
  766. GetConfiguration_LocalAuthorizeOffline,
  767. GetConfiguration_LocalPreAuthorize,
  768. GetConfiguration_MaxEnergyOnInvalidId,
  769. GetConfiguration_MeterValuesAlignedData,
  770. GetConfiguration_MeterValuesAlignedDataMaxLength,
  771. GetConfiguration_MeterValuesSampledData,
  772. GetConfiguration_MeterValuesSampledDataMaxLength,
  773. GetConfiguration_MeterValueSampleInterval,
  774. GetConfiguration_MinimumStatusDuration,
  775. GetConfiguration_NumberOfConnectors,
  776. GetConfiguration_ResetRetries,
  777. GetConfiguration_ConnectorPhaseRotation,
  778. GetConfiguration_ConnectorPhaseRotationMaxLength,
  779. GetConfiguration_StopTransactionOnEVSideDisconnect,
  780. GetConfiguration_StopTransactionOnInvalidId,
  781. GetConfiguration_StopTxnAlignedData,
  782. GetConfiguration_StopTxnAlignedDataMaxLength,
  783. GetConfiguration_StopTxnSampledData,
  784. GetConfiguration_StopTxnSampledDataMaxLength,
  785. GetConfiguration_SupportedFeatureProfiles,
  786. GetConfiguration_SupportedFeatureProfilesMaxLength,
  787. GetConfiguration_TransactionMessageAttempts,
  788. GetConfiguration_TransactionMessageRetryInterval,
  789. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  790. GetConfiguration_WebSocketPingInterval,
  791. GetConfiguration_LocalAuthListEnabled,
  792. GetConfiguration_LocalAuthListMaxLength,
  793. GetConfiguration_SendLocalListMaxLength,
  794. GetConfiguration_ReserveConnectorZeroSupported,
  795. GetConfiguration_ChargeProfileMaxStackLevel,
  796. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  797. GetConfiguration_ChargingScheduleMaxPeriods,
  798. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  799. GetConfiguration_MaxChargingProfilesInstalled,
  800. };
  801. //GetConfiguration Array
  802. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  803. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  804. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  805. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  806. //==========================================
  807. // Init all share memory
  808. //==========================================
  809. int InitShareMemory()
  810. {
  811. int result = PASS;
  812. int MeterSMId;
  813. //printf("1\n");
  814. //creat ShmSysConfigAndInfo
  815. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  816. {
  817. #ifdef SystemLogMessage
  818. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  819. #endif
  820. result = FAIL;
  821. }
  822. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  823. {
  824. #ifdef SystemLogMessage
  825. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  826. #endif
  827. result = FAIL;
  828. }
  829. else
  830. {}
  831. //printf("2\n");
  832. //creat ShmStatusCodeData
  833. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  834. {
  835. #ifdef SystemLogMessage
  836. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  837. #endif
  838. result = FAIL;
  839. }
  840. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  841. {
  842. #ifdef SystemLogMessage
  843. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  844. #endif
  845. result = FAIL;
  846. }
  847. else
  848. {}
  849. //printf("3\n");
  850. //creat ShmPsuData
  851. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  852. {
  853. #ifdef SystemLogMessage
  854. DEBUG_ERROR("shmget ShmPsuData NG\n");
  855. #endif
  856. result = FAIL;
  857. }
  858. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  859. {
  860. #ifdef SystemLogMessage
  861. DEBUG_ERROR("shmat ShmPsuData NG\n");
  862. #endif
  863. result = FAIL;
  864. }
  865. else
  866. {}
  867. //creat ShmOCPP16Data
  868. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  872. #endif
  873. result = FAIL;
  874. }
  875. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  876. {
  877. #ifdef SystemLogMessage
  878. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  879. #endif
  880. result = FAIL;
  881. }
  882. else
  883. {}
  884. /****************************** For TEST ************************************************/
  885. //inital settings
  886. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  887. memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY));
  888. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  889. {
  890. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  891. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  892. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  893. }
  894. // Charger PRE_SYS_MODE
  895. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  896. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  897. clientTime.Heartbeat=time((time_t*)NULL);
  898. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  899. {
  900. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  901. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  902. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  903. }
  904. //HeartBeatWaitTime = 10;
  905. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  906. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  907. // allocate Configuration memory address
  908. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  909. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  910. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  911. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  912. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  913. {
  914. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  915. DEBUG_INFO("DC ...\n");
  916. }
  917. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  918. {
  919. SystemInitial = AC_QUANTITY;
  920. DEBUG_INFO("AC ...\n");
  921. }
  922. //Status Setting
  923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  924. {
  925. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  926. }
  927. for (int index = 0; index < CCS_QUANTITY; index++)
  928. {
  929. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  930. }
  931. for (int index = 0; index < GB_QUANTITY; index++)
  932. {
  933. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  934. }
  935. for (int index = 0; index < AC_QUANTITY; index++)
  936. {
  937. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  938. }
  939. //memset(unknownkey, 0, 10);
  940. return result;
  941. }
  942. int ProcessShareMemory()
  943. {
  944. if(InitShareMemory() == FAIL)
  945. {
  946. #ifdef SystemLogMessage
  947. DEBUG_ERROR("InitShareMemory NG\n");
  948. #endif
  949. if(ShmStatusCodeData!=NULL)
  950. {
  951. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  952. }
  953. sleep(5);
  954. return FAIL;
  955. }
  956. return PASS;
  957. }
  958. //---------------------------------------------
  959. // new:
  960. // enum SYSTEM_STATUS
  961. // {
  962. // SYS_MODE_BOOTING = 0,
  963. // SYS_MODE_IDLE = 1,
  964. // SYS_MODE_AUTHORIZING = 2,
  965. // SYS_MODE_PREPARING = 3,
  966. // SYS_MODE_CHARGING = 4,
  967. // SYS_MODE_TERMINATING = 5,
  968. // SYS_MODE_ALARM = 6,
  969. // SYS_MODE_FAULT = 7,
  970. // SYS_MODE_RESERVATION = 8,
  971. // SYS_MODE_BOOKING = 9,
  972. // SYS_MODE_MAINTAIN = 10,
  973. // SYS_MODE_DEBUG = 11,
  974. // SYS_MODE_REASSIGN_CHECK = 12,
  975. // SYS_MODE_REASSIGN = 13,
  976. // SYS_MODE_PRECHARGE = 14,
  977. // SYS_MODE_PREPARING_EV = 15,
  978. // SYS_MODE_PREPARING_EVSE = 16,
  979. // SYS_MODE_COMPLETE = 17
  980. // };
  981. //
  982. // old:
  983. // enum _SYSTEM_STATUS
  984. // {
  985. // S_BOOTING = 0,
  986. // S_IDLE, =1
  987. // S_AUTHORIZING, =2
  988. // S_REASSIGN_CHECK, =3
  989. // S_REASSIGN, =4
  990. // S_PRECHARGE, =5
  991. // S_PREPARING_FOR_EV, =6
  992. // S_PREPARING_FOR_EVSE, =7
  993. // S_CHARGING, =8
  994. // S_TERMINATING, =9
  995. // S_COMPLETE, =10
  996. // S_ALARM, =11
  997. // S_FAULT =12
  998. // };
  999. //
  1000. //-----------------------------------------
  1001. void CheckSystemValue(void)
  1002. {
  1003. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1004. int IdleModeCnt = 0;
  1005. char filenmae[100]={0};
  1006. char str[100]={0};
  1007. //===============================
  1008. // send Heartbeat
  1009. //===============================
  1010. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1011. {
  1012. //parameter for test
  1013. sendHeartbeatRequest(0);
  1014. //==============================================
  1015. // Reset Waiting Time
  1016. //==============================================
  1017. clientTime.Heartbeat=time((time_t*)NULL);
  1018. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1019. }
  1020. //==============================================
  1021. // Update firmware request
  1022. //==============================================
  1023. if(isUpdateRequest == TRUE )
  1024. {
  1025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1026. {
  1027. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1028. {
  1029. //check SystemStatus
  1030. /*************************DC*******************************/
  1031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1032. {
  1033. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1034. {
  1035. IdleModeCnt = IdleModeCnt + 1;
  1036. }
  1037. }
  1038. for (int index = 0; index < CCS_QUANTITY; index++)
  1039. {
  1040. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1041. {
  1042. IdleModeCnt = IdleModeCnt + 1;
  1043. }
  1044. }
  1045. for (int index = 0; index < GB_QUANTITY; index++)
  1046. {
  1047. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1048. {
  1049. IdleModeCnt = IdleModeCnt + 1;
  1050. }
  1051. }
  1052. }
  1053. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1054. {
  1055. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1056. isUpdateRequest = FALSE;
  1057. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1058. }
  1059. }
  1060. else
  1061. {
  1062. /*************************AC*******************************/
  1063. for (int index = 0; index < AC_QUANTITY; index++)
  1064. {
  1065. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1066. {
  1067. IdleModeCnt = IdleModeCnt + 1;
  1068. }
  1069. }
  1070. if(IdleModeCnt == AC_QUANTITY)
  1071. {
  1072. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1073. isUpdateRequest = FALSE;
  1074. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1075. }
  1076. }
  1077. }
  1078. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1079. for(int gun_index=0;gun_index < gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY )*/ ;gun_index++)
  1080. {
  1081. //===============================
  1082. // CSU Trigger Reset Conf
  1083. //===============================
  1084. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1085. {
  1086. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1087. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1088. {
  1089. server_sign = FALSE;
  1090. }
  1091. }
  1092. //===============================
  1093. // CSU Trigger Authorize Request
  1094. //===============================
  1095. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1096. {
  1097. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1098. {
  1099. sendAuthorizeRequest(0);
  1100. authorizeRetryTimes = authorizeRetryTimes + 1;
  1101. // authenrequest = TRUE
  1102. if(authorizeRetryTimes < 3)
  1103. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1104. }
  1105. }
  1106. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1107. {
  1108. authorizeRetryTimes = 0;
  1109. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1110. server_sign = FALSE;
  1111. }
  1112. //==============================================
  1113. // Charger start transaction
  1114. //==============================================
  1115. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1116. {
  1117. sendStartTransactionRequest(gun_index);
  1118. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1119. clientTime.StartTransaction = time((time_t*)NULL);
  1120. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1121. }
  1122. //==============================================
  1123. // Charger stop transaction
  1124. //==============================================
  1125. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1126. {
  1127. sendStopTransactionRequest(gun_index);
  1128. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1129. clientTime.StopTransaction = time((time_t*)NULL);
  1130. }
  1131. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1132. //==============================================
  1133. // Charger status report
  1134. //==============================================
  1135. /* Check Mode Change */
  1136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1137. {
  1138. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1139. {
  1140. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1141. {
  1142. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1143. {
  1144. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1145. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1146. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1147. statusModeChage[gun_index] = TRUE;
  1148. }
  1149. }
  1150. }
  1151. for (int index = 0; index < CCS_QUANTITY; index++)
  1152. {
  1153. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1154. {
  1155. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1156. {
  1157. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1158. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1159. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1160. statusModeChage[gun_index] = TRUE;
  1161. }
  1162. }
  1163. }
  1164. for (int index = 0; index < GB_QUANTITY; index++)
  1165. {
  1166. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1167. {
  1168. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1169. {
  1170. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1171. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1172. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1173. statusModeChage[gun_index] = TRUE;
  1174. }
  1175. }
  1176. }
  1177. }
  1178. else //AC
  1179. {
  1180. for (int index = 0; index < AC_QUANTITY; index++)
  1181. {
  1182. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1183. {
  1184. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1185. {
  1186. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1187. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1188. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1189. statusModeChage[gun_index] = TRUE;
  1190. }
  1191. }
  1192. }// END OF FOR
  1193. }// END OF ELSE
  1194. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1195. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1196. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1197. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1198. {
  1199. if(SystemInitial != 0)
  1200. SystemInitial = SystemInitial -1;
  1201. //GunStatusInterval= GunStatusInterval* gun_index;
  1202. sendStatusNotificationRequest(gun_index);
  1203. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1204. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1205. statusModeChage[gun_index] = FALSE;
  1206. //sleep(30); // sleep for 30 seconds
  1207. }
  1208. //==============================================
  1209. // Meter report
  1210. //==============================================
  1211. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1212. {
  1213. //check Transaction active
  1214. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1215. {
  1216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1217. {
  1218. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1219. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1220. {
  1221. meterValueSend[gun_index] =1;
  1222. }
  1223. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1224. {
  1225. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1226. if((access(filenmae,F_OK))!=-1)
  1227. {
  1228. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1229. sprintf(str,"rm -f %s",filenmae);
  1230. system(str);
  1231. }
  1232. }
  1233. }// End for CHAdeMO
  1234. for (int index = 0; index < CCS_QUANTITY; index++)
  1235. {
  1236. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1237. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1238. {
  1239. meterValueSend[gun_index] =1;
  1240. }
  1241. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1242. {
  1243. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1244. if((access(filenmae,F_OK))!=-1)
  1245. {
  1246. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1247. sprintf(str,"rm -f %s",filenmae);
  1248. system(str);
  1249. }
  1250. }
  1251. } // End for CCS
  1252. for (int index = 0; index < GB_QUANTITY; index++)
  1253. {
  1254. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1255. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1256. {
  1257. meterValueSend[gun_index] =1;
  1258. }
  1259. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1260. {
  1261. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1262. if((access(filenmae,F_OK))!=-1)
  1263. {
  1264. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1265. sprintf(str,"rm -f %s",filenmae);
  1266. system(str);
  1267. }
  1268. }
  1269. }// End for GB
  1270. }
  1271. else
  1272. {
  1273. for (int index = 0; index < AC_QUANTITY; index++)
  1274. {
  1275. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1276. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1277. {
  1278. meterValueSend[gun_index] =1;
  1279. }
  1280. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1281. {
  1282. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1283. if((access(filenmae,F_OK))!=-1)
  1284. {
  1285. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1286. sprintf(str,"rm -f %s",filenmae);
  1287. system(str);
  1288. }
  1289. }
  1290. }//End for AC
  1291. }//END OF ELSE
  1292. // sleep(1);
  1293. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1294. if(meterValueSend[gun_index] == 1)
  1295. sendMeterValuesRequest(gun_index);
  1296. }
  1297. //==============================================
  1298. // Check Connector reserved
  1299. //==============================================
  1300. //===============================
  1301. // Check if Reserve is expired
  1302. //===============================
  1303. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1304. {
  1305. double diff_t;
  1306. struct tm tp;
  1307. // current time
  1308. time_t t = time(NULL);
  1309. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1310. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1311. tp.tm_isdst = -1;
  1312. time_t utc = mktime(&tp);
  1313. diff_t = difftime(utc, t);
  1314. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1315. if(diff_t <= 0)
  1316. {
  1317. DEBUG_INFO("reserve expired !!! \n");
  1318. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1319. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1320. }
  1321. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1322. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1323. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1324. {
  1325. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1326. }
  1327. else
  1328. {
  1329. //check Transaction active
  1330. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1331. {
  1332. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1333. {
  1334. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1335. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1336. {
  1337. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1338. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1339. {
  1340. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1341. }
  1342. }
  1343. }
  1344. for (int index = 0; index < CCS_QUANTITY; index++)
  1345. {
  1346. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1347. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1348. {
  1349. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1350. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1351. {
  1352. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1353. }
  1354. }
  1355. }
  1356. for (int index = 0; index < GB_QUANTITY; index++)
  1357. {
  1358. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1359. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1360. {
  1361. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1362. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1363. {
  1364. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1365. }
  1366. }
  1367. }
  1368. }
  1369. else //AC
  1370. {
  1371. for (int index = 0; index < AC_QUANTITY; index++)
  1372. {
  1373. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1374. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1375. {
  1376. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1377. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1378. {
  1379. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1380. }
  1381. }
  1382. }
  1383. }// END OF ELSE
  1384. }// END OF check Transaction active
  1385. }//END OF Check if Reserve is expired
  1386. //==========================================
  1387. // csu trigger FirmwareStatusNotificationReq
  1388. //==========================================
  1389. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1390. {
  1391. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1392. }
  1393. //==========================================
  1394. // csu trigger CancelReservationConf
  1395. //==========================================
  1396. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1397. {
  1398. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1399. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1400. }
  1401. //==========================================
  1402. // csu trigger ChangeAvailabilityConf
  1403. //==========================================
  1404. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1405. {
  1406. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1407. }
  1408. //==========================================
  1409. // csu trigger UnlockConnectorConf
  1410. //==========================================
  1411. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1412. {
  1413. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1414. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1415. }
  1416. //==========================================
  1417. // csu trigger ReserveNowConf
  1418. //==========================================
  1419. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1420. {
  1421. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1422. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1423. }
  1424. //==========================================
  1425. // csu trigger DataTransferReq
  1426. //==========================================
  1427. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1428. {
  1429. sendDataTransferRequest(gun_index);
  1430. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1431. }
  1432. }
  1433. }
  1434. //==========================================
  1435. // send request routine
  1436. //==========================================
  1437. int sendAuthorizeRequest(int gun_index)
  1438. {
  1439. mtrace();
  1440. int result = FAIL;
  1441. char message[100]={0};
  1442. char guid[37];
  1443. char tempdata[65]={0};
  1444. DEBUG_INFO("sendAuthorizeRequest \n");
  1445. //Local Authorize
  1446. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1447. {
  1448. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1449. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1450. {
  1451. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1452. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1453. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1454. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1455. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1456. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1457. authorizeRetryTimes = 0;
  1458. return result;
  1459. }
  1460. else
  1461. {
  1462. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1463. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1464. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1465. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1466. result = PASS;
  1467. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1468. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1469. authorizeRetryTimes = 0;
  1470. return result;
  1471. }
  1472. }
  1473. //initailize struct Authorize
  1474. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1475. //get data from shared memory
  1476. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1477. random_uuid(guid);
  1478. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1479. LWS_Send(message);
  1480. sprintf(tempdata, "Authorize,%d", gun_index);
  1481. if(hashmap_operation(0, guid, tempdata) == 1)
  1482. {
  1483. result = PASS;
  1484. DEBUG_ERROR("Authorize mapItem pass\n");
  1485. }
  1486. //#ifdef SystemLogMessage
  1487. //DEBUG_INFO(">>>>>Authorize request\n");
  1488. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1489. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1490. //#endif
  1491. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1492. return result;
  1493. }
  1494. int sendBootNotificationRequest(void)
  1495. {
  1496. mtrace();
  1497. int result = FAIL;
  1498. char message[500]={0}, payload[700]={0};
  1499. char guid[37]={0};
  1500. char tempdata[65]={0};
  1501. int IsGunCharging = FALSE;
  1502. //check Transaction active
  1503. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1504. {
  1505. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1506. {
  1507. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1508. {
  1509. IsGunCharging = TRUE;
  1510. }
  1511. }
  1512. for (int index = 0; index < CCS_QUANTITY; index++)
  1513. {
  1514. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1515. {
  1516. IsGunCharging = TRUE;
  1517. }
  1518. }
  1519. for (int index = 0; index < GB_QUANTITY; index++)
  1520. {
  1521. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1522. {
  1523. IsGunCharging = TRUE;
  1524. }
  1525. }
  1526. }
  1527. else
  1528. {
  1529. for (int index = 0; index < AC_QUANTITY; index++)
  1530. {
  1531. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1532. {
  1533. IsGunCharging = TRUE;
  1534. }
  1535. }
  1536. }
  1537. if(IsGunCharging == TRUE)
  1538. {
  1539. server_sign = TRUE;
  1540. return result;
  1541. }
  1542. // Fill BootNotification fields
  1543. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1544. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1545. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1546. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1547. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1548. ShmOCPP16Data->ChargeBoxId
  1549. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1550. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1551. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1552. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1553. ,ShmOCPP16Data->BootNotification.CpIccid
  1554. ,ShmOCPP16Data->BootNotification.CpImsi
  1555. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1556. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1557. random_uuid(guid);
  1558. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1559. LWS_Send(message);
  1560. sprintf(tempdata, "BootNotification,0");
  1561. 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*/)
  1562. {
  1563. result = PASS;
  1564. }
  1565. memset(queuedata, 0, sizeof(queuedata));
  1566. strcpy(queuedata,message);
  1567. //#ifdef SystemLogMessage
  1568. //DEBUG_INFO(">>>>>BootNotification request\n");
  1569. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1570. //#endif
  1571. return result;
  1572. }
  1573. int sendDataTransferRequest(int gun_index)
  1574. {
  1575. mtrace();
  1576. char message[1000]={0};
  1577. char guid[37]={0};
  1578. char tempdata[65]={0};
  1579. int result = FAIL;
  1580. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1581. random_uuid(guid);
  1582. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1583. MESSAGE_TYPE_CALL,
  1584. guid,
  1585. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1586. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1587. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1588. LWS_Send(message);
  1589. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1590. 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*/)
  1591. {
  1592. result = PASS;
  1593. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1594. }
  1595. //#ifdef SystemLogMessage
  1596. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1597. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1598. //#endif
  1599. return result;
  1600. }
  1601. int sendDiagnosticsStatusNotificationRequest(char *status)
  1602. {
  1603. mtrace();
  1604. int result = FAIL;
  1605. char message[110]={0};
  1606. char guid[37]={0};
  1607. char tempdata[65]={0};
  1608. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1609. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1610. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1611. random_uuid(guid);
  1612. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1613. LWS_Send(message);
  1614. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1615. if(hashmap_operation(0, guid, tempdata) == 1)
  1616. {
  1617. result = PASS;
  1618. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1619. }
  1620. //#ifdef SystemLogMessage
  1621. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1622. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1623. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1624. //#endif
  1625. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1626. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1627. //record status
  1628. if(strcmp(status,"Idle")==0)
  1629. {
  1630. DiagnosticsStatusNotificationStatus = 0;
  1631. }
  1632. else if(strcmp(status,"Uploaded")==0)
  1633. {
  1634. DiagnosticsStatusNotificationStatus = 1;
  1635. }
  1636. else if(strcmp(status,"UploadFailed")==0)
  1637. {
  1638. DiagnosticsStatusNotificationStatus = 2;
  1639. }
  1640. else if(strcmp(status,"Uploading")==0)
  1641. {
  1642. DiagnosticsStatusNotificationStatus = 3;
  1643. }
  1644. return result;
  1645. }
  1646. int sendFirmwareStatusNotificationRequest(char *status)
  1647. {
  1648. mtrace();
  1649. int result = FAIL;
  1650. char message[110]={0};
  1651. char guid[37]={0};
  1652. char tempdata[65]={0};
  1653. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1654. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1655. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1656. random_uuid(guid);
  1657. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1658. LWS_Send(message);
  1659. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1660. 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*/)
  1661. {
  1662. result = PASS;
  1663. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1664. }
  1665. //#ifdef SystemLogMessage
  1666. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1667. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1668. //#endif
  1669. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1670. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1671. //record status
  1672. if(strcmp(status,"Downloaded")==0)
  1673. {
  1674. FirmwareStatusNotificationStatus = 0;
  1675. }
  1676. else if(strcmp(status,"DownloadFailed")==0)
  1677. {
  1678. FirmwareStatusNotificationStatus = 1;
  1679. }
  1680. else if(strcmp(status,"Downloading")==0)
  1681. {
  1682. FirmwareStatusNotificationStatus = 2;
  1683. }
  1684. else if(strcmp(status,"Idle")==0)
  1685. {
  1686. FirmwareStatusNotificationStatus = 3;
  1687. }
  1688. else if(strcmp(status,"InstallationFailed")==0)
  1689. {
  1690. FirmwareStatusNotificationStatus = 4;
  1691. }
  1692. else if(strcmp(status,"Installing")==0)
  1693. {
  1694. FirmwareStatusNotificationStatus = 5;
  1695. }
  1696. else if(strcmp(status,"Installed")==0)
  1697. {
  1698. FirmwareStatusNotificationStatus = 6;
  1699. }
  1700. return result;
  1701. }
  1702. int sendHeartbeatRequest(int gun_index)
  1703. {
  1704. mtrace();
  1705. int result = FAIL;
  1706. char message[80]={0};
  1707. char guid[37]={0};
  1708. char tempdata[65]={0};
  1709. random_uuid(guid);
  1710. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1711. , MESSAGE_TYPE_CALL
  1712. , guid );
  1713. LWS_Send(message);
  1714. sprintf(tempdata, "Heartbeat,%d", 0);
  1715. 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*/)
  1716. {
  1717. result = PASS;
  1718. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1719. }
  1720. //#ifdef SystemLogMessage
  1721. //DEBUG_INFO(">>>>>Heartbeat request\n");
  1722. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1723. //#endif
  1724. return result;
  1725. }
  1726. int sendStartTransactionRequest(int gun_index)
  1727. {
  1728. mtrace();
  1729. int result = FAIL;
  1730. char message[250]={0};
  1731. char guid[37]={0};
  1732. struct timeval tmnow;
  1733. struct tm *tm;
  1734. char buf[30];//, usec_buf[6];
  1735. char tempdata[65]={0};
  1736. DEBUG_INFO("sendStartTransactionRequest...");
  1737. gettimeofday(&tmnow, NULL);
  1738. time_t t;
  1739. t = time(NULL);
  1740. /*UTC time and date*/
  1741. tm = gmtime(&t);
  1742. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1743. #if 0 // remove temporally
  1744. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1745. strcat(buf,".");
  1746. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1747. strcat(buf,usec_buf);
  1748. #endif
  1749. //printf("Start Charging Time :%s",buf);
  1750. // set value
  1751. if(ShmOCPP16Data->OcppConnStatus == 1 )
  1752. {
  1753. memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1754. }
  1755. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1756. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1757. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1759. {
  1760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1761. {
  1762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1763. {
  1764. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1765. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1766. }
  1767. }
  1768. for (int index = 0; index < CCS_QUANTITY; index++)
  1769. {
  1770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1771. {
  1772. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1773. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1774. }
  1775. }
  1776. for (int index = 0; index < GB_QUANTITY; index++)
  1777. {
  1778. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1779. {
  1780. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1781. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1782. }
  1783. }
  1784. }
  1785. else
  1786. {
  1787. for (int index = 0; index < AC_QUANTITY; index++)
  1788. {
  1789. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1790. {
  1791. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1792. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1793. }
  1794. }
  1795. }//END OF ELSE
  1796. random_uuid(guid);
  1797. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1798. , MESSAGE_TYPE_CALL
  1799. , guid
  1800. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1801. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1802. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1803. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1804. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1805. LWS_Send(message);
  1806. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1807. 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*/)
  1808. {
  1809. result = PASS;
  1810. }
  1811. strcpy(queuedata, message);
  1812. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1813. //#ifdef SystemLogMessage
  1814. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1815. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1816. //#endif
  1817. return result;
  1818. }
  1819. int sendStatusNotificationRequest(int gun_index)
  1820. {
  1821. mtrace();
  1822. int result = FAIL;
  1823. char message[600]={0};
  1824. char guid[37];
  1825. int currentStatus = 0;
  1826. struct timeval tmnow;
  1827. struct tm *tm;
  1828. char buf[30];//, usec_buf[6];
  1829. char tempdata[65]={0};
  1830. gettimeofday(&tmnow, NULL);
  1831. time_t t;
  1832. t = time(NULL);
  1833. /*UTC time and date*/
  1834. tm = gmtime(&t);
  1835. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1836. #if 0 // remove temporally
  1837. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1838. strcat(buf,".");
  1839. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1840. strcat(buf,usec_buf);
  1841. #endif
  1842. printf("%s",buf);
  1843. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1844. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1845. // it's option
  1846. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1847. /*
  1848. enum _SYSTEM_STATUS
  1849. {
  1850. S_BOOTING = 0,
  1851. S_IDLE, = 1
  1852. S_AUTHORIZING, =2
  1853. S_REASSIGN_CHECK, =3
  1854. S_REASSIGN, =4
  1855. S_PRECHARGE, =5
  1856. S_PREPARING_FOR_EV, =6
  1857. S_PREPARING_FOR_EVSE, =7
  1858. S_CHARGING, =8
  1859. S_TERMINATING, =9
  1860. S_COMPLETE, =10
  1861. S_ALARM, =11
  1862. S_FAULT =12
  1863. }
  1864. */
  1865. //check Transaction active
  1866. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1867. {
  1868. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1869. {
  1870. //printf("gun_index=%d\n",gun_index);
  1871. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1872. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1873. {
  1874. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1875. currentStatus = 0; //OCPP Status
  1876. }
  1877. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1878. {
  1879. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1880. currentStatus = 1; //OCPP Status
  1881. }
  1882. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1883. {
  1884. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1885. currentStatus = 2; //OCPP Status
  1886. }
  1887. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1888. {
  1889. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1890. currentStatus = 5; //OCPP Status
  1891. }
  1892. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1893. {
  1894. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1895. currentStatus = 4; //OCPP Status
  1896. }
  1897. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  1898. {
  1899. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1900. currentStatus = 7; //OCPP Status: Unavailable
  1901. }
  1902. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1903. {
  1904. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1905. currentStatus = 8; //OCPP Status: Faulted
  1906. }
  1907. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1908. {
  1909. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1910. currentStatus = 6; //OCPP Status: Reserved
  1911. }
  1912. }//end of for CHAdeMO_QUANTITY
  1913. for (int index = 0; index < CCS_QUANTITY; index++)
  1914. {
  1915. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1916. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1917. {
  1918. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1919. currentStatus = 0; //OCPP Status
  1920. }
  1921. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1922. {
  1923. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1924. currentStatus = 1; //OCPP Status
  1925. }
  1926. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1927. {
  1928. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1929. currentStatus = 2; //OCPP Status
  1930. }
  1931. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1932. {
  1933. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1934. currentStatus = 5; //OCPP Status
  1935. }
  1936. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1937. {
  1938. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1939. currentStatus = 4; //OCPP Status
  1940. }
  1941. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  1942. {
  1943. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1944. currentStatus = 7; //OCPP Status
  1945. }
  1946. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1947. {
  1948. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1949. currentStatus = 8; //OCPP Status
  1950. }
  1951. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1952. {
  1953. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1954. currentStatus = 6; //OCPP Status
  1955. }
  1956. }
  1957. for (int index = 0; index < GB_QUANTITY; index++)
  1958. {
  1959. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1960. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1961. {
  1962. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1963. currentStatus = 0; //OCPP Status
  1964. }
  1965. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1966. {
  1967. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1968. currentStatus = 1; //OCPP Status
  1969. }
  1970. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1971. {
  1972. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1973. currentStatus = 2; //OCPP Status
  1974. }
  1975. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1976. {
  1977. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1978. currentStatus = 5; //OCPP Status
  1979. }
  1980. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1981. {
  1982. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1983. currentStatus = 4; //OCPP Status
  1984. }
  1985. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  1986. {
  1987. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1988. currentStatus = 7; //OCPP Status: Unavailable
  1989. }
  1990. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1991. {
  1992. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1993. currentStatus = 8; //OCPP Status: Faulted
  1994. }
  1995. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1996. {
  1997. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1998. currentStatus = 6; //OCPP Status: Faulted
  1999. }
  2000. }
  2001. }
  2002. else
  2003. {
  2004. for (int index = 0; index < AC_QUANTITY; index++)
  2005. {
  2006. //printf("gun_index=%d\n",gun_index);
  2007. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2008. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2009. {
  2010. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2011. currentStatus = 0; //OCPP Status
  2012. }
  2013. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2014. {
  2015. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2016. currentStatus = 1; //OCPP Status
  2017. }
  2018. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2019. {
  2020. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2021. currentStatus = 2; //OCPP Status
  2022. }
  2023. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2024. {
  2025. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2026. currentStatus = 5; //OCPP Status
  2027. }
  2028. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2029. {
  2030. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2031. currentStatus = 4; //OCPP Status
  2032. }
  2033. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  2034. {
  2035. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2036. currentStatus = 7; //OCPP Status: Unavailable
  2037. }
  2038. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2039. {
  2040. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2041. currentStatus = 8; //OCPP Status: Faulted
  2042. }
  2043. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2044. {
  2045. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2046. currentStatus = 6; //OCPP Status: Reserved
  2047. }
  2048. }//end of for AC_QUANTITY
  2049. }//END OF ELSE
  2050. //it's option
  2051. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2052. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2053. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2054. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2055. random_uuid(guid);
  2056. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2057. , MESSAGE_TYPE_CALL
  2058. , guid
  2059. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2060. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2061. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2062. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2063. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2064. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2065. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2066. LWS_Send(message);
  2067. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2068. 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*/)
  2069. {
  2070. //DEBUG_ERROR("statusNotification mapitem pass");
  2071. result = PASS;
  2072. }
  2073. //#ifdef SystemLogMessage
  2074. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2075. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2076. //#endif
  2077. return result;
  2078. }
  2079. int sendStopTransactionRequest(int gun_index)
  2080. {
  2081. mtrace();
  2082. int result = FAIL;
  2083. char message[1500]={0};
  2084. char guid[37]={0};
  2085. char tempdata[65]={0};
  2086. int idx_sample=0;
  2087. DEBUG_ERROR("sendStopTransactionRequest \n");
  2088. //memset(&(ShmOCPP16Data->StopTransaction[gun_index].TransactionData), 0, sizeof(struct StructMeterValue));
  2089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId/*ShmOCPP16Data->Authorize.IdTag*/);
  2090. //ENERGY_ACTIVE_IMPORT_REGISTER
  2091. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2092. {
  2093. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2094. {
  2095. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2096. {
  2097. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2098. //Check Status
  2099. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2100. {
  2101. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2102. }
  2103. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2104. }
  2105. }// END OF CHAdeMO_QUANTITY
  2106. for (int index = 0; index < CCS_QUANTITY; index++)
  2107. {
  2108. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2109. {
  2110. //for test
  2111. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2112. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2113. //Check Status
  2114. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2115. {
  2116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2117. }
  2118. else
  2119. {
  2120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2121. }
  2122. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2123. }
  2124. }// END OF CCS_QUANTITY
  2125. for (int index = 0; index < GB_QUANTITY; index++)
  2126. {
  2127. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2128. {
  2129. // for test
  2130. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2131. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2132. //Check Status
  2133. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2134. {
  2135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2136. }
  2137. else
  2138. {
  2139. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2140. }
  2141. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2142. }
  2143. }// END OF GB_QUANTITY
  2144. }
  2145. else
  2146. {
  2147. for (int index = 0; index < AC_QUANTITY; index++)
  2148. {
  2149. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2150. {
  2151. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2152. //Check Status
  2153. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2154. {
  2155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2156. }
  2157. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2158. }
  2159. }// END OF AC_QUANTITY
  2160. }//END OF ELSE
  2161. //Stop Transaction Time
  2162. struct timeval tmnow;
  2163. struct tm *tm;
  2164. char buf[30];//, usec_buf[6];
  2165. gettimeofday(&tmnow, NULL);
  2166. time_t t;
  2167. t = time(NULL);
  2168. /*UTC time and date*/
  2169. tm = gmtime(&t);
  2170. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2171. #if 0 // remove temporally
  2172. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2173. strcat(buf,".");
  2174. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2175. strcat(buf,usec_buf);
  2176. #endif
  2177. printf("StopTransaction Time %s\n",buf);
  2178. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2180. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2181. random_uuid(guid);
  2182. sprintf(message,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":"
  2183. ,MESSAGE_TYPE_CALL
  2184. ,guid
  2185. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2186. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2187. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2188. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2189. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
  2190. /***********************************transactionData******************************************************/
  2191. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2192. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2193. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2194. {
  2195. //transactionData = json_object_new_object();
  2196. //json_object_object_add(transactionData, "timestamp", json_object_new_string("2019-05-04T18:15:33Z"));
  2197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp, buf/*"2019-05-04T18:15:33Z"*/);
  2198. sprintf(message + strlen(message), "[{\"timestamp\":\"%s\",\"sampledValue\":[", (const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp);
  2199. //=================================
  2200. // Transaction_Begin
  2201. //=================================
  2202. // Energy.Active.Export.Interval
  2203. idx_sample=0;
  2204. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2211. sprintf(message + strlen(message), "{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2212. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2213. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2214. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2215. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2216. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2217. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2218. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2219. );
  2220. //=================================
  2221. // Transaction_End
  2222. //=================================
  2223. //Current.Export
  2224. idx_sample=1;
  2225. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2226. {
  2227. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2228. {
  2229. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2230. {
  2231. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2232. }
  2233. }
  2234. for (int index = 0; index < CCS_QUANTITY; index++)
  2235. {
  2236. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2237. {
  2238. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2239. }
  2240. }
  2241. for (int index = 0; index < GB_QUANTITY; index++)
  2242. {
  2243. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2244. {
  2245. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2246. }
  2247. }
  2248. }
  2249. else
  2250. {
  2251. for (int index = 0; index < AC_QUANTITY; index++)
  2252. {
  2253. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2254. {
  2255. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2256. }
  2257. }
  2258. }// END FOR AC ELSE
  2259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Current_Export/*Energy_Reactive_Export_Register*/]);
  2262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A/*UnitOfMeasure_kWh*/]);
  2265. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2266. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2267. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2268. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2269. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2270. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2271. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2272. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2273. );
  2274. //Energy.Active.Export.Interval
  2275. idx_sample=2;
  2276. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2277. {
  2278. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2279. {
  2280. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2281. {
  2282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2283. }
  2284. }
  2285. for (int index = 0; index < CCS_QUANTITY; index++)
  2286. {
  2287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2288. {
  2289. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2290. }
  2291. }
  2292. for (int index = 0; index < GB_QUANTITY; index++)
  2293. {
  2294. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2295. {
  2296. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2297. }
  2298. }
  2299. }
  2300. else
  2301. {
  2302. for (int index = 0; index < AC_QUANTITY; index++)
  2303. {
  2304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2305. {
  2306. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2307. }
  2308. }
  2309. }// END FOR AC ELSE
  2310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2316. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2317. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2318. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2319. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2320. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2321. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2322. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2323. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2324. );
  2325. //Power.Active.Export
  2326. idx_sample=3;
  2327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2328. {
  2329. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2330. {
  2331. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2332. {
  2333. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2334. }
  2335. }
  2336. for (int index = 0; index < CCS_QUANTITY; index++)
  2337. {
  2338. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2339. {
  2340. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2341. }
  2342. }
  2343. for (int index = 0; index < GB_QUANTITY; index++)
  2344. {
  2345. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2346. {
  2347. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2348. }
  2349. }
  2350. }
  2351. else
  2352. {
  2353. for (int index = 0; index < AC_QUANTITY; index++)
  2354. {
  2355. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2356. {
  2357. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2358. }
  2359. }
  2360. }// END FOR AC ELSE
  2361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2367. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2368. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2369. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2370. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2371. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2372. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2373. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2374. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2375. );
  2376. //Voltage
  2377. idx_sample=4;
  2378. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2379. {
  2380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2381. {
  2382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2383. {
  2384. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2385. }
  2386. }
  2387. for (int index = 0; index < CCS_QUANTITY; index++)
  2388. {
  2389. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2390. {
  2391. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2392. }
  2393. }
  2394. for (int index = 0; index < GB_QUANTITY; index++)
  2395. {
  2396. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2397. {
  2398. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2399. }
  2400. }
  2401. }
  2402. else
  2403. {
  2404. for (int index = 0; index < AC_QUANTITY; index++)
  2405. {
  2406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2407. {
  2408. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2409. }
  2410. }
  2411. }// END FOR AC ELSE
  2412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2418. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2419. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2420. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2421. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2422. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2423. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2424. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2425. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2426. );
  2427. //SoC
  2428. idx_sample=5;
  2429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2430. {
  2431. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2432. {
  2433. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2434. {
  2435. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2436. }
  2437. }
  2438. for (int index = 0; index < CCS_QUANTITY; index++)
  2439. {
  2440. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2441. {
  2442. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2443. }
  2444. }
  2445. for (int index = 0; index < GB_QUANTITY; index++)
  2446. {
  2447. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2448. {
  2449. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2450. }
  2451. }
  2452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2458. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2459. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2460. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2461. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2462. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2463. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2464. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2465. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2466. );
  2467. } // END FOR DC CASE
  2468. sprintf(message + strlen(message)," ] } ] } ]");
  2469. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue);
  2470. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);
  2471. }
  2472. LWS_Send(message);
  2473. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2474. if(hashmap_operation(0, guid, tempdata) == 1)
  2475. {
  2476. result = PASS;
  2477. DEBUG_INFO("StopTransaction mapitem pass\n");
  2478. }
  2479. strcpy(queuedata, message);
  2480. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2481. //#ifdef SystemLogMessage
  2482. //DEBUG_INFO(">>>>>StopTransaction request\n");
  2483. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2484. //#endif
  2485. //for test
  2486. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2487. return result;
  2488. }
  2489. int sendMeterValuesRequest(int gun_index)
  2490. {
  2491. mtrace();
  2492. int result = FAIL;
  2493. char message[1500]={0};
  2494. char guid[37]={0};
  2495. int idx_sample=0;
  2496. //int length = 0;
  2497. char tempdata[65]={0};
  2498. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2499. DEBUG_ERROR("gun_index =%d\n",gun_index);
  2500. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2501. {
  2502. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2503. DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2504. DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2505. return result;
  2506. }
  2507. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2508. {
  2509. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2510. }
  2511. //set value
  2512. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2513. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2514. random_uuid(guid);
  2515. sprintf(message,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":"
  2516. ,MESSAGE_TYPE_CALL
  2517. ,guid
  2518. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2519. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId);
  2520. //,comfirmpayload);
  2521. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2522. {
  2523. //allocate memory space
  2524. //ShmOCPP16Data->MeterValues[gun_index].MeterValue = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2525. //UTC Date time
  2526. struct timeval tmnow;
  2527. struct tm *tm;
  2528. char buf[30];//, usec_buf[6];
  2529. gettimeofday(&tmnow, NULL);
  2530. time_t t;
  2531. t = time(NULL);
  2532. /*UTC time and date*/
  2533. tm = gmtime(&t);
  2534. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2535. #if 0 // remove temporally
  2536. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2537. strcat(buf,".");
  2538. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2539. strcat(buf,usec_buf);
  2540. #endif
  2541. // printf("%s",buf);
  2542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp, buf);
  2543. //allocate memory space
  2544. //ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*6);
  2545. sprintf(message + strlen(message),"[{\"timestamp\":\"%s\",\"sampledValue\":[",(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp);
  2546. idx_sample=0;
  2547. //********************************(1)Current.Export************************************************/
  2548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2549. {
  2550. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2551. {
  2552. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2553. {
  2554. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2555. }
  2556. }
  2557. for (int index = 0; index < CCS_QUANTITY; index++)
  2558. {
  2559. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2560. {
  2561. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2562. }
  2563. }
  2564. for (int index = 0; index < GB_QUANTITY; index++)
  2565. {
  2566. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2567. {
  2568. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2569. }
  2570. }
  2571. }
  2572. else
  2573. {
  2574. for (int index = 0; index < AC_QUANTITY; index++)
  2575. {
  2576. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2577. {
  2578. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2579. }
  2580. }
  2581. }// END FOR AC ELSE
  2582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Current_Export]);
  2585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2587. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2588. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2589. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2590. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2591. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2592. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2593. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2594. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2595. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2596. );
  2597. #if 0
  2598. idx_sample=1;
  2599. //****************************************************(2)Energy.Active.Export.Register*********************************************/
  2600. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2601. {
  2602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2603. {
  2604. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2605. {
  2606. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2607. }
  2608. }
  2609. for (int index = 0; index < CCS_QUANTITY; index++)
  2610. {
  2611. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2612. {
  2613. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2614. }
  2615. }
  2616. for (int index = 0; index < GB_QUANTITY; index++)
  2617. {
  2618. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2619. {
  2620. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2621. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2622. }
  2623. }
  2624. }
  2625. else
  2626. {
  2627. for (int index = 0; index < AC_QUANTITY; index++)
  2628. {
  2629. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2630. {
  2631. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2632. }
  2633. }
  2634. }// END FOR AC ELSE
  2635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2636. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Register]);
  2638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2641. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2642. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2643. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2644. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2645. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2646. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2647. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2648. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2649. );
  2650. #endif
  2651. idx_sample=1;
  2652. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2653. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2654. {
  2655. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2656. {
  2657. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2658. {
  2659. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2660. }
  2661. }
  2662. for (int index = 0; index < CCS_QUANTITY; index++)
  2663. {
  2664. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2666. {
  2667. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2668. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2669. }
  2670. }
  2671. for (int index = 0; index < GB_QUANTITY; index++)
  2672. {
  2673. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2674. {
  2675. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2676. }
  2677. }
  2678. }
  2679. else
  2680. {
  2681. for (int index = 0; index < AC_QUANTITY; index++)
  2682. {
  2683. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2684. {
  2685. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2686. }
  2687. }
  2688. }//END FOR AC ELSE
  2689. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2690. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2691. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2692. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2693. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2694. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2695. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2696. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2697. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2698. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2699. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2700. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2701. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2702. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2703. );
  2704. idx_sample=2;
  2705. //********************************(4)Power.Active.Export************************************************/
  2706. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2707. {
  2708. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2709. {
  2710. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2711. {
  2712. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2713. }
  2714. }
  2715. for (int index = 0; index < CCS_QUANTITY; index++)
  2716. {
  2717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2718. {
  2719. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2720. }
  2721. }
  2722. for (int index = 0; index < GB_QUANTITY; index++)
  2723. {
  2724. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2725. {
  2726. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2727. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2728. }
  2729. }
  2730. }
  2731. else
  2732. {
  2733. for (int index = 0; index < AC_QUANTITY; index++)
  2734. {
  2735. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2736. {
  2737. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2738. }
  2739. }
  2740. }// END FOR AC ELSE
  2741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2743. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Power_Active_Export]);
  2744. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2745. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2746. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2747. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2748. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2749. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2750. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2751. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2752. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2753. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2754. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2755. );
  2756. idx_sample=3;
  2757. //***********************************************(5)VOLTAGE******************************************************/
  2758. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2759. {
  2760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2761. {
  2762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2763. {
  2764. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2765. }
  2766. }
  2767. for (int index = 0; index < CCS_QUANTITY; index++)
  2768. {
  2769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2770. {
  2771. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2772. }
  2773. }
  2774. for (int index = 0; index < GB_QUANTITY; index++)
  2775. {
  2776. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2777. {
  2778. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2779. }
  2780. }
  2781. }
  2782. else
  2783. {
  2784. for (int index = 0; index < AC_QUANTITY; index++)
  2785. {
  2786. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2787. {
  2788. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2789. }
  2790. }
  2791. }//END FOR AC ELSE
  2792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Voltage]);
  2795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2796. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2797. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2798. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2799. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2800. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2801. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2802. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2803. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2804. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2805. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2806. );
  2807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2808. {
  2809. idx_sample=4;
  2810. //sampledValue = NULL;
  2811. //***********************************************(6)SOC******************************************************/
  2812. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2813. {
  2814. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2815. {
  2816. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2817. }
  2818. }
  2819. for (int index = 0; index < CCS_QUANTITY; index++)
  2820. {
  2821. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2822. {
  2823. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2824. }
  2825. }
  2826. for (int index = 0; index < GB_QUANTITY; index++)
  2827. {
  2828. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2829. {
  2830. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2831. }
  2832. }
  2833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[SoC]);
  2836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2838. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2839. sprintf(message + strlen(message),",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2840. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2841. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2842. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2843. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2844. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2845. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2846. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2847. );
  2848. }
  2849. //}
  2850. sprintf(message + strlen(message)," ] } ] } ]");
  2851. //free(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue);
  2852. }
  2853. LWS_Send(message);
  2854. //memset(mapItem, 0, sizeof(data_struct_t));
  2855. // Put request guid to hash map
  2856. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2857. 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*/)
  2858. {
  2859. result = PASS;
  2860. DEBUG_INFO("MeterValues mapitem pass\n");
  2861. }
  2862. strcpy(queuedata, message);
  2863. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2864. //#ifdef SystemLogMessage
  2865. //DEBUG_INFO(">>>>>MeerValues request\n");
  2866. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2867. //#endif
  2868. return result;
  2869. }
  2870. //==========================================
  2871. // send confirm routine
  2872. //==========================================
  2873. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2874. {
  2875. mtrace();
  2876. int result = FAIL;
  2877. char message[100]={0};
  2878. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2879. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2880. LWS_Send(message);
  2881. result = TRUE;
  2882. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2883. return result;
  2884. }
  2885. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2886. {
  2887. mtrace();
  2888. int result = FAIL;
  2889. char message[100]={0};
  2890. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2891. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2892. LWS_Send(message);
  2893. result = TRUE;
  2894. return result;
  2895. }
  2896. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2897. {
  2898. mtrace();
  2899. int result = FAIL;
  2900. char message[100]={0};
  2901. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2902. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2903. LWS_Send(message);
  2904. result = TRUE;
  2905. return result;
  2906. }
  2907. int sendClearCacheConfirmation(char *uuid,char *payload)
  2908. {
  2909. mtrace();
  2910. int result = FAIL;
  2911. char message[500]={0};
  2912. // int count = 0;
  2913. // int gun_index = 0;
  2914. // char guid[37];
  2915. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2916. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2917. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2918. LWS_Send(message);
  2919. return result;
  2920. }
  2921. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2922. {
  2923. mtrace();
  2924. int result = FAIL;
  2925. char message[500]={0};
  2926. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2927. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2928. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2929. LWS_Send(message);
  2930. return result;
  2931. }
  2932. int sendDataTransferConfirmation(char *uuid,char *payload)
  2933. {
  2934. mtrace();
  2935. char statusStr[20]={0};
  2936. char dataStr[10]={0};
  2937. char sstr[20]={0};
  2938. int c = 0;
  2939. char *loc;
  2940. int result = FAIL;
  2941. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2942. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2943. /**********************status**************************/
  2944. loc = strstr(payload, "status");
  2945. memset(sstr ,0, sizeof(sstr) );
  2946. c = 0;
  2947. while (loc[3+strlen("status")+c] != '\"')
  2948. {
  2949. sstr[c] = loc[3+strlen("status")+c];
  2950. c++;
  2951. }
  2952. sstr[c] = '\0';
  2953. strcpy(statusStr, sstr);
  2954. /**********************data**************************/
  2955. loc = strstr(payload, "data");
  2956. memset(sstr ,0, sizeof(sstr) );
  2957. c = 0;
  2958. while (loc[3+strlen("data")+c] != '\"')
  2959. {
  2960. sstr[c] = loc[3+strlen("data")+c];
  2961. c++;
  2962. }
  2963. sstr[c] = '\0';
  2964. strcpy(dataStr, sstr);
  2965. return result;
  2966. }
  2967. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2968. {
  2969. mtrace();
  2970. int result = FAIL;
  2971. char message[1000]={0};
  2972. double diff_f = 0.0;
  2973. int diff_i = 0;
  2974. struct tm tp;
  2975. DEBUG_ERROR("handle sendGetCompositeScheduleConfirmation ...\n");
  2976. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2977. tp.tm_isdst = -1;
  2978. time_t utc = mktime(&tp);
  2979. time_t t = time(NULL);
  2980. diff_f = difftime(t, utc);
  2981. diff_i = (int)diff_f;
  2982. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2983. #if 0 //remove temporally
  2984. 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}"
  2985. ,MESSAGE_TYPE_CALLRESULT
  2986. ,uuid
  2987. ,payload
  2988. ,connectorIdInt
  2989. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2990. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2991. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2992. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2993. #endif
  2994. if(nPeriod == 0)
  2995. {
  2996. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2997. ,MESSAGE_TYPE_CALLRESULT
  2998. ,uuid
  2999. ,payload
  3000. ,connectorIdInt
  3001. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule);
  3002. }
  3003. else
  3004. {
  3005. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3006. ,MESSAGE_TYPE_CALLRESULT
  3007. ,uuid
  3008. ,payload
  3009. ,connectorIdInt
  3010. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3011. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3012. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3013. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3014. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3015. #if 1 // remove temporally
  3016. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3017. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3018. {
  3019. if (idx_sample == 0)
  3020. {
  3021. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3022. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  3023. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3024. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3025. }
  3026. else
  3027. {
  3028. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3029. , (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diff_i /*-1*/)
  3030. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3031. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3032. }
  3033. }
  3034. #endif
  3035. sprintf(message + strlen(message), "]}}]");
  3036. }
  3037. LWS_Send(message);
  3038. result = TRUE;
  3039. return result;
  3040. }
  3041. int sendGetConfigurationConfirmation(char *uuid)
  3042. {
  3043. mtrace();
  3044. int result = FAIL;
  3045. int MaxKeySupported = 0;
  3046. int sentConfigurationNumber= 0;
  3047. int sentunConfigurationNumber= 0;
  3048. char message[4000]={0};
  3049. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3050. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3051. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3052. ,MESSAGE_TYPE_CALLRESULT
  3053. ,uuid );
  3054. //configuration key
  3055. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3056. {
  3057. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3058. {
  3059. if (sentConfigurationNumber == 0)
  3060. {
  3061. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3062. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3063. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3064. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3065. }
  3066. else
  3067. {
  3068. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3069. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3070. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3071. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3072. }
  3073. sentConfigurationNumber = sentConfigurationNumber + 1;
  3074. }
  3075. }
  3076. sprintf(message + strlen(message), "]");
  3077. if(UnknownKeynum != 0)
  3078. {
  3079. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3080. //unkown key
  3081. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3082. {
  3083. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3084. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3085. if(sentunConfigurationNumber == 0)
  3086. {
  3087. sprintf(message + strlen(message), "\"%s\""
  3088. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3089. }
  3090. else
  3091. {
  3092. sprintf(message + strlen(message), ",\"%s\""
  3093. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3094. }
  3095. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3096. }
  3097. sprintf(message + strlen(message), "]");
  3098. }
  3099. sprintf(message + strlen(message), "} ]");
  3100. LWS_Send(message);
  3101. #if 0
  3102. printf("error 1-0\n");
  3103. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3104. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3105. #endif
  3106. return result;
  3107. }
  3108. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3109. {
  3110. mtrace();
  3111. int result = FAIL;
  3112. char message[400]={0};
  3113. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3114. if(strcmp(payload,"")==0)
  3115. {
  3116. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3117. }
  3118. else
  3119. {
  3120. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3121. }
  3122. LWS_Send(message);
  3123. result = TRUE;
  3124. return result;
  3125. }
  3126. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3127. {
  3128. mtrace();
  3129. int result = FAIL;
  3130. char message[80]={0};
  3131. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3132. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3133. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3134. LWS_Send(message);
  3135. result = TRUE;
  3136. return result;
  3137. }
  3138. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3139. {
  3140. mtrace();
  3141. int result = FAIL;
  3142. char message[80]={0};
  3143. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3144. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3145. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3146. LWS_Send(message);
  3147. result = TRUE;
  3148. return result;
  3149. }
  3150. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3151. {
  3152. mtrace();
  3153. int result = FAIL;
  3154. char message[80]={0};
  3155. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3156. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3157. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3158. LWS_Send(message);
  3159. result = TRUE;
  3160. return result;
  3161. }
  3162. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3163. {
  3164. mtrace();
  3165. int result = FAIL;
  3166. char message[80]={0};
  3167. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3168. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3169. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3170. LWS_Send(message);
  3171. result = TRUE;
  3172. return result;
  3173. }
  3174. int sendResetConfirmation(char *uuid,char *payload)
  3175. {
  3176. mtrace();
  3177. int result = FAIL;
  3178. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3179. char message[80]={0};
  3180. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3181. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3182. LWS_Send(message);
  3183. result = TRUE;
  3184. return result;
  3185. }
  3186. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3187. {
  3188. mtrace();
  3189. int result = FAIL;
  3190. char message[500]={0};
  3191. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3192. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3193. LWS_Send(message);
  3194. result = TRUE;
  3195. return result;
  3196. }
  3197. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3198. {
  3199. mtrace();
  3200. int result = FAIL;
  3201. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3202. char message[80]={0};
  3203. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  3204. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3205. LWS_Send(message);
  3206. result = TRUE;
  3207. return result;
  3208. }
  3209. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3210. {
  3211. mtrace();
  3212. int result = FAIL;
  3213. char message[80]={0};
  3214. DEBUG_ERROR("sendTriggerMessageConfirmation\n");
  3215. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3216. LWS_Send(message);
  3217. result = TRUE;
  3218. return result;
  3219. }
  3220. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3221. {
  3222. mtrace();
  3223. int result = FAIL;
  3224. char message[80]={0};
  3225. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3226. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  3227. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3228. LWS_Send(message);
  3229. result = TRUE;
  3230. return result;
  3231. }
  3232. int sendUpdateFirmwareConfirmation(char *uuid)
  3233. {
  3234. mtrace();
  3235. int result = FAIL;
  3236. char message[60]={0};
  3237. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3238. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3239. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3240. LWS_Send(message);
  3241. result = TRUE;
  3242. return result;
  3243. }
  3244. //==========================================
  3245. // send CallError routine
  3246. //==========================================
  3247. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3248. {
  3249. mtrace();
  3250. //int result = FAIL;
  3251. char message[220]={0};
  3252. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3253. #ifdef SystemLogMessage
  3254. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3255. uniqueId, action, errorCode, errorDescription);
  3256. #endif
  3257. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3258. LWS_Send(message);
  3259. //result = TRUE;
  3260. }
  3261. //==========================================
  3262. // Handle server request routine Start
  3263. //==========================================
  3264. #define GUN_NUM 1
  3265. int handleCancelReservationRequest(char *uuid, char *payload)
  3266. {
  3267. mtrace();
  3268. int result = FAIL;
  3269. int gunNO = 0;
  3270. int reservationIdInt =0;
  3271. char comfirmstr[20];
  3272. int c = 0;
  3273. char *loc;
  3274. char sstr[100]={0};
  3275. DEBUG_INFO("handle CancelReservationRequest\n");
  3276. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3277. c = 0;
  3278. loc = strstr(payload, "reservationId");
  3279. memset(sstr ,0, sizeof(sstr) );
  3280. while (loc[strlen("reservationId")+2+c] != '}')
  3281. {
  3282. sstr[c] = loc[strlen("reservationId")+2+c];
  3283. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3284. c++;
  3285. }
  3286. sstr[c] = '\0';
  3287. reservationIdInt = atoi(sstr);
  3288. memset(comfirmstr, 0, sizeof comfirmstr);
  3289. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3290. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3291. //check Transaction active
  3292. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3293. {
  3294. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3295. {
  3296. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3297. {
  3298. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3299. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3300. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3301. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3302. goto end;
  3303. }
  3304. }
  3305. for (int index = 0; index < CCS_QUANTITY; index++)
  3306. {
  3307. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3308. {
  3309. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3310. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3311. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3312. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3313. goto end;
  3314. }
  3315. }
  3316. for (int index = 0; index < GB_QUANTITY; index++)
  3317. {
  3318. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3319. {
  3320. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3321. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3322. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3323. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3324. goto end;
  3325. }
  3326. }
  3327. }
  3328. else
  3329. {
  3330. for (int index = 0; index < AC_QUANTITY; index++)
  3331. {
  3332. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3333. {
  3334. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3335. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3336. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3337. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3338. goto end;
  3339. }
  3340. }
  3341. }// END FOR AC ELSE
  3342. //The reservationId does NOT match the reservationId
  3343. sendCancelReservationConfirmation(uuid, comfirmstr);
  3344. end:
  3345. // Fill in ocpp packet uuid
  3346. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3347. return result;
  3348. }
  3349. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3350. {
  3351. mtrace();
  3352. int result = FAIL;
  3353. int gunIndex = 0;
  3354. char sstr[90]={0};
  3355. char typeStr[16]={0};
  3356. char comfirmstr[20];
  3357. int specificId = FALSE;
  3358. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3359. char *loc;
  3360. //int intervalInt = 0;
  3361. int c = 0;
  3362. /*** connectorId ****/
  3363. c = 0;
  3364. loc = strstr(payload, "connectorId");
  3365. memset(sstr ,0, sizeof(sstr) );
  3366. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3367. {
  3368. sstr[c] = loc[strlen("connectorId")+2+c];
  3369. c++;
  3370. }
  3371. sstr[c] = '\0';
  3372. gunIndex = atoi(sstr);
  3373. /***type ****/
  3374. loc = strstr(payload, "type");
  3375. memset(sstr ,0, sizeof(sstr) );
  3376. c = 0;
  3377. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3378. {
  3379. sstr[c] = loc[3+strlen("type")+c];
  3380. c++;
  3381. }
  3382. sstr[c] = '\0';
  3383. strcpy(typeStr, sstr);
  3384. if(gunIndex != 0)
  3385. {
  3386. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3387. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3388. }
  3389. else
  3390. {
  3391. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3392. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3393. }
  3394. memset(comfirmstr, 0, sizeof comfirmstr);
  3395. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3396. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3397. {
  3398. specificId = TRUE;
  3399. }
  3400. if(specificId == FALSE)
  3401. goto end;
  3402. if(gunIndex != 0)
  3403. {
  3404. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3405. }
  3406. else
  3407. {
  3408. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3409. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3410. }
  3411. /*
  3412. enum _SYSTEM_STATUS
  3413. {
  3414. S_BOOTING = 0,
  3415. S_IDLE, = 1
  3416. S_AUTHORIZING, =2
  3417. S_REASSIGN_CHECK, =3
  3418. S_REASSIGN, =4
  3419. S_PRECHARGE, =5
  3420. S_PREPARING_FOR_EV, =6
  3421. S_PREPARING_FOR_EVSE, =7
  3422. S_CHARGING, =8
  3423. S_TERMINATING, =9
  3424. S_COMPLETE, =10
  3425. S_ALARM, =11
  3426. S_FAULT =12
  3427. }
  3428. */
  3429. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3430. {
  3431. //check Transaction active
  3432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3433. {
  3434. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3435. {
  3436. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3437. {
  3438. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3439. {
  3440. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3441. }
  3442. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3443. {
  3444. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3445. }
  3446. else
  3447. {
  3448. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3449. }
  3450. goto end;
  3451. }
  3452. }//END FOR CHAdeMO_QUANTITY
  3453. for (int index = 0; index < CCS_QUANTITY; index++)
  3454. {
  3455. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3456. {
  3457. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3458. {
  3459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3460. }
  3461. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3462. {
  3463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3464. }
  3465. else
  3466. {
  3467. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3468. }
  3469. goto end;
  3470. }
  3471. }//END FOR CCS_QUANTITY
  3472. for (int index = 0; index < GB_QUANTITY; index++)
  3473. {
  3474. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3475. {
  3476. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3477. {
  3478. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3479. }
  3480. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3481. {
  3482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3483. }
  3484. else
  3485. {
  3486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3487. }
  3488. goto end;
  3489. }
  3490. }// END FOR GB_QUANTITY
  3491. }
  3492. else
  3493. {
  3494. for (int index = 0; index < AC_QUANTITY; index++)
  3495. {
  3496. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3497. {
  3498. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3499. {
  3500. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3501. }
  3502. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3503. {
  3504. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3505. }
  3506. else
  3507. {
  3508. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3509. }
  3510. goto end;
  3511. }
  3512. }//END FOR AC_QUANTITY
  3513. }// END FOR AC ELSE
  3514. }//END FOR AvailabilityTypeStr[Inoperative]
  3515. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3516. {
  3517. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3518. //check Transaction active
  3519. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3520. {
  3521. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3522. {
  3523. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3524. {
  3525. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3526. goto end;
  3527. }
  3528. }//END FOR CHAdeMO_QUANTITY
  3529. for (int index = 0; index < CCS_QUANTITY; index++)
  3530. {
  3531. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3532. {
  3533. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3534. goto end;
  3535. }
  3536. }//END FOR CCS_QUANTITY
  3537. for (int index = 0; index < GB_QUANTITY; index++)
  3538. {
  3539. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3540. {
  3541. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3543. goto end;
  3544. }
  3545. }// END FOR GB_QUANTITY
  3546. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3547. }
  3548. else
  3549. {
  3550. for (int index = 0; index < AC_QUANTITY; index++)
  3551. {
  3552. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3553. {
  3554. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3555. goto end;
  3556. }
  3557. }//END FOR CHAdeMO_QUANTITY
  3558. }//END FOR AC ELSE
  3559. }//END FOR AvailabilityTypeStr[Operative]
  3560. end:
  3561. if(gunIndex != 0)
  3562. {
  3563. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3564. }
  3565. else
  3566. {
  3567. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3568. }
  3569. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3570. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3571. return result;
  3572. }
  3573. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3574. {
  3575. mtrace();
  3576. int result = FAIL;
  3577. char sstr[100]={0};
  3578. char keystr[40]={0};
  3579. char valuestr[16]={0};
  3580. char *loc;
  3581. int c = 0;
  3582. char comfirmstr[20];
  3583. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3584. /***key ****/
  3585. loc = strstr(payload, "key");
  3586. memset(sstr ,0, sizeof(sstr) );
  3587. c = 0;
  3588. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3589. {
  3590. sstr[c] = loc[3+strlen("key")+c];
  3591. c++;
  3592. }
  3593. sstr[c] = '\0';
  3594. strcpy(keystr, sstr);
  3595. /***value ****/
  3596. loc = strstr(payload, "value");
  3597. memset(sstr ,0, sizeof(sstr) );
  3598. c = 0;
  3599. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3600. {
  3601. sstr[c] = loc[3+strlen("value")+c];
  3602. c++;
  3603. }
  3604. sstr[c] = '\0';
  3605. strcpy(valuestr, sstr);
  3606. if((uuid==NULL) || (payload ==NULL) )
  3607. {
  3608. #ifdef Debug
  3609. DEBUG_INFO("payload is null\n");
  3610. #endif
  3611. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3612. }
  3613. else
  3614. {
  3615. int status = setKeyValue(keystr, valuestr);
  3616. switch(status)
  3617. {
  3618. case ConfigurationStatus_Accepted:
  3619. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3620. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3621. break;
  3622. case ConfigurationStatus_Rejected:
  3623. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3624. break;
  3625. case RebootRequired:
  3626. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3627. break;
  3628. case NotSupported:
  3629. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3630. break;
  3631. default:
  3632. break;
  3633. }
  3634. }
  3635. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3636. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3637. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3638. return result;
  3639. }
  3640. int handleClearCacheRequest(char *uuid, char *payload)
  3641. {
  3642. mtrace();
  3643. int result = FAIL;
  3644. char comfirmstr[20];
  3645. int fd;
  3646. char rmFileCmd[100]={0};
  3647. struct stat stats;
  3648. DEBUG_ERROR("handle ClearCacheRequest\n");
  3649. stat("../Storage/OCPP", &stats);
  3650. // Check for directory existence
  3651. if (S_ISDIR(stats.st_mode) == 1)
  3652. {
  3653. //DEBUG_ERROR("\n OCPP directory exist \n");
  3654. }
  3655. else
  3656. {
  3657. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3658. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3659. system(rmFileCmd);
  3660. }
  3661. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  3662. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3663. {
  3664. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3665. }
  3666. else
  3667. {
  3668. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3669. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3670. if(log == NULL)
  3671. {
  3672. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3673. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3674. goto end;
  3675. }
  3676. else
  3677. {
  3678. fclose(log);
  3679. }
  3680. }
  3681. fd = open(AuthorizationCache_JSON,O_RDWR);
  3682. if(fd < 0)
  3683. {
  3684. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3685. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3686. }
  3687. else
  3688. {
  3689. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3690. //* 清空?�件 */
  3691. ftruncate(fd,0);
  3692. //* ?�新设置?�件?�移??*/
  3693. lseek(fd,0,SEEK_SET);
  3694. close(fd);
  3695. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3696. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3697. }
  3698. end:
  3699. sendClearCacheConfirmation(uuid, comfirmstr);
  3700. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3701. return result;
  3702. }
  3703. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3704. {
  3705. mtrace();
  3706. int result = FAIL;
  3707. int resultRename;
  3708. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3709. char chargingProfilePurposeStr[26]={0};
  3710. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3711. char tempchargingProfilePurposeStr[26]={0};
  3712. char sstr[160]={0};//sstr[200]={ 0 };
  3713. char str[100]={0};
  3714. int c = 0;
  3715. //int i = 0;
  3716. //char * pch;
  3717. char *loc;
  3718. char fname[200];
  3719. char comfirmstr[20]={0};
  3720. char word[1000]={0};
  3721. int clearflag = FALSE;
  3722. int chargingProfileIdIsNULL = FALSE;
  3723. int connectorIsNULL = FALSE;
  3724. int chargingProfilePurposeIsNULL = FALSE;
  3725. int stackLevelIsNULL = FALSE;
  3726. FILE *fptr1, *fptr2;
  3727. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3728. int n_chargingProfile=0;
  3729. char sLineWord[1060]={0};
  3730. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3731. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3732. //***id ****/
  3733. c = 0;
  3734. loc = strstr(payload, "id");
  3735. memset(sstr ,0, sizeof(sstr) );
  3736. if(loc == NULL)
  3737. {
  3738. chargingProfileIdIsNULL = TRUE;
  3739. }
  3740. else
  3741. {
  3742. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3743. {
  3744. sstr[c] = loc[strlen("id")+2+c];
  3745. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3746. c++;
  3747. }
  3748. sstr[c] = '\0';
  3749. chargingProfileIdInt = atoi(sstr);
  3750. }
  3751. //***connectorId ****/
  3752. c=0;
  3753. loc = strstr(payload, "connectorId");
  3754. memset(sstr ,0, sizeof(sstr) );
  3755. if(loc == NULL)
  3756. {
  3757. connectorIsNULL = TRUE;
  3758. }
  3759. else
  3760. {
  3761. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3762. {
  3763. sstr[c] = loc[strlen("connectorId")+2+c];
  3764. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3765. c++;
  3766. }
  3767. sstr[c] = '\0';
  3768. connectorIdInt = atoi(sstr);
  3769. }
  3770. //***chargingProfilePurpose ****/
  3771. loc = strstr(payload, "chargingProfilePurpose");
  3772. memset(sstr ,0, sizeof(sstr) );
  3773. c = 0;
  3774. if(loc == NULL)
  3775. {
  3776. chargingProfilePurposeIsNULL = TRUE;
  3777. }
  3778. else
  3779. {
  3780. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3781. {
  3782. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3783. c++;
  3784. }
  3785. sstr[c] = '\0';
  3786. strcpy(chargingProfilePurposeStr, sstr);
  3787. }
  3788. //***stackLevel ****/
  3789. c=0;
  3790. loc = strstr(payload, "stackLevel");
  3791. memset(sstr ,0, sizeof(sstr) );
  3792. if(loc == NULL)
  3793. {
  3794. stackLevelIsNULL = TRUE;
  3795. }
  3796. else
  3797. {
  3798. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3799. {
  3800. sstr[c] = loc[strlen("stackLevel")+2+c];
  3801. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3802. c++;
  3803. }
  3804. sstr[c] = '\0';
  3805. stackLevelInt = atoi(sstr);
  3806. }
  3807. if(connectorIsNULL == FALSE)
  3808. {
  3809. switch(connectorIdInt)
  3810. {
  3811. case 0:
  3812. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3813. {
  3814. strcpy(fname, ChargePointMaxProfile_JSON);
  3815. }
  3816. // else
  3817. // {
  3818. // strcpy(fname, TxDefaultProfile_0_JSON);
  3819. // }
  3820. break;
  3821. case 1:
  3822. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3823. {
  3824. strcpy(fname, TxDefaultProfile_1_JSON);
  3825. }
  3826. // else
  3827. // {
  3828. // strcpy(fname, TxProfile_1_JSON);
  3829. // }
  3830. break;
  3831. case 2:
  3832. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3833. {
  3834. strcpy(fname, TxDefaultProfile_2_JSON);
  3835. }
  3836. // else
  3837. // {
  3838. // strcpy(fname, TxProfile_2_JSON);
  3839. // }
  3840. break;
  3841. default:
  3842. strcpy(fname, ChargePointMaxProfile_JSON );
  3843. break;
  3844. }
  3845. }
  3846. else
  3847. {
  3848. strcpy(fname, ChargePointMaxProfile_JSON );
  3849. }
  3850. fptr1 = fopen(fname, "r");
  3851. if (!fptr1)
  3852. {
  3853. //file not exist
  3854. DEBUG_ERROR("Unable to open the input file!!\n");
  3855. fptr1 = fopen(fname, "w+");
  3856. }
  3857. fclose(fptr1);
  3858. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3859. {
  3860. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3861. goto end;
  3862. }
  3863. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3864. {
  3865. //clear the whole contents of a file in C
  3866. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3867. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3868. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3869. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3870. fclose(fopen(TxProfile_1_JSON, "w"));
  3871. fclose(fopen(TxProfile_2_JSON, "w"));
  3872. #if 0
  3873. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3874. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3875. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3876. #endif
  3877. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3878. }
  3879. else
  3880. {
  3881. fptr1 = fopen(fname, "r");
  3882. fptr2 = fopen(temp, "w+");
  3883. while(fscanf(fptr1, "%s", word) != EOF)
  3884. {
  3885. //DEBUG_INFO("word=%s\n",word);
  3886. if(strcmp(word, "chargingProfileId") == 0)
  3887. {
  3888. n_chargingProfile = n_chargingProfile + 1;
  3889. DEBUG_INFO("chargingProfileId Found\n");
  3890. }
  3891. }
  3892. rewind(fptr1);
  3893. //search Charging Profile Element
  3894. //int i= 0;
  3895. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3896. {
  3897. //*************************tempconnectorIdInt*********************************/
  3898. loc = strstr(sLineWord, "connectorId");
  3899. c = 0;
  3900. memset(sstr ,0, sizeof(sstr) );
  3901. while (loc[strlen("connectorId")+2+c] != ',')
  3902. {
  3903. sstr[c] = loc[strlen("connectorId")+2+c];
  3904. c++;
  3905. }
  3906. sstr[c] = '\0';
  3907. tempconnectorIdInt = atoi(sstr);
  3908. //chargingProfileId
  3909. c = 0;
  3910. loc = strstr(sLineWord, "chargingProfileId");
  3911. memset(sstr ,0, sizeof(sstr) );
  3912. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3913. {
  3914. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3915. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3916. c++;
  3917. }
  3918. sstr[c] = '\0';
  3919. tempchargingProfileIdInt = atoi(sstr);
  3920. //stackLevel
  3921. c = 0;
  3922. loc = strstr(sLineWord, "stackLevel");
  3923. memset(sstr ,0, sizeof(sstr) );
  3924. while (loc[strlen("stackLevel")+2+c] != ',')
  3925. {
  3926. sstr[c] = loc[strlen("stackLevel")+2+c];
  3927. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3928. c++;
  3929. }
  3930. sstr[c] = '\0';
  3931. tempstackLevelInt = atoi(sstr);
  3932. c = 0;
  3933. loc = strstr(sLineWord, "chargingProfilePurpose");
  3934. memset(sstr ,0, sizeof(sstr) );
  3935. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3936. {
  3937. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3938. c++;
  3939. }
  3940. sstr[c] = '\0';
  3941. strcpy(tempchargingProfilePurposeStr, sstr);
  3942. if(chargingProfileIdIsNULL == FALSE)
  3943. {
  3944. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3945. {
  3946. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3947. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3948. clearflag = TRUE;
  3949. continue;
  3950. }
  3951. else
  3952. {
  3953. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3954. //json_object_array_add(newHeatMap, jsonitem);
  3955. fprintf(fptr2, sLineWord);//writing data into file
  3956. }
  3957. }
  3958. else
  3959. {
  3960. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3961. {
  3962. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3963. {
  3964. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3965. clearflag = TRUE;
  3966. continue;
  3967. }
  3968. }
  3969. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3970. {
  3971. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3972. {
  3973. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3974. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3975. {
  3976. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3977. clearflag = TRUE;
  3978. continue;
  3979. }
  3980. }
  3981. }
  3982. else
  3983. {
  3984. //json_object_array_add(newHeatMap, jsonitem);
  3985. fprintf(fptr2, sLineWord);//writing data into file
  3986. }
  3987. }
  3988. memset(sLineWord, 0, sizeof sLineWord);
  3989. }
  3990. if(clearflag == FALSE)
  3991. {
  3992. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3993. goto end;
  3994. }
  3995. fclose(fptr1);
  3996. fclose(fptr2);
  3997. sprintf(str,"rm -f %s",fname);
  3998. system(str);
  3999. resultRename = rename(temp, fname);
  4000. if(resultRename == 0)
  4001. {
  4002. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4003. }
  4004. else
  4005. {
  4006. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4007. }
  4008. }
  4009. end:
  4010. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4011. return result;
  4012. }
  4013. int handleDataTransferRequest(char *uuid, char *payload)
  4014. {
  4015. mtrace();
  4016. int result = FAIL;
  4017. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4018. char tempvendorId[255]={0};
  4019. char tempmessageId[50]={0};
  4020. char tempdata[50]={0};
  4021. char sstr[160]={0};//sstr[200]={ 0 };
  4022. char message[80]={0};
  4023. int c = 0;
  4024. char *loc;
  4025. DEBUG_INFO("handle DataTransferRequest\n");
  4026. if((uuid != NULL) && (payload != NULL))
  4027. {
  4028. //===============================
  4029. // vendorId
  4030. //===============================
  4031. c = 0;
  4032. loc = strstr(payload, "vendorId");
  4033. while (loc[strlen("vendorId")+3+c] != '\"')
  4034. {
  4035. sstr[c] = loc[strlen("vendorId")+3+c];
  4036. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4037. c++;
  4038. }
  4039. sstr[c] = '\0';
  4040. strcpy(tempvendorId,sstr);
  4041. //===============================
  4042. // messageId
  4043. //===============================
  4044. memset(sstr ,0, sizeof(sstr) );
  4045. c = 0;
  4046. loc = strstr(payload, "messageId");
  4047. while (loc[strlen("messageId")+3+c] != '\"')
  4048. {
  4049. sstr[c] = loc[strlen("messageId")+3+c];
  4050. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4051. c++;
  4052. }
  4053. sstr[c] = '\0';
  4054. strcpy(tempmessageId,sstr);
  4055. //===============================
  4056. // data
  4057. //===============================
  4058. memset(sstr ,0, sizeof(sstr) );
  4059. c = 0;
  4060. loc = strstr(payload, "data");
  4061. printf("loc=%s\n",loc);
  4062. while (loc[strlen("data")+3+c] != '\"')
  4063. {
  4064. sstr[c] = loc[strlen("data")+3+c];
  4065. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4066. c++;
  4067. }
  4068. sstr[c] = '\0';
  4069. strcpy(tempdata,sstr);
  4070. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4071. }
  4072. else
  4073. {
  4074. char guid[37]={0};
  4075. random_uuid(guid);
  4076. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4077. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4078. }
  4079. LWS_Send(message);
  4080. return result;
  4081. }
  4082. #if 0
  4083. long long diff_tm(struct tm *a, struct tm *b) {
  4084. return a->tm_sec - b->tm_sec
  4085. + 60LL * (a->tm_min - b->tm_min)
  4086. + 3600LL * (a->tm_hour - b->tm_hour)
  4087. + 86400LL * (a->tm_yday - b->tm_yday)
  4088. + (a->tm_year - 70) * 31536000LL
  4089. - (a->tm_year - 69) / 4 * 86400LL
  4090. + (a->tm_year - 1) / 100 * 86400LL
  4091. - (a->tm_year + 299) / 400 * 86400LL
  4092. - (b->tm_year - 70) * 31536000LL
  4093. + (b->tm_year - 69) / 4 * 86400LL
  4094. - (b->tm_year - 1) / 100 * 86400LL
  4095. + (b->tm_year + 299) /400 * 86400LL;
  4096. }
  4097. #endif
  4098. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4099. {
  4100. mtrace();
  4101. int result = FAIL;
  4102. int connectorIdInt, durationInt;
  4103. char chargingRateUnitStr[4]={0};
  4104. //int tempconnectorIdInt,
  4105. int tempdurationInt;
  4106. float tempminChargingRateFloat = 0.0;
  4107. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4108. int tempStartPeriodInt=0;
  4109. float tempLimitInt=0.0;//0.1;
  4110. int tempNumberPhasesInt=0;
  4111. char fname[200];
  4112. char comfirmstr[20];
  4113. //float totallimit =0.0;
  4114. float MinChargingRate =0.0;
  4115. double diff_t;
  4116. struct tm tp;
  4117. //int clearflag = FALSE;
  4118. FILE *fptr1;//, *fptr2;
  4119. //char temp[] = "../Storage/OCPP/temp.json";
  4120. int c = 0;
  4121. //int i = 0;
  4122. char * pch;
  4123. char *loc;
  4124. char sstr[200]={ 0 };
  4125. int n_chargingProfile = 0;
  4126. int n_SchedulePeriods = 0;
  4127. char SchedulePeriodList[10][200]={0};
  4128. char sLineWord[800]={0};
  4129. //int n_periods = 0;
  4130. char word[1000]={0};
  4131. int confirmPeriods = 0;
  4132. struct StructProfile ChargePointMaxProfile;
  4133. struct StructProfile TxDefaultProfile;
  4134. struct StructProfile TxProfile;
  4135. struct StructProfile TxDefaultProfiletemp[2]={0};
  4136. int TxDefaultProfileFileIsNull=FALSE;
  4137. int ChargePointMaxProfileIsNull=FALSE;
  4138. int TxProfileIsNull=FALSE;
  4139. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4140. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4141. memset(&TxProfile,0,sizeof(struct StructProfile));
  4142. c=0;
  4143. loc = strstr(payload, "connectorId");
  4144. memset(sstr ,0, sizeof(sstr) );
  4145. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4146. {
  4147. sstr[c] = loc[strlen("connectorId")+2+c];
  4148. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4149. c++;
  4150. }
  4151. sstr[c] = '\0';
  4152. connectorIdInt = atoi(sstr);
  4153. c=0;
  4154. loc = strstr(payload, "duration");
  4155. memset(sstr ,0, sizeof(sstr) );
  4156. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4157. {
  4158. sstr[c] = loc[strlen("duration")+2+c];
  4159. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4160. c++;
  4161. }
  4162. sstr[c] = '\0';
  4163. durationInt = atoi(sstr);
  4164. c = 0;
  4165. loc = strstr(payload, "chargingRateUnit");
  4166. memset(sstr ,0, sizeof(sstr) );
  4167. if(loc == NULL)
  4168. {
  4169. }
  4170. else
  4171. {
  4172. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4173. {
  4174. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4175. c++;
  4176. }
  4177. sstr[c] = '\0';
  4178. strcpy(chargingRateUnitStr, sstr);
  4179. }
  4180. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4181. if(connectorIdInt==0) // connectorId is 0
  4182. {
  4183. //******************************ChargePointMaxProfile*****************************************************/
  4184. strcpy(fname, ChargePointMaxProfile_JSON );
  4185. char word[30]={0};
  4186. char sLineWord[1060]={0};
  4187. int n_chargingProfile=0;
  4188. ChargePointMaxProfileIsNull=TRUE;
  4189. if((access(fname,F_OK))!=-1)
  4190. {
  4191. fptr1 = fopen(fname, "r");
  4192. int c;
  4193. c = fgetc(fptr1);
  4194. //DEBUG_INFO("c:%d\n",c);
  4195. rewind(fptr1);
  4196. if(c == EOF)
  4197. {
  4198. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4199. ChargePointMaxProfileIsNull=TRUE;
  4200. fclose(fptr1);
  4201. }
  4202. else
  4203. {
  4204. ChargePointMaxProfileIsNull=FALSE;
  4205. while(fscanf(fptr1, "%s", word) != EOF)
  4206. {
  4207. if(strcmp(word, "chargingProfileId") == 0)
  4208. {
  4209. n_chargingProfile = n_chargingProfile + 1;
  4210. printf("Found\n");
  4211. }
  4212. }
  4213. rewind(fptr1);
  4214. //search Charging Profile Element
  4215. int i= 0;
  4216. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4217. #if 0
  4218. /***********connectorId****************/
  4219. c = 0;
  4220. loc = strstr(sLineWord, "connectorId");
  4221. // printf("loc=%s\n",loc);
  4222. memset(sstr ,0, sizeof(sstr) );
  4223. while (loc[strlen("connectorId")+2+c] != ',')
  4224. {
  4225. sstr[c] = loc[strlen("connectorId")+2+c];
  4226. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4227. c++;
  4228. }
  4229. sstr[c] = '\0';
  4230. tempconnectorIdInt = atoi(sstr);
  4231. #endif
  4232. //***********validFrom**************/
  4233. c = 0;
  4234. loc = strstr(sLineWord, "validFrom");
  4235. //DEBUG_INFO("loc=%s\n",loc);
  4236. memset(sstr ,0, sizeof(sstr) );
  4237. if(loc != NULL)
  4238. {
  4239. while (loc[3+strlen("validFrom")+c] != '\"')
  4240. {
  4241. sstr[c] = loc[3+strlen("validFrom")+c];
  4242. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4243. c++;
  4244. }
  4245. sstr[c] = '\0';
  4246. DEBUG_INFO("validFrom=%s\n",sstr);
  4247. strcpy(tempvalidFromStr,sstr);
  4248. }
  4249. else
  4250. {
  4251. strcpy(tempvalidFromStr,"");
  4252. }
  4253. //**********startSchedule**********/
  4254. c = 0;
  4255. loc = strstr(sLineWord, "startSchedule");
  4256. //DEBUG_INFO("loc=%s\n",loc);
  4257. memset(sstr ,0, sizeof(sstr) );
  4258. while (loc[3+strlen("startSchedule")+c] != '\"')
  4259. {
  4260. sstr[c] = loc[3+strlen("startSchedule")+c];
  4261. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4262. c++;
  4263. }
  4264. sstr[c] = '\0';
  4265. strcpy(tempstartScheduleStr, sstr);
  4266. //**********startSchedule**********/
  4267. c = 0;
  4268. loc = strstr(sLineWord, "chargingRateUnit");
  4269. memset(sstr ,0, sizeof(sstr) );
  4270. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4271. {
  4272. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4273. c++;
  4274. }
  4275. sstr[c] = '\0';
  4276. strcpy(tempchargingRateUnitStr, sstr);
  4277. //**********minChargingRate*******/
  4278. c = 0;
  4279. loc = strstr(sLineWord, "minChargingRate");
  4280. //printf("loc=%s\n",loc);
  4281. if(loc != NULL)
  4282. {
  4283. memset(sstr ,0, sizeof(sstr) );
  4284. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4285. {
  4286. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4287. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4288. c++;
  4289. }
  4290. sstr[c] = '\0';
  4291. tempminChargingRateFloat = atof(sstr);
  4292. }
  4293. else
  4294. {
  4295. tempminChargingRateFloat = 0.0;
  4296. }
  4297. //
  4298. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4299. tp.tm_isdst = -1;
  4300. time_t utc = mktime(&tp);
  4301. // current time
  4302. time_t t = time(NULL);
  4303. diff_t = difftime(t, utc);
  4304. //parsing strings to words
  4305. i = 0;
  4306. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4307. loc = loc+3+strlen("chargingSchedulePeriod");
  4308. pch = strtok(loc ,"{");
  4309. while (pch != NULL)
  4310. {
  4311. strcpy(SchedulePeriodList[i], pch);
  4312. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4313. //printf ("%s\n",pch);
  4314. pch = strtok (NULL, "{");
  4315. i = i + 1;
  4316. }
  4317. n_SchedulePeriods = i;
  4318. for(int i=0;i<n_SchedulePeriods;i++)
  4319. {
  4320. //*************startPeriod****************/
  4321. c = 0;
  4322. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4323. memset(sstr ,0, sizeof(sstr) );
  4324. while (loc[strlen("startPeriod")+2+c] != ',')
  4325. {
  4326. sstr[c] = loc[strlen("startPeriod")+2+c];
  4327. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4328. c++;
  4329. }
  4330. sstr[c] = '\0';
  4331. tempStartPeriodInt = atoi(sstr);
  4332. //*************limit****************/
  4333. c = 0;
  4334. loc = strstr(SchedulePeriodList[i], "limit");
  4335. memset(sstr ,0, sizeof(sstr) );
  4336. while (loc[strlen("limit")+2+c] != ',')
  4337. {
  4338. sstr[c] = loc[strlen("limit")+2+c];
  4339. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4340. c++;
  4341. }
  4342. sstr[c] = '\0';
  4343. tempLimitInt = atof(sstr);
  4344. //*************numberPhases****************/
  4345. c = 0;
  4346. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4347. memset(sstr ,0, sizeof(sstr) );
  4348. while (loc[strlen("numberPhases")+2+c] != ',')
  4349. {
  4350. sstr[c] = loc[strlen("numberPhases")+2+c];
  4351. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4352. c++;
  4353. }
  4354. sstr[c] = '\0';
  4355. tempNumberPhasesInt = atoi(sstr);
  4356. ChargePointMaxProfile.Duration = durationInt;
  4357. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4358. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4359. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4360. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4361. }
  4362. if(MinChargingRate < tempminChargingRateFloat)
  4363. MinChargingRate = tempminChargingRateFloat;
  4364. }
  4365. }// End of file ChargingProfile
  4366. } //THE END OF ACCESS ChargePointMaxProfile
  4367. //******************************TxDefaultProfile***********************************************/
  4368. strcpy(fname, TxDefaultProfile_0_JSON);
  4369. memset(word, 0, 30);
  4370. memset(sLineWord, 0, 1060);
  4371. //char word[30]={0};
  4372. //char sLineWord[1060]={0};
  4373. n_chargingProfile=0;
  4374. TxDefaultProfileFileIsNull=TRUE;
  4375. if((access(fname,F_OK))!=-1)
  4376. {
  4377. fptr1 = fopen(fname, "r");
  4378. c = 0;
  4379. c = fgetc(fptr1);
  4380. //DEBUG_INFO("c:%d\n",c);
  4381. rewind(fptr1);
  4382. if(c == EOF)
  4383. {
  4384. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4385. TxDefaultProfileFileIsNull=TRUE;
  4386. fclose(fptr1);
  4387. }
  4388. else
  4389. {
  4390. TxDefaultProfileFileIsNull=FALSE;
  4391. while(fscanf(fptr1, "%s", word) != EOF)
  4392. {
  4393. if(strcmp(word, "chargingProfileId") == 0)
  4394. {
  4395. n_chargingProfile = n_chargingProfile + 1;
  4396. printf("Found\n");
  4397. }
  4398. }
  4399. rewind(fptr1);
  4400. //search Charging Profile Element
  4401. int i= 0;
  4402. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4403. #if 0
  4404. /***********connectorId****************/
  4405. c = 0;
  4406. loc = strstr(sLineWord, "connectorId");
  4407. // printf("loc=%s\n",loc);
  4408. memset(sstr ,0, sizeof(sstr) );
  4409. while (loc[strlen("connectorId")+2+c] != ',')
  4410. {
  4411. sstr[c] = loc[strlen("connectorId")+2+c];
  4412. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4413. c++;
  4414. }
  4415. sstr[c] = '\0';
  4416. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4417. tempconnectorIdInt = atoi(sstr);
  4418. #endif
  4419. //***********validFrom**************/
  4420. c = 0;
  4421. loc = strstr(sLineWord, "validFrom");
  4422. //DEBUG_INFO("loc=%s\n",loc);
  4423. memset(sstr ,0, sizeof(sstr) );
  4424. if(loc != NULL)
  4425. {
  4426. while (loc[3+strlen("validFrom")+c] != '\"')
  4427. {
  4428. sstr[c] = loc[3+strlen("validFrom")+c];
  4429. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4430. c++;
  4431. }
  4432. sstr[c] = '\0';
  4433. DEBUG_INFO("validFrom=%s\n",sstr);
  4434. strcpy(tempvalidFromStr,sstr);
  4435. }
  4436. else
  4437. {
  4438. strcpy(tempvalidFromStr,"");
  4439. }
  4440. //**********startSchedule**********/
  4441. c = 0;
  4442. loc = strstr(sLineWord, "startSchedule");
  4443. //DEBUG_INFO("loc=%s\n",loc);
  4444. memset(sstr ,0, sizeof(sstr) );
  4445. while (loc[3+strlen("startSchedule")+c] != '\"')
  4446. {
  4447. sstr[c] = loc[3+strlen("startSchedule")+c];
  4448. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4449. c++;
  4450. }
  4451. sstr[c] = '\0';
  4452. strcpy(tempstartScheduleStr, sstr);
  4453. DEBUG_INFO(" debug 3-1\n");
  4454. //**********startSchedule**********/
  4455. c = 0;
  4456. loc = strstr(sLineWord, "chargingRateUnit");
  4457. memset(sstr ,0, sizeof(sstr) );
  4458. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4459. {
  4460. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4461. c++;
  4462. }
  4463. sstr[c] = '\0';
  4464. strcpy(tempchargingRateUnitStr, sstr);
  4465. //**********minChargingRate*******/
  4466. c = 0;
  4467. loc = strstr(sLineWord, "minChargingRate");
  4468. //printf("loc=%s\n",loc);
  4469. if(loc != NULL)
  4470. {
  4471. memset(sstr ,0, sizeof(sstr) );
  4472. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4473. {
  4474. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4475. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4476. c++;
  4477. }
  4478. sstr[c] = '\0';
  4479. tempminChargingRateFloat = atof(sstr);
  4480. }
  4481. else
  4482. {
  4483. tempminChargingRateFloat = 0.0;
  4484. }
  4485. //
  4486. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4487. tp.tm_isdst = -1;
  4488. time_t utc = mktime(&tp);
  4489. // current time
  4490. time_t t = time(NULL);
  4491. diff_t = difftime(t, utc);
  4492. //parsing strings to words
  4493. i = 0;
  4494. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4495. loc = loc+3+strlen("chargingSchedulePeriod");
  4496. pch = strtok(loc ,"{");
  4497. while (pch != NULL)
  4498. {
  4499. strcpy(SchedulePeriodList[i], pch);
  4500. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4501. //printf ("%s\n",pch);
  4502. pch = strtok (NULL, "{");
  4503. i = i + 1;
  4504. }
  4505. n_SchedulePeriods = i;
  4506. for(int i=0;i<n_SchedulePeriods;i++)
  4507. {
  4508. //*************startPeriod****************/
  4509. c = 0;
  4510. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4511. memset(sstr ,0, sizeof(sstr) );
  4512. while (loc[strlen("startPeriod")+2+c] != ',')
  4513. {
  4514. sstr[c] = loc[strlen("startPeriod")+2+c];
  4515. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4516. c++;
  4517. }
  4518. sstr[c] = '\0';
  4519. tempStartPeriodInt = atoi(sstr);
  4520. //*************limit****************/
  4521. c = 0;
  4522. loc = strstr(SchedulePeriodList[i], "limit");
  4523. memset(sstr ,0, sizeof(sstr) );
  4524. while (loc[strlen("limit")+2+c] != ',')
  4525. {
  4526. sstr[c] = loc[strlen("limit")+2+c];
  4527. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4528. c++;
  4529. }
  4530. sstr[c] = '\0';
  4531. tempLimitInt = atof(sstr);
  4532. //*************numberPhases****************/
  4533. c = 0;
  4534. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4535. memset(sstr ,0, sizeof(sstr) );
  4536. while (loc[strlen("numberPhases")+2+c] != ',')
  4537. {
  4538. sstr[c] = loc[strlen("numberPhases")+2+c];
  4539. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4540. c++;
  4541. }
  4542. sstr[c] = '\0';
  4543. tempNumberPhasesInt = atoi(sstr);
  4544. TxDefaultProfile.Duration = durationInt;
  4545. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4546. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4547. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4548. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4549. }
  4550. if(MinChargingRate < tempminChargingRateFloat)
  4551. MinChargingRate = tempminChargingRateFloat;
  4552. }
  4553. }
  4554. }// the end of ACCESS TxDefaultProfile
  4555. // Composite Schedule
  4556. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4557. {
  4558. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4559. {
  4560. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4561. {
  4562. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4563. }
  4564. else
  4565. {
  4566. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4567. }
  4568. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4569. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4570. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4571. }
  4572. }
  4573. //* Define temporary variables */
  4574. struct tm *gtime;
  4575. time_t now;
  4576. char buf[28];
  4577. /* Read the current system time */
  4578. time(&now);
  4579. /* Convert the system time to GMT (now UTC) */
  4580. gtime = gmtime(&now);
  4581. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4582. // make .conf
  4583. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  4584. //MaxChargingProfilesInstalled is 10
  4585. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4586. memset(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4587. //nPeriod = 1;
  4588. if(chargingRateUnitStr[0] != 0)
  4589. {
  4590. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4591. }
  4592. else
  4593. {
  4594. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, "" );
  4595. }
  4596. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4597. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4598. confirmPeriods = 1;
  4599. }
  4600. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4601. {
  4602. //*****************************ChargePointMaxProfile******************************************/
  4603. strcpy(fname, ChargePointMaxProfile_JSON);
  4604. ChargePointMaxProfileIsNull=TRUE;
  4605. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4606. {
  4607. fptr1 = fopen(fname, "r");
  4608. int c;
  4609. c = fgetc(fptr1);
  4610. //DEBUG_INFO("c:%d\n",c);
  4611. rewind(fptr1);
  4612. if(c == EOF)
  4613. {
  4614. DEBUG_INFO("\n End of file reached.");
  4615. ChargePointMaxProfileIsNull=TRUE;
  4616. fclose(fptr1);
  4617. }
  4618. else
  4619. {
  4620. ChargePointMaxProfileIsNull=FALSE;
  4621. while(fscanf(fptr1, "%s", word) != EOF)
  4622. {
  4623. if(strcmp(word, "chargingProfileId") == 0)
  4624. {
  4625. n_chargingProfile = n_chargingProfile + 1;
  4626. }
  4627. }
  4628. rewind(fptr1);
  4629. //search Charging Profile Element
  4630. int i = 0;
  4631. int j = 0;
  4632. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4633. #if 0
  4634. /***********connectorId****************/
  4635. c = 0;
  4636. loc = strstr(sLineWord, "connectorId");
  4637. memset(sstr ,0, sizeof(sstr) );
  4638. while (loc[strlen("connectorId")+2+c] != ',')
  4639. {
  4640. sstr[c] = loc[strlen("connectorId")+2+c];
  4641. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4642. c++;
  4643. }
  4644. sstr[c] = '\0';
  4645. tempconnectorIdInt = atoi(sstr);
  4646. #endif
  4647. //***********validFrom**************/
  4648. c = 0;
  4649. loc = strstr(sLineWord, "validFrom");
  4650. if(loc != NULL)
  4651. {
  4652. memset(sstr ,0, sizeof(sstr) );
  4653. while (loc[3+strlen("validFrom")+c] != '\"')
  4654. {
  4655. sstr[c] = loc[3+strlen("validFrom")+c];
  4656. c++;
  4657. }
  4658. sstr[c] = '\0';
  4659. strcpy(tempvalidFromStr,sstr);
  4660. }
  4661. else
  4662. {
  4663. strcpy(tempvalidFromStr,"");
  4664. }
  4665. //***********validFrom**************/
  4666. c = 0;
  4667. loc = strstr(sLineWord, "duration");
  4668. if(loc != NULL)
  4669. {
  4670. memset(sstr ,0, sizeof(sstr) );
  4671. while (loc[2+strlen("duration")+c] != ',')
  4672. {
  4673. sstr[c] = loc[2+strlen("duration")+c];
  4674. c++;
  4675. }
  4676. sstr[c] = '\0';
  4677. tempdurationInt = atoi(sstr);
  4678. }
  4679. else
  4680. {
  4681. tempdurationInt = 0;
  4682. }
  4683. //**********startSchedule**********/
  4684. c = 0;
  4685. loc = strstr(sLineWord, "startSchedule");
  4686. memset(sstr ,0, sizeof(sstr) );
  4687. while (loc[3+strlen("startSchedule")+c] != '\"')
  4688. {
  4689. sstr[c] = loc[3+strlen("startSchedule")+c];
  4690. c++;
  4691. }
  4692. sstr[c] = '\0';
  4693. strcpy(tempstartScheduleStr, sstr);
  4694. //**********startSchedule**********/
  4695. c = 0;
  4696. loc = strstr(sLineWord, "chargingRateUnit");
  4697. memset(sstr ,0, sizeof(sstr) );
  4698. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4699. {
  4700. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4701. c++;
  4702. }
  4703. sstr[c] = '\0';
  4704. strcpy(tempchargingRateUnitStr, sstr);
  4705. //**********minChargingRate*******/
  4706. c = 0;
  4707. loc = strstr(sLineWord, "minChargingRate");
  4708. if(loc != NULL)
  4709. {
  4710. memset(sstr ,0, sizeof(sstr) );
  4711. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4712. {
  4713. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4714. c++;
  4715. }
  4716. sstr[c] = '\0';
  4717. tempminChargingRateFloat = atof(sstr);
  4718. }
  4719. else
  4720. {
  4721. tempminChargingRateFloat = 0.0;
  4722. }
  4723. //
  4724. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4725. tp.tm_isdst = -1;
  4726. time_t utc = mktime(&tp);
  4727. time_t t = time(NULL);
  4728. diff_t = difftime(t, utc);
  4729. DEBUG_INFO("diff_t=%f\n",diff_t);
  4730. DEBUG_INFO(" debug 5 -1\n");
  4731. //parsing strings to words
  4732. i = 0;
  4733. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4734. loc = loc+3+strlen("chargingSchedulePeriod");
  4735. pch = strtok(loc ,"{");
  4736. while (pch != NULL)
  4737. {
  4738. strcpy(SchedulePeriodList[i], pch);
  4739. pch = strtok (NULL, "{");
  4740. i = i + 1;
  4741. }
  4742. n_SchedulePeriods = i;
  4743. for(int i=0;i<n_SchedulePeriods;i++)
  4744. {
  4745. //*************startPeriod****************/
  4746. c = 0;
  4747. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4748. memset(sstr ,0, sizeof(sstr) );
  4749. while (loc[strlen("startPeriod")+2+c] != ',')
  4750. {
  4751. sstr[c] = loc[strlen("startPeriod")+2+c];
  4752. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4753. c++;
  4754. }
  4755. sstr[c] = '\0';
  4756. tempStartPeriodInt = atoi(sstr);
  4757. //*************limit****************/
  4758. c = 0;
  4759. loc = strstr(SchedulePeriodList[i], "limit");
  4760. memset(sstr ,0, sizeof(sstr) );
  4761. while (loc[strlen("limit")+2+c] != ',')
  4762. {
  4763. sstr[c] = loc[strlen("limit")+2+c];
  4764. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4765. c++;
  4766. }
  4767. sstr[c] = '\0';
  4768. tempLimitInt = atof(sstr);
  4769. //*************numberPhases****************/
  4770. c = 0;
  4771. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4772. memset(sstr ,0, sizeof(sstr) );
  4773. while (loc[strlen("numberPhases")+2+c] != '}')
  4774. {
  4775. sstr[c] = loc[strlen("numberPhases")+2+c];
  4776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4777. c++;
  4778. }
  4779. sstr[c] = '\0';
  4780. tempNumberPhasesInt = atoi(sstr);
  4781. if(j == 0)
  4782. {
  4783. ChargePointMaxProfile.Duration = tempdurationInt;
  4784. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4785. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4786. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4787. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4788. }
  4789. }
  4790. if(MinChargingRate < tempminChargingRateFloat)
  4791. {
  4792. MinChargingRate = tempminChargingRateFloat;
  4793. }
  4794. if(confirmPeriods < n_SchedulePeriods)
  4795. {
  4796. confirmPeriods = n_SchedulePeriods;
  4797. }
  4798. j = j + 1;
  4799. }
  4800. fclose(fptr1);
  4801. }
  4802. }// the end of access file ChargePointMaxProfile
  4803. //****************************TxDefaultProfile************************************************/
  4804. switch(connectorIdInt)
  4805. {
  4806. case 0:
  4807. break;
  4808. case 1:
  4809. strcpy(fname, TxDefaultProfile_1_JSON );
  4810. break;
  4811. case 2:
  4812. strcpy(fname, TxDefaultProfile_2_JSON );
  4813. break;
  4814. default:
  4815. strcpy(fname, TxDefaultProfile_1_JSON );
  4816. break;
  4817. }
  4818. TxDefaultProfileFileIsNull=TRUE;
  4819. if((access(fname,F_OK))!=-1)
  4820. {
  4821. fptr1 = fopen(fname, "r");
  4822. c = 0;
  4823. c = fgetc(fptr1);
  4824. //DEBUG_INFO("c:%d\n",c);
  4825. rewind(fptr1);
  4826. if(c == EOF)
  4827. {
  4828. DEBUG_INFO("\n End of file reached.");
  4829. TxDefaultProfileFileIsNull=TRUE;
  4830. fclose(fptr1);
  4831. }
  4832. else
  4833. {
  4834. TxDefaultProfileFileIsNull=FALSE;
  4835. while(fscanf(fptr1, "%s", word) != EOF)
  4836. {
  4837. if(strcmp(word, "chargingProfileId") == 0)
  4838. {
  4839. n_chargingProfile = n_chargingProfile + 1;
  4840. }
  4841. }
  4842. rewind(fptr1);
  4843. //search Charging Profile Element
  4844. int i = 0;
  4845. int j = 0;
  4846. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4847. #if 0
  4848. /***********connectorId****************/
  4849. c = 0;
  4850. loc = strstr(sLineWord, "connectorId");
  4851. memset(sstr ,0, sizeof(sstr) );
  4852. while (loc[strlen("connectorId")+2+c] != ',')
  4853. {
  4854. sstr[c] = loc[strlen("connectorId")+2+c];
  4855. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4856. c++;
  4857. }
  4858. sstr[c] = '\0';
  4859. tempconnectorIdInt = atoi(sstr);
  4860. #endif
  4861. //***********validFrom**************/
  4862. c = 0;
  4863. loc = strstr(sLineWord, "validFrom");
  4864. if(loc != NULL)
  4865. {
  4866. memset(sstr ,0, sizeof(sstr) );
  4867. while (loc[3+strlen("validFrom")+c] != '\"')
  4868. {
  4869. sstr[c] = loc[3+strlen("validFrom")+c];
  4870. c++;
  4871. }
  4872. sstr[c] = '\0';
  4873. strcpy(tempvalidFromStr,sstr);
  4874. }
  4875. else
  4876. {
  4877. strcpy(tempvalidFromStr,"");
  4878. }
  4879. //***********validFrom**************/
  4880. c = 0;
  4881. loc = strstr(sLineWord, "duration");
  4882. if(loc != NULL)
  4883. {
  4884. memset(sstr ,0, sizeof(sstr) );
  4885. while (loc[2+strlen("duration")+c] != ',')
  4886. {
  4887. sstr[c] = loc[2+strlen("duration")+c];
  4888. c++;
  4889. }
  4890. sstr[c] = '\0';
  4891. tempdurationInt = atoi(sstr);
  4892. }
  4893. else
  4894. {
  4895. tempdurationInt = 0;
  4896. }
  4897. //**********startSchedule**********/
  4898. c = 0;
  4899. loc = strstr(sLineWord, "startSchedule");
  4900. memset(sstr ,0, sizeof(sstr) );
  4901. while (loc[3+strlen("startSchedule")+c] != '\"')
  4902. {
  4903. sstr[c] = loc[3+strlen("startSchedule")+c];
  4904. c++;
  4905. }
  4906. sstr[c] = '\0';
  4907. strcpy(tempstartScheduleStr, sstr);
  4908. //**********startSchedule**********/
  4909. c = 0;
  4910. loc = strstr(sLineWord, "chargingRateUnit");
  4911. memset(sstr ,0, sizeof(sstr) );
  4912. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4913. {
  4914. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4915. c++;
  4916. }
  4917. sstr[c] = '\0';
  4918. strcpy(tempchargingRateUnitStr, sstr);
  4919. //**********minChargingRate*******/
  4920. c = 0;
  4921. loc = strstr(sLineWord, "minChargingRate");
  4922. if(loc != NULL)
  4923. {
  4924. memset(sstr ,0, sizeof(sstr) );
  4925. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4926. {
  4927. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4928. c++;
  4929. }
  4930. sstr[c] = '\0';
  4931. tempminChargingRateFloat = atof(sstr);
  4932. }
  4933. else
  4934. {
  4935. tempminChargingRateFloat = 0.0;
  4936. }
  4937. //
  4938. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4939. tp.tm_isdst = -1;
  4940. time_t utc = mktime(&tp);
  4941. time_t t = time(NULL);
  4942. diff_t = difftime(t, utc);
  4943. DEBUG_INFO("diff_t=%f\n",diff_t);
  4944. DEBUG_INFO(" debug 5 -1\n");
  4945. //parsing strings to words
  4946. i = 0;
  4947. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4948. loc = loc+3+strlen("chargingSchedulePeriod");
  4949. pch = strtok(loc ,"{");
  4950. while (pch != NULL)
  4951. {
  4952. strcpy(SchedulePeriodList[i], pch);
  4953. pch = strtok (NULL, "{");
  4954. i = i + 1;
  4955. }
  4956. n_SchedulePeriods = i;
  4957. for(int i=0;i<n_SchedulePeriods;i++)
  4958. {
  4959. //*************startPeriod****************/
  4960. c = 0;
  4961. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4962. memset(sstr ,0, sizeof(sstr) );
  4963. while (loc[strlen("startPeriod")+2+c] != ',')
  4964. {
  4965. sstr[c] = loc[strlen("startPeriod")+2+c];
  4966. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4967. c++;
  4968. }
  4969. sstr[c] = '\0';
  4970. tempStartPeriodInt = atoi(sstr);
  4971. //*************limit****************/
  4972. c = 0;
  4973. loc = strstr(SchedulePeriodList[i], "limit");
  4974. memset(sstr ,0, sizeof(sstr) );
  4975. while (loc[strlen("limit")+2+c] != ',')
  4976. {
  4977. sstr[c] = loc[strlen("limit")+2+c];
  4978. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4979. c++;
  4980. }
  4981. sstr[c] = '\0';
  4982. tempLimitInt = atof(sstr);
  4983. //*************numberPhases****************/
  4984. c = 0;
  4985. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4986. memset(sstr ,0, sizeof(sstr) );
  4987. while (loc[strlen("numberPhases")+2+c] != '}')
  4988. {
  4989. sstr[c] = loc[strlen("numberPhases")+2+c];
  4990. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4991. c++;
  4992. }
  4993. sstr[c] = '\0';
  4994. tempNumberPhasesInt = atoi(sstr);
  4995. if(j == 0)
  4996. {
  4997. TxDefaultProfile.Duration = tempdurationInt;
  4998. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4999. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5000. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5001. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5002. }
  5003. else
  5004. {
  5005. //other stack level charging Profile
  5006. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5007. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5008. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5009. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5010. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5011. }
  5012. }
  5013. if(MinChargingRate < tempminChargingRateFloat)
  5014. MinChargingRate = tempminChargingRateFloat;
  5015. if(confirmPeriods < n_SchedulePeriods)
  5016. confirmPeriods = n_SchedulePeriods;
  5017. j = j + 1;
  5018. }
  5019. fclose(fptr1);
  5020. //Stacking Charging Profiles
  5021. for(int l=0; l <(j-1) ;l++)
  5022. {
  5023. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5024. {
  5025. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5026. {
  5027. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5028. {
  5029. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5030. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5031. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5032. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5033. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5034. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5035. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5036. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5037. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5038. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5039. }
  5040. else
  5041. {
  5042. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5043. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5044. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5045. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5046. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5047. }
  5048. }
  5049. }
  5050. }
  5051. //end of Stacking Charging Profiles
  5052. }
  5053. }// the end of ACCESS TxDefaultProfile
  5054. //****************************TxProfile************************************************/
  5055. switch(connectorIdInt)
  5056. {
  5057. case 0:
  5058. break;
  5059. case 1:
  5060. strcpy(fname, TxProfile_1_JSON );
  5061. break;
  5062. case 2:
  5063. strcpy(fname, TxProfile_2_JSON );
  5064. break;
  5065. default:
  5066. strcpy(fname, TxProfile_1_JSON );
  5067. break;
  5068. }
  5069. TxProfileIsNull=TRUE;
  5070. if((access(fname,F_OK))!=-1)
  5071. {
  5072. fptr1 = fopen(fname, "r");
  5073. c = 0;
  5074. c = fgetc(fptr1);
  5075. //DEBUG_INFO("c:%d\n",c);
  5076. rewind(fptr1);
  5077. if(c == EOF)
  5078. {
  5079. DEBUG_INFO("\n End of file reached.");
  5080. TxProfileIsNull=TRUE;
  5081. fclose(fptr1);
  5082. }
  5083. else
  5084. {
  5085. TxProfileIsNull=FALSE;
  5086. while(fscanf(fptr1, "%s", word) != EOF)
  5087. {
  5088. if(strcmp(word, "chargingProfileId") == 0)
  5089. {
  5090. n_chargingProfile = n_chargingProfile + 1;
  5091. }
  5092. }
  5093. rewind(fptr1);
  5094. //search Charging Profile Element
  5095. int i= 0;
  5096. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5097. #if 0
  5098. /***********connectorId****************/
  5099. c = 0;
  5100. loc = strstr(sLineWord, "connectorId");
  5101. memset(sstr ,0, sizeof(sstr) );
  5102. while (loc[strlen("connectorId")+2+c] != ',')
  5103. {
  5104. sstr[c] = loc[strlen("connectorId")+2+c];
  5105. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5106. c++;
  5107. }
  5108. sstr[c] = '\0';
  5109. tempconnectorIdInt = atoi(sstr);
  5110. #endif
  5111. //***********validFrom**************/
  5112. c = 0;
  5113. loc = strstr(sLineWord, "validFrom");
  5114. if(loc != NULL)
  5115. {
  5116. memset(sstr ,0, sizeof(sstr) );
  5117. while (loc[3+strlen("validFrom")+c] != '\"')
  5118. {
  5119. sstr[c] = loc[3+strlen("validFrom")+c];
  5120. c++;
  5121. }
  5122. sstr[c] = '\0';
  5123. strcpy(tempvalidFromStr,sstr);
  5124. }
  5125. else
  5126. {
  5127. strcpy(tempvalidFromStr,"");
  5128. }
  5129. //**********startSchedule**********/
  5130. c = 0;
  5131. loc = strstr(sLineWord, "startSchedule");
  5132. memset(sstr ,0, sizeof(sstr) );
  5133. while (loc[3+strlen("startSchedule")+c] != '\"')
  5134. {
  5135. sstr[c] = loc[3+strlen("startSchedule")+c];
  5136. c++;
  5137. }
  5138. sstr[c] = '\0';
  5139. strcpy(tempstartScheduleStr, sstr);
  5140. //**********startSchedule**********/
  5141. c = 0;
  5142. loc = strstr(sLineWord, "chargingRateUnit");
  5143. memset(sstr ,0, sizeof(sstr) );
  5144. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5145. {
  5146. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5147. c++;
  5148. }
  5149. sstr[c] = '\0';
  5150. strcpy(tempchargingRateUnitStr, sstr);
  5151. //**********minChargingRate*******/
  5152. c = 0;
  5153. loc = strstr(sLineWord, "minChargingRate");
  5154. if(loc != NULL)
  5155. {
  5156. memset(sstr ,0, sizeof(sstr) );
  5157. while (loc[3+strlen("minChargingRate")+c] != '\"')
  5158. {
  5159. sstr[c] = loc[3+strlen("minChargingRate")+c];
  5160. c++;
  5161. }
  5162. sstr[c] = '\0';
  5163. tempminChargingRateFloat = atof(sstr);
  5164. }
  5165. else
  5166. {
  5167. tempminChargingRateFloat = 0.0;
  5168. }
  5169. //
  5170. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5171. tp.tm_isdst = -1;
  5172. time_t utc = mktime(&tp);
  5173. time_t t = time(NULL);
  5174. diff_t = difftime(t, utc);
  5175. DEBUG_INFO("diff_t=%f\n",diff_t);
  5176. //parsing strings to words
  5177. i = 0;
  5178. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5179. loc = loc+3+strlen("chargingSchedulePeriod");
  5180. pch = strtok(loc ,"{");
  5181. while (pch != NULL)
  5182. {
  5183. strcpy(SchedulePeriodList[i], pch);
  5184. pch = strtok (NULL, "{");
  5185. i = i + 1;
  5186. }
  5187. n_SchedulePeriods = i;
  5188. for(int i=0;i<n_SchedulePeriods;i++)
  5189. {
  5190. //*************startPeriod****************/
  5191. c = 0;
  5192. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5193. memset(sstr ,0, sizeof(sstr) );
  5194. while (loc[strlen("startPeriod")+2+c] != ',')
  5195. {
  5196. sstr[c] = loc[strlen("startPeriod")+2+c];
  5197. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5198. c++;
  5199. }
  5200. sstr[c] = '\0';
  5201. tempStartPeriodInt = atoi(sstr);
  5202. //*************limit****************/
  5203. c = 0;
  5204. loc = strstr(SchedulePeriodList[i], "limit");
  5205. memset(sstr ,0, sizeof(sstr) );
  5206. while (loc[strlen("limit")+2+c] != ',')
  5207. {
  5208. sstr[c] = loc[strlen("limit")+2+c];
  5209. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5210. c++;
  5211. }
  5212. sstr[c] = '\0';
  5213. tempLimitInt = atof(sstr);
  5214. //*************numberPhases****************/
  5215. c = 0;
  5216. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5217. memset(sstr ,0, sizeof(sstr) );
  5218. while (loc[strlen("numberPhases")+2+c] != '}')
  5219. {
  5220. sstr[c] = loc[strlen("numberPhases")+2+c];
  5221. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5222. c++;
  5223. }
  5224. sstr[c] = '\0';
  5225. tempNumberPhasesInt = atoi(sstr);
  5226. TxProfile.Duration = durationInt;
  5227. TxProfile.TotalPeriod = n_SchedulePeriods;
  5228. TxProfile.Period[i].Limit = tempLimitInt;
  5229. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5230. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5231. }
  5232. if(MinChargingRate < tempminChargingRateFloat)
  5233. MinChargingRate = tempminChargingRateFloat;
  5234. if(confirmPeriods < n_SchedulePeriods)
  5235. confirmPeriods = n_SchedulePeriods;
  5236. }
  5237. fclose(fptr1);
  5238. }
  5239. }// the end of ACCESS TxProfile
  5240. //CompositeSchedule
  5241. int period=0;
  5242. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5243. {
  5244. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5245. {
  5246. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5247. {
  5248. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5249. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5250. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5251. period = period + 1;
  5252. }
  5253. else
  5254. {
  5255. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5256. {
  5257. }
  5258. else
  5259. {
  5260. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5261. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5262. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5263. period = period + 1;
  5264. }
  5265. }
  5266. }
  5267. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5268. {
  5269. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5270. {
  5271. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5272. {
  5273. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5274. }
  5275. else
  5276. {
  5277. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5278. }
  5279. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5280. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5281. period = period + 1;
  5282. }
  5283. }
  5284. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5285. {
  5286. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5287. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5288. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5289. period = period + 1;
  5290. }
  5291. }
  5292. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5293. {
  5294. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5295. {
  5296. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5297. {
  5298. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5299. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5300. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5301. period = period + 1;
  5302. }
  5303. else
  5304. {
  5305. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5306. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5307. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5308. period = period + 1;
  5309. }
  5310. }
  5311. }
  5312. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5313. {
  5314. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5315. {
  5316. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5317. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5318. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5319. period = period + 1;
  5320. }
  5321. }
  5322. confirmPeriods = period;
  5323. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5324. //* Define temporary variables */
  5325. struct tm *gtime;
  5326. time_t now;
  5327. char buf[28];
  5328. //* Read the current system time */
  5329. time(&now);
  5330. //* Convert the system time to GMT (now UTC) */
  5331. gtime = gmtime(&now);
  5332. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5333. // make .conf
  5334. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  5335. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = durationInt;
  5336. //DEBUG_INFO(" debug 11\n");
  5337. // if(chargingRateUnitStr[0] != 0)
  5338. // {
  5339. // strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  5340. // }
  5341. // else
  5342. {
  5343. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5344. }
  5345. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5346. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5347. }
  5348. else
  5349. {
  5350. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5351. }
  5352. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5353. return result;
  5354. }
  5355. int handleGetConfigurationRequest(char *uuid, char *payload)
  5356. {
  5357. mtrace();
  5358. int result = FAIL;
  5359. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5360. //struct json_object *jsonitem;
  5361. int MaxKeySupported = 0;
  5362. int n_keys = 0;
  5363. char requestKey[43][50]={0};
  5364. char search[]="[";
  5365. char sstr[500]={ 0 };
  5366. //int pos;
  5367. int l, c = 0;
  5368. int i = 0;
  5369. char *delim = "\",\"";
  5370. char * pch;
  5371. char *loc = strstr(payload, search);
  5372. //********************* Parsing String ***********************************/
  5373. if(loc == NULL) {
  5374. DEBUG_INFO("no key match in Configuration \n");
  5375. }
  5376. else {
  5377. //pos = loc - payload;
  5378. l = strlen(loc)-4;
  5379. while (c < l)
  5380. {
  5381. sstr[c] = loc[c+2];
  5382. c++;
  5383. }
  5384. sstr[c] = '\0';
  5385. //parsing strings to words
  5386. pch = strtok(sstr,delim);
  5387. if(pch == NULL)
  5388. {
  5389. strcpy(requestKey[0], sstr);
  5390. }
  5391. else
  5392. {
  5393. while (pch != NULL)
  5394. {
  5395. strcpy(requestKey[i], pch);
  5396. pch = strtok (NULL, delim);
  5397. i = i + 1;
  5398. }
  5399. n_keys = i;
  5400. }
  5401. }
  5402. UnknownKeynum = 0;
  5403. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5404. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5405. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5406. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5407. if(n_keys != 0)
  5408. {
  5409. for(int i=0;i<n_keys;i++)
  5410. {
  5411. getKeyValue(requestKey[i]);
  5412. //json_object_put(jsonitem);
  5413. }
  5414. }
  5415. else
  5416. {
  5417. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5418. getKeyValue("");
  5419. }
  5420. processUnkownKey();
  5421. sendGetConfigurationConfirmation(uuid);
  5422. return result;
  5423. }
  5424. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5425. {
  5426. mtrace();
  5427. int result = FAIL;
  5428. //void *ret; //
  5429. char fnamePlusPath[50]="";
  5430. char fname[16]="";
  5431. pthread_t t; // pthread 變數
  5432. time_t rawtime;
  5433. struct tm * timeinfo;
  5434. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5435. system("exec /root/logPackTools 'log' 6");
  5436. //char buffer [128];
  5437. time (&rawtime);
  5438. //printf("%ld\n", rawtime);
  5439. timeinfo = localtime (&rawtime);
  5440. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5441. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5442. if((access(fnamePlusPath,F_OK))!=-1)
  5443. {
  5444. DEBUG_INFO("fnamePlusPath exist.\n");
  5445. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5446. }
  5447. else
  5448. {
  5449. DEBUG_INFO("fnamePlusPath not exist!\n");
  5450. }
  5451. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5452. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5453. pthread_join(t, NULL/*&ret*/);
  5454. return result;
  5455. }
  5456. void* GetDiagnosticsProcess(void* data)
  5457. {
  5458. mtrace();
  5459. int retriesInt=0, retryIntervalInt=0;
  5460. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5461. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5462. 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};
  5463. int port=0;
  5464. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5465. char fname[16]="";
  5466. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5467. int c = 0;
  5468. char *loc;
  5469. int isSuccess = FALSE;
  5470. char ftpbuf[200]={0};
  5471. //char temp[100]={0};
  5472. char * pch;
  5473. // [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"}]
  5474. char *str = (char*) data; // ?��?輸入資�?
  5475. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5476. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5477. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5478. //****************location*******************/
  5479. c = 0;
  5480. memset(sstr ,0, sizeof(sstr) );
  5481. loc = strstr(str, "location");
  5482. while (loc[3+strlen("location")+c] != '\"')
  5483. {
  5484. sstr[c] = loc[3+strlen("location")+c];
  5485. c++;
  5486. }
  5487. sstr[c] = '\0';
  5488. strcpy(locationstr,sstr);
  5489. if(strcmp(locationstr,"")==0)
  5490. {
  5491. DEBUG_INFO("location is <Empty>!\n");
  5492. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5493. goto end;
  5494. }
  5495. //****************retries*******************/
  5496. c = 0;
  5497. loc = strstr(str, "retries");
  5498. if(loc == NULL)
  5499. {
  5500. retriesIsNULL = TRUE;
  5501. }
  5502. else
  5503. {
  5504. while (loc[strlen("retries")+2+c] != ',')
  5505. {
  5506. sstr[c] = loc[strlen("retries")+2+c];
  5507. c++;
  5508. }
  5509. sstr[c] = '\0';
  5510. retriesInt = atoi(sstr);
  5511. }
  5512. if(retriesIsNULL == TRUE)
  5513. {
  5514. retriesInt = 0;
  5515. }
  5516. //****************retryInterval*******************/
  5517. c = 0;
  5518. loc = strstr(str, "retryInterval");
  5519. if(loc == NULL)
  5520. {
  5521. retryIntervalIsNULL = TRUE;
  5522. }
  5523. else
  5524. {
  5525. while (loc[strlen("retryInterval")+2+c] != ',')
  5526. {
  5527. sstr[c] = loc[strlen("retryInterval")+2+c];
  5528. c++;
  5529. }
  5530. sstr[c] = '\0';
  5531. retryIntervalInt = atoi(sstr);
  5532. }
  5533. //****************startTime*******************/
  5534. c = 0;
  5535. memset(sstr ,0, sizeof(sstr) );
  5536. loc = strstr(str, "startTime");
  5537. if(loc == NULL)
  5538. {
  5539. startTimeIsNULL = TRUE;
  5540. }
  5541. else
  5542. {
  5543. while (loc[3+strlen("startTime")+c] != '\"')
  5544. {
  5545. sstr[c] = loc[3+strlen("startTime")+c];
  5546. c++;
  5547. }
  5548. sstr[c] = '\0';
  5549. strcpy(startTimestr,sstr);
  5550. }
  5551. //****************stopTime*******************/
  5552. c = 0;
  5553. memset(sstr ,0, sizeof(sstr) );
  5554. loc = strstr(str, "stopTime");
  5555. if(loc == NULL)
  5556. {
  5557. stopTimeIsNULL = TRUE;
  5558. }
  5559. else
  5560. {
  5561. while (loc[3+strlen("stopTime")+c] != '\"')
  5562. {
  5563. sstr[c] = loc[3+strlen("stopTime")+c];
  5564. c++;
  5565. }
  5566. sstr[c] = '\0';
  5567. strcpy(stopTimestr,sstr);
  5568. }
  5569. memset(protocol, 0, sizeof(protocol));
  5570. memset(user, 0, sizeof(user) );
  5571. memset(password, 0, sizeof(password));
  5572. memset(host, 0, sizeof(host));
  5573. memset(path, 0, sizeof(path));
  5574. memset(ftppath, 0, sizeof(ftppath));
  5575. memset(host1, 0, sizeof(host1));
  5576. memset(path1, 0, sizeof(path1));
  5577. /*location: ftp://user:password@host:port/path*/
  5578. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5579. // protocol, user, password, host, &port, path);
  5580. #if 0 // remove for temporally
  5581. //zip files in /Storage
  5582. system("exec /root/logPackTools 'log' 6");
  5583. #endif
  5584. // system("exec /root/Module_WebService 'log' 6");
  5585. time_t rawtime;
  5586. struct tm * timeinfo;
  5587. //char buffer [128];
  5588. time (&rawtime);
  5589. //printf("%ld\n", rawtime);
  5590. timeinfo = localtime (&rawtime);
  5591. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5592. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5593. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5594. if((access(fnamePlusPath,F_OK))!=-1)
  5595. {
  5596. DEBUG_INFO("fnamePlusPath exist.\n");
  5597. }
  5598. else
  5599. {
  5600. DEBUG_INFO("fnamePlusPath not exist!\n");
  5601. goto end;
  5602. }
  5603. pch=strchr(locationstr,'@');
  5604. if(pch==NULL)
  5605. {
  5606. sscanf(locationstr,
  5607. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5608. protocol, host, &port, path);
  5609. strcpy(user,"anonymous");
  5610. strcpy(password,"");
  5611. }
  5612. else
  5613. {
  5614. DEBUG_INFO("pch=%s\n", pch);
  5615. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5616. protocol, user, password, host, &port, path);
  5617. }
  5618. if(strcmp(protocol,"ftp")!=0)
  5619. {
  5620. DEBUG_INFO("protocol is not ftp!\n");
  5621. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5622. goto end;
  5623. }
  5624. sscanf(host,"%[^/]%s",host1, path1);
  5625. sprintf(ftppath,"%s", path1);
  5626. DEBUG_INFO("protocol =%s\n",protocol);
  5627. DEBUG_INFO("user =%s\n",user);
  5628. DEBUG_INFO("password =%s\n",password);
  5629. DEBUG_INFO("host1 =%s\n",host1);
  5630. DEBUG_INFO("port =%d\n",port);
  5631. DEBUG_INFO("path1 =%s\n",path1);
  5632. DEBUG_INFO("ftppath=%s\n",ftppath);
  5633. int ftppathlen=strlen(ftppath);
  5634. int i=1;
  5635. char filenametemp[50];
  5636. while(i < ftppathlen)
  5637. {
  5638. int len=ftppathlen-i;
  5639. if(ftppath[len]== 47) // '/' ascll code: 47
  5640. {
  5641. DEBUG_INFO("find '/' all right\n");
  5642. break;
  5643. }
  5644. i=i+1;
  5645. }
  5646. memset(filenametemp, 0, sizeof(filenametemp));
  5647. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5648. filenametemp[i+1] = 0;
  5649. //httpDownLoadFile(host, ftppath, fname);
  5650. memset(ftpbuf, 0, sizeof(ftpbuf));
  5651. if(port == 0)
  5652. port = 21;
  5653. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5654. do{
  5655. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5656. sleep(retryIntervalInt);
  5657. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5658. if(!isSuccess)
  5659. {
  5660. //BulldogUtil.sleepMs(interval*1000);
  5661. DEBUG_INFO("Diagnostics fail.\n");
  5662. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5663. }
  5664. else
  5665. {
  5666. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5667. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5668. //isUpdateRequest = TRUE;
  5669. }
  5670. end:
  5671. // json_object_put(obj);
  5672. DiagnosticsStatusNotificationStatus = 0; //Idle
  5673. pthread_exit(NULL/*(void *) fname*/); // ?��?子執行�?
  5674. }
  5675. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5676. {
  5677. mtrace();
  5678. int result = FAIL;
  5679. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5680. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5681. {
  5682. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5683. localversion = -1;
  5684. }
  5685. else
  5686. {
  5687. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5688. OCPP_getListVerion();
  5689. }
  5690. //from db.OCPP_getListVerion
  5691. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5692. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5693. sendGetLocalListVersionConfirmation(uuid,"");
  5694. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5695. return result;
  5696. }
  5697. int handleRemoteStartRequest(char *uuid, char *payload)
  5698. {
  5699. mtrace();
  5700. int result = FAIL;
  5701. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5702. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5703. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5704. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5705. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5706. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5707. int chargingSchedulePeriodCount = 0;
  5708. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5709. int c = 0;
  5710. char *loc;
  5711. char comfirmstr[20]={0};
  5712. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5713. if(server_pending == TRUE)
  5714. {
  5715. return 0;
  5716. }
  5717. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5718. //**********connectorId****************/
  5719. c = 0;
  5720. memset(sstr ,0, sizeof(sstr) );
  5721. loc = strstr(payload, "connectorId");
  5722. if(loc == NULL)
  5723. {
  5724. connectorIdIsNULL = TRUE;
  5725. }
  5726. else
  5727. {
  5728. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5729. {
  5730. sstr[c] = loc[strlen("connectorId")+2+c];
  5731. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5732. c++;
  5733. }
  5734. sstr[c] = '\0';
  5735. connectorIdInt = atoi(sstr);
  5736. }
  5737. if(connectorIdIsNULL == TRUE) // need to discussion
  5738. {
  5739. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5740. goto end;
  5741. }
  5742. //****************idTag*******************/
  5743. c = 0;
  5744. memset(sstr ,0, sizeof(sstr) );
  5745. loc = strstr(payload, "idTag");
  5746. while (loc[3+strlen("idTag")+c] != '\"')
  5747. {
  5748. sstr[c] = loc[3+strlen("idTag")+c];
  5749. c++;
  5750. }
  5751. sstr[c] = '\0';
  5752. strcpy(idTagstr,sstr);
  5753. //****************chargingProfile*******************/
  5754. c = 0;
  5755. memset(sstr ,0, sizeof(sstr) );
  5756. loc = strstr(payload, "chargingProfile");
  5757. if(loc == NULL)
  5758. {
  5759. chargingProfileIsNULL = TRUE;
  5760. }
  5761. else
  5762. {
  5763. //****************chargingProfileId*******************/
  5764. c=0;
  5765. loc = strstr(payload, "chargingProfileId");
  5766. memset(sstr ,0, sizeof(sstr) );
  5767. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5768. {
  5769. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5770. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5771. c++;
  5772. }
  5773. sstr[c] = '\0';
  5774. chargingProfileIdInt = atoi(sstr);
  5775. //****************transactionId*******************/
  5776. loc = strstr(payload, "transactionId");
  5777. if(loc == NULL)
  5778. {
  5779. transactionIdIsNULL = TRUE;
  5780. }
  5781. else
  5782. {
  5783. c=0;
  5784. memset(sstr ,0, sizeof(sstr) );
  5785. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5786. {
  5787. sstr[c] = loc[strlen("transactionId")+2+c];
  5788. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5789. c++;
  5790. }
  5791. sstr[c] = '\0';
  5792. transactionIdInt = atoi(sstr);
  5793. }
  5794. //****************stackLevel*******************/
  5795. c=0;
  5796. loc = strstr(payload, "stackLevel");
  5797. memset(sstr ,0, sizeof(sstr) );
  5798. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5799. {
  5800. sstr[c] = loc[strlen("stackLevel")+2+c];
  5801. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5802. c++;
  5803. }
  5804. sstr[c] = '\0';
  5805. stackLevelInt = atoi(sstr);
  5806. //****************chargingProfilePurpose*******************/
  5807. c = 0;
  5808. memset(sstr ,0, sizeof(sstr) );
  5809. loc = strstr(payload, "chargingProfilePurpose");
  5810. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5811. {
  5812. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5813. c++;
  5814. }
  5815. sstr[c] = '\0';
  5816. strcpy(chargingProfilePurposestr,sstr);
  5817. //****************chargingProfileKind*******************/
  5818. c = 0;
  5819. memset(sstr ,0, sizeof(sstr) );
  5820. loc = strstr(payload, "chargingProfileKind");
  5821. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5822. {
  5823. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5824. c++;
  5825. }
  5826. sstr[c] = '\0';
  5827. strcpy(chargingProfileKindstr,sstr);
  5828. //****************recurrencyKind*******************/
  5829. loc = strstr(payload, "recurrencyKind");
  5830. if(loc == NULL)
  5831. {
  5832. recurrencyKindIsNULL = TRUE;
  5833. }
  5834. else
  5835. {
  5836. c = 0;
  5837. memset(sstr ,0, sizeof(sstr) );
  5838. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5839. {
  5840. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5841. c++;
  5842. }
  5843. sstr[c] = '\0';
  5844. strcpy(recurrencyKindstr,sstr);
  5845. }
  5846. //****************validFrom*******************/
  5847. loc = strstr(payload, "validFrom");
  5848. if(loc == NULL)
  5849. {
  5850. validFromIsNULL = TRUE;
  5851. }
  5852. else
  5853. {
  5854. c = 0;
  5855. memset(sstr ,0, sizeof(sstr) );
  5856. while (loc[3+strlen("validFrom")+c] != '\"')
  5857. {
  5858. sstr[c] = loc[3+strlen("validFrom")+c];
  5859. c++;
  5860. }
  5861. sstr[c] = '\0';
  5862. strcpy(validFromstr,sstr);
  5863. }
  5864. //****************validTo*******************/
  5865. loc = strstr(payload, "validTo");
  5866. if(loc == NULL)
  5867. {
  5868. validToIsNULL = TRUE;
  5869. }
  5870. else
  5871. {
  5872. c = 0;
  5873. memset(sstr ,0, sizeof(sstr) );
  5874. while (loc[3+strlen("validTo")+c] != '\"')
  5875. {
  5876. sstr[c] = loc[3+strlen("validTo")+c];
  5877. c++;
  5878. }
  5879. sstr[c] = '\0';
  5880. strcpy(validTostr,sstr);
  5881. }
  5882. //****************chargingSchedule*******************/
  5883. loc = strstr(payload, "chargingSchedule");
  5884. if(loc != NULL)
  5885. {
  5886. //****************duration*******************/
  5887. loc = strstr(payload, "duration");
  5888. if(loc == NULL)
  5889. {
  5890. durationIsNULL = TRUE;
  5891. }
  5892. else
  5893. {
  5894. c=0;
  5895. memset(sstr ,0, sizeof(sstr) );
  5896. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5897. {
  5898. sstr[c] = loc[strlen("duration")+2+c];
  5899. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5900. c++;
  5901. }
  5902. sstr[c] = '\0';
  5903. durationInt = atoi(sstr);
  5904. }
  5905. //****************startSchedule******************/
  5906. loc = strstr(payload, "startSchedule");
  5907. if(loc == NULL)
  5908. {
  5909. startScheduleIsNULL = TRUE;
  5910. }
  5911. else
  5912. {
  5913. c = 0;
  5914. memset(sstr ,0, sizeof(sstr) );
  5915. while (loc[3+strlen("startSchedule")+c] != '\"')
  5916. {
  5917. sstr[c] = loc[3+strlen("startSchedule")+c];
  5918. c++;
  5919. }
  5920. sstr[c] = '\0';
  5921. strcpy(startSchedulestr,sstr);
  5922. }
  5923. //****************chargingRateUnit*******************/
  5924. c = 0;
  5925. memset(sstr ,0, sizeof(sstr) );
  5926. loc = strstr(payload, "chargingRateUnit");
  5927. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5928. {
  5929. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5930. c++;
  5931. }
  5932. sstr[c] = '\0';
  5933. strcpy(chargingRateUnitstr,sstr);
  5934. //****************minChargingRate*******************/
  5935. loc = strstr(payload, "minChargingRate");
  5936. if(loc == NULL)
  5937. {
  5938. minChargingRateIsNULL = TRUE;
  5939. }
  5940. else
  5941. {
  5942. c=0;
  5943. memset(sstr ,0, sizeof(sstr) );
  5944. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5945. {
  5946. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5947. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5948. c++;
  5949. }
  5950. sstr[c] = '\0';
  5951. minChargingRateflaot = atof(sstr);
  5952. }
  5953. //****************chargingSchedulePeriod count*******************/
  5954. int what_len = strlen("startPeriod");
  5955. char *where = payload;
  5956. while ((where = strstr(where, "startPeriod"))) {
  5957. where += what_len;
  5958. chargingSchedulePeriodCount++;
  5959. }
  5960. where = payload;
  5961. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5962. {
  5963. //****************startPeriod*******************/
  5964. c=0;
  5965. loc = strstr(where, "startPeriod");
  5966. memset(sstr ,0, sizeof(sstr) );
  5967. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5968. {
  5969. sstr[c] = loc[strlen("startPeriod")+2+c];
  5970. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5971. c++;
  5972. }
  5973. sstr[c] = '\0';
  5974. startPeriodInt[periodNums] = atoi(sstr);
  5975. //****************limit*******************/
  5976. c=0;
  5977. loc = strstr(where, "limit");
  5978. memset(sstr ,0, sizeof(sstr) );
  5979. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5980. {
  5981. sstr[c] = loc[strlen("limit")+2+c];
  5982. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5983. c++;
  5984. }
  5985. sstr[c] = '\0';
  5986. limitflaot[periodNums] = atof(sstr);
  5987. //****************numberPhases*******************/
  5988. loc = strstr(where, "numberPhases");
  5989. if(loc == NULL)
  5990. {
  5991. numberPhasesIsNULL = TRUE;
  5992. }
  5993. else
  5994. {
  5995. c=0;
  5996. memset(sstr ,0, sizeof(sstr) );
  5997. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  5998. {
  5999. sstr[c] = loc[strlen("numberPhases")+2+c];
  6000. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6001. c++;
  6002. }
  6003. sstr[c] = '\0';
  6004. numberPhasesInt[periodNums] = atoi(sstr);
  6005. }
  6006. where = loc;
  6007. }
  6008. }
  6009. }
  6010. /*
  6011. enum _SYSTEM_STATUS
  6012. {
  6013. S_BOOTING = 0,
  6014. S_IDLE, = 1
  6015. S_AUTHORIZING, =2
  6016. S_REASSIGN_CHECK, =3
  6017. S_REASSIGN, =4
  6018. S_PRECHARGE, =5
  6019. S_PREPARING_FOR_EV, =6
  6020. S_PREPARING_FOR_EVSE, =7
  6021. S_CHARGING, =8
  6022. S_TERMINATING, =9
  6023. S_COMPLETE, =10
  6024. S_ALARM, =11
  6025. S_FAULT =12
  6026. }
  6027. */
  6028. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6029. {
  6030. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6031. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6032. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6033. //check Transaction active
  6034. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6035. {
  6036. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6037. {
  6038. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6039. {
  6040. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6041. {
  6042. //Reserved
  6043. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6044. }
  6045. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6046. {
  6047. //Reserved
  6048. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6049. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6050. goto end;
  6051. }
  6052. else
  6053. {
  6054. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6055. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6056. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6057. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6058. {
  6059. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6060. goto end;
  6061. }
  6062. }//END FOR ELSE
  6063. }
  6064. }// END FOR CHAdeMO_QUANTITY
  6065. for (int index = 0; index < CCS_QUANTITY; index++)
  6066. {
  6067. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6068. {
  6069. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6070. {
  6071. //Reserved
  6072. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6073. }
  6074. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6075. {
  6076. //Reserved
  6077. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6078. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6079. goto end;
  6080. }
  6081. else
  6082. {
  6083. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6084. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6085. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6086. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6087. {
  6088. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6089. goto end;
  6090. }
  6091. }// END FOR ELSE
  6092. }
  6093. }// END FOR CCS_QUANTITY
  6094. for (int index = 0; index < GB_QUANTITY; index++)
  6095. {
  6096. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6097. {
  6098. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6099. {
  6100. //Reserved
  6101. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6102. }
  6103. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6104. {
  6105. //Reserved
  6106. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6107. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6108. goto end;
  6109. }
  6110. else
  6111. {
  6112. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6113. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6114. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6115. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6116. {
  6117. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6118. goto end;
  6119. }
  6120. }// END FOR ELSE
  6121. }
  6122. } // END FOR GB_QUANTITY
  6123. }
  6124. else
  6125. {
  6126. for (int index = 0; index < AC_QUANTITY; index++)
  6127. {
  6128. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6129. {
  6130. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6131. {
  6132. //Reserved
  6133. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6134. }
  6135. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6136. {
  6137. //Reserved
  6138. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6139. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6140. goto end;
  6141. }
  6142. else
  6143. {
  6144. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6145. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6146. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6147. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6148. {
  6149. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6150. goto end;
  6151. }
  6152. }//END FOR ELSE
  6153. }
  6154. }// END FOR AC_QUANTITY
  6155. }
  6156. if(chargingProfileIsNULL == FALSE)
  6157. {
  6158. //ChargingProfile
  6159. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6160. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6161. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6162. if(recurrencyKindIsNULL == FALSE) //OPTION
  6163. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6164. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6165. if(transactionIdIsNULL == FALSE) // OPTION
  6166. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6167. if(validFromIsNULL == FALSE) // OPTION
  6168. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6169. if(validToIsNULL == FALSE) //OPTION
  6170. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6171. //ChargingSchedule
  6172. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6173. if(durationIsNULL == FALSE) //OPTION
  6174. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6175. if(minChargingRateIsNULL == FALSE) //OPTION
  6176. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6177. if(startScheduleIsNULL == FALSE) //OPTION
  6178. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6179. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6180. {
  6181. //ChargingSchedulePeriod
  6182. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6183. if(numberPhasesIsNULL == FALSE)
  6184. {
  6185. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6186. }
  6187. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6188. }
  6189. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6190. {
  6191. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6192. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6193. }
  6194. else
  6195. {
  6196. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6197. }
  6198. }
  6199. else
  6200. {
  6201. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6202. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6203. }
  6204. }
  6205. else
  6206. {
  6207. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6208. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6209. }
  6210. end:
  6211. if(connectorIdIsNULL == FALSE)
  6212. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6213. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6214. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6215. //OCPP send RemoteStartConfirmation by first.
  6216. sendRemoteStartConfirmation(uuid, comfirmstr);
  6217. return result;
  6218. }
  6219. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6220. {
  6221. mtrace();
  6222. int result = FAIL;
  6223. int match = FALSE;
  6224. int GunNO = 0;
  6225. int transactionIdInt=0;
  6226. int transactionIdIsNULL= FALSE;
  6227. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6228. int c = 0;
  6229. char *loc;
  6230. char comfirmstr[20];
  6231. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6232. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6233. if(server_pending == TRUE)
  6234. {
  6235. return 0;
  6236. }
  6237. c=0;
  6238. loc = strstr(payload, "transactionId");
  6239. if(loc == NULL)
  6240. {
  6241. transactionIdIsNULL= TRUE;
  6242. }
  6243. else
  6244. {
  6245. memset(sstr ,0, sizeof(sstr) );
  6246. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6247. {
  6248. sstr[c] = loc[strlen("transactionId")+2+c];
  6249. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6250. c++;
  6251. }
  6252. sstr[c] = '\0';
  6253. transactionIdInt = atoi(sstr);
  6254. }
  6255. if(transactionIdIsNULL == FALSE)
  6256. {
  6257. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6258. {
  6259. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6260. {
  6261. //check Transaction active
  6262. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6263. {
  6264. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6265. {
  6266. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6267. {
  6268. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6269. {
  6270. match = TRUE;
  6271. GunNO = gun_index;
  6272. }
  6273. }
  6274. }// END FOR CHAdeMO_QUANTITY
  6275. for (int index = 0; index < CCS_QUANTITY; index++)
  6276. {
  6277. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6278. {
  6279. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6280. {
  6281. match = TRUE;
  6282. GunNO = gun_index;
  6283. }
  6284. }
  6285. }// END FOR CCS_QUANTITY
  6286. for (int index = 0; index < GB_QUANTITY; index++)
  6287. {
  6288. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6289. {
  6290. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6291. {
  6292. match = TRUE;
  6293. GunNO = gun_index;
  6294. }
  6295. }
  6296. }// END FOR GB_QUANTITY
  6297. }
  6298. else
  6299. {
  6300. for (int index = 0; index < AC_QUANTITY; index++)
  6301. {
  6302. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6303. {
  6304. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6305. {
  6306. match = TRUE;
  6307. GunNO = gun_index;
  6308. }
  6309. }
  6310. }// END FOR CHAdeMO_QUANTITY
  6311. }// END FOR AC ELSE
  6312. }// CHECK IF ResponseTransactionId == transactionIdInt
  6313. }//END FOR
  6314. if( match == TRUE)
  6315. {
  6316. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6317. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6318. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6319. }
  6320. else
  6321. {
  6322. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6323. }
  6324. }
  6325. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6326. return result;
  6327. }
  6328. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6329. {
  6330. mtrace();
  6331. int result = FAIL;
  6332. int connectorIdInt=0, reservationIdInt=0;
  6333. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6334. char comfirmstr[20]={0};
  6335. char sstr[180]={ 0 };
  6336. int c = 0;
  6337. char *loc;
  6338. //char *ptr;
  6339. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6340. //***(1)connectorId ****/
  6341. c=0;
  6342. loc = strstr(payload, "connectorId");
  6343. memset(sstr ,0, sizeof(sstr) );
  6344. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6345. {
  6346. sstr[c] = loc[strlen("connectorId")+2+c];
  6347. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6348. c++;
  6349. }
  6350. sstr[c] = '\0';
  6351. connectorIdInt = atoi(sstr);
  6352. //***(2)expiryDate ****/
  6353. loc = strstr(payload, "expiryDate");
  6354. memset(sstr ,0, sizeof(sstr) );
  6355. c = 0;
  6356. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6357. {
  6358. sstr[c] = loc[3+strlen("expiryDate")+c];
  6359. c++;
  6360. }
  6361. sstr[c] = '\0';
  6362. strcpy(expiryDatestr, sstr);
  6363. //***(3)idTag ****/
  6364. loc = strstr(payload, "idTag");
  6365. memset(sstr ,0, sizeof(sstr) );
  6366. c = 0;
  6367. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6368. {
  6369. sstr[c] = loc[3+strlen("idTag")+c];
  6370. c++;
  6371. }
  6372. sstr[c] = '\0';
  6373. strcpy(idTagstr, sstr);
  6374. //***(4)parentIdTag ****/
  6375. loc = strstr(payload, "parentIdTag");
  6376. memset(sstr ,0, sizeof(sstr) );
  6377. c = 0;
  6378. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6379. {
  6380. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6381. c++;
  6382. }
  6383. sstr[c] = '\0';
  6384. strcpy(parentIdTagstr, sstr);
  6385. //***(5)reservationId ****/
  6386. c=0;
  6387. loc = strstr(payload, "reservationId");
  6388. memset(sstr ,0, sizeof(sstr) );
  6389. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6390. {
  6391. sstr[c] = loc[strlen("reservationId")+2+c];
  6392. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6393. c++;
  6394. }
  6395. sstr[c] = '\0';
  6396. reservationIdInt = atoi(sstr);
  6397. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6398. /*
  6399. enum _SYSTEM_STATUS
  6400. {
  6401. S_BOOTING = 0,
  6402. S_IDLE, = 1
  6403. S_AUTHORIZING, =2
  6404. S_REASSIGN_CHECK, =3
  6405. S_REASSIGN, =4
  6406. S_PRECHARGE, =5
  6407. S_PREPARING_FOR_EV, =6
  6408. S_PREPARING_FOR_EVSE, =7
  6409. S_CHARGING, =8
  6410. S_TERMINATING, =9
  6411. S_COMPLETE, =10
  6412. S_ALARM, =11
  6413. S_FAULT =12
  6414. }
  6415. */
  6416. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6417. {
  6418. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6419. goto end;
  6420. }
  6421. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6422. {
  6423. //check Transaction active
  6424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6425. {
  6426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6427. {
  6428. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6429. {
  6430. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6431. {
  6432. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6433. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6434. {
  6435. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6436. {
  6437. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6438. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6439. }
  6440. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6441. {
  6442. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6443. }
  6444. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6445. {
  6446. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6447. }
  6448. else
  6449. {
  6450. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6451. }
  6452. }
  6453. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6454. {
  6455. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6456. }
  6457. }
  6458. else
  6459. {
  6460. //replace reservation
  6461. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6462. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6463. }
  6464. }
  6465. } // END FOR CHAdeMO_QUANTITY
  6466. for (int index = 0; index < CCS_QUANTITY; index++)
  6467. {
  6468. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6469. {
  6470. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6471. {
  6472. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6473. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6474. {
  6475. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6476. {
  6477. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6478. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6479. }
  6480. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6481. {
  6482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6483. }
  6484. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6485. {
  6486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6487. }
  6488. else
  6489. {
  6490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6491. }
  6492. }
  6493. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6494. {
  6495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6496. }
  6497. }
  6498. else
  6499. {
  6500. //replace reservation
  6501. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6502. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6503. }
  6504. }
  6505. } // END FOR CCS_QUANTITY
  6506. for (int index = 0; index < GB_QUANTITY; index++)
  6507. {
  6508. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6509. {
  6510. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6511. {
  6512. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6513. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6514. {
  6515. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6516. {
  6517. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6519. }
  6520. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6521. {
  6522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6523. }
  6524. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6525. {
  6526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6527. }
  6528. else
  6529. {
  6530. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6531. }
  6532. }
  6533. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6534. {
  6535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6536. }
  6537. }
  6538. else
  6539. {
  6540. //replace reservation
  6541. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6543. }
  6544. }
  6545. }// END FOR GB_QUANTITY
  6546. }
  6547. else
  6548. {
  6549. for (int index = 0; index < AC_QUANTITY; index++)
  6550. {
  6551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6552. {
  6553. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6554. {
  6555. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6556. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6557. {
  6558. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6559. {
  6560. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6561. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6562. }
  6563. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6564. {
  6565. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6566. }
  6567. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6568. {
  6569. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6570. }
  6571. else
  6572. {
  6573. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6574. }
  6575. }
  6576. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6577. {
  6578. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6579. }
  6580. }
  6581. else
  6582. {
  6583. //replace reservation
  6584. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6586. }
  6587. }
  6588. } // END FOR AC_QUANTITY
  6589. }//END FOR AC ELSE
  6590. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6591. }
  6592. else if(connectorIdInt == 0)
  6593. {
  6594. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6595. {
  6596. //check Transaction active
  6597. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6598. {
  6599. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6600. {
  6601. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6602. {
  6603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6604. goto end;
  6605. }
  6606. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6607. {
  6608. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6609. goto end;
  6610. }
  6611. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6612. {
  6613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6614. goto end;
  6615. }
  6616. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6617. {
  6618. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6619. goto end;
  6620. }
  6621. }
  6622. }// END FOR CHAdeMO_QUANTITY
  6623. for (int index = 0; index < CCS_QUANTITY; index++)
  6624. {
  6625. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6626. {
  6627. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6628. {
  6629. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6630. }
  6631. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6632. {
  6633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6634. }
  6635. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6636. {
  6637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6638. }
  6639. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6640. {
  6641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6642. }
  6643. }
  6644. } // END FOR CCS_QUANTITY
  6645. for (int index = 0; index < GB_QUANTITY; index++)
  6646. {
  6647. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6648. {
  6649. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6650. {
  6651. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6652. }
  6653. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6654. {
  6655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6656. }
  6657. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6658. {
  6659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6660. }
  6661. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6662. {
  6663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6664. }
  6665. }
  6666. } // END FOR GB_QUANTITY
  6667. }
  6668. else
  6669. {
  6670. for (int index = 0; index < AC_QUANTITY; index++)
  6671. {
  6672. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6673. {
  6674. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6675. {
  6676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6677. goto end;
  6678. }
  6679. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6680. {
  6681. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6682. goto end;
  6683. }
  6684. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6685. {
  6686. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6687. goto end;
  6688. }
  6689. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6690. {
  6691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6692. goto end;
  6693. }
  6694. }
  6695. }// END FOR AC_QUANTITY
  6696. }
  6697. //The connectorId is 0
  6698. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6700. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6701. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6702. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6703. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6704. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6705. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6706. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6707. result = TRUE;
  6708. return result;
  6709. }
  6710. else
  6711. {
  6712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6713. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6714. }
  6715. if(strcmp(comfirmstr,"Accepted") == 0)
  6716. {
  6717. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6718. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6719. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6720. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6721. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6722. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6723. result = TRUE;
  6724. return result;
  6725. }
  6726. end:
  6727. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6728. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6729. return result;
  6730. }
  6731. int handleResetRequest(char *uuid, char *payload)
  6732. {
  6733. mtrace();
  6734. int result = FAIL;
  6735. char sstr[10]={0};
  6736. char typestr[10]={0};
  6737. char comfirmstr[20]={0};
  6738. int c = 0;
  6739. char *loc;
  6740. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6741. DEBUG_INFO("handleResetRequest ...\n");
  6742. loc = strstr(payload, "type");
  6743. memset(sstr ,0, sizeof(sstr) );
  6744. c = 0;
  6745. while (loc[3+strlen("type")+c] != '\"')
  6746. {
  6747. sstr[c] = loc[3+strlen("type")+c];
  6748. c++;
  6749. }
  6750. sstr[c] = '\0';
  6751. strcpy(typestr,sstr);
  6752. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6753. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6754. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6755. {
  6756. //check Transaction active
  6757. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6758. {
  6759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6760. {
  6761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6762. {
  6763. //0: unplug, 1: Plug-in
  6764. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6765. }
  6766. }
  6767. for (int index = 0; index < CCS_QUANTITY; index++)
  6768. {
  6769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6770. {
  6771. //0: unplug, 1: Plug-in
  6772. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6773. }
  6774. }
  6775. for (int index = 0; index < GB_QUANTITY; index++)
  6776. {
  6777. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6778. {
  6779. //0: unplug, 1: Plug-in
  6780. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6781. }
  6782. }
  6783. }
  6784. else
  6785. {
  6786. for (int index = 0; index < AC_QUANTITY; index++)
  6787. {
  6788. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6789. {
  6790. //0: unplug, 1: Plug-in
  6791. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6792. }
  6793. }
  6794. }// END FOR AC ELSE
  6795. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6796. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6797. result = TRUE;
  6798. return result;
  6799. }
  6800. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6801. {
  6802. //check Transaction active
  6803. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6804. {
  6805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6806. {
  6807. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6808. {
  6809. //0: unplug, 1: Plug-in
  6810. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6811. }
  6812. }
  6813. for (int index = 0; index < CCS_QUANTITY; index++)
  6814. {
  6815. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6816. {
  6817. //0: unplug, 1: Plug-in
  6818. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6819. }
  6820. }
  6821. for (int index = 0; index < GB_QUANTITY; index++)
  6822. {
  6823. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6824. {
  6825. //0: unplug, 1: Plug-in
  6826. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6827. }
  6828. }
  6829. }
  6830. else
  6831. {
  6832. for (int index = 0; index < AC_QUANTITY; index++)
  6833. {
  6834. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6835. {
  6836. //0: unplug, 1: Plug-in
  6837. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6838. }
  6839. }
  6840. }// END FOR AC ELSE
  6841. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6842. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6843. result = TRUE;
  6844. return result;
  6845. }
  6846. else
  6847. {
  6848. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6849. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6850. goto errorend;
  6851. }
  6852. errorend:
  6853. sendResetConfirmation(uuid, comfirmstr);
  6854. return result;
  6855. }
  6856. int handleSendLocalListRequest(char *uuid, char *payload)
  6857. {
  6858. mtrace();
  6859. int result = FAIL;
  6860. int listVersionInt;
  6861. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6862. char listsearch[]="listVersion";
  6863. char updateTypesearch[]="updateType";
  6864. char localAuthorizationListsearch[]="localAuthorizationList";
  6865. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6866. char CardList[500][160]={0};
  6867. char updateTypestr[15]={0};
  6868. char idTagstr[20]={0};
  6869. char parentIdTag[20]={0};
  6870. char expiryDate[30]={0};
  6871. char idTagstatus[16]={0};
  6872. int c = 0;
  6873. int i = 0;
  6874. char *delim1 = "}";
  6875. char * pch;
  6876. char *loc;
  6877. //char *ptr;
  6878. char comfirmstr[20];
  6879. //int n_localAuthorizations = 0;
  6880. int checkState_Faulted = FALSE;
  6881. DEBUG_INFO("handleSendLocalListRequest\n");
  6882. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6883. {
  6884. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6885. goto end;
  6886. }
  6887. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6888. {
  6889. //check Charge Point state
  6890. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6891. {
  6892. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6893. {
  6894. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6895. }
  6896. }
  6897. for (int index = 0; index < CCS_QUANTITY; index++)
  6898. {
  6899. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6900. {
  6901. checkState_Faulted = TRUE; //OCPP Status
  6902. }
  6903. }
  6904. for (int index = 0; index < GB_QUANTITY; index++)
  6905. {
  6906. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6907. {
  6908. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6909. }
  6910. }
  6911. }
  6912. else
  6913. {
  6914. //check Charge Point state
  6915. for (int index = 0; index < AC_QUANTITY; index++)
  6916. {
  6917. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6918. {
  6919. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6920. }
  6921. }
  6922. }// END FOR AC ELSE
  6923. if(checkState_Faulted == TRUE)
  6924. {
  6925. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6926. goto end;
  6927. }
  6928. //listVersion
  6929. c = 0;
  6930. loc = strstr(payload, listsearch);
  6931. while (loc[strlen("listVersion")+2+c] != ',')
  6932. {
  6933. sstr[c] = loc[strlen("listVersion")+2+c];
  6934. c++;
  6935. }
  6936. sstr[c] = '\0';
  6937. listVersionInt = atoi(sstr);
  6938. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6939. //updateType
  6940. loc = strstr(payload, updateTypesearch);
  6941. c = 0;
  6942. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6943. {
  6944. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6945. c++;
  6946. }
  6947. sstr[c] = '\0';
  6948. strcpy(updateTypestr, sstr);
  6949. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6950. //localAuthorizationList
  6951. memset(sstr ,0, sizeof(sstr) );
  6952. loc = strstr(payload, localAuthorizationListsearch);
  6953. if(loc != NULL) // localAuthorizationList is not NULL
  6954. {
  6955. //Check UpdateType
  6956. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6957. {
  6958. //Local list full update
  6959. printf("Local list full update.\n");
  6960. OCPP_cleanLocalList();
  6961. }
  6962. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6963. {
  6964. //Local list different update
  6965. printf("Local list different update.\n");
  6966. OCPP_getListVerion();
  6967. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6968. {
  6969. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6970. goto end;
  6971. }
  6972. }
  6973. else
  6974. {
  6975. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6976. goto end;
  6977. }
  6978. c = 0;
  6979. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6980. {
  6981. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6982. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6983. c++;
  6984. }
  6985. sstr[c] = '\0';
  6986. //parsing strings to words
  6987. i = 0;
  6988. pch = strtok(sstr,delim1);
  6989. while (pch != NULL)
  6990. {
  6991. strcpy(CardList[i], pch);
  6992. pch = strtok (NULL, delim1);
  6993. i = i + 1;
  6994. }
  6995. //local Authorizations List Numbers
  6996. //n_localAuthorizations = i;
  6997. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6998. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  6999. c= 0;
  7000. while(c < i)
  7001. {
  7002. //Search "IdToken"
  7003. memset(sstr ,0, sizeof(sstr) );
  7004. loc = strstr(CardList[c], "idTag");
  7005. int j = 0;
  7006. while (loc[3+strlen("idTag")+j] != '\"')
  7007. {
  7008. sstr[j] = loc[3+strlen("idTag")+j];
  7009. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7010. j++;
  7011. }
  7012. sstr[j] = '\0';
  7013. strcpy(idTagstr, sstr);
  7014. //Search "expiryDate"
  7015. memset(sstr ,0, sizeof(sstr) );
  7016. loc = strstr(CardList[c], "expiryDate");
  7017. j = 0;
  7018. while (loc[3+strlen("expiryDate")+j] != '\"')
  7019. {
  7020. sstr[j] = loc[3+strlen("expiryDate")+j];
  7021. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7022. j++;
  7023. }
  7024. sstr[j] = '\0';
  7025. strcpy(expiryDate, sstr);
  7026. //Search "parentIdTag"
  7027. memset(sstr ,0, sizeof(sstr) );
  7028. loc = strstr(CardList[c], "parentIdTag");
  7029. j = 0;
  7030. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7031. {
  7032. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7033. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7034. j++;
  7035. }
  7036. sstr[j] = '\0';
  7037. strcpy(parentIdTag, sstr);
  7038. //Search "status"
  7039. memset(sstr ,0, sizeof(sstr) );
  7040. loc = strstr(CardList[c], "status");
  7041. j = 0;
  7042. while (loc[3+strlen("status")+j] != '\"')
  7043. {
  7044. sstr[j] = loc[3+strlen("status")+j];
  7045. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7046. j++;
  7047. }
  7048. sstr[j] = '\0';
  7049. strcpy(idTagstatus, sstr);
  7050. OCPP_getIdTag(idTagstr);
  7051. //OCPP_getIdTag("test"); For Test
  7052. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7053. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7054. {
  7055. //Local list full update
  7056. DEBUG_INFO("Local list full update.\n");
  7057. // update list
  7058. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7059. OCPP_get_TableAuthlocalAllData();
  7060. }
  7061. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7062. {
  7063. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7064. {
  7065. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7066. }
  7067. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7068. {
  7069. OCPP_deleteIdTag(idTagstr);
  7070. }
  7071. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7072. {
  7073. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7074. }
  7075. }
  7076. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7077. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7078. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7079. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7080. c++;
  7081. }
  7082. }
  7083. else
  7084. {
  7085. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7086. {
  7087. //Local list different update
  7088. DEBUG_INFO("Local list different update.\n");
  7089. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7090. goto end;
  7091. }
  7092. }
  7093. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7094. end:
  7095. sendSendLocalListConfirmation(uuid, comfirmstr);
  7096. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7097. #if 0
  7098. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7099. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7100. #endif
  7101. return result;
  7102. }
  7103. /*
  7104. enum _SYSTEM_STATUS
  7105. {
  7106. S_BOOTING = 0,
  7107. S_IDLE, =1
  7108. S_AUTHORIZING, =2
  7109. S_REASSIGN_CHECK, =3
  7110. S_REASSIGN, =4
  7111. S_PRECHARGE, =5
  7112. S_PREPARING_FOR_EV, =6
  7113. S_PREPARING_FOR_EVSE, =7
  7114. S_CHARGING, =8
  7115. S_TERMINATING, =9
  7116. S_COMPLETE, =10
  7117. S_ALARM, =11
  7118. S_FAULT =12
  7119. };
  7120. */
  7121. #define MAX 200
  7122. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7123. {
  7124. mtrace();
  7125. int result = FAIL;
  7126. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7127. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7128. char chargingProfilePurposeStr[30]={0};
  7129. char chargingProfileKindStr[16]={0};
  7130. char recurrencyKindStr[10]={0};
  7131. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7132. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7133. int chargingSchedulePeriodCount = 0;
  7134. //int updateflag = FALSE;
  7135. char comfirmstr[20]={0};
  7136. int meet= FALSE;
  7137. char sstr[10]={0};
  7138. int c = 0;
  7139. char *loc;
  7140. FILE *fptr1;//, *fptr2;
  7141. //int lno=0;//, linectr = 0;
  7142. //int modifyflag = FALSE;
  7143. char filename[MAX]={0};
  7144. char tempfile[] = "../Storage/OCPP/temp.json";
  7145. int resultRename=0;
  7146. char rmFileCmd[50]={0};
  7147. char tempchargingProfilePurposeStr[30]={0};
  7148. //[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}}}]
  7149. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7150. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7151. //*********************connectorId***************************/
  7152. loc = strstr(payload, "connectorId");
  7153. c = 0;
  7154. memset(sstr ,0, sizeof(sstr) );
  7155. while (loc[strlen("connectorId")+2+c] != ',')
  7156. {
  7157. sstr[c] = loc[strlen("connectorId")+2+c];
  7158. c++;
  7159. }
  7160. sstr[c] = '\0';
  7161. connectorIdInt = atoi(sstr);
  7162. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7163. {
  7164. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7165. }
  7166. else
  7167. {
  7168. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7169. }
  7170. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7171. //*********************chargingProfileId***************************/
  7172. loc = strstr(payload, "chargingProfileId");
  7173. c = 0;
  7174. memset(sstr ,0, sizeof(sstr) );
  7175. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7176. {
  7177. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7178. c++;
  7179. }
  7180. sstr[c] = '\0';
  7181. chargingProfileIdInt = atoi(sstr);
  7182. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7183. {
  7184. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7185. }
  7186. else
  7187. {
  7188. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7189. }
  7190. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7191. //*********************transactionId***************************/
  7192. loc = strstr(payload, "transactionId");
  7193. if(loc != NULL)
  7194. {
  7195. c = 0;
  7196. memset(sstr ,0, sizeof(sstr) );
  7197. while (loc[strlen("transactionId")+2+c] != ',')
  7198. {
  7199. sstr[c] = loc[strlen("transactionId")+2+c];
  7200. c++;
  7201. }
  7202. sstr[c] = '\0';
  7203. transactionIdInt = atoi(sstr);
  7204. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7205. {
  7206. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7207. }
  7208. else
  7209. {
  7210. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7211. }
  7212. }
  7213. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7214. //*********************stackLevel***************************/
  7215. loc = strstr(payload, "stackLevel");
  7216. c = 0;
  7217. memset(sstr ,0, sizeof(sstr) );
  7218. while (loc[strlen("stackLevel")+2+c] != ',')
  7219. {
  7220. sstr[c] = loc[strlen("stackLevel")+2+c];
  7221. c++;
  7222. }
  7223. sstr[c] = '\0';
  7224. stackLevelInt = atoi(sstr);
  7225. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7226. {
  7227. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7228. }
  7229. else
  7230. {
  7231. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7232. }
  7233. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7234. //*********************chargingProfilePurpose***************************/
  7235. loc = strstr(payload, "chargingProfilePurpose");
  7236. c = 0;
  7237. memset(sstr ,0, sizeof(sstr) );
  7238. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7239. {
  7240. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7241. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7242. c++;
  7243. }
  7244. sstr[c] = '\0';
  7245. strcpy(chargingProfilePurposeStr,sstr);
  7246. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7247. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7248. {
  7249. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7250. }
  7251. else
  7252. {
  7253. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7254. }
  7255. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7256. //*********************chargingProfileKind***************************/
  7257. loc = strstr(payload, "chargingProfileKind");
  7258. c = 0;
  7259. memset(sstr ,0, sizeof(sstr) );
  7260. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7261. {
  7262. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7263. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7264. c++;
  7265. }
  7266. sstr[c] = '\0';
  7267. strcpy(chargingProfileKindStr,sstr);
  7268. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7269. {
  7270. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7271. }
  7272. else
  7273. {
  7274. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7275. }
  7276. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7277. //*********************recurrencyKind***************************/
  7278. loc = strstr(payload, "recurrencyKind");
  7279. if(loc != NULL)
  7280. {
  7281. c = 0;
  7282. memset(sstr ,0, sizeof(sstr) );
  7283. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7284. {
  7285. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7286. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7287. c++;
  7288. }
  7289. sstr[c] = '\0';
  7290. strcpy(recurrencyKindStr,sstr);
  7291. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7292. {
  7293. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7294. }
  7295. else
  7296. {
  7297. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7298. }
  7299. }
  7300. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7301. //*********************validFrom***************************/
  7302. loc = strstr(payload, "validFrom");
  7303. if(loc != NULL)
  7304. {
  7305. c = 0;
  7306. memset(sstr ,0, sizeof(sstr) );
  7307. while (loc[3+strlen("validFrom")+c] != '\"')
  7308. {
  7309. sstr[c] = loc[3+strlen("validFrom")+c];
  7310. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7311. c++;
  7312. }
  7313. sstr[c] = '\0';
  7314. strcpy(validFromStr,sstr);
  7315. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7316. {
  7317. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7318. }
  7319. else
  7320. {
  7321. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7322. }
  7323. }
  7324. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7325. //*********************validTo***************************/
  7326. loc = strstr(payload, "validTo");
  7327. if(loc != NULL)
  7328. {
  7329. c = 0;
  7330. memset(sstr ,0, sizeof(sstr) );
  7331. while (loc[3+strlen("validTo")+c] != '\"')
  7332. {
  7333. sstr[c] = loc[3+strlen("validTo")+c];
  7334. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7335. c++;
  7336. }
  7337. sstr[c] = '\0';
  7338. strcpy(validToStr,sstr);
  7339. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7340. {
  7341. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7342. }
  7343. else
  7344. {
  7345. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7346. }
  7347. }
  7348. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7349. //*********************duration***************************/
  7350. loc = strstr(payload, "duration");
  7351. if(loc != NULL)
  7352. {
  7353. c = 0;
  7354. memset(sstr ,0, sizeof(sstr) );
  7355. while (loc[strlen("duration")+2+c] != ',')
  7356. {
  7357. sstr[c] = loc[strlen("duration")+2+c];
  7358. c++;
  7359. }
  7360. sstr[c] = '\0';
  7361. durationInt = atoi(sstr);
  7362. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7363. {
  7364. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7365. }
  7366. else
  7367. {
  7368. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7369. }
  7370. }
  7371. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7372. //*********************startSchedule***************************/
  7373. loc = strstr(payload, "startSchedule");
  7374. if(loc != NULL)
  7375. {
  7376. c = 0;
  7377. memset(sstr ,0, sizeof(sstr) );
  7378. while (loc[3+strlen("startSchedule")+c] != '\"')
  7379. {
  7380. sstr[c] = loc[3+strlen("startSchedule")+c];
  7381. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7382. c++;
  7383. }
  7384. sstr[c] = '\0';
  7385. strcpy(startScheduleStr,sstr);
  7386. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7387. {
  7388. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7389. }
  7390. else
  7391. {
  7392. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7393. }
  7394. }
  7395. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7396. //*********************chargingRateUnit***************************/
  7397. loc = strstr(payload, "chargingRateUnit");
  7398. if(loc != NULL)
  7399. {
  7400. c = 0;
  7401. memset(sstr ,0, sizeof(sstr) );
  7402. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7403. {
  7404. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7405. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7406. c++;
  7407. }
  7408. sstr[c] = '\0';
  7409. strcpy(chargingRateUnitStr,sstr);
  7410. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7411. {
  7412. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7413. }
  7414. else
  7415. {
  7416. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7417. }
  7418. }
  7419. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7420. //****************chargingSchedulePeriod count start*******************/
  7421. int what_len = strlen("startPeriod");
  7422. char *where = payload;
  7423. if (what_len)
  7424. while ((where = strstr(where, "startPeriod"))) {
  7425. where += what_len;
  7426. chargingSchedulePeriodCount++;
  7427. }
  7428. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7429. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7430. where = payload;
  7431. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7432. {
  7433. //****************startPeriod*******************/
  7434. c=0;
  7435. loc = strstr(where, "startPeriod");
  7436. memset(sstr ,0, sizeof(sstr) );
  7437. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7438. {
  7439. sstr[c] = loc[strlen("startPeriod")+2+c];
  7440. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7441. c++;
  7442. }
  7443. sstr[c] = '\0';
  7444. startPeriodInt[periodNums] = atoi(sstr);
  7445. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7446. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7447. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7448. {
  7449. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7450. }
  7451. else
  7452. {
  7453. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7454. }
  7455. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7456. //****************limit*******************/
  7457. c=0;
  7458. loc = strstr(where, "limit");
  7459. memset(sstr ,0, sizeof(sstr) );
  7460. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7461. {
  7462. sstr[c] = loc[strlen("limit")+2+c];
  7463. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7464. c++;
  7465. }
  7466. sstr[c] = '\0';
  7467. limitflaot[periodNums] = atof(sstr);
  7468. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7469. {
  7470. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7471. }
  7472. else
  7473. {
  7474. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7475. }
  7476. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7477. //****************numberPhases*******************/
  7478. loc = strstr(where, "numberPhases");
  7479. if(loc != NULL)
  7480. {
  7481. c=0;
  7482. memset(sstr ,0, sizeof(sstr) );
  7483. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7484. {
  7485. sstr[c] = loc[strlen("numberPhases")+2+c];
  7486. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7487. c++;
  7488. }
  7489. sstr[c] = '\0';
  7490. numberPhasesInt[periodNums] = atoi(sstr);
  7491. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7492. {
  7493. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7494. }
  7495. else
  7496. {
  7497. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7498. }
  7499. }
  7500. where = loc;
  7501. }
  7502. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7503. //****************chargingSchedulePeriod count end*******************/
  7504. //*********************minChargingRate***************************/
  7505. loc = strstr(payload, "minChargingRate");
  7506. if(loc != NULL)
  7507. {
  7508. c = 0;
  7509. memset(sstr ,0, sizeof(sstr) );
  7510. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7511. {
  7512. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7513. c++;
  7514. }
  7515. sstr[c] = '\0';
  7516. minChargingRateFloat = atof(sstr);
  7517. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7518. {
  7519. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7520. }
  7521. else
  7522. {
  7523. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7524. }
  7525. }
  7526. DEBUG_INFO("\n\n Replace a specific line in a text file with a new text :\n");
  7527. DEBUG_INFO("-------------------------------------------------------------\n");
  7528. DEBUG_INFO(" Input the file name to be opened : ");
  7529. //fgets(fname, MAX, stdin);
  7530. //fname[strlen(fname) - 1] = '\0';
  7531. #if 0
  7532. switch(connectorIdInt)
  7533. {
  7534. case 0:
  7535. strcpy(filename, ChargingProfile_0_JSON );
  7536. break;
  7537. case 1:
  7538. strcpy(filename, ChargingProfile_1_JSON );
  7539. break;
  7540. case 2:
  7541. strcpy(filename, ChargingProfile_2_JSON );
  7542. break;
  7543. default:
  7544. strcpy(filename, ChargingProfile_0_JSON );
  7545. break;
  7546. }
  7547. fptr1 = fopen(filename, "r");
  7548. if (!fptr1)
  7549. {
  7550. //file not exist
  7551. DEBUG_INFO("Unable to open the input file!!\n");
  7552. fptr1 = fopen(filename, "w+");
  7553. }
  7554. fclose(fptr1);
  7555. #endif
  7556. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7557. //DEBUG_INFO(" ChargingProfilePurposeTypeStr[TxProfile]=%s\n", ChargingProfilePurposeTypeStr[TxProfile]);
  7558. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7559. {
  7560. //printf("set chargingProfile 1-2\n");
  7561. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7562. if(connectorIdInt != 0)
  7563. {
  7564. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7565. goto end;
  7566. }
  7567. strcpy(filename, ChargePointMaxProfile_JSON );
  7568. fptr1 = fopen(filename, "r");
  7569. if (!fptr1)
  7570. {
  7571. //file not exist
  7572. DEBUG_INFO("Unable to open the input file!!\n");
  7573. fptr1 = fopen(filename, "w+");
  7574. }
  7575. fclose(fptr1);
  7576. }
  7577. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7578. {
  7579. //printf("set chargingProfile 1-3\n");
  7580. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7581. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7582. {
  7583. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7584. goto end;
  7585. }
  7586. switch(connectorIdInt)
  7587. {
  7588. case 0:
  7589. strcpy(filename, TxDefaultProfile_0_JSON );
  7590. break;
  7591. case 1:
  7592. strcpy(filename, TxDefaultProfile_1_JSON );
  7593. break;
  7594. case 2:
  7595. strcpy(filename, TxDefaultProfile_2_JSON );
  7596. break;
  7597. default:
  7598. strcpy(filename, TxDefaultProfile_0_JSON );
  7599. break;
  7600. }
  7601. fptr1 = fopen(filename, "r");
  7602. if (!fptr1)
  7603. {
  7604. //file not exist
  7605. DEBUG_INFO("Unable to open the input file!!\n");
  7606. fptr1 = fopen(filename, "w+");
  7607. }
  7608. fclose(fptr1);
  7609. }
  7610. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7611. {
  7612. //printf("set chargingProfile 1-4\n");
  7613. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7614. //check Transaction active
  7615. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7616. {
  7617. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7618. {
  7619. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7620. {
  7621. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7622. {
  7623. meet = TRUE;
  7624. break;
  7625. }
  7626. }
  7627. }
  7628. }
  7629. for (int index = 0; index < CCS_QUANTITY; index++)
  7630. {
  7631. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7632. {
  7633. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7634. {
  7635. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7636. {
  7637. meet = TRUE;
  7638. break;
  7639. }
  7640. }
  7641. }
  7642. }
  7643. for (int index = 0; index < GB_QUANTITY; index++)
  7644. {
  7645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7646. {
  7647. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7648. {
  7649. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7650. {
  7651. meet = TRUE;
  7652. break;
  7653. }
  7654. }
  7655. }
  7656. }
  7657. if(meet == FALSE)
  7658. {
  7659. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7660. goto end;
  7661. }
  7662. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7663. {
  7664. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7665. goto end;
  7666. }
  7667. switch(connectorIdInt)
  7668. {
  7669. case 0:
  7670. break;
  7671. case 1:
  7672. strcpy(filename, TxProfile_1_JSON);
  7673. break;
  7674. case 2:
  7675. strcpy(filename, TxProfile_2_JSON);
  7676. break;
  7677. default:
  7678. strcpy(filename, TxProfile_1_JSON);
  7679. break;
  7680. }
  7681. fptr1 = fopen(filename, "r");
  7682. if (!fptr1)
  7683. {
  7684. //file not exist
  7685. DEBUG_INFO("Unable to open the input file!!\n");
  7686. fptr1 = fopen(filename, "w+");
  7687. }
  7688. fclose(fptr1);
  7689. }
  7690. //**********************************Write to File********************************************************/
  7691. FILE *infile;
  7692. FILE *outfile;
  7693. // open file for writing
  7694. infile = fopen (filename, "r");
  7695. outfile = fopen (tempfile, "w");
  7696. int d =0;
  7697. d = fgetc(infile);
  7698. DEBUG_INFO("d:%d\n",d);
  7699. rewind(infile);
  7700. //*检测到文件结束标识返回1,否则返回0。*/
  7701. if(d == EOF)
  7702. {
  7703. DEBUG_INFO("ChargingProfile content is NULL\n");
  7704. fprintf(outfile,"[%s]\n",payload);
  7705. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7706. fclose(infile);
  7707. fclose(outfile);
  7708. sprintf(rmFileCmd,"rm -f %s",filename);
  7709. system(rmFileCmd);
  7710. resultRename = rename(tempfile, filename);
  7711. if(resultRename == 0)
  7712. {
  7713. DEBUG_INFO("File chargingProfile renamed successfully");
  7714. }
  7715. else
  7716. {
  7717. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7718. }
  7719. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7720. //system(rmFileCmd);
  7721. }
  7722. else
  7723. {
  7724. char buf[1000]={0};
  7725. while (fgets(buf, sizeof(buf), infile) != NULL)
  7726. {
  7727. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7728. //*************************tempconnectorIdInt*********************************/
  7729. loc = strstr(buf, "connectorId");
  7730. c = 0;
  7731. memset(sstr ,0, sizeof(sstr) );
  7732. while (loc[strlen("connectorId")+2+c] != ',')
  7733. {
  7734. sstr[c] = loc[strlen("connectorId")+2+c];
  7735. c++;
  7736. }
  7737. sstr[c] = '\0';
  7738. tempconnectorIdInt = atoi(sstr);
  7739. //*************************tempchargingProfileIdInt*********************************/
  7740. loc = strstr(buf, "chargingProfileId");
  7741. c = 0;
  7742. memset(sstr ,0, sizeof(sstr) );
  7743. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7744. {
  7745. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7746. c++;
  7747. }
  7748. sstr[c] = '\0';
  7749. tempchargingProfileIdInt = atoi(sstr);
  7750. //*************************tempstackLevelInt*********************************/
  7751. loc = strstr(buf, "stackLevel");
  7752. c = 0;
  7753. memset(sstr ,0, sizeof(sstr) );
  7754. while (loc[strlen("stackLevel")+2+c] != ',')
  7755. {
  7756. sstr[c] = loc[strlen("stackLevel")+2+c];
  7757. c++;
  7758. }
  7759. sstr[c] = '\0';
  7760. tempstackLevelInt = atoi(sstr);
  7761. //*************************tempchargingProfilePurposeStr*********************************/
  7762. loc = strstr(payload, "chargingProfilePurpose");
  7763. c = 0;
  7764. memset(sstr ,0, sizeof(sstr) );
  7765. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7766. {
  7767. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7768. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7769. c++;
  7770. }
  7771. sstr[c] = '\0';
  7772. strcpy(tempchargingProfilePurposeStr,sstr);
  7773. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7774. {
  7775. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7776. {
  7777. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7778. fprintf(outfile,"[%s]\n",payload);
  7779. }
  7780. else
  7781. {
  7782. //DEBUG_INFO("update set chargingProfile to file -1\n");
  7783. if(tempstackLevelInt < stackLevelInt)
  7784. {
  7785. //DEBUG_INFO("update set chargingProfile to file -2\n");
  7786. fprintf(outfile,"[%s]\n",payload);
  7787. fprintf(outfile,"[%s]\n",buf);
  7788. }
  7789. else
  7790. {
  7791. fprintf(outfile,"[%s]\n",buf);
  7792. fprintf(outfile,"[%s]\n",payload);
  7793. }
  7794. }
  7795. DEBUG_INFO("update set chargingProfile to file\n");
  7796. }
  7797. else
  7798. {
  7799. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7800. {
  7801. fprintf(outfile,"[%s]\n",payload);
  7802. fprintf(outfile,"[%s]\n",buf);
  7803. }
  7804. else if(tempstackLevelInt < stackLevelInt)
  7805. {
  7806. fprintf(outfile,"[%s]\n",payload);
  7807. fprintf(outfile,"[%s]\n",buf);
  7808. }
  7809. else
  7810. {
  7811. fprintf(outfile,"[%s]\n",buf);
  7812. fprintf(outfile,"[%s]\n",payload);
  7813. }
  7814. fprintf(outfile,"[%s]\n",buf);
  7815. DEBUG_INFO("add set chargingProfile to file\n");
  7816. }
  7817. } // end of while loop
  7818. fclose(infile);
  7819. fclose(outfile);
  7820. sprintf(rmFileCmd,"rm -f %s",filename);
  7821. system(rmFileCmd);
  7822. resultRename = rename(tempfile, filename);
  7823. if(resultRename == 0)
  7824. {
  7825. DEBUG_INFO("File chargingProfile renamed successfully");
  7826. }
  7827. else
  7828. {
  7829. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7830. }
  7831. result = TRUE;
  7832. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7833. }
  7834. end:
  7835. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7836. return result;
  7837. return result;
  7838. }
  7839. int handleTriggerMessageRequest(char *uuid, char *payload)
  7840. {
  7841. mtrace();
  7842. int result = FAIL;
  7843. int connectorIdIsNULL = FALSE;
  7844. int connectorIdInt =0;
  7845. char sstr[40]={0};
  7846. char requestedMessagestr[40]={0};
  7847. char comfirmstr[20]={0};
  7848. int c = 0;
  7849. char *loc;
  7850. DEBUG_INFO("handleTriggerMessageRequest\n");
  7851. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7852. c = 0;
  7853. loc = strstr(payload, "requestedMessage");
  7854. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7855. {
  7856. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7857. c++;
  7858. }
  7859. sstr[c] = '\0';
  7860. strcpy(requestedMessagestr, sstr);
  7861. c = 0;
  7862. loc = strstr(payload, "connectorId");
  7863. if(loc == NULL)
  7864. {
  7865. connectorIdIsNULL = TRUE;
  7866. }
  7867. else
  7868. {
  7869. memset(sstr ,0, sizeof(sstr) );
  7870. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7871. {
  7872. sstr[c] = loc[strlen("connectorId")+2+c];
  7873. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7874. c++;
  7875. }
  7876. sstr[c] = '\0';
  7877. connectorIdInt = atoi(sstr);
  7878. }
  7879. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7880. {
  7881. //connectorIdInt = json_object_get_int(connectorId);
  7882. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7883. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7884. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7885. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7886. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7887. }
  7888. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7889. {
  7890. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7891. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7892. return TRUE;
  7893. }
  7894. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7895. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7896. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7897. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7898. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7899. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7900. {
  7901. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7902. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7903. return TRUE;
  7904. }
  7905. else
  7906. {
  7907. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7908. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7909. }
  7910. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7911. {
  7912. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7913. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7914. }
  7915. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7916. {
  7917. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7918. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7919. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7920. }
  7921. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7922. {
  7923. sendBootNotificationRequest();
  7924. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7925. }
  7926. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7927. {
  7928. sendHeartbeatRequest(connectorIdInt);
  7929. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7930. }
  7931. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7932. {
  7933. if(connectorIdIsNULL == FALSE)
  7934. {
  7935. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7936. {
  7937. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7938. sendMeterValuesRequest(connectorIdInt -1);
  7939. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7940. }
  7941. }
  7942. else
  7943. {
  7944. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7945. {
  7946. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  7947. sendMeterValuesRequest(idx);
  7948. }
  7949. }
  7950. }
  7951. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  7952. {
  7953. if(connectorIdIsNULL == FALSE)
  7954. {
  7955. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7956. {
  7957. sendStatusNotificationRequest(connectorIdInt -1);
  7958. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7959. }
  7960. }
  7961. else
  7962. {
  7963. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7964. sendStatusNotificationRequest(idx);
  7965. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7966. }
  7967. }
  7968. return result;
  7969. }
  7970. int handleUnlockConnectorRequest(char *uuid, char *payload)
  7971. {
  7972. mtrace();
  7973. int result = FAIL;
  7974. char sstr[6]={0};
  7975. int connectorIdInt =0;
  7976. char comfirmstr[20]={0};
  7977. int c = 0;
  7978. char *loc;
  7979. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  7980. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  7981. c = 0;
  7982. loc = strstr(payload, "connectorId");
  7983. memset(sstr ,0, sizeof(sstr) );
  7984. while (loc[strlen("connectorId")+2+c] != '}')
  7985. {
  7986. sstr[c] = loc[strlen("connectorId")+2+c];
  7987. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7988. c++;
  7989. }
  7990. sstr[c] = '\0';
  7991. connectorIdInt = atoi(sstr);
  7992. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  7993. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  7994. {
  7995. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  7996. goto end;
  7997. }
  7998. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  7999. {
  8000. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8001. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8002. goto end;
  8003. }
  8004. else
  8005. {
  8006. //check Transaction active
  8007. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8008. {
  8009. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8010. {
  8011. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8012. {
  8013. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8014. }
  8015. }
  8016. for (int index = 0; index < CCS_QUANTITY; index++)
  8017. {
  8018. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8019. {
  8020. //stop Transaction
  8021. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8022. }
  8023. }
  8024. for (int index = 0; index < GB_QUANTITY; index++)
  8025. {
  8026. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8027. {
  8028. //stop Transaction
  8029. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8030. }
  8031. }
  8032. }
  8033. else
  8034. {
  8035. for (int index = 0; index < AC_QUANTITY; index++)
  8036. {
  8037. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8038. {
  8039. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8040. }
  8041. }
  8042. }// END FOR AC ELSE
  8043. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8044. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8045. result = TRUE;
  8046. return result;
  8047. }
  8048. end:
  8049. //json_object_put(obj); --- remove temporally
  8050. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8051. return result;
  8052. }
  8053. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8054. {
  8055. mtrace();
  8056. int result = FAIL;
  8057. pthread_t t;
  8058. sendUpdateFirmwareConfirmation(uuid);
  8059. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8060. ////pthread_join(t, NULL); //
  8061. pthread_detach(t);
  8062. //sendUpdateFirmwareConfirmation(uuid);
  8063. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8064. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8065. return result;
  8066. }
  8067. void *UpdateFirmwareProcess(void *data)
  8068. {
  8069. mtrace();
  8070. int retriesInt =0, retryIntervalInt=0;
  8071. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8072. int port=0;
  8073. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8074. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8075. //char comfirmstr[20];
  8076. int isSuccess = 0;
  8077. char ftpbuf[200];
  8078. char temp[100];
  8079. char * pch;
  8080. int retriesISNULL=FALSE;
  8081. int retryInterval=FALSE;
  8082. int c = 0;
  8083. //int i = 0;
  8084. char *loc;
  8085. char sstr[300]={ 0 };
  8086. char *str = (char*) data; // ?��?輸入資�?
  8087. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8088. //***************location **************/
  8089. loc = strstr(str, "location");
  8090. memset(sstr ,0, sizeof(sstr) );
  8091. c = 0;
  8092. while (loc[3+strlen("location")+c] != '\"')
  8093. {
  8094. sstr[c] = loc[3+strlen("location")+c];
  8095. c++;
  8096. }
  8097. sstr[c] = '\0';
  8098. strcpy(locationstr, sstr);
  8099. //***************retries**************/
  8100. c = 0;
  8101. loc = strstr(str, "retries");
  8102. if(loc == NULL)
  8103. {
  8104. retriesISNULL=TRUE;
  8105. }
  8106. else
  8107. {
  8108. memset(sstr ,0, sizeof(sstr) );
  8109. while (loc[strlen("retries")+2+c] != ',')
  8110. {
  8111. sstr[c] = loc[strlen("retries")+2+c];
  8112. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8113. c++;
  8114. }
  8115. sstr[c] = '\0';
  8116. }
  8117. if(retriesISNULL == FALSE)
  8118. {
  8119. retriesInt = atoi(sstr);
  8120. }
  8121. //***************retrieveDate **************/
  8122. loc = strstr(str, "retrieveDate");
  8123. memset(sstr ,0, sizeof(sstr) );
  8124. c = 0;
  8125. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8126. {
  8127. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8128. c++;
  8129. }
  8130. sstr[c] = '\0';
  8131. strcpy(retrieveDatestr, sstr);
  8132. //***************retryInterval **************/
  8133. c = 0;
  8134. loc = strstr(str, "retryInterval");
  8135. memset(sstr ,0, sizeof(sstr) );
  8136. if(loc == NULL)
  8137. {
  8138. retryInterval=TRUE;
  8139. }
  8140. else
  8141. {
  8142. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8143. {
  8144. sstr[c] = loc[strlen("retryInterval")+2+c];
  8145. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8146. c++;
  8147. }
  8148. sstr[c] = '\0';
  8149. }
  8150. if(retryInterval==FALSE)
  8151. {
  8152. retryIntervalInt = atoi(sstr);
  8153. }
  8154. memset(ftppath, 0, sizeof(ftppath));
  8155. memset(path, 0, sizeof(path));
  8156. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8157. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8158. if(strncmp(locationstr,"http", 4) == 0)
  8159. {
  8160. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8161. protocol, host, path);
  8162. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8163. // protocol, user, password, host, path);
  8164. sprintf(ftppath,"/%s", path);
  8165. DEBUG_INFO("protocol =%s\n",protocol);
  8166. DEBUG_INFO("host =%s\n",host);
  8167. DEBUG_INFO("path =%s\n",path);
  8168. DEBUG_INFO("ftppath=%s\n",ftppath);
  8169. int ftppathlen=strlen(ftppath);
  8170. int i=1;
  8171. char filenametemp[50];
  8172. while(i < ftppathlen)
  8173. {
  8174. int len=ftppathlen-i;
  8175. if(ftppath[len]== 47) // '/' ascll code: 47
  8176. {
  8177. DEBUG_INFO("compare '/' all right\n");
  8178. break;
  8179. }
  8180. i=i+1;
  8181. }
  8182. memset(filenametemp, 0, sizeof(filenametemp));
  8183. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8184. filenametemp[i+1] = 0;
  8185. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8186. do{
  8187. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8188. sleep(retryIntervalInt);
  8189. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8190. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8191. if(!isSuccess)
  8192. {
  8193. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8194. }
  8195. else
  8196. {
  8197. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8198. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8199. isUpdateRequest = TRUE;
  8200. }
  8201. }
  8202. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8203. {
  8204. memset(ftpbuf, 0, sizeof(ftpbuf));
  8205. memset(temp, 0, sizeof(temp));
  8206. DEBUG_INFO("locationstr=%s\n",locationstr);
  8207. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8208. int ftppathlen=strlen(ftpbuf);
  8209. int i=1;
  8210. char filenametemp[50];
  8211. while(i < ftppathlen)
  8212. {
  8213. int len=ftppathlen-i;
  8214. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8215. {
  8216. DEBUG_INFO(" compare '/' all right\n");
  8217. break;
  8218. }
  8219. i=i+1;
  8220. }
  8221. memset(filenametemp, 0, sizeof(filenametemp));
  8222. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8223. filenametemp[i+1] = 0;
  8224. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8225. pch=strchr(temp,'@');
  8226. if(pch==NULL)
  8227. {
  8228. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8229. protocol, host, &port, path);
  8230. strcpy(user,"anonymous");
  8231. strcpy(password,"");
  8232. }
  8233. else
  8234. {
  8235. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8236. protocol, user, password, host, &port, path);
  8237. }
  8238. sscanf(host,"%[^/]%s",host1, path1);
  8239. sprintf(ftppath,"%s", path1);
  8240. DEBUG_INFO("protocol =%s\n",protocol);
  8241. DEBUG_INFO("user =%s\n",user);
  8242. DEBUG_INFO("password =%s\n",password);
  8243. DEBUG_INFO("host1 =%s\n",host1);
  8244. DEBUG_INFO("port =%d\n",port);
  8245. DEBUG_INFO("path1 =%s\n",path1);
  8246. DEBUG_INFO("ftppath=%s\n",ftppath);
  8247. //ftpFile(host, user, password, port, ftppath, fname);
  8248. //download firmware pthred
  8249. if(port == 0)
  8250. {
  8251. port = 21;
  8252. }
  8253. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8254. do{
  8255. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8256. sleep(retryIntervalInt);
  8257. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8258. if(!isSuccess)
  8259. {
  8260. //BulldogUtil.sleepMs(interval*1000);
  8261. DEBUG_INFO("Update firmware request and download file fail.\n");
  8262. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8263. }
  8264. else
  8265. {
  8266. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8267. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8268. isUpdateRequest = TRUE;
  8269. }
  8270. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8271. }
  8272. else
  8273. {
  8274. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8275. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8276. }
  8277. pthread_exit(NULL);
  8278. }
  8279. //==========================================
  8280. // Handle server response routine
  8281. //==========================================
  8282. void handleAuthorizeResponse(char *payload, int gun_index)
  8283. {
  8284. mtrace();
  8285. char expiryDatestr[30]={0};
  8286. char parentIdTagstr[20]={0};
  8287. char statusstr[20]={0};
  8288. char expiryDatestrtemp[30]={0};
  8289. char parentIdTagstrtemp[20]={0};
  8290. char IdTagstrtemp[20]={0};
  8291. char statusstrtemp[20]={0};
  8292. int expiryDateISNULL=FALSE;
  8293. int parentIdTagISNULL=FALSE;
  8294. char sstr[160]={ 0 };
  8295. char* filename = AuthorizationCache_JSON;
  8296. char tempfile[] = "../Storage/OCPP/temp.json";
  8297. int c = 0;
  8298. char *loc;
  8299. int resultRename=0;
  8300. int responseIdTagInfoAsZero= 0;
  8301. char rmFileCmd[50]={0};
  8302. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8303. //***********expiryDate*************/
  8304. loc = strstr(payload, "expiryDate");
  8305. memset(sstr ,0, sizeof(sstr) );
  8306. c = 0;
  8307. if(loc == NULL)
  8308. {
  8309. expiryDateISNULL = TRUE;
  8310. }
  8311. else
  8312. {
  8313. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8314. {
  8315. sstr[c] = loc[3+strlen("expiryDate")+c];
  8316. c++;
  8317. }
  8318. sstr[c] = '\0';
  8319. strcpy(expiryDatestr, sstr);
  8320. }
  8321. //***********parentIdTag*************/
  8322. loc = strstr(payload, "parentIdTag");
  8323. memset(sstr ,0, sizeof(sstr) );
  8324. c = 0;
  8325. if(loc == NULL)
  8326. {
  8327. parentIdTagISNULL = TRUE;
  8328. }
  8329. else
  8330. {
  8331. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8332. {
  8333. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8334. c++;
  8335. }
  8336. sstr[c] = '\0';
  8337. strcpy(parentIdTagstr, sstr);
  8338. }
  8339. //***********status*************/
  8340. loc = strstr(payload, "status");
  8341. memset(sstr ,0, sizeof(sstr) );
  8342. c = 0;
  8343. while (loc[3+strlen("status")+c] != '\"')
  8344. {
  8345. sstr[c] = loc[3+strlen("status")+c];
  8346. c++;
  8347. }
  8348. sstr[c] = '\0';
  8349. strcpy(statusstr, sstr);
  8350. //#ifdef SystemLogMessage
  8351. // if(expiryDateISNULL == FALSE)
  8352. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8353. // if(parentIdTagISNULL == FALSE)
  8354. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8355. // DEBUG_INFO("status: %s\n", statusstr);
  8356. //#endif
  8357. if(expiryDateISNULL == FALSE)
  8358. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8359. if(parentIdTagISNULL == FALSE)
  8360. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8361. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8362. //Update idTag information to authorization cache if supproted
  8363. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8364. {
  8365. if((access(filename,F_OK))!=-1)
  8366. {
  8367. DEBUG_INFO("AuthorizationCache exist.\n");
  8368. }
  8369. else
  8370. {
  8371. DEBUG_INFO("AuthorizationCache not exist\n");
  8372. FILE *log = fopen(filename, "w+");
  8373. if(log == NULL)
  8374. {
  8375. DEBUG_INFO("log is NULL\n");
  8376. goto out;
  8377. }
  8378. else
  8379. {
  8380. fclose(log);
  8381. }
  8382. }
  8383. FILE *infile;
  8384. FILE *outfile;
  8385. // open file for writing
  8386. infile = fopen (filename, "r");
  8387. outfile = fopen (tempfile, "w");
  8388. //*检测到文件结束标识返回1,否则返回0。*/
  8389. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8390. int c;
  8391. c = fgetc(infile);
  8392. //DEBUG_INFO("c:%d\n",c);
  8393. rewind(infile);
  8394. if(c == EOF)
  8395. {
  8396. DEBUG_INFO("Orignal File is NULL\n");
  8397. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8398. {
  8399. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8400. }
  8401. else
  8402. {
  8403. strcpy(expiryDatestrtemp, "");
  8404. }
  8405. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8406. {
  8407. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8408. }
  8409. else
  8410. {
  8411. //write Authorize IdTag
  8412. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8413. }
  8414. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8415. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8416. fclose(infile);
  8417. fclose(outfile);
  8418. sprintf(rmFileCmd,"rm -f %s",filename);
  8419. system(rmFileCmd);
  8420. resultRename = rename(tempfile, filename);
  8421. if(resultRename == 0)
  8422. {
  8423. DEBUG_INFO("File renamed successfully");
  8424. }
  8425. else
  8426. {
  8427. DEBUG_INFO("Error: unable to rename the file");
  8428. }
  8429. }
  8430. else
  8431. {
  8432. char buf[160]={0};
  8433. //DEBUG_INFO("Orignal File is not NULL\n");
  8434. while (fgets(buf, sizeof(buf), infile) != NULL)
  8435. {
  8436. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8437. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8438. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8439. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8440. memset(statusstr, 0, sizeof(statusstrtemp));
  8441. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8442. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8443. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8444. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8445. //------------------IdTag-----------------------
  8446. loc = strstr(buf, "idTag");
  8447. memset(sstr ,0, sizeof(sstr) );
  8448. c = 0;
  8449. while (loc[3+strlen("idTag")+c] != '\"')
  8450. {
  8451. sstr[c] = loc[3+strlen("idTag")+c];
  8452. c++;
  8453. }
  8454. sstr[c] = '\0';
  8455. strcpy(IdTagstrtemp,sstr);
  8456. //*********************expiryDate***************/
  8457. loc = strstr(buf, "expiryDate");
  8458. memset(sstr ,0, sizeof(sstr) );
  8459. c = 0;
  8460. while (loc[3+strlen("expiryDate")+c] != '\"')
  8461. {
  8462. sstr[c] = loc[3+strlen("expiryDate")+c];
  8463. c++;
  8464. }
  8465. sstr[c] = '\0';
  8466. strcpy(expiryDatestr,sstr);
  8467. //*********************parentIdTag***************/
  8468. loc = strstr(buf, "parentIdTag");
  8469. memset(sstr ,0, sizeof(sstr) );
  8470. c = 0;
  8471. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8472. {
  8473. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8474. c++;
  8475. }
  8476. sstr[c] = '\0';
  8477. strcpy(parentIdTagstr,sstr);
  8478. //*********************status***************/
  8479. loc = strstr(buf, "status");
  8480. memset(sstr ,0, sizeof(sstr) );
  8481. c = 0;
  8482. while (loc[3+strlen("status")+c] != '\"')
  8483. {
  8484. sstr[c] = loc[3+strlen("status")+c];
  8485. c++;
  8486. }
  8487. sstr[c] = '\0';
  8488. strcpy(statusstr,sstr);
  8489. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8490. {
  8491. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8492. responseIdTagInfoAsZero = 1;
  8493. }
  8494. else
  8495. {
  8496. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8497. }
  8498. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8499. {
  8500. //modify item
  8501. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8502. {
  8503. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8504. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8505. }
  8506. else
  8507. {
  8508. strcpy(expiryDatestrtemp, "");
  8509. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8510. }
  8511. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8512. {
  8513. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8514. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8515. }
  8516. else
  8517. {
  8518. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8519. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8520. }
  8521. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8522. }
  8523. else
  8524. {
  8525. //wrie original item
  8526. strcpy(expiryDatestrtemp, expiryDatestr);
  8527. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8528. strcpy(statusstrtemp, statusstr);
  8529. }
  8530. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8531. }
  8532. fclose(infile);
  8533. fclose(outfile);
  8534. sprintf(rmFileCmd,"rm -f %s",filename);
  8535. system(rmFileCmd);
  8536. resultRename = rename(tempfile, filename);
  8537. if(resultRename == 0)
  8538. {
  8539. DEBUG_INFO("File renamed successfully");
  8540. }
  8541. else
  8542. {
  8543. DEBUG_INFO("Error: unable to rename the file");
  8544. }
  8545. }
  8546. }
  8547. out:
  8548. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8549. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8550. authorizeRetryTimes = 0;
  8551. }
  8552. void handleBootNotificationResponse(char *payload, int gun_index)
  8553. {
  8554. mtrace();
  8555. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8556. char statusStr[12]={0};
  8557. char currentTimeStr[30]={0};
  8558. char *loc;
  8559. int intervalInt = 0;
  8560. int c = 0;
  8561. //double diff_t;
  8562. struct tm tp;
  8563. char buf[28]={0};
  8564. char timebuf[50]={0};
  8565. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8566. //*** interval ****/
  8567. c = 0;
  8568. loc = strstr(payload, "interval");
  8569. //printf("loc=%s\n",loc);
  8570. memset(sstr ,0, sizeof(sstr) );
  8571. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8572. {
  8573. sstr[c] = loc[strlen("interval")+2+c];
  8574. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8575. c++;
  8576. }
  8577. sstr[c] = '\0';
  8578. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8579. intervalInt = atoi(sstr);
  8580. //***status ****/
  8581. loc = strstr(payload, "status");
  8582. memset(sstr ,0, sizeof(sstr) );
  8583. c = 0;
  8584. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8585. {
  8586. sstr[c] = loc[3+strlen("status")+c];
  8587. c++;
  8588. }
  8589. sstr[c] = '\0';
  8590. strcpy(statusStr, sstr);
  8591. //***currentTime ****/
  8592. loc = strstr(payload, "currentTime");
  8593. //printf("loc=%s\n",loc);
  8594. memset(sstr ,0, sizeof(sstr) );
  8595. c = 0;
  8596. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8597. {
  8598. sstr[c] = loc[3+strlen("currentTime")+c];
  8599. c++;
  8600. }
  8601. sstr[c] = '\0';
  8602. strcpy(currentTimeStr, sstr);
  8603. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8604. HeartBeatWaitTime = BootNotificationInterval;
  8605. //#ifdef SystemLogMessage
  8606. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8607. // DEBUG_INFO("interval: %d\n", intervalInt);
  8608. // DEBUG_INFO("status: %s\n", statusStr);
  8609. //#endif
  8610. //write back to ShmOCPP16Data->BootNotification
  8611. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8612. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8613. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8614. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8615. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8616. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8617. {
  8618. server_sign = TRUE;
  8619. server_pending =FALSE;
  8620. }
  8621. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8622. {
  8623. server_pending = TRUE;
  8624. }
  8625. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8626. tp.tm_isdst = -1;
  8627. //time_t utc = mktime(&tp);
  8628. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8629. memset(timebuf, 0, sizeof timebuf);
  8630. sprintf(timebuf,"date -s '%s'",buf);
  8631. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8632. system(timebuf);
  8633. //==============================================
  8634. // RTC sync
  8635. //==============================================
  8636. system("/sbin/hwclock -w --systohc");
  8637. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8638. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8639. }
  8640. void handleDataTransferResponse(char *payload, int gun_index)
  8641. {
  8642. char sstr[160]={0};//sstr[200]={ 0 };
  8643. int c = 0;
  8644. char *loc;
  8645. DEBUG_INFO("handleDataTransferResponse ...\n");
  8646. loc = strstr(payload, "status");
  8647. printf("loc=%s\n",loc);
  8648. c = 0;
  8649. while (loc[3+strlen("status")+c] != '\"')
  8650. {
  8651. sstr[c] = loc[3+strlen("status")+c];
  8652. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8653. c++;
  8654. }
  8655. sstr[c] = '\0';
  8656. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8657. //#ifdef SystemLogMessage
  8658. //DEBUG_INFO("data: %s\n", payload);
  8659. //#endif
  8660. }
  8661. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8662. {
  8663. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8664. //struct json_object *obj;
  8665. // obj = json_tokener_parse(payload);
  8666. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8667. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8668. //No fields are defined.
  8669. }
  8670. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8671. {
  8672. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8673. //struct json_object *obj;
  8674. // obj = json_tokener_parse(payload);
  8675. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8676. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8677. //No fields are defined.
  8678. }
  8679. void handleHeartbeatResponse(char *payload, int gun_index)
  8680. {
  8681. mtrace();
  8682. //double diff_t;
  8683. struct tm tp;
  8684. char buf[28]={0};
  8685. char timebuf[50]={0};
  8686. char sstr[30]={ 0 };
  8687. int c = 0;
  8688. char *loc;
  8689. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8690. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8691. c = 0;
  8692. loc = strstr(payload, "currentTime");
  8693. memset(sstr ,0, sizeof(sstr) );
  8694. while (loc[3+strlen("currentTime")+c] != '\"')
  8695. {
  8696. sstr[c] = loc[3+strlen("currentTime")+c];
  8697. c++;
  8698. }
  8699. sstr[c] = '\0';
  8700. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8701. // #ifdef SystemLogMessage
  8702. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8703. // #endif
  8704. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8705. tp.tm_isdst = -1;
  8706. //time_t utc = mktime(&tp);
  8707. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8708. memset(timebuf, 0, sizeof timebuf);
  8709. sprintf(timebuf,"date -s '%s'",buf);
  8710. system(timebuf);
  8711. //==============================================
  8712. // RTC sync
  8713. //==============================================
  8714. system("/sbin/hwclock -w --systohc");
  8715. if(FirstHeartBeat == 0)
  8716. {
  8717. FirstHeartBeat = 1;
  8718. }
  8719. HeartBeatWithNOResponse = 0;
  8720. }
  8721. void handleMeterValuesResponse(char *payload, int gun_index)
  8722. {
  8723. mtrace();
  8724. //struct json_object *obj;
  8725. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8726. //No fields are defined.
  8727. }
  8728. void handleStartTransactionResponse(char *payload, int gun_index)
  8729. {
  8730. mtrace();
  8731. char sstr[30]={ 0 };
  8732. int c = 0;
  8733. char *loc;
  8734. int transactionIdInt = 0;
  8735. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8736. DEBUG_INFO("handleStartTransactionResponse\n");
  8737. //****************expiryDate********************/
  8738. loc = strstr(payload, "expiryDate");
  8739. if(loc == NULL)
  8740. {
  8741. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8742. }
  8743. else
  8744. {
  8745. c = 0;
  8746. memset(sstr ,0, sizeof(sstr) );
  8747. while (loc[3+strlen("expiryDate")+c] != '\"')
  8748. {
  8749. sstr[c] = loc[3+strlen("expiryDate")+c];
  8750. c++;
  8751. }
  8752. sstr[c] = '\0';
  8753. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8754. }
  8755. //****************parentIdTag********************/
  8756. loc = strstr(payload, "parentIdTag");
  8757. if(loc == NULL)
  8758. {
  8759. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8760. }
  8761. else
  8762. {
  8763. c = 0;
  8764. memset(sstr ,0, sizeof(sstr) );
  8765. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8766. {
  8767. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8768. c++;
  8769. }
  8770. sstr[c] = '\0';
  8771. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8772. }
  8773. //****************status********************/
  8774. loc = strstr(payload, "status");
  8775. if(loc == NULL)
  8776. {
  8777. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8778. }
  8779. else
  8780. {
  8781. c = 0;
  8782. memset(sstr ,0, sizeof(sstr) );
  8783. while (loc[3+strlen("status")+c] != '\"')
  8784. {
  8785. sstr[c] = loc[3+strlen("status")+c];
  8786. c++;
  8787. }
  8788. sstr[c] = '\0';
  8789. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8790. }
  8791. //****************transactionId********************/
  8792. c=0;
  8793. loc = strstr(payload, "transactionId");
  8794. memset(sstr ,0, sizeof(sstr) );
  8795. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8796. {
  8797. sstr[c] = loc[strlen("transactionId")+2+c];
  8798. c++;
  8799. }
  8800. sstr[c] = '\0';
  8801. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8802. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8803. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8804. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8805. #ifdef SystemLogMessage
  8806. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8807. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8808. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8809. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8810. #endif
  8811. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8812. {
  8813. //add Charging Record
  8814. SettingChargingRecord(gun_index, transactionIdInt);
  8815. }
  8816. }
  8817. void handleStatusNotificationResponse(char *payload, int gun_index)
  8818. {
  8819. mtrace();
  8820. printf("handleStatusNotificationResponse\n");
  8821. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8822. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8823. }
  8824. void handleStopTransactionnResponse(char *payload, int gun_index)
  8825. {
  8826. mtrace();
  8827. char sstr[30]={ 0 };
  8828. int c = 0;
  8829. char *loc;
  8830. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8831. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8832. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8833. loc = strstr(payload, "idTagInfo");
  8834. //***********************idTagInfo************************/
  8835. if(loc != NULL)
  8836. {
  8837. //***********************expiryDate************************/
  8838. loc = strstr(payload, "expiryDate");
  8839. if(loc != NULL)
  8840. {
  8841. memset(sstr ,0, sizeof(sstr) );
  8842. c = 0;
  8843. while (loc[3+strlen("expiryDate")+c] != '\"')
  8844. {
  8845. sstr[c] = loc[3+strlen("expiryDate")+c];
  8846. c++;
  8847. }
  8848. sstr[c] = '\0';
  8849. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8850. }
  8851. //***********************parentIdTag************************/
  8852. loc = strstr(payload, "parentIdTag");
  8853. if(loc != NULL)
  8854. {
  8855. memset(sstr ,0, sizeof(sstr) );
  8856. c = 0;
  8857. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8858. {
  8859. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8860. c++;
  8861. }
  8862. sstr[c] = '\0';
  8863. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8864. }
  8865. //***********************status************************/
  8866. loc = strstr(payload, "status");
  8867. memset(sstr ,0, sizeof(sstr) );
  8868. c = 0;
  8869. while (loc[3+strlen("status")+c] != '\"')
  8870. {
  8871. sstr[c] = loc[3+strlen("status")+c];
  8872. c++;
  8873. }
  8874. sstr[c] = '\0';
  8875. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8876. }
  8877. #ifdef SystemLogMessage
  8878. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8879. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8880. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8881. #endif
  8882. }
  8883. //==========================================
  8884. // Handle Error routine
  8885. //==========================================
  8886. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8887. {
  8888. mtrace();
  8889. #ifdef SystemLogMessage
  8890. DEBUG_INFO("errorCode: %s\n", errorCode);
  8891. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8892. DEBUG_INFO("errorDetails: %s\n", payload);
  8893. #endif
  8894. }
  8895. //===============================================
  8896. // Common routine
  8897. //===============================================
  8898. int initialConfigurationTable(void)
  8899. {
  8900. printf("initialConfigurationTable \n");
  8901. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8902. /*Core Profile*/
  8903. //AllowOfflineTxForUnknownId
  8904. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8905. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8908. //AuthorizationCacheEnabled
  8909. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8912. //AuthorizeRemoteTxRequests
  8913. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8916. //BlinkRepeat
  8917. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8920. //ClockAlignedDataInterval
  8921. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8924. //ConnectionTimeOut
  8925. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8928. //GetConfigurationMaxKeys
  8929. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  8932. // HeartbeatInterval
  8933. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  8934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  8935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  8936. // LightIntensity
  8937. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  8938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  8939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  8940. // LocalAuthorizeOffline
  8941. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  8942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  8943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  8944. // LocalPreAuthorize
  8945. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  8946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  8947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  8948. // MaxEnergyOnInvalidId
  8949. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  8950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  8951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  8952. // MeterValuesAlignedData
  8953. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  8954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  8955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  8956. // MeterValuesAlignedDataMaxLength
  8957. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  8958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  8959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  8960. // MeterValuesSampledData
  8961. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  8962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  8963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  8964. // MeterValuesSampledDataMaxLength
  8965. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  8966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  8967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  8968. // MeterValueSampleInterval
  8969. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  8970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  8971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  8972. // MinimumStatusDuration
  8973. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  8974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  8975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  8976. // NumberOfConnectors
  8977. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  8978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  8979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  8980. // ResetRetries
  8981. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  8982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  8983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  8984. // ConnectorPhaseRotation
  8985. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  8986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  8987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  8988. // ConnectorPhaseRotationMaxLength
  8989. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  8990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  8991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  8992. // StopTransactionOnEVSideDisconnect
  8993. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  8994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  8995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  8996. // StopTransactionOnInvalidId
  8997. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  8998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  8999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9000. // StopTxnAlignedData
  9001. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9004. // StopTxnAlignedDataMaxLength
  9005. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9008. // StopTxnSampledData
  9009. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9012. // StopTxnSampledDataMaxLength
  9013. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9016. // SupportedFeatureProfiles
  9017. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9020. // SupportedFeatureProfilesMaxLength
  9021. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9024. // TransactionMessageAttempts
  9025. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9028. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9029. // TransactionMessageRetryInterval
  9030. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9033. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9034. // UnlockConnectorOnEVSideDisconnect
  9035. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9038. // WebSocketPingInterval
  9039. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9042. //* Local Auth List Management Profile*/
  9043. #if 0
  9044. //For OCTT Test Case
  9045. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9048. #endif
  9049. #if 1
  9050. //LocalAuthListEnabled
  9051. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9054. #endif
  9055. //LocalAuthListMaxLength
  9056. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9059. //SendLocalListMaxLength
  9060. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9063. //ReserveConnectorZeroSupported
  9064. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9067. //* Smart Charging Profile */
  9068. //ChargeProfileMaxStackLevel
  9069. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9072. // ChargingScheduleAllowedChargingRateUnit
  9073. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9076. // ChargingScheduleMaxPeriods
  9077. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9080. // ConnectorSwitch3to1PhaseSupported
  9081. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9084. // MaxChargingProfilesInstalled
  9085. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9088. return 0;
  9089. }
  9090. void getKeyValue(char *keyReq)
  9091. {
  9092. int isEmpty = FALSE;
  9093. int isKnowKey = FALSE;
  9094. //int unKnowIndex = 0;
  9095. DEBUG_INFO("getKeyValue \n");
  9096. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9097. isEmpty = TRUE;
  9098. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9099. {
  9100. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9103. {
  9104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9105. }
  9106. else
  9107. {
  9108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9109. }
  9110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9111. isKnowKey = TRUE;
  9112. }
  9113. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9114. {
  9115. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9118. {
  9119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9120. }
  9121. else
  9122. {
  9123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9124. }
  9125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9126. isKnowKey = TRUE;
  9127. }
  9128. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9129. {
  9130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9133. {
  9134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9135. }
  9136. else
  9137. {
  9138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9139. }
  9140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9141. isKnowKey = TRUE;
  9142. }
  9143. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9144. {
  9145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9148. {
  9149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9150. }
  9151. else
  9152. {
  9153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9154. }
  9155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9156. isKnowKey = TRUE;
  9157. }
  9158. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9159. {
  9160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9163. {
  9164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9165. }
  9166. else
  9167. {
  9168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9169. }
  9170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9171. isKnowKey = TRUE;
  9172. }
  9173. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9174. {
  9175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9178. {
  9179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9180. }
  9181. else
  9182. {
  9183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9184. }
  9185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9186. isKnowKey = TRUE;
  9187. }
  9188. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9189. {
  9190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9193. {
  9194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9195. }
  9196. else
  9197. {
  9198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9199. }
  9200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9201. isKnowKey = TRUE;
  9202. }
  9203. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9204. {
  9205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9208. {
  9209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9210. }
  9211. else
  9212. {
  9213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9214. }
  9215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9216. isKnowKey = TRUE;
  9217. }
  9218. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9219. {
  9220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9223. {
  9224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9225. }
  9226. else
  9227. {
  9228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9229. }
  9230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9231. isKnowKey = TRUE;
  9232. }
  9233. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9234. {
  9235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9238. {
  9239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9240. }
  9241. else
  9242. {
  9243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9244. }
  9245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9246. isKnowKey = TRUE;
  9247. }
  9248. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9249. {
  9250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9253. {
  9254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9255. }
  9256. else
  9257. {
  9258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9259. }
  9260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9261. isKnowKey = TRUE;
  9262. }
  9263. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9264. {
  9265. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9268. {
  9269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9270. }
  9271. else
  9272. {
  9273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9274. }
  9275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9276. isKnowKey = TRUE;
  9277. }
  9278. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9279. {
  9280. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9283. {
  9284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9285. }
  9286. else
  9287. {
  9288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9289. }
  9290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9291. isKnowKey = TRUE;
  9292. }
  9293. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9294. {
  9295. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9298. {
  9299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9300. }
  9301. else
  9302. {
  9303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9304. }
  9305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9306. isKnowKey = TRUE;
  9307. }
  9308. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9309. {
  9310. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9313. {
  9314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9315. }
  9316. else
  9317. {
  9318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9319. }
  9320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9321. isKnowKey = TRUE;
  9322. }
  9323. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9324. {
  9325. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9327. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9328. {
  9329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9330. }
  9331. else
  9332. {
  9333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9334. }
  9335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9336. isKnowKey = TRUE;
  9337. }
  9338. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9339. {
  9340. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9342. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9343. {
  9344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9345. }
  9346. else
  9347. {
  9348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9349. }
  9350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9351. isKnowKey = TRUE;
  9352. }
  9353. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9354. {
  9355. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9358. {
  9359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9360. }
  9361. else
  9362. {
  9363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9364. }
  9365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9366. isKnowKey = TRUE;
  9367. }
  9368. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9369. {
  9370. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9372. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9373. {
  9374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9375. }
  9376. else
  9377. {
  9378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9379. }
  9380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9381. isKnowKey = TRUE;
  9382. }
  9383. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9384. {
  9385. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9388. {
  9389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9390. }
  9391. else
  9392. {
  9393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9394. }
  9395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9396. isKnowKey = TRUE;
  9397. }
  9398. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9399. {
  9400. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9402. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9403. {
  9404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9405. }
  9406. else
  9407. {
  9408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9409. }
  9410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9411. isKnowKey = TRUE;
  9412. }
  9413. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9414. {
  9415. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9418. {
  9419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9420. }
  9421. else
  9422. {
  9423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9424. }
  9425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9426. isKnowKey = TRUE;
  9427. }
  9428. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9429. {
  9430. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9432. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9433. {
  9434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9435. }
  9436. else
  9437. {
  9438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9439. }
  9440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9441. isKnowKey = TRUE;
  9442. }
  9443. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9444. {
  9445. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9447. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9448. {
  9449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9450. }
  9451. else
  9452. {
  9453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9454. }
  9455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9456. isKnowKey = TRUE;
  9457. }
  9458. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9459. {
  9460. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9463. {
  9464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9465. }
  9466. else
  9467. {
  9468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9469. }
  9470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9471. isKnowKey = TRUE;
  9472. }
  9473. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9474. {
  9475. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9478. {
  9479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9480. }
  9481. else
  9482. {
  9483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9484. }
  9485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9486. isKnowKey = TRUE;
  9487. }
  9488. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9489. {
  9490. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9493. {
  9494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9495. }
  9496. else
  9497. {
  9498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9499. }
  9500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9501. isKnowKey = TRUE;
  9502. }
  9503. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9504. {
  9505. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9507. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9508. {
  9509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9510. }
  9511. else
  9512. {
  9513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9514. }
  9515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9516. isKnowKey = TRUE;
  9517. }
  9518. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9519. {
  9520. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9522. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9523. {
  9524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9525. }
  9526. else
  9527. {
  9528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9529. }
  9530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9531. isKnowKey = TRUE;
  9532. }
  9533. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9534. {
  9535. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9538. {
  9539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9540. }
  9541. else
  9542. {
  9543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9544. }
  9545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9546. isKnowKey = TRUE;
  9547. }
  9548. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9549. {
  9550. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9552. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9553. {
  9554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9555. }
  9556. else
  9557. {
  9558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9559. }
  9560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9561. isKnowKey = TRUE;
  9562. }
  9563. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9564. {
  9565. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9568. {
  9569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9570. }
  9571. else
  9572. {
  9573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9574. }
  9575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9576. isKnowKey = TRUE;
  9577. }
  9578. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9579. {
  9580. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9582. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9583. {
  9584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9585. }
  9586. else
  9587. {
  9588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9589. }
  9590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9591. isKnowKey = TRUE;
  9592. }
  9593. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9594. {
  9595. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9598. {
  9599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9600. }
  9601. else
  9602. {
  9603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9604. }
  9605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9606. isKnowKey = TRUE;
  9607. }
  9608. #if 0
  9609. //For OCTT Test Case
  9610. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9611. {
  9612. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9614. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9615. {
  9616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9617. }
  9618. else
  9619. {
  9620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9621. }
  9622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9623. isKnowKey = TRUE;
  9624. }
  9625. #endif
  9626. #if 1
  9627. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9628. {
  9629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9631. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9632. {
  9633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9634. }
  9635. else
  9636. {
  9637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9638. }
  9639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9640. isKnowKey = TRUE;
  9641. }
  9642. #endif
  9643. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9644. {
  9645. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9647. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9648. {
  9649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9650. }
  9651. else
  9652. {
  9653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9654. }
  9655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9656. isKnowKey = TRUE;
  9657. }
  9658. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9659. {
  9660. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9662. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9663. {
  9664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9665. }
  9666. else
  9667. {
  9668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9669. }
  9670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9671. isKnowKey = TRUE;
  9672. }
  9673. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9674. {
  9675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9677. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9678. {
  9679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9680. }
  9681. else
  9682. {
  9683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9684. }
  9685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9686. isKnowKey = TRUE;
  9687. }
  9688. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9689. {
  9690. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9692. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9693. {
  9694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9695. }
  9696. else
  9697. {
  9698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9699. }
  9700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9701. isKnowKey = TRUE;
  9702. }
  9703. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9704. {
  9705. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9707. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9708. {
  9709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9710. }
  9711. else
  9712. {
  9713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9714. }
  9715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9716. isKnowKey = TRUE;
  9717. }
  9718. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9719. {
  9720. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9722. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9723. {
  9724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9725. }
  9726. else
  9727. {
  9728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9729. }
  9730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9731. isKnowKey = TRUE;
  9732. }
  9733. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9734. {
  9735. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9737. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9738. {
  9739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9740. }
  9741. else
  9742. {
  9743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9744. }
  9745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9746. isKnowKey = TRUE;
  9747. }
  9748. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9749. {
  9750. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9752. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9753. {
  9754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9755. }
  9756. else
  9757. {
  9758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9759. }
  9760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9761. isKnowKey = TRUE;
  9762. }
  9763. //=========================================================
  9764. if(!isEmpty && !isKnowKey)
  9765. {
  9766. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9767. strcpy(unknownkey[UnknownKeynum], keyReq);
  9768. UnknownKeynum = UnknownKeynum + 1;
  9769. }
  9770. }
  9771. void processUnkownKey(void)
  9772. {
  9773. DEBUG_INFO("processUnkownKey\n");
  9774. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9775. for(int index=0; index < UnknownKeynum; index++)
  9776. {
  9777. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9778. {
  9779. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9780. }
  9781. }
  9782. }
  9783. int setKeyValue(char *key, char *value)
  9784. {
  9785. int isSuccess = NotSupported;
  9786. int check_ascii=0;
  9787. #ifdef Debug
  9788. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9789. #endif
  9790. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9791. {
  9792. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9793. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9794. {
  9795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9796. isSuccess = ConfigurationStatus_Accepted;
  9797. }
  9798. else
  9799. {
  9800. isSuccess = ConfigurationStatus_Rejected;
  9801. }
  9802. }
  9803. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9804. {
  9805. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9807. {
  9808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9809. isSuccess = ConfigurationStatus_Accepted;
  9810. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9811. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9812. }
  9813. else
  9814. {
  9815. isSuccess = ConfigurationStatus_Rejected;
  9816. }
  9817. }
  9818. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9819. {
  9820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9821. {
  9822. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9823. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9824. isSuccess = ConfigurationStatus_Accepted;
  9825. }
  9826. else
  9827. {
  9828. isSuccess = ConfigurationStatus_Rejected;
  9829. }
  9830. }
  9831. if(strcmp(key, "BlinkRepeat") == 0)
  9832. {
  9833. //Charger.BlinkRepeat = Integer.parseInt(value);
  9834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9835. {
  9836. check_ascii = value[0];
  9837. if( (check_ascii < 48) || (check_ascii > 57) )
  9838. {
  9839. isSuccess = ConfigurationStatus_Rejected;
  9840. }
  9841. else
  9842. {
  9843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9844. isSuccess = ConfigurationStatus_Accepted;
  9845. }
  9846. }
  9847. else
  9848. {
  9849. isSuccess = ConfigurationStatus_Rejected;
  9850. }
  9851. }
  9852. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9853. {
  9854. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9855. {
  9856. check_ascii = value[0];
  9857. if( (check_ascii < 48) || (check_ascii > 57) )
  9858. {
  9859. isSuccess = ConfigurationStatus_Rejected;
  9860. }
  9861. else
  9862. {
  9863. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9865. isSuccess = ConfigurationStatus_Accepted;
  9866. }
  9867. }
  9868. else
  9869. {
  9870. isSuccess = ConfigurationStatus_Rejected;
  9871. }
  9872. }
  9873. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9874. {
  9875. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9876. {
  9877. check_ascii = value[0];
  9878. if( (check_ascii < 48) || (check_ascii > 57) )
  9879. {
  9880. isSuccess = ConfigurationStatus_Rejected;
  9881. }
  9882. else
  9883. {
  9884. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9886. isSuccess = ConfigurationStatus_Accepted;
  9887. }
  9888. }
  9889. else
  9890. {
  9891. isSuccess = ConfigurationStatus_Rejected;
  9892. }
  9893. }
  9894. if(strcmp(key, "HeartbeatInterval") == 0)
  9895. {
  9896. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9897. {
  9898. check_ascii = value[0];
  9899. if( (check_ascii < 48) || (check_ascii > 57) )
  9900. {
  9901. isSuccess = ConfigurationStatus_Rejected;
  9902. }
  9903. else
  9904. {
  9905. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9907. HeartBeatWaitTime = atoi(value);
  9908. isSuccess = ConfigurationStatus_Accepted;
  9909. }
  9910. }
  9911. else
  9912. {
  9913. isSuccess = ConfigurationStatus_Rejected;
  9914. }
  9915. }
  9916. if(strcmp(key, "LightIntensity") == 0)
  9917. {
  9918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9919. {
  9920. check_ascii = value[0];
  9921. if( (check_ascii < 48) || (check_ascii > 57) )
  9922. {
  9923. isSuccess = ConfigurationStatus_Rejected;
  9924. }
  9925. else
  9926. {
  9927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9928. isSuccess = ConfigurationStatus_Accepted;
  9929. }
  9930. }
  9931. else
  9932. {
  9933. isSuccess = ConfigurationStatus_Rejected;
  9934. }
  9935. }
  9936. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  9937. {
  9938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9939. {
  9940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9941. isSuccess = ConfigurationStatus_Accepted;
  9942. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9943. }
  9944. else
  9945. {
  9946. isSuccess = ConfigurationStatus_Rejected;
  9947. }
  9948. }
  9949. if(strcmp(key, "LocalPreAuthorize") == 0)
  9950. {
  9951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9952. {
  9953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9954. isSuccess = ConfigurationStatus_Accepted;
  9955. }
  9956. else
  9957. {
  9958. isSuccess = ConfigurationStatus_Rejected;
  9959. }
  9960. }
  9961. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  9962. {
  9963. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9964. {
  9965. check_ascii = value[0];
  9966. if( (check_ascii < 48) || (check_ascii > 57) )
  9967. {
  9968. isSuccess = ConfigurationStatus_Rejected;
  9969. }
  9970. else
  9971. {
  9972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  9973. isSuccess = ConfigurationStatus_Accepted;
  9974. }
  9975. }
  9976. else
  9977. {
  9978. isSuccess = ConfigurationStatus_Rejected;
  9979. }
  9980. }
  9981. if(strcmp(key, "MeterValuesAlignedData") == 0)
  9982. {
  9983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9984. {
  9985. //int valueLength = strlen(value);
  9986. for(int i = 0; value[i]; i++){
  9987. value[i] = tolower(value[i]);
  9988. }
  9989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  9990. isSuccess = ConfigurationStatus_Accepted;
  9991. }
  9992. else
  9993. {
  9994. isSuccess = ConfigurationStatus_Rejected;
  9995. }
  9996. }
  9997. if(strcmp(key, "MeterValuesSampledData") == 0 )
  9998. {
  9999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10000. {
  10001. //int valueLength = strlen(value);
  10002. for(int i = 0; value[i]; i++){
  10003. value[i] = tolower(value[i]);
  10004. }
  10005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10006. isSuccess = ConfigurationStatus_Accepted;
  10007. }
  10008. else
  10009. {
  10010. isSuccess = ConfigurationStatus_Rejected;
  10011. }
  10012. }
  10013. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10014. {
  10015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10016. {
  10017. check_ascii = value[0];
  10018. if( (check_ascii < 48) || (check_ascii > 57) )
  10019. {
  10020. isSuccess = ConfigurationStatus_Rejected;
  10021. }
  10022. else
  10023. {
  10024. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10026. isSuccess = ConfigurationStatus_Accepted;
  10027. }
  10028. #ifdef Debug
  10029. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10030. #endif
  10031. }
  10032. else
  10033. {
  10034. isSuccess = ConfigurationStatus_Rejected;
  10035. #ifdef Debug
  10036. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10037. #endif
  10038. }
  10039. }
  10040. if(strcmp(key, "MinimumStatusDuration") == 0)
  10041. {
  10042. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10043. {
  10044. check_ascii = value[0];
  10045. if( (check_ascii < 48) || (check_ascii > 57) )
  10046. {
  10047. isSuccess = ConfigurationStatus_Rejected;
  10048. }
  10049. else
  10050. {
  10051. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10052. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10053. isSuccess = ConfigurationStatus_Accepted;
  10054. }
  10055. }
  10056. else
  10057. {
  10058. isSuccess = ConfigurationStatus_Rejected;
  10059. }
  10060. }
  10061. if(strcmp(key, "ResetRetries") == 0)
  10062. {
  10063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10064. {
  10065. check_ascii = value[0];
  10066. if( (check_ascii < 48) || (check_ascii > 57) )
  10067. {
  10068. isSuccess = ConfigurationStatus_Rejected;
  10069. }
  10070. else
  10071. {
  10072. //Charger.ResetRetries = Integer.parseInt(value);
  10073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10074. isSuccess = ConfigurationStatus_Accepted;
  10075. }
  10076. }
  10077. else
  10078. {
  10079. isSuccess = ConfigurationStatus_Rejected;
  10080. }
  10081. }
  10082. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10083. {
  10084. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10085. {
  10086. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10087. //int valueLength = strlen(value);
  10088. for(int i = 0; value[i]; i++){
  10089. value[i] = tolower(value[i]);
  10090. }
  10091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10092. isSuccess = ConfigurationStatus_Accepted;
  10093. }
  10094. else
  10095. {
  10096. isSuccess = ConfigurationStatus_Rejected;
  10097. }
  10098. }
  10099. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10100. {
  10101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10102. {
  10103. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10105. isSuccess = ConfigurationStatus_Accepted;
  10106. }
  10107. else
  10108. {
  10109. isSuccess = ConfigurationStatus_Rejected;
  10110. }
  10111. }
  10112. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10113. {
  10114. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10115. {
  10116. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10118. isSuccess = ConfigurationStatus_Accepted;
  10119. }
  10120. else
  10121. {
  10122. isSuccess = ConfigurationStatus_Rejected;
  10123. }
  10124. }
  10125. if(strcmp(key, "StopTxnAlignedData") == 0)
  10126. {
  10127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10128. {
  10129. //Charger.StopTxnAlignedData = value.toLowerCase();
  10130. //int valueLength = strlen(value);
  10131. for(int i = 0; value[i]; i++){
  10132. value[i] = tolower(value[i]);
  10133. }
  10134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10135. isSuccess = ConfigurationStatus_Accepted;
  10136. }
  10137. else
  10138. {
  10139. isSuccess = ConfigurationStatus_Rejected;
  10140. }
  10141. }
  10142. if(strcmp(key, "StopTxnSampledData") == 0)
  10143. {
  10144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10145. {
  10146. //Charger.StopTxnSampledData = value.toLowerCase();
  10147. //int valueLength = strlen(value);
  10148. for(int i = 0; value[i]; i++){
  10149. value[i] = tolower(value[i]);
  10150. }
  10151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10152. isSuccess = ConfigurationStatus_Accepted;
  10153. }
  10154. else
  10155. {
  10156. isSuccess = ConfigurationStatus_Rejected;
  10157. }
  10158. }
  10159. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10160. {
  10161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10162. {
  10163. check_ascii = value[0];
  10164. if( (check_ascii < 48) || (check_ascii > 57) )
  10165. {
  10166. isSuccess = ConfigurationStatus_Rejected;
  10167. }
  10168. else
  10169. {
  10170. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10172. TransactionMessageAttemptsValue = atoi(value);
  10173. isSuccess = ConfigurationStatus_Accepted;
  10174. }
  10175. }
  10176. else
  10177. {
  10178. isSuccess = ConfigurationStatus_Rejected;
  10179. }
  10180. }
  10181. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10182. {
  10183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10184. {
  10185. check_ascii = value[0];
  10186. if( (check_ascii < 48) || (check_ascii > 57) )
  10187. {
  10188. isSuccess = ConfigurationStatus_Rejected;
  10189. }
  10190. else
  10191. {
  10192. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10194. TransactionMessageRetryIntervalValue = atoi(value);
  10195. isSuccess = ConfigurationStatus_Accepted;
  10196. }
  10197. }
  10198. else
  10199. {
  10200. isSuccess = ConfigurationStatus_Rejected;
  10201. }
  10202. }
  10203. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10204. {
  10205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10206. {
  10207. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10209. isSuccess = ConfigurationStatus_Accepted;
  10210. }
  10211. else
  10212. {
  10213. isSuccess = ConfigurationStatus_Rejected;
  10214. }
  10215. }
  10216. if(strcmp(key, "WebSocketPingInterval") == 0)
  10217. {
  10218. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10219. {
  10220. check_ascii = value[0];
  10221. if( (check_ascii < 48) || (check_ascii > 57) )
  10222. {
  10223. isSuccess = ConfigurationStatus_Rejected;
  10224. }
  10225. else
  10226. {
  10227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10228. isSuccess = ConfigurationStatus_Accepted;
  10229. }
  10230. }
  10231. else
  10232. {
  10233. isSuccess = ConfigurationStatus_Rejected;
  10234. }
  10235. }
  10236. #if 0
  10237. //For OCPP Test Case
  10238. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10239. {
  10240. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10241. {
  10242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10243. isSuccess = ConfigurationStatus_Accepted;
  10244. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10245. }
  10246. else
  10247. {
  10248. isSuccess = ConfigurationStatus_Rejected;
  10249. }
  10250. }
  10251. #endif
  10252. #if 1
  10253. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10254. {
  10255. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10256. {
  10257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10258. isSuccess = ConfigurationStatus_Accepted;
  10259. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10260. }
  10261. else
  10262. {
  10263. isSuccess = ConfigurationStatus_Rejected;
  10264. }
  10265. }
  10266. #endif
  10267. return isSuccess;
  10268. }
  10269. int updateSetting(char *key, char *value)
  10270. {
  10271. mtrace();
  10272. int isSuccess = FALSE;
  10273. char string[1000]={0}, buffer[1000]={0};
  10274. char strtemp[50]={0};
  10275. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10276. int pos, c = 0;
  10277. char *loc;
  10278. int pos1=0;
  10279. FILE *f = fopen("/var/www/settings1", "r");
  10280. if(f == NULL)
  10281. {
  10282. #ifdef Debug
  10283. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10284. #endif
  10285. return isSuccess;
  10286. }
  10287. fseek(f, 0, SEEK_END);
  10288. long fsize = ftell(f);
  10289. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10290. fread(string, 1, fsize, f);
  10291. fclose(f);
  10292. string[fsize] = 0;
  10293. loc = strstr(string, key);
  10294. if(loc != NULL)
  10295. {
  10296. DEBUG_INFO("key exist!\n");
  10297. pos = loc - string-1;
  10298. f = fopen("/var/www/settings1", "w");
  10299. strncpy(buffer, string, pos);
  10300. fprintf(f, "%s", buffer);
  10301. memset(sstr ,0, sizeof(sstr) );
  10302. c = 0;
  10303. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10304. {
  10305. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10306. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10307. c++;
  10308. }
  10309. sstr[c] = '\0';
  10310. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10311. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10312. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10313. memset(buffer ,0, sizeof(buffer) );
  10314. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10315. //printf("buffer=%s",buffer);
  10316. fprintf(f, "%s", buffer);
  10317. fclose(f);
  10318. }
  10319. else
  10320. {
  10321. printf("key not exist!\n");
  10322. f = fopen("/var/www/settings1", "w+");
  10323. fputs(string, f);
  10324. fseek(f, -1, SEEK_CUR);
  10325. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10326. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10327. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10328. fclose(f);
  10329. }
  10330. isSuccess = TRUE;
  10331. return isSuccess;
  10332. }
  10333. int TransactionMessageAttemptsGet(void)
  10334. {
  10335. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10336. }
  10337. int FirstHeartBeatResponse(void)
  10338. {
  10339. return FirstHeartBeat;
  10340. }
  10341. int TransactionMessageRetryIntervalGet(void)
  10342. {
  10343. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10344. }
  10345. #define SA struct sockaddr
  10346. #define MAXBUF 1024
  10347. //static int m_socket_data;
  10348. //static int sockfd;
  10349. int ReadHttpStatus(int sock){
  10350. //char c;
  10351. char buff[1024]="",*ptr=buff+1;
  10352. int bytes_received, status;
  10353. DEBUG_INFO("Begin Response ..\n");
  10354. while((bytes_received = recv(sock, ptr, 1, 0))){
  10355. if(bytes_received==-1){
  10356. perror("ReadHttpStatus");
  10357. exit(1);
  10358. }
  10359. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10360. ptr++;
  10361. }
  10362. *ptr=0;
  10363. ptr=buff+1;
  10364. sscanf(ptr,"%*s %d ", &status);
  10365. DEBUG_INFO("%s\n",ptr);
  10366. DEBUG_INFO("status=%d\n",status);
  10367. DEBUG_INFO("End Response ..\n");
  10368. return (bytes_received>0)?status:0;
  10369. }
  10370. //the only filed that it parsed is 'Content-Length'
  10371. int ParseHeader(int sock){
  10372. //char c;
  10373. char buff[1024]="",*ptr=buff+4;
  10374. int bytes_received;
  10375. DEBUG_INFO("Begin HEADER ..\n");
  10376. while((bytes_received = recv(sock, ptr, 1, 0))){
  10377. if(bytes_received==-1){
  10378. perror("Parse Header");
  10379. exit(1);
  10380. }
  10381. if(
  10382. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10383. (ptr[-1]=='\r') && (*ptr=='\n' )
  10384. ) break;
  10385. ptr++;
  10386. }
  10387. *ptr=0;
  10388. ptr=buff+4;
  10389. //printf("%s",ptr);
  10390. if(bytes_received){
  10391. ptr=strstr(ptr,"Content-Length:");
  10392. if(ptr){
  10393. sscanf(ptr,"%*s %d",&bytes_received);
  10394. }else
  10395. bytes_received=-1; //unknown size
  10396. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10397. }
  10398. DEBUG_INFO("End HEADER ..\n");
  10399. return bytes_received ;
  10400. }
  10401. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10402. {
  10403. char rmFileCmd[100]={0};
  10404. char FilePath[100]={0};
  10405. char ftpbuf[200];
  10406. int systemresult;
  10407. DEBUG_INFO("filename=%s\n",filename);
  10408. DEBUG_INFO("url=%s\n",url);
  10409. sprintf(FilePath,"../mnt/%s",filename);
  10410. if((access(FilePath,F_OK))!=-1)
  10411. {
  10412. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10413. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10414. system(rmFileCmd);
  10415. }
  10416. memset(ftpbuf, 0, sizeof(ftpbuf));
  10417. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10418. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10419. systemresult = system(ftpbuf);
  10420. DEBUG_INFO("systemresult=%d\n",systemresult);
  10421. if(systemresult != 0)
  10422. {
  10423. DEBUG_INFO("http DownLoad error!\n");
  10424. return FALSE;
  10425. }
  10426. return TRUE;
  10427. }
  10428. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10429. {
  10430. char rmFileCmd[100]={0};
  10431. char FilePath[100]={0};
  10432. char ftpbuf[200];
  10433. int systemresult;
  10434. //char temp[100];
  10435. #if 0
  10436. struct hostent* server;
  10437. char *IPbuffer;
  10438. server = gethostbyname(location);
  10439. // To convert an Internet network
  10440. // address into ASCII string
  10441. IPbuffer = inet_ntoa(*((struct in_addr*)
  10442. server->h_addr_list[0]));
  10443. #endif
  10444. sprintf(FilePath,"../mnt/%s",filename);
  10445. if((access(FilePath,F_OK))!=-1)
  10446. {
  10447. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10448. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10449. system(rmFileCmd);
  10450. }
  10451. memset(ftpbuf, 0, sizeof(ftpbuf));
  10452. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10453. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10454. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10455. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10456. systemresult = system(ftpbuf);
  10457. DEBUG_INFO("systemresult=%d\n",systemresult);
  10458. if(systemresult != 0)
  10459. {
  10460. printf("ftpget error!\n");
  10461. return FALSE;
  10462. }
  10463. return TRUE;
  10464. }
  10465. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10466. {
  10467. struct hostent* server;
  10468. char *IPbuffer;
  10469. char ftpbuf[200];
  10470. int systemresult;
  10471. // To retrieve host information
  10472. server = gethostbyname(location);
  10473. // To convert an Internet network
  10474. // address into ASCII string
  10475. IPbuffer = inet_ntoa(*((struct in_addr*)
  10476. server->h_addr_list[0]));
  10477. memset(ftpbuf, 0, sizeof(ftpbuf));
  10478. /* format : ftpput -u username -p passwd IP target source*/
  10479. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10480. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10481. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10482. systemresult = system(ftpbuf);
  10483. DEBUG_INFO("systemresult=%d\n",systemresult);
  10484. if(systemresult != 0)
  10485. {
  10486. DEBUG_INFO("ftpput error!\n");
  10487. return FALSE;
  10488. }
  10489. return TRUE;
  10490. }
  10491. int SettingChargingRecord(int target, int transactionId)
  10492. {
  10493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10494. {
  10495. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10496. {
  10497. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10498. {
  10499. addBuff(target, transactionId, 0);
  10500. return TRUE;
  10501. }
  10502. }
  10503. for (int index = 0; index < CCS_QUANTITY; index++)
  10504. {
  10505. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10506. {
  10507. addBuff(target, transactionId, 0);
  10508. return TRUE;
  10509. }
  10510. }
  10511. for (int index = 0; index < GB_QUANTITY; index++)
  10512. {
  10513. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10514. {
  10515. addBuff(target, transactionId, 0);
  10516. return TRUE;
  10517. }
  10518. }
  10519. }
  10520. else
  10521. {
  10522. for (int index = 0; index < AC_QUANTITY; index++)
  10523. {
  10524. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10525. {
  10526. addBuff(target, transactionId, 0);
  10527. return TRUE;
  10528. }
  10529. }
  10530. }
  10531. return FALSE;
  10532. }
  10533. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10534. {
  10535. int isSuccess = FALSE;
  10536. //char *query = NULL;
  10537. sqlite3_stmt *stmt;
  10538. int rc; // return code
  10539. char str[20];
  10540. sprintf(str,"%d",user_id);
  10541. 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 */
  10542. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10543. rc = sqlite3_step(stmt); /* 3 */
  10544. if (rc != SQLITE_DONE) {
  10545. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10546. goto out;
  10547. }
  10548. sqlite3_finalize(stmt);
  10549. // free(query);
  10550. out:
  10551. //----------------------
  10552. // close SQLite database
  10553. //----------------------
  10554. sqlite3_close(db);
  10555. printf("database closed.\n");
  10556. return isSuccess;
  10557. }
  10558. /**
  10559. * Place the contents of the specified file into a memory buffer
  10560. *
  10561. * @param[in] filename The path and name of the file to read
  10562. * @param[out] filebuffer A pointer to the contents in memory
  10563. * @return status 0 success, 1 on failure
  10564. */
  10565. int get_file_contents(const char* filename, char** outbuffer) {
  10566. FILE* file = NULL;
  10567. long filesize;
  10568. const int blocksize = 1;
  10569. size_t readsize;
  10570. char* filebuffer;
  10571. // Open the file
  10572. file = fopen(filename, "r");
  10573. if (NULL == file)
  10574. {
  10575. printf("'%s' not opened\n", filename);
  10576. exit(EXIT_FAILURE);
  10577. }
  10578. // Determine the file size
  10579. fseek(file, 0, SEEK_END);
  10580. filesize = ftell(file);
  10581. rewind (file);
  10582. // Allocate memory for the file contents
  10583. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10584. *outbuffer = filebuffer;
  10585. if (filebuffer == NULL)
  10586. {
  10587. fputs ("malloc out-of-memory", stderr);
  10588. exit(EXIT_FAILURE);
  10589. }
  10590. // Read in the file
  10591. readsize = fread(filebuffer, blocksize, filesize, file);
  10592. if (readsize != filesize)
  10593. {
  10594. fputs ("didn't read file completely",stderr);
  10595. exit(EXIT_FAILURE);
  10596. }
  10597. // Clean exit
  10598. fclose(file);
  10599. return EXIT_SUCCESS;
  10600. }
  10601. static int selectSqlCount = 0;
  10602. static int callback(void *data, int argc, char **argv, char **azColName){
  10603. int i;
  10604. printf("%s: ", (const char*)data);
  10605. selectSqlCount = argc;
  10606. for(i = 0; i<argc; i++){
  10607. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10608. }
  10609. printf("\n");
  10610. return 0;
  10611. }
  10612. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10613. //int i;
  10614. //printf("%s:\n", (const char*)data);
  10615. localversion = argv[5] ? atoi(argv[5]) : 0;
  10616. printf("localversion=%d\n", localversion);
  10617. return 0;
  10618. }
  10619. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10620. //int i;
  10621. //printf("%s:\n", (const char*)data);
  10622. //idTag
  10623. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10624. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10625. //parentIdTag
  10626. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10627. //expir_date
  10628. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10629. //status
  10630. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10631. //version
  10632. idTagQuery.listVersionInt = atoi(argv[5]);
  10633. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10634. return 0;
  10635. }
  10636. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10637. int i;
  10638. //printf("%s:\n", (const char*)data);
  10639. #if 1
  10640. for(i=0; i<argc; i++){
  10641. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10642. }
  10643. //printf("");
  10644. #endif
  10645. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10646. // printf("localversion=%d\n", localversion);
  10647. return 0;
  10648. }
  10649. /** sqlite3_exec的回调。
  10650. *
  10651. * 向控制台打印查询的结果。
  10652. *
  10653. * @param in data 传递给回调函数的数据。
  10654. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10655. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10656. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10657. * @return 状态码。
  10658. */
  10659. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10660. {
  10661. for (int i = 0; i < n_columns; i++)
  10662. {
  10663. DEBUG_INFO("%s/t", col_values[i]);
  10664. }
  10665. DEBUG_INFO("/n");
  10666. return 0;
  10667. }
  10668. void OCPP_getListVerion()
  10669. {
  10670. int rc = 0;
  10671. // const char* data = "Callback function called";
  10672. char sql[100];
  10673. char zErrMsg[100];
  10674. memset(sql, 0, 100);
  10675. memset(zErrMsg, 0, 100);
  10676. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10677. /* Execute SQL statement */
  10678. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10679. DEBUG_INFO("rc=%d\n",rc);
  10680. if( rc != SQLITE_OK ){
  10681. DEBUG_INFO("SQL error: %s", zErrMsg);
  10682. //sqlite3_free(zErrMsg);
  10683. }else{
  10684. DEBUG_INFO("Operation done successfully");
  10685. }
  10686. }
  10687. void OCPP_getIdTag(char *idTag)
  10688. {
  10689. int rc = 0;
  10690. // const char* data = "Callback function called";
  10691. char sql[100];
  10692. char zErrMsg[100];
  10693. memset(sql, 0, 100);
  10694. memset(zErrMsg, 0, 100);
  10695. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10696. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10697. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10698. /* Execute SQL statement */
  10699. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10700. if( rc != SQLITE_OK ){
  10701. DEBUG_INFO("SQL error: %s", zErrMsg);
  10702. //sqlite3_free(zErrMsg);
  10703. }else{
  10704. printf("Operation done successfully");
  10705. }
  10706. //return ver;
  10707. }
  10708. void OCPP_get_TableAuthlocalAllData(void)
  10709. {
  10710. int rc = 0;
  10711. // const char* data = "Callback function called";
  10712. char sql[100];
  10713. char zErrMsg[100];
  10714. memset(sql, 0, 100);
  10715. memset(zErrMsg, 0, 100);
  10716. sprintf(sql,"select * from ocpp_auth_local ");
  10717. /* Execute SQL statement */
  10718. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10719. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10720. if( rc != SQLITE_OK ){
  10721. DEBUG_INFO("SQL error: %s", zErrMsg);
  10722. //sqlite3_free(zErrMsg);
  10723. }else{
  10724. DEBUG_INFO("Operation done successfully");
  10725. }
  10726. //return ver;
  10727. }
  10728. int OCPP_cleanLocalList()
  10729. {
  10730. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10731. char *errMsg = 0;
  10732. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10733. if (SQLITE_OK != rc)
  10734. {
  10735. DEBUG_INFO("%s\n",errMsg);
  10736. return FALSE;
  10737. }
  10738. else
  10739. {
  10740. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10741. }
  10742. return TRUE;
  10743. }
  10744. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10745. {
  10746. int isSuccess = FALSE;
  10747. int ret = 0;
  10748. //const char* data = "Callback function called";
  10749. char sql[200];
  10750. char zErrMsg[100];
  10751. memset(sql, 0, 200);
  10752. memset(zErrMsg, 0, 100);
  10753. 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);
  10754. //* Execute SQL statement */
  10755. //zErrMsg = 0;
  10756. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10757. if( ret != SQLITE_OK ){
  10758. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10759. // free(zErrMsg);
  10760. // free(sql);
  10761. return isSuccess;
  10762. }
  10763. DEBUG_INFO("successfully Insert records created\n");
  10764. isSuccess = TRUE;
  10765. return isSuccess;
  10766. }
  10767. void OCPP_deleteIdTag(char *idTag)
  10768. {
  10769. //int ver = 0;
  10770. //int isSuccess = FALSE;
  10771. int rc = 0;
  10772. char sql[100];
  10773. char zErrMsg[100];
  10774. memset(sql, 0, 100);
  10775. memset(zErrMsg, 0, 100);
  10776. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10777. //* Execute SQL statement */
  10778. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10779. if( rc != SQLITE_OK ){
  10780. DEBUG_INFO("SQL error: %s", zErrMsg);
  10781. //sqlite3_free(zErrMsg);
  10782. }else{
  10783. DEBUG_INFO("Operation done successfully");
  10784. }
  10785. }
  10786. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10787. {
  10788. int isSuccess = FALSE;
  10789. int ret = 0;
  10790. const char* data = "Callback function called";
  10791. char sql[200];
  10792. char zErrMsg[100];
  10793. memset(sql, 0, 200);
  10794. memset(zErrMsg, 0, 100);
  10795. //* selectFromTable */
  10796. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10797. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10798. //* Execute SQL statement */
  10799. selectSqlCount = 0;
  10800. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10801. if( ret != SQLITE_OK ){
  10802. printf("Error SQL: %s\n", zErrMsg);
  10803. }
  10804. printf("successfully select operation done\n");
  10805. memset(sql, 0, 200);
  10806. memset(zErrMsg, 0, 100);
  10807. if(selectSqlCount == 0)
  10808. {
  10809. //Insert
  10810. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
  10811. 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);
  10812. DEBUG_INFO("sql:%s\n", sql);
  10813. //* Execute SQL statement */
  10814. //zErrMsg = 0;
  10815. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10816. if( ret != SQLITE_OK ){
  10817. printf("SQL error: %s\n", zErrMsg);
  10818. return isSuccess;
  10819. }
  10820. DEBUG_INFO("successfully Insert records created\n");
  10821. isSuccess = TRUE;
  10822. }
  10823. else
  10824. {
  10825. //Update
  10826. //* Create merged SQL statement */
  10827. 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);
  10828. /* Execute SQL statement */
  10829. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10830. if( ret != SQLITE_OK ){
  10831. printf("SQL error: %s\n", zErrMsg);
  10832. //sqlite3_free(zErrMsg);
  10833. //sqlite3_free(sql);
  10834. return isSuccess;
  10835. }
  10836. DEBUG_INFO("Successfully operation done \n");
  10837. isSuccess = TRUE;
  10838. }
  10839. return isSuccess;
  10840. }
  10841. char *GetOcppServerURL()
  10842. {
  10843. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10844. memset(OcppHost, 0, sizeof(OcppHost));
  10845. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10846. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  10847. {
  10848. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  10849. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  10850. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10851. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10852. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10853. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10854. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10855. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10856. goto End;
  10857. }
  10858. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  10859. {
  10860. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  10861. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10862. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10863. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10864. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10865. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10866. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10867. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10868. goto End;
  10869. }
  10870. else
  10871. {
  10872. strcpy(OcppHost,"");
  10873. }
  10874. End:
  10875. return OcppHost;
  10876. }
  10877. char *GetOcppPath()
  10878. {
  10879. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  10880. {
  10881. if(OcppTempPath == NULL)
  10882. {
  10883. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10884. }
  10885. else
  10886. {
  10887. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10888. }
  10889. goto End;
  10890. }
  10891. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  10892. {
  10893. if(OcppTempPath == NULL)
  10894. {
  10895. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10896. }
  10897. else
  10898. {
  10899. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10900. }
  10901. goto End;
  10902. }
  10903. else
  10904. {
  10905. strcpy(OcppHost,"");
  10906. }
  10907. End:
  10908. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10909. return OcppPath;
  10910. }
  10911. int GetOcppPort()
  10912. {
  10913. return OcppPort;
  10914. }
  10915. int GetOcppConnStatus(void)
  10916. {
  10917. return ShmOCPP16Data->OcppConnStatus;
  10918. }
  10919. void SetOcppConnStatus(uint8_t status)
  10920. {
  10921. ShmOCPP16Data->OcppConnStatus = status;
  10922. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  10923. if(status == FALSE)
  10924. {
  10925. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10926. {
  10927. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  10928. }
  10929. else
  10930. {
  10931. SystemInitial = AC_QUANTITY;
  10932. }
  10933. }
  10934. }
  10935. int GetHeartBeatWithNOResponse(void)
  10936. {
  10937. return HeartBeatWithNOResponse;
  10938. }
  10939. void SetHeartBeatWithNOResponse(void)
  10940. {
  10941. HeartBeatWithNOResponse = 0;
  10942. }
  10943. int InternetDisconnect(void)
  10944. {
  10945. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  10946. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  10947. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  10948. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  10949. }
  10950. #if 0
  10951. void Send(struct json_object *message)
  10952. {
  10953. printf("Send -1 \n");
  10954. printf("message=%s\n",json_object_to_json_string(message));
  10955. LWS_Send(json_object_to_json_string(message));
  10956. }
  10957. #endif
  10958. void LWS_Send(char * str)
  10959. {
  10960. #if 1
  10961. //=====================================================
  10962. // Check InternetConn 0: disconnected, 1: connected
  10963. //====================================================
  10964. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  10965. {
  10966. DEBUG_INFO("\n offline now !!!\n");
  10967. return;
  10968. }
  10969. #endif
  10970. pthread_mutex_lock(&lock);
  10971. memset(SendBuffer,0,SendBufLen);
  10972. sprintf((char *)SendBuffer, "%s", str);
  10973. pthread_mutex_unlock(&lock);
  10974. lws_callback_on_writable(wsi_client);
  10975. lws_service(context, 10000);//timeout_ms
  10976. //usleep(10000); // 等�??��?微�?
  10977. //DEBUG_INFO("Send message end\n");
  10978. }