MessageHandler.c 455 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985
  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 Initial Settings************************************************/
  885. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  886. memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY));
  887. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  888. {
  889. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  890. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  891. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  892. }
  893. // Charger PRE_SYS_MODE
  894. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  895. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  896. clientTime.Heartbeat=time((time_t*)NULL);
  897. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  898. {
  899. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  900. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  901. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  902. }
  903. //HeartBeatWaitTime = 10;
  904. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  905. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  906. // allocate Configuration memory address
  907. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  908. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  909. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  910. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  912. {
  913. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  914. DEBUG_INFO("DC ...\n");
  915. }
  916. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  917. {
  918. SystemInitial = AC_QUANTITY;
  919. DEBUG_INFO("AC ...\n");
  920. }
  921. //Status Setting
  922. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  923. {
  924. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  925. }
  926. for (int index = 0; index < CCS_QUANTITY; index++)
  927. {
  928. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  929. }
  930. for (int index = 0; index < GB_QUANTITY; index++)
  931. {
  932. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  933. }
  934. for (int index = 0; index < AC_QUANTITY; index++)
  935. {
  936. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  937. }
  938. //memset(unknownkey, 0, 10);
  939. return result;
  940. }
  941. int ProcessShareMemory()
  942. {
  943. if(InitShareMemory() == FAIL)
  944. {
  945. #ifdef SystemLogMessage
  946. DEBUG_ERROR("InitShareMemory NG\n");
  947. #endif
  948. if(ShmStatusCodeData!=NULL)
  949. {
  950. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  951. }
  952. sleep(5);
  953. return FAIL;
  954. }
  955. return PASS;
  956. }
  957. //---------------------------------------------
  958. // new:
  959. // enum SYSTEM_STATUS
  960. // {
  961. // SYS_MODE_BOOTING = 0,
  962. // SYS_MODE_IDLE = 1,
  963. // SYS_MODE_AUTHORIZING = 2,
  964. // SYS_MODE_PREPARING = 3,
  965. // SYS_MODE_CHARGING = 4,
  966. // SYS_MODE_TERMINATING = 5,
  967. // SYS_MODE_ALARM = 6,
  968. // SYS_MODE_FAULT = 7,
  969. // SYS_MODE_RESERVATION = 8,
  970. // SYS_MODE_BOOKING = 9,
  971. // SYS_MODE_MAINTAIN = 10,
  972. // SYS_MODE_DEBUG = 11,
  973. // SYS_MODE_REASSIGN_CHECK = 12,
  974. // SYS_MODE_REASSIGN = 13,
  975. // SYS_MODE_PRECHARGE = 14,
  976. // SYS_MODE_PREPARING_EV = 15,
  977. // SYS_MODE_PREPARING_EVSE = 16,
  978. // SYS_MODE_COMPLETE = 17
  979. // };
  980. //
  981. // old:
  982. // enum _SYSTEM_STATUS
  983. // {
  984. // S_BOOTING = 0,
  985. // S_IDLE, =1
  986. // S_AUTHORIZING, =2
  987. // S_REASSIGN_CHECK, =3
  988. // S_REASSIGN, =4
  989. // S_PRECHARGE, =5
  990. // S_PREPARING_FOR_EV, =6
  991. // S_PREPARING_FOR_EVSE, =7
  992. // S_CHARGING, =8
  993. // S_TERMINATING, =9
  994. // S_COMPLETE, =10
  995. // S_ALARM, =11
  996. // S_FAULT =12
  997. // };
  998. //
  999. //-----------------------------------------
  1000. void CheckSystemValue(void)
  1001. {
  1002. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1003. int IdleModeCnt = 0;
  1004. char filenmae[100]={0};
  1005. char str[100]={0};
  1006. //===============================
  1007. // send Heartbeat
  1008. //===============================
  1009. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1010. {
  1011. //parameter for test
  1012. sendHeartbeatRequest(0);
  1013. //==============================================
  1014. // Reset Waiting Time
  1015. //==============================================
  1016. clientTime.Heartbeat=time((time_t*)NULL);
  1017. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1018. }
  1019. //==============================================
  1020. // Update firmware request
  1021. //==============================================
  1022. if(isUpdateRequest == TRUE )
  1023. {
  1024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1025. {
  1026. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1027. {
  1028. //check SystemStatus
  1029. /*************************DC*******************************/
  1030. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1031. {
  1032. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1033. {
  1034. IdleModeCnt = IdleModeCnt + 1;
  1035. }
  1036. }
  1037. for (int index = 0; index < CCS_QUANTITY; index++)
  1038. {
  1039. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1040. {
  1041. IdleModeCnt = IdleModeCnt + 1;
  1042. }
  1043. }
  1044. for (int index = 0; index < GB_QUANTITY; index++)
  1045. {
  1046. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1047. {
  1048. IdleModeCnt = IdleModeCnt + 1;
  1049. }
  1050. }
  1051. }
  1052. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1053. {
  1054. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1055. isUpdateRequest = FALSE;
  1056. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1057. }
  1058. }
  1059. else
  1060. {
  1061. /*************************AC*******************************/
  1062. for (int index = 0; index < AC_QUANTITY; index++)
  1063. {
  1064. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1065. {
  1066. IdleModeCnt = IdleModeCnt + 1;
  1067. }
  1068. }
  1069. if(IdleModeCnt == AC_QUANTITY)
  1070. {
  1071. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1072. isUpdateRequest = FALSE;
  1073. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1074. }
  1075. }
  1076. }
  1077. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1078. for(int gun_index=0;gun_index < gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY )*/ ;gun_index++)
  1079. {
  1080. //===============================
  1081. // CSU Trigger Reset Conf
  1082. //===============================
  1083. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1084. {
  1085. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1086. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1087. {
  1088. server_sign = FALSE;
  1089. }
  1090. }
  1091. //===============================
  1092. // CSU Trigger Authorize Request
  1093. //===============================
  1094. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1095. {
  1096. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1097. {
  1098. sendAuthorizeRequest(0);
  1099. authorizeRetryTimes = authorizeRetryTimes + 1;
  1100. // authenrequest = TRUE
  1101. if(authorizeRetryTimes < 3)
  1102. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1103. }
  1104. }
  1105. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1106. {
  1107. authorizeRetryTimes = 0;
  1108. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1109. server_sign = FALSE;
  1110. }
  1111. //==============================================
  1112. // Charger start transaction
  1113. //==============================================
  1114. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1115. {
  1116. sendStartTransactionRequest(gun_index);
  1117. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1118. clientTime.StartTransaction = time((time_t*)NULL);
  1119. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1120. }
  1121. //==============================================
  1122. // Charger stop transaction
  1123. //==============================================
  1124. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1125. {
  1126. sendStopTransactionRequest(gun_index);
  1127. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1128. clientTime.StopTransaction = time((time_t*)NULL);
  1129. }
  1130. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1131. //==============================================
  1132. // Charger status report
  1133. //==============================================
  1134. /* Check Mode Change */
  1135. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1136. {
  1137. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1138. {
  1139. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1140. {
  1141. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1142. {
  1143. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1144. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1145. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1146. statusModeChage[gun_index] = TRUE;
  1147. }
  1148. }
  1149. }
  1150. for (int index = 0; index < CCS_QUANTITY; index++)
  1151. {
  1152. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1153. {
  1154. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1155. {
  1156. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1157. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1158. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1159. statusModeChage[gun_index] = TRUE;
  1160. }
  1161. }
  1162. }
  1163. for (int index = 0; index < GB_QUANTITY; index++)
  1164. {
  1165. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1166. {
  1167. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1168. {
  1169. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1170. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1171. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1172. statusModeChage[gun_index] = TRUE;
  1173. }
  1174. }
  1175. }
  1176. }
  1177. else //AC
  1178. {
  1179. for (int index = 0; index < AC_QUANTITY; index++)
  1180. {
  1181. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1182. {
  1183. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1184. {
  1185. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1186. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1187. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1188. statusModeChage[gun_index] = TRUE;
  1189. }
  1190. }
  1191. }// END OF FOR
  1192. }// END OF ELSE
  1193. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1194. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1195. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1196. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1197. {
  1198. if(SystemInitial != 0)
  1199. SystemInitial = SystemInitial -1;
  1200. //GunStatusInterval= GunStatusInterval* gun_index;
  1201. sendStatusNotificationRequest(gun_index);
  1202. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1203. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1204. statusModeChage[gun_index] = FALSE;
  1205. //sleep(30); // sleep for 30 seconds
  1206. }
  1207. //==============================================
  1208. // Meter report
  1209. //==============================================
  1210. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1211. {
  1212. //check Transaction active
  1213. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1214. {
  1215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1216. {
  1217. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1218. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1219. {
  1220. meterValueSend[gun_index] =1;
  1221. }
  1222. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1223. {
  1224. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1225. if((access(filenmae,F_OK))!=-1)
  1226. {
  1227. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1228. sprintf(str,"rm -f %s",filenmae);
  1229. system(str);
  1230. }
  1231. }
  1232. }// End for CHAdeMO
  1233. for (int index = 0; index < CCS_QUANTITY; index++)
  1234. {
  1235. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1236. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1237. {
  1238. meterValueSend[gun_index] =1;
  1239. }
  1240. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1241. {
  1242. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1243. if((access(filenmae,F_OK))!=-1)
  1244. {
  1245. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1246. sprintf(str,"rm -f %s",filenmae);
  1247. system(str);
  1248. }
  1249. }
  1250. } // End for CCS
  1251. for (int index = 0; index < GB_QUANTITY; index++)
  1252. {
  1253. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1254. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1255. {
  1256. meterValueSend[gun_index] =1;
  1257. }
  1258. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1259. {
  1260. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1261. if((access(filenmae,F_OK))!=-1)
  1262. {
  1263. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1264. sprintf(str,"rm -f %s",filenmae);
  1265. system(str);
  1266. }
  1267. }
  1268. }// End for GB
  1269. }
  1270. else
  1271. {
  1272. for (int index = 0; index < AC_QUANTITY; index++)
  1273. {
  1274. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1275. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1276. {
  1277. meterValueSend[gun_index] =1;
  1278. }
  1279. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1280. {
  1281. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1282. if((access(filenmae,F_OK))!=-1)
  1283. {
  1284. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1285. sprintf(str,"rm -f %s",filenmae);
  1286. system(str);
  1287. }
  1288. }
  1289. }//End for AC
  1290. }//END OF ELSE
  1291. // sleep(1);
  1292. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1293. if(meterValueSend[gun_index] == 1)
  1294. sendMeterValuesRequest(gun_index);
  1295. }
  1296. //==============================================
  1297. // Check Connector reserved
  1298. //==============================================
  1299. //===============================
  1300. // Check if Reserve is expired
  1301. //===============================
  1302. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1303. {
  1304. double diff_t;
  1305. struct tm tp;
  1306. // current time
  1307. time_t t = time(NULL);
  1308. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1309. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1310. tp.tm_isdst = -1;
  1311. time_t utc = mktime(&tp);
  1312. diff_t = difftime(utc, t);
  1313. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1314. if(diff_t <= 0)
  1315. {
  1316. DEBUG_INFO("reserve expired !!! \n");
  1317. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1318. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1319. }
  1320. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1321. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1322. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1323. {
  1324. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1325. }
  1326. else
  1327. {
  1328. //check Transaction active
  1329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1330. {
  1331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1332. {
  1333. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1334. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1335. {
  1336. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1337. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1338. {
  1339. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1340. }
  1341. }
  1342. }
  1343. for (int index = 0; index < CCS_QUANTITY; index++)
  1344. {
  1345. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1346. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1347. {
  1348. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1349. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1350. {
  1351. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1352. }
  1353. }
  1354. }
  1355. for (int index = 0; index < GB_QUANTITY; index++)
  1356. {
  1357. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1358. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1359. {
  1360. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1361. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1362. {
  1363. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1364. }
  1365. }
  1366. }
  1367. }
  1368. else //AC
  1369. {
  1370. for (int index = 0; index < AC_QUANTITY; index++)
  1371. {
  1372. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1373. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1374. {
  1375. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1376. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1377. {
  1378. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1379. }
  1380. }
  1381. }
  1382. }// END OF ELSE
  1383. }// END OF check Transaction active
  1384. }//END OF Check if Reserve is expired
  1385. //==========================================
  1386. // csu trigger FirmwareStatusNotificationReq
  1387. //==========================================
  1388. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1389. {
  1390. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1391. }
  1392. //==========================================
  1393. // csu trigger CancelReservationConf
  1394. //==========================================
  1395. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1396. {
  1397. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1398. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1399. }
  1400. //==========================================
  1401. // csu trigger ChangeAvailabilityConf
  1402. //==========================================
  1403. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1404. {
  1405. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1406. }
  1407. //==========================================
  1408. // csu trigger UnlockConnectorConf
  1409. //==========================================
  1410. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1411. {
  1412. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1413. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1414. }
  1415. //==========================================
  1416. // csu trigger ReserveNowConf
  1417. //==========================================
  1418. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1419. {
  1420. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1421. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1422. }
  1423. //==========================================
  1424. // csu trigger DataTransferReq
  1425. //==========================================
  1426. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1427. {
  1428. sendDataTransferRequest(gun_index);
  1429. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1430. }
  1431. }
  1432. }
  1433. //==========================================
  1434. // send request routine
  1435. //==========================================
  1436. int sendAuthorizeRequest(int gun_index)
  1437. {
  1438. mtrace();
  1439. int result = FAIL;
  1440. char message[100]={0};
  1441. char guid[37];
  1442. char tempdata[65]={0};
  1443. DEBUG_INFO("sendAuthorizeRequest \n");
  1444. //Local Authorize
  1445. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1446. {
  1447. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1448. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1449. {
  1450. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1451. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1452. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1453. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1454. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1455. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1456. authorizeRetryTimes = 0;
  1457. return result;
  1458. }
  1459. else
  1460. {
  1461. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1462. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1463. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1464. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1465. result = PASS;
  1466. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1467. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1468. authorizeRetryTimes = 0;
  1469. return result;
  1470. }
  1471. }
  1472. //initailize struct Authorize
  1473. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1474. //get data from shared memory
  1475. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1476. random_uuid(guid);
  1477. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1478. LWS_Send(message);
  1479. sprintf(tempdata, "Authorize,%d", gun_index);
  1480. if(hashmap_operation(0, guid, tempdata) == 1)
  1481. {
  1482. result = PASS;
  1483. DEBUG_ERROR("Authorize mapItem pass\n");
  1484. }
  1485. //#ifdef SystemLogMessage
  1486. //DEBUG_INFO(">>>>>Authorize request\n");
  1487. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1488. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1489. //#endif
  1490. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1491. return result;
  1492. }
  1493. int sendBootNotificationRequest(void)
  1494. {
  1495. mtrace();
  1496. int result = FAIL;
  1497. char message[500]={0}, payload[700]={0};
  1498. char guid[37]={0};
  1499. char tempdata[65]={0};
  1500. int IsGunCharging = FALSE;
  1501. //check Transaction active
  1502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1503. {
  1504. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1505. {
  1506. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1507. {
  1508. IsGunCharging = TRUE;
  1509. }
  1510. }
  1511. for (int index = 0; index < CCS_QUANTITY; index++)
  1512. {
  1513. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1514. {
  1515. IsGunCharging = TRUE;
  1516. }
  1517. }
  1518. for (int index = 0; index < GB_QUANTITY; index++)
  1519. {
  1520. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1521. {
  1522. IsGunCharging = TRUE;
  1523. }
  1524. }
  1525. }
  1526. else
  1527. {
  1528. for (int index = 0; index < AC_QUANTITY; index++)
  1529. {
  1530. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1531. {
  1532. IsGunCharging = TRUE;
  1533. }
  1534. }
  1535. }
  1536. if(IsGunCharging == TRUE)
  1537. {
  1538. server_sign = TRUE;
  1539. return result;
  1540. }
  1541. // Fill BootNotification fields
  1542. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1543. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1544. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1545. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1546. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1547. ShmOCPP16Data->ChargeBoxId
  1548. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1549. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1550. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1551. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1552. ,ShmOCPP16Data->BootNotification.CpIccid
  1553. ,ShmOCPP16Data->BootNotification.CpImsi
  1554. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1555. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1556. random_uuid(guid);
  1557. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1558. LWS_Send(message);
  1559. sprintf(tempdata, "BootNotification,0");
  1560. 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*/)
  1561. {
  1562. result = PASS;
  1563. }
  1564. memset(queuedata, 0, sizeof(queuedata));
  1565. strcpy(queuedata,message);
  1566. //#ifdef SystemLogMessage
  1567. //DEBUG_INFO(">>>>>BootNotification request\n");
  1568. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1569. //#endif
  1570. return result;
  1571. }
  1572. int sendDataTransferRequest(int gun_index)
  1573. {
  1574. mtrace();
  1575. char message[1000]={0};
  1576. char guid[37]={0};
  1577. char tempdata[65]={0};
  1578. int result = FAIL;
  1579. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1580. random_uuid(guid);
  1581. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1582. MESSAGE_TYPE_CALL,
  1583. guid,
  1584. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1585. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1586. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1587. LWS_Send(message);
  1588. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1589. 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*/)
  1590. {
  1591. result = PASS;
  1592. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1593. }
  1594. //#ifdef SystemLogMessage
  1595. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1596. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1597. //#endif
  1598. return result;
  1599. }
  1600. int sendDiagnosticsStatusNotificationRequest(char *status)
  1601. {
  1602. mtrace();
  1603. int result = FAIL;
  1604. char message[110]={0};
  1605. char guid[37]={0};
  1606. char tempdata[65]={0};
  1607. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1608. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1609. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1610. random_uuid(guid);
  1611. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1612. LWS_Send(message);
  1613. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1614. if(hashmap_operation(0, guid, tempdata) == 1)
  1615. {
  1616. result = PASS;
  1617. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1618. }
  1619. //#ifdef SystemLogMessage
  1620. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1621. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1622. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1623. //#endif
  1624. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1625. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1626. //record status
  1627. if(strcmp(status,"Idle")==0)
  1628. {
  1629. DiagnosticsStatusNotificationStatus = 0;
  1630. }
  1631. else if(strcmp(status,"Uploaded")==0)
  1632. {
  1633. DiagnosticsStatusNotificationStatus = 1;
  1634. }
  1635. else if(strcmp(status,"UploadFailed")==0)
  1636. {
  1637. DiagnosticsStatusNotificationStatus = 2;
  1638. }
  1639. else if(strcmp(status,"Uploading")==0)
  1640. {
  1641. DiagnosticsStatusNotificationStatus = 3;
  1642. }
  1643. return result;
  1644. }
  1645. int sendFirmwareStatusNotificationRequest(char *status)
  1646. {
  1647. mtrace();
  1648. int result = FAIL;
  1649. char message[110]={0};
  1650. char guid[37]={0};
  1651. char tempdata[65]={0};
  1652. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1653. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1654. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1655. random_uuid(guid);
  1656. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1657. LWS_Send(message);
  1658. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1659. 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*/)
  1660. {
  1661. result = PASS;
  1662. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1663. }
  1664. //#ifdef SystemLogMessage
  1665. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1666. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1667. //#endif
  1668. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1669. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1670. //record status
  1671. if(strcmp(status,"Downloaded")==0)
  1672. {
  1673. FirmwareStatusNotificationStatus = 0;
  1674. }
  1675. else if(strcmp(status,"DownloadFailed")==0)
  1676. {
  1677. FirmwareStatusNotificationStatus = 1;
  1678. }
  1679. else if(strcmp(status,"Downloading")==0)
  1680. {
  1681. FirmwareStatusNotificationStatus = 2;
  1682. }
  1683. else if(strcmp(status,"Idle")==0)
  1684. {
  1685. FirmwareStatusNotificationStatus = 3;
  1686. }
  1687. else if(strcmp(status,"InstallationFailed")==0)
  1688. {
  1689. FirmwareStatusNotificationStatus = 4;
  1690. }
  1691. else if(strcmp(status,"Installing")==0)
  1692. {
  1693. FirmwareStatusNotificationStatus = 5;
  1694. }
  1695. else if(strcmp(status,"Installed")==0)
  1696. {
  1697. FirmwareStatusNotificationStatus = 6;
  1698. }
  1699. return result;
  1700. }
  1701. int sendHeartbeatRequest(int gun_index)
  1702. {
  1703. mtrace();
  1704. int result = FAIL;
  1705. char message[80]={0};
  1706. char guid[37]={0};
  1707. char tempdata[65]={0};
  1708. random_uuid(guid);
  1709. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1710. , MESSAGE_TYPE_CALL
  1711. , guid );
  1712. LWS_Send(message);
  1713. sprintf(tempdata, "Heartbeat,%d", 0);
  1714. 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*/)
  1715. {
  1716. result = PASS;
  1717. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1718. }
  1719. //#ifdef SystemLogMessage
  1720. //DEBUG_INFO(">>>>>Heartbeat request\n");
  1721. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1722. //#endif
  1723. return result;
  1724. }
  1725. int sendStartTransactionRequest(int gun_index)
  1726. {
  1727. mtrace();
  1728. int result = FAIL;
  1729. char message[250]={0};
  1730. char guid[37]={0};
  1731. struct timeval tmnow;
  1732. struct tm *tm;
  1733. char buf[30];//, usec_buf[6];
  1734. char tempdata[65]={0};
  1735. DEBUG_INFO("sendStartTransactionRequest...");
  1736. gettimeofday(&tmnow, NULL);
  1737. time_t t;
  1738. t = time(NULL);
  1739. /*UTC time and date*/
  1740. tm = gmtime(&t);
  1741. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1742. #if 0 // remove temporally
  1743. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1744. strcat(buf,".");
  1745. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1746. strcat(buf,usec_buf);
  1747. #endif
  1748. //printf("Start Charging Time :%s",buf);
  1749. // set value
  1750. if(ShmOCPP16Data->OcppConnStatus == 1 )
  1751. {
  1752. //memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1753. }
  1754. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1755. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1756. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1757. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1758. {
  1759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1760. {
  1761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1762. {
  1763. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1764. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1765. }
  1766. }
  1767. for (int index = 0; index < CCS_QUANTITY; index++)
  1768. {
  1769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1770. {
  1771. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1772. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1773. }
  1774. }
  1775. for (int index = 0; index < GB_QUANTITY; index++)
  1776. {
  1777. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1778. {
  1779. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1780. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1781. }
  1782. }
  1783. }
  1784. else
  1785. {
  1786. for (int index = 0; index < AC_QUANTITY; index++)
  1787. {
  1788. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1789. {
  1790. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1791. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1792. }
  1793. }
  1794. }//END OF ELSE
  1795. random_uuid(guid);
  1796. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1797. , MESSAGE_TYPE_CALL
  1798. , guid
  1799. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1800. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1801. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1802. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1803. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1804. LWS_Send(message);
  1805. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1806. 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*/)
  1807. {
  1808. result = PASS;
  1809. }
  1810. strcpy(queuedata, message);
  1811. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1812. //#ifdef SystemLogMessage
  1813. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1814. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1815. //#endif
  1816. return result;
  1817. }
  1818. int sendStatusNotificationRequest(int gun_index)
  1819. {
  1820. mtrace();
  1821. int result = FAIL;
  1822. char message[600]={0};
  1823. char guid[37];
  1824. int currentStatus = 0;
  1825. struct timeval tmnow;
  1826. struct tm *tm;
  1827. char buf[30];//, usec_buf[6];
  1828. char tempdata[65]={0};
  1829. gettimeofday(&tmnow, NULL);
  1830. time_t t;
  1831. t = time(NULL);
  1832. /*UTC time and date*/
  1833. tm = gmtime(&t);
  1834. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1835. #if 0 // remove temporally
  1836. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1837. strcat(buf,".");
  1838. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1839. strcat(buf,usec_buf);
  1840. #endif
  1841. printf("%s",buf);
  1842. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1843. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1844. // it's option
  1845. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1846. /*
  1847. enum _SYSTEM_STATUS
  1848. {
  1849. S_BOOTING = 0,
  1850. S_IDLE, = 1
  1851. S_AUTHORIZING, =2
  1852. S_REASSIGN_CHECK, =3
  1853. S_REASSIGN, =4
  1854. S_PRECHARGE, =5
  1855. S_PREPARING_FOR_EV, =6
  1856. S_PREPARING_FOR_EVSE, =7
  1857. S_CHARGING, =8
  1858. S_TERMINATING, =9
  1859. S_COMPLETE, =10
  1860. S_ALARM, =11
  1861. S_FAULT =12
  1862. }
  1863. */
  1864. //check Transaction active
  1865. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1866. {
  1867. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1868. {
  1869. //printf("gun_index=%d\n",gun_index);
  1870. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1871. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1872. {
  1873. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1874. currentStatus = 0; //OCPP Status
  1875. }
  1876. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1877. {
  1878. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1879. currentStatus = 1; //OCPP Status
  1880. }
  1881. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1882. {
  1883. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1884. currentStatus = 2; //OCPP Status
  1885. }
  1886. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1887. {
  1888. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1889. currentStatus = 5; //OCPP Status
  1890. }
  1891. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1892. {
  1893. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1894. currentStatus = 4; //OCPP Status
  1895. }
  1896. 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
  1897. {
  1898. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1899. currentStatus = 7; //OCPP Status: Unavailable
  1900. }
  1901. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1902. {
  1903. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1904. currentStatus = 8; //OCPP Status: Faulted
  1905. }
  1906. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1907. {
  1908. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1909. currentStatus = 6; //OCPP Status: Reserved
  1910. }
  1911. }//end of for CHAdeMO_QUANTITY
  1912. for (int index = 0; index < CCS_QUANTITY; index++)
  1913. {
  1914. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1915. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1916. {
  1917. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1918. currentStatus = 0; //OCPP Status
  1919. }
  1920. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1921. {
  1922. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1923. currentStatus = 1; //OCPP Status
  1924. }
  1925. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1926. {
  1927. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1928. currentStatus = 2; //OCPP Status
  1929. }
  1930. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1931. {
  1932. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1933. currentStatus = 5; //OCPP Status
  1934. }
  1935. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1936. {
  1937. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1938. currentStatus = 4; //OCPP Status
  1939. }
  1940. 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
  1941. {
  1942. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1943. currentStatus = 7; //OCPP Status
  1944. }
  1945. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1946. {
  1947. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1948. currentStatus = 8; //OCPP Status
  1949. }
  1950. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1951. {
  1952. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1953. currentStatus = 6; //OCPP Status
  1954. }
  1955. }
  1956. for (int index = 0; index < GB_QUANTITY; index++)
  1957. {
  1958. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1959. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1960. {
  1961. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1962. currentStatus = 0; //OCPP Status
  1963. }
  1964. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1965. {
  1966. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1967. currentStatus = 1; //OCPP Status
  1968. }
  1969. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1970. {
  1971. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1972. currentStatus = 2; //OCPP Status
  1973. }
  1974. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1975. {
  1976. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1977. currentStatus = 5; //OCPP Status
  1978. }
  1979. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1980. {
  1981. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1982. currentStatus = 4; //OCPP Status
  1983. }
  1984. 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
  1985. {
  1986. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1987. currentStatus = 7; //OCPP Status: Unavailable
  1988. }
  1989. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1990. {
  1991. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1992. currentStatus = 8; //OCPP Status: Faulted
  1993. }
  1994. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1995. {
  1996. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1997. currentStatus = 6; //OCPP Status: Faulted
  1998. }
  1999. }
  2000. }
  2001. else
  2002. {
  2003. for (int index = 0; index < AC_QUANTITY; index++)
  2004. {
  2005. //printf("gun_index=%d\n",gun_index);
  2006. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2007. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2008. {
  2009. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2010. currentStatus = 0; //OCPP Status
  2011. }
  2012. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2013. {
  2014. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2015. currentStatus = 1; //OCPP Status
  2016. }
  2017. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2018. {
  2019. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2020. currentStatus = 2; //OCPP Status
  2021. }
  2022. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2023. {
  2024. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2025. currentStatus = 5; //OCPP Status
  2026. }
  2027. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2028. {
  2029. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2030. currentStatus = 4; //OCPP Status
  2031. }
  2032. 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
  2033. {
  2034. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2035. currentStatus = 7; //OCPP Status: Unavailable
  2036. }
  2037. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2038. {
  2039. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2040. currentStatus = 8; //OCPP Status: Faulted
  2041. }
  2042. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2043. {
  2044. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2045. currentStatus = 6; //OCPP Status: Reserved
  2046. }
  2047. }//end of for AC_QUANTITY
  2048. }//END OF ELSE
  2049. //it's option
  2050. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2051. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2052. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2053. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2054. random_uuid(guid);
  2055. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2056. , MESSAGE_TYPE_CALL
  2057. , guid
  2058. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2059. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2060. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2061. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2062. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2063. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2064. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2065. LWS_Send(message);
  2066. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2067. 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*/)
  2068. {
  2069. //DEBUG_ERROR("statusNotification mapitem pass");
  2070. result = PASS;
  2071. }
  2072. //#ifdef SystemLogMessage
  2073. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2074. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2075. //#endif
  2076. return result;
  2077. }
  2078. int sendStopTransactionRequest(int gun_index)
  2079. {
  2080. mtrace();
  2081. int result = FAIL;
  2082. char message[1500]={0};
  2083. char guid[37]={0};
  2084. char tempdata[65]={0};
  2085. int idx_sample=0;
  2086. DEBUG_ERROR("sendStopTransactionRequest \n");
  2087. //memset(&(ShmOCPP16Data->StopTransaction[gun_index].TransactionData), 0, sizeof(struct StructMeterValue));
  2088. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId/*ShmOCPP16Data->Authorize.IdTag*/);
  2089. //ENERGY_ACTIVE_IMPORT_REGISTER
  2090. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2091. {
  2092. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2093. {
  2094. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2095. {
  2096. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2097. //Check Status
  2098. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2099. {
  2100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2101. }
  2102. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2103. }
  2104. }// END OF CHAdeMO_QUANTITY
  2105. for (int index = 0; index < CCS_QUANTITY; index++)
  2106. {
  2107. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2108. {
  2109. //for test
  2110. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2111. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2112. //Check Status
  2113. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2114. {
  2115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2116. }
  2117. else
  2118. {
  2119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2120. }
  2121. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2122. }
  2123. }// END OF CCS_QUANTITY
  2124. for (int index = 0; index < GB_QUANTITY; index++)
  2125. {
  2126. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2127. {
  2128. // for test
  2129. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2130. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2131. //Check Status
  2132. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2133. {
  2134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2135. }
  2136. else
  2137. {
  2138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2139. }
  2140. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2141. }
  2142. }// END OF GB_QUANTITY
  2143. }
  2144. else
  2145. {
  2146. for (int index = 0; index < AC_QUANTITY; index++)
  2147. {
  2148. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2149. {
  2150. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2151. //Check Status
  2152. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2153. {
  2154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2155. }
  2156. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2157. }
  2158. }// END OF AC_QUANTITY
  2159. }//END OF ELSE
  2160. //Stop Transaction Time
  2161. struct timeval tmnow;
  2162. struct tm *tm;
  2163. char buf[30];//, usec_buf[6];
  2164. gettimeofday(&tmnow, NULL);
  2165. time_t t;
  2166. t = time(NULL);
  2167. /*UTC time and date*/
  2168. tm = gmtime(&t);
  2169. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2170. #if 0 // remove temporally
  2171. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2172. strcat(buf,".");
  2173. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2174. strcat(buf,usec_buf);
  2175. #endif
  2176. printf("StopTransaction Time %s\n",buf);
  2177. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2179. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2180. random_uuid(guid);
  2181. sprintf(message,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":"
  2182. ,MESSAGE_TYPE_CALL
  2183. ,guid
  2184. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2185. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2186. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2187. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2188. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
  2189. /***********************************transactionData******************************************************/
  2190. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2191. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2192. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2193. {
  2194. //transactionData = json_object_new_object();
  2195. //json_object_object_add(transactionData, "timestamp", json_object_new_string("2019-05-04T18:15:33Z"));
  2196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp, buf/*"2019-05-04T18:15:33Z"*/);
  2197. sprintf(message + strlen(message), "[{\"timestamp\":\"%s\",\"sampledValue\":[", (const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp);
  2198. //=================================
  2199. // Transaction_Begin
  2200. //=================================
  2201. // Energy.Active.Export.Interval
  2202. idx_sample=0;
  2203. 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
  2204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2210. sprintf(message + strlen(message), "{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2211. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2212. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2213. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2214. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2215. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2216. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2217. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2218. );
  2219. //=================================
  2220. // Transaction_End
  2221. //=================================
  2222. //Current.Export
  2223. idx_sample=1;
  2224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2225. {
  2226. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2227. {
  2228. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2229. {
  2230. 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
  2231. }
  2232. }
  2233. for (int index = 0; index < CCS_QUANTITY; index++)
  2234. {
  2235. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2236. {
  2237. 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
  2238. }
  2239. }
  2240. for (int index = 0; index < GB_QUANTITY; index++)
  2241. {
  2242. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2243. {
  2244. 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
  2245. }
  2246. }
  2247. }
  2248. else
  2249. {
  2250. for (int index = 0; index < AC_QUANTITY; index++)
  2251. {
  2252. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2253. {
  2254. 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
  2255. }
  2256. }
  2257. }// END FOR AC ELSE
  2258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Current_Export/*Energy_Reactive_Export_Register*/]);
  2261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A/*UnitOfMeasure_kWh*/]);
  2264. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2265. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2266. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2267. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2268. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2269. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2270. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2271. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2272. );
  2273. //Energy.Active.Export.Interval
  2274. idx_sample=2;
  2275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2276. {
  2277. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2278. {
  2279. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2280. {
  2281. 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
  2282. }
  2283. }
  2284. for (int index = 0; index < CCS_QUANTITY; index++)
  2285. {
  2286. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2287. {
  2288. 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
  2289. }
  2290. }
  2291. for (int index = 0; index < GB_QUANTITY; index++)
  2292. {
  2293. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2294. {
  2295. 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
  2296. }
  2297. }
  2298. }
  2299. else
  2300. {
  2301. for (int index = 0; index < AC_QUANTITY; index++)
  2302. {
  2303. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2304. {
  2305. 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
  2306. }
  2307. }
  2308. }// END FOR AC ELSE
  2309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2315. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2316. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2317. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2318. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2319. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2320. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2321. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2322. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2323. );
  2324. //Power.Active.Export
  2325. idx_sample=3;
  2326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2327. {
  2328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2329. {
  2330. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2331. {
  2332. 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
  2333. }
  2334. }
  2335. for (int index = 0; index < CCS_QUANTITY; index++)
  2336. {
  2337. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2338. {
  2339. 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
  2340. }
  2341. }
  2342. for (int index = 0; index < GB_QUANTITY; index++)
  2343. {
  2344. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2345. {
  2346. 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
  2347. }
  2348. }
  2349. }
  2350. else
  2351. {
  2352. for (int index = 0; index < AC_QUANTITY; index++)
  2353. {
  2354. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2355. {
  2356. 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
  2357. }
  2358. }
  2359. }// END FOR AC ELSE
  2360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2366. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2367. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2368. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2369. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2370. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2371. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2372. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2373. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2374. );
  2375. //Voltage
  2376. idx_sample=4;
  2377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2378. {
  2379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2380. {
  2381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2382. {
  2383. 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
  2384. }
  2385. }
  2386. for (int index = 0; index < CCS_QUANTITY; index++)
  2387. {
  2388. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2389. {
  2390. 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
  2391. }
  2392. }
  2393. for (int index = 0; index < GB_QUANTITY; index++)
  2394. {
  2395. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2396. {
  2397. 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
  2398. }
  2399. }
  2400. }
  2401. else
  2402. {
  2403. for (int index = 0; index < AC_QUANTITY; index++)
  2404. {
  2405. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2406. {
  2407. 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
  2408. }
  2409. }
  2410. }// END FOR AC ELSE
  2411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2417. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2418. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2419. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2420. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2421. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2422. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2423. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2424. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2425. );
  2426. //SoC
  2427. idx_sample=5;
  2428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2429. {
  2430. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2431. {
  2432. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2433. {
  2434. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2435. }
  2436. }
  2437. for (int index = 0; index < CCS_QUANTITY; index++)
  2438. {
  2439. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2440. {
  2441. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2442. }
  2443. }
  2444. for (int index = 0; index < GB_QUANTITY; index++)
  2445. {
  2446. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2447. {
  2448. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2449. }
  2450. }
  2451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2457. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2458. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2459. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2460. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2461. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2462. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2463. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2464. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2465. );
  2466. } // END FOR DC CASE
  2467. sprintf(message + strlen(message)," ] } ] } ]");
  2468. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue);
  2469. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);
  2470. }
  2471. LWS_Send(message);
  2472. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2473. if(hashmap_operation(0, guid, tempdata) == 1)
  2474. {
  2475. result = PASS;
  2476. DEBUG_INFO("StopTransaction mapitem pass\n");
  2477. }
  2478. strcpy(queuedata, message);
  2479. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2480. //#ifdef SystemLogMessage
  2481. //DEBUG_INFO(">>>>>StopTransaction request\n");
  2482. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2483. //#endif
  2484. //for test
  2485. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2486. return result;
  2487. }
  2488. int sendMeterValuesRequest(int gun_index)
  2489. {
  2490. mtrace();
  2491. int result = FAIL;
  2492. char message[1500]={0};
  2493. char guid[37]={0};
  2494. int idx_sample=0;
  2495. //int length = 0;
  2496. char tempdata[65]={0};
  2497. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2498. DEBUG_ERROR("gun_index =%d\n",gun_index);
  2499. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2500. {
  2501. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2502. DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2503. DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2504. return result;
  2505. }
  2506. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2507. {
  2508. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2509. }
  2510. //set value
  2511. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2512. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2513. random_uuid(guid);
  2514. sprintf(message,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":"
  2515. ,MESSAGE_TYPE_CALL
  2516. ,guid
  2517. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2518. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId);
  2519. //,comfirmpayload);
  2520. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2521. {
  2522. //allocate memory space
  2523. //ShmOCPP16Data->MeterValues[gun_index].MeterValue = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2524. //UTC Date time
  2525. struct timeval tmnow;
  2526. struct tm *tm;
  2527. char buf[30];//, usec_buf[6];
  2528. gettimeofday(&tmnow, NULL);
  2529. time_t t;
  2530. t = time(NULL);
  2531. /*UTC time and date*/
  2532. tm = gmtime(&t);
  2533. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2534. #if 0 // remove temporally
  2535. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2536. strcat(buf,".");
  2537. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2538. strcat(buf,usec_buf);
  2539. #endif
  2540. // printf("%s",buf);
  2541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp, buf);
  2542. //allocate memory space
  2543. //ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*6);
  2544. sprintf(message + strlen(message),"[{\"timestamp\":\"%s\",\"sampledValue\":[",(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp);
  2545. idx_sample=0;
  2546. //********************************(1)Current.Export************************************************/
  2547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2548. {
  2549. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2550. {
  2551. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2552. {
  2553. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2554. }
  2555. }
  2556. for (int index = 0; index < CCS_QUANTITY; index++)
  2557. {
  2558. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2559. {
  2560. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2561. }
  2562. }
  2563. for (int index = 0; index < GB_QUANTITY; index++)
  2564. {
  2565. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2566. {
  2567. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2568. }
  2569. }
  2570. }
  2571. else
  2572. {
  2573. for (int index = 0; index < AC_QUANTITY; index++)
  2574. {
  2575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2576. {
  2577. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2578. }
  2579. }
  2580. }// END FOR AC ELSE
  2581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Current_Export]);
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2587. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2588. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2589. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2590. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2591. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2592. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2593. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2594. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2595. );
  2596. #if 0
  2597. idx_sample=1;
  2598. //****************************************************(2)Energy.Active.Export.Register*********************************************/
  2599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2600. {
  2601. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2602. {
  2603. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2604. {
  2605. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2606. }
  2607. }
  2608. for (int index = 0; index < CCS_QUANTITY; index++)
  2609. {
  2610. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2611. {
  2612. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2613. }
  2614. }
  2615. for (int index = 0; index < GB_QUANTITY; index++)
  2616. {
  2617. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2618. {
  2619. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2620. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2621. }
  2622. }
  2623. }
  2624. else
  2625. {
  2626. for (int index = 0; index < AC_QUANTITY; index++)
  2627. {
  2628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2629. {
  2630. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2631. }
  2632. }
  2633. }// END FOR AC ELSE
  2634. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2636. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Register]);
  2637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2640. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2641. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2642. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2643. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2644. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2645. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2646. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2647. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2648. );
  2649. #endif
  2650. idx_sample=1;
  2651. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2653. {
  2654. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2655. {
  2656. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2657. {
  2658. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2659. }
  2660. }
  2661. for (int index = 0; index < CCS_QUANTITY; index++)
  2662. {
  2663. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2664. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2665. {
  2666. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2667. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2668. }
  2669. }
  2670. for (int index = 0; index < GB_QUANTITY; index++)
  2671. {
  2672. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2673. {
  2674. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2675. }
  2676. }
  2677. }
  2678. else
  2679. {
  2680. for (int index = 0; index < AC_QUANTITY; index++)
  2681. {
  2682. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2683. {
  2684. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2685. }
  2686. }
  2687. }//END FOR AC ELSE
  2688. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2689. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2690. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2691. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2692. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2693. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2694. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2695. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2696. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2697. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2698. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2699. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2700. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2701. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2702. );
  2703. idx_sample=2;
  2704. //********************************(4)Power.Active.Export************************************************/
  2705. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2706. {
  2707. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2708. {
  2709. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2710. {
  2711. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2712. }
  2713. }
  2714. for (int index = 0; index < CCS_QUANTITY; index++)
  2715. {
  2716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2717. {
  2718. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2719. }
  2720. }
  2721. for (int index = 0; index < GB_QUANTITY; index++)
  2722. {
  2723. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2724. {
  2725. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2726. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2727. }
  2728. }
  2729. }
  2730. else
  2731. {
  2732. for (int index = 0; index < AC_QUANTITY; index++)
  2733. {
  2734. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2735. {
  2736. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2737. }
  2738. }
  2739. }// END FOR AC ELSE
  2740. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Power_Active_Export]);
  2743. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2744. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2745. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2746. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2747. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2748. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2749. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2750. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2751. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2752. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2753. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2754. );
  2755. idx_sample=3;
  2756. //***********************************************(5)VOLTAGE******************************************************/
  2757. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2758. {
  2759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2760. {
  2761. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2762. {
  2763. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2764. }
  2765. }
  2766. for (int index = 0; index < CCS_QUANTITY; index++)
  2767. {
  2768. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2769. {
  2770. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2771. }
  2772. }
  2773. for (int index = 0; index < GB_QUANTITY; index++)
  2774. {
  2775. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2776. {
  2777. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2778. }
  2779. }
  2780. }
  2781. else
  2782. {
  2783. for (int index = 0; index < AC_QUANTITY; index++)
  2784. {
  2785. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2786. {
  2787. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2788. }
  2789. }
  2790. }//END FOR AC ELSE
  2791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2792. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Voltage]);
  2794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2796. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2797. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2798. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2799. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2800. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2801. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2802. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2803. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2804. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2805. );
  2806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2807. {
  2808. idx_sample=4;
  2809. //sampledValue = NULL;
  2810. //***********************************************(6)SOC******************************************************/
  2811. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2812. {
  2813. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2814. {
  2815. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2816. }
  2817. }
  2818. for (int index = 0; index < CCS_QUANTITY; index++)
  2819. {
  2820. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2821. {
  2822. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2823. }
  2824. }
  2825. for (int index = 0; index < GB_QUANTITY; index++)
  2826. {
  2827. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2828. {
  2829. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2830. }
  2831. }
  2832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2833. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2834. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[SoC]);
  2835. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2837. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2838. sprintf(message + strlen(message),",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2839. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2840. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2841. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2842. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2843. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2844. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2845. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2846. );
  2847. }
  2848. //}
  2849. sprintf(message + strlen(message)," ] } ] } ]");
  2850. //free(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue);
  2851. }
  2852. LWS_Send(message);
  2853. //memset(mapItem, 0, sizeof(data_struct_t));
  2854. // Put request guid to hash map
  2855. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2856. 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*/)
  2857. {
  2858. result = PASS;
  2859. DEBUG_INFO("MeterValues mapitem pass\n");
  2860. }
  2861. strcpy(queuedata, message);
  2862. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2863. //#ifdef SystemLogMessage
  2864. //DEBUG_INFO(">>>>>MeerValues request\n");
  2865. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2866. //#endif
  2867. return result;
  2868. }
  2869. //==========================================
  2870. // send confirm routine
  2871. //==========================================
  2872. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2873. {
  2874. mtrace();
  2875. int result = FAIL;
  2876. char message[100]={0};
  2877. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2878. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2879. LWS_Send(message);
  2880. result = TRUE;
  2881. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2882. return result;
  2883. }
  2884. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2885. {
  2886. mtrace();
  2887. int result = FAIL;
  2888. char message[100]={0};
  2889. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2890. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2891. LWS_Send(message);
  2892. result = TRUE;
  2893. return result;
  2894. }
  2895. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2896. {
  2897. mtrace();
  2898. int result = FAIL;
  2899. char message[100]={0};
  2900. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2901. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2902. LWS_Send(message);
  2903. result = TRUE;
  2904. return result;
  2905. }
  2906. int sendClearCacheConfirmation(char *uuid,char *payload)
  2907. {
  2908. mtrace();
  2909. int result = FAIL;
  2910. char message[500]={0};
  2911. // int count = 0;
  2912. // int gun_index = 0;
  2913. // char guid[37];
  2914. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2915. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2916. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2917. LWS_Send(message);
  2918. return result;
  2919. }
  2920. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2921. {
  2922. mtrace();
  2923. int result = FAIL;
  2924. char message[500]={0};
  2925. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2926. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2927. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2928. LWS_Send(message);
  2929. return result;
  2930. }
  2931. int sendDataTransferConfirmation(char *uuid,char *payload)
  2932. {
  2933. mtrace();
  2934. char statusStr[20]={0};
  2935. char dataStr[10]={0};
  2936. char sstr[20]={0};
  2937. int c = 0;
  2938. char *loc;
  2939. int result = FAIL;
  2940. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2941. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2942. /**********************status**************************/
  2943. loc = strstr(payload, "status");
  2944. memset(sstr ,0, sizeof(sstr) );
  2945. c = 0;
  2946. while (loc[3+strlen("status")+c] != '\"')
  2947. {
  2948. sstr[c] = loc[3+strlen("status")+c];
  2949. c++;
  2950. }
  2951. sstr[c] = '\0';
  2952. strcpy(statusStr, sstr);
  2953. /**********************data**************************/
  2954. loc = strstr(payload, "data");
  2955. memset(sstr ,0, sizeof(sstr) );
  2956. c = 0;
  2957. while (loc[3+strlen("data")+c] != '\"')
  2958. {
  2959. sstr[c] = loc[3+strlen("data")+c];
  2960. c++;
  2961. }
  2962. sstr[c] = '\0';
  2963. strcpy(dataStr, sstr);
  2964. return result;
  2965. }
  2966. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2967. {
  2968. mtrace();
  2969. int result = FAIL;
  2970. char message[1000]={0};
  2971. double diff_f = 0.0;
  2972. int diff_i = 0;
  2973. struct tm tp;
  2974. int TimeZero = FALSE;
  2975. int CompositeScheduleIndex = 0;
  2976. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2977. if(connectorIdInt > 0)
  2978. {
  2979. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2980. {
  2981. TimeZero = TRUE;
  2982. }
  2983. else
  2984. {
  2985. strptime((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2986. }
  2987. }
  2988. else
  2989. {
  2990. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2991. {
  2992. TimeZero = TRUE;
  2993. }
  2994. else
  2995. {
  2996. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2997. }
  2998. }
  2999. DEBUG_INFO("ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule=%s\n",ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule);
  3000. if(TimeZero == FALSE)
  3001. {
  3002. tp.tm_isdst = -1;
  3003. time_t utc = mktime(&tp);
  3004. time_t t = time(NULL);
  3005. diff_f = difftime(t, utc);
  3006. diff_i = (int)diff_f;
  3007. }
  3008. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3009. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3010. #if 0 //remove temporally
  3011. 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}"
  3012. ,MESSAGE_TYPE_CALLRESULT
  3013. ,uuid
  3014. ,payload
  3015. ,connectorIdInt
  3016. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3017. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3018. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3019. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3020. #endif
  3021. if(nPeriod == 0)
  3022. {
  3023. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3024. ,MESSAGE_TYPE_CALLRESULT
  3025. ,uuid
  3026. ,payload
  3027. ,connectorIdInt
  3028. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3029. }
  3030. else
  3031. {
  3032. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3033. ,MESSAGE_TYPE_CALLRESULT
  3034. ,uuid
  3035. ,payload
  3036. ,connectorIdInt
  3037. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3038. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3039. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3040. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3041. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3042. #if 1 // remove temporally
  3043. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3044. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diff_i)
  3045. {
  3046. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3047. , 0
  3048. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3049. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3050. }
  3051. else
  3052. {
  3053. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3054. {
  3055. if (idx_sample == 0)
  3056. {
  3057. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3058. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  3059. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3060. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3061. }
  3062. else
  3063. {
  3064. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3065. , (((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diff_i /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diff_i /*-1*/))
  3066. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3067. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3068. }
  3069. }
  3070. }
  3071. #endif
  3072. sprintf(message + strlen(message), "]}}]");
  3073. }
  3074. LWS_Send(message);
  3075. result = TRUE;
  3076. return result;
  3077. }
  3078. int sendGetConfigurationConfirmation(char *uuid)
  3079. {
  3080. mtrace();
  3081. int result = FAIL;
  3082. int MaxKeySupported = 0;
  3083. int sentConfigurationNumber= 0;
  3084. int sentunConfigurationNumber= 0;
  3085. char message[4000]={0};
  3086. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3087. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3088. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3089. ,MESSAGE_TYPE_CALLRESULT
  3090. ,uuid );
  3091. //configuration key
  3092. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3093. {
  3094. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3095. {
  3096. if (sentConfigurationNumber == 0)
  3097. {
  3098. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3099. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3100. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3101. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3102. }
  3103. else
  3104. {
  3105. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3106. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3107. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3108. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3109. }
  3110. sentConfigurationNumber = sentConfigurationNumber + 1;
  3111. }
  3112. }
  3113. sprintf(message + strlen(message), "]");
  3114. if(UnknownKeynum != 0)
  3115. {
  3116. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3117. //unkown key
  3118. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3119. {
  3120. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3121. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3122. if(sentunConfigurationNumber == 0)
  3123. {
  3124. sprintf(message + strlen(message), "\"%s\""
  3125. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3126. }
  3127. else
  3128. {
  3129. sprintf(message + strlen(message), ",\"%s\""
  3130. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3131. }
  3132. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3133. }
  3134. sprintf(message + strlen(message), "]");
  3135. }
  3136. sprintf(message + strlen(message), "} ]");
  3137. LWS_Send(message);
  3138. #if 0
  3139. printf("error 1-0\n");
  3140. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3141. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3142. #endif
  3143. return result;
  3144. }
  3145. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3146. {
  3147. mtrace();
  3148. int result = FAIL;
  3149. char message[400]={0};
  3150. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3151. if(strcmp(payload,"")==0)
  3152. {
  3153. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3154. }
  3155. else
  3156. {
  3157. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3158. }
  3159. LWS_Send(message);
  3160. result = TRUE;
  3161. return result;
  3162. }
  3163. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3164. {
  3165. mtrace();
  3166. int result = FAIL;
  3167. char message[80]={0};
  3168. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3169. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3170. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3171. LWS_Send(message);
  3172. result = TRUE;
  3173. return result;
  3174. }
  3175. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3176. {
  3177. mtrace();
  3178. int result = FAIL;
  3179. char message[80]={0};
  3180. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3181. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3182. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3183. LWS_Send(message);
  3184. result = TRUE;
  3185. return result;
  3186. }
  3187. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3188. {
  3189. mtrace();
  3190. int result = FAIL;
  3191. char message[80]={0};
  3192. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3193. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3194. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3195. LWS_Send(message);
  3196. result = TRUE;
  3197. return result;
  3198. }
  3199. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3200. {
  3201. mtrace();
  3202. int result = FAIL;
  3203. char message[80]={0};
  3204. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3205. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3206. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3207. LWS_Send(message);
  3208. result = TRUE;
  3209. return result;
  3210. }
  3211. int sendResetConfirmation(char *uuid,char *payload)
  3212. {
  3213. mtrace();
  3214. int result = FAIL;
  3215. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3216. char message[80]={0};
  3217. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3218. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3219. LWS_Send(message);
  3220. result = TRUE;
  3221. return result;
  3222. }
  3223. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3224. {
  3225. mtrace();
  3226. int result = FAIL;
  3227. char message[500]={0};
  3228. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3229. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3230. LWS_Send(message);
  3231. result = TRUE;
  3232. return result;
  3233. }
  3234. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3235. {
  3236. mtrace();
  3237. int result = FAIL;
  3238. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3239. char message[80]={0};
  3240. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  3241. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3242. LWS_Send(message);
  3243. result = TRUE;
  3244. return result;
  3245. }
  3246. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3247. {
  3248. mtrace();
  3249. int result = FAIL;
  3250. char message[80]={0};
  3251. DEBUG_ERROR("sendTriggerMessageConfirmation\n");
  3252. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3253. LWS_Send(message);
  3254. result = TRUE;
  3255. return result;
  3256. }
  3257. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3258. {
  3259. mtrace();
  3260. int result = FAIL;
  3261. char message[80]={0};
  3262. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3263. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  3264. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3265. LWS_Send(message);
  3266. result = TRUE;
  3267. return result;
  3268. }
  3269. int sendUpdateFirmwareConfirmation(char *uuid)
  3270. {
  3271. mtrace();
  3272. int result = FAIL;
  3273. char message[60]={0};
  3274. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3275. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3276. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3277. LWS_Send(message);
  3278. result = TRUE;
  3279. return result;
  3280. }
  3281. //==========================================
  3282. // send CallError routine
  3283. //==========================================
  3284. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3285. {
  3286. mtrace();
  3287. //int result = FAIL;
  3288. char message[220]={0};
  3289. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3290. #ifdef SystemLogMessage
  3291. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3292. uniqueId, action, errorCode, errorDescription);
  3293. #endif
  3294. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3295. LWS_Send(message);
  3296. //result = TRUE;
  3297. }
  3298. //==========================================
  3299. // Handle server request routine Start
  3300. //==========================================
  3301. #define GUN_NUM 1
  3302. int handleCancelReservationRequest(char *uuid, char *payload)
  3303. {
  3304. mtrace();
  3305. int result = FAIL;
  3306. int gunNO = 0;
  3307. int reservationIdInt =0;
  3308. char comfirmstr[20];
  3309. int c = 0;
  3310. char *loc;
  3311. char sstr[100]={0};
  3312. DEBUG_INFO("handle CancelReservationRequest\n");
  3313. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3314. c = 0;
  3315. loc = strstr(payload, "reservationId");
  3316. memset(sstr ,0, sizeof(sstr) );
  3317. while (loc[strlen("reservationId")+2+c] != '}')
  3318. {
  3319. sstr[c] = loc[strlen("reservationId")+2+c];
  3320. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3321. c++;
  3322. }
  3323. sstr[c] = '\0';
  3324. reservationIdInt = atoi(sstr);
  3325. memset(comfirmstr, 0, sizeof comfirmstr);
  3326. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3327. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3328. //check Transaction active
  3329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3330. {
  3331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3332. {
  3333. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3334. {
  3335. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3336. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3337. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3338. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3339. goto end;
  3340. }
  3341. }
  3342. for (int index = 0; index < CCS_QUANTITY; index++)
  3343. {
  3344. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3345. {
  3346. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3347. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3348. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3349. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3350. goto end;
  3351. }
  3352. }
  3353. for (int index = 0; index < GB_QUANTITY; index++)
  3354. {
  3355. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3356. {
  3357. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3358. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3359. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3360. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3361. goto end;
  3362. }
  3363. }
  3364. }
  3365. else
  3366. {
  3367. for (int index = 0; index < AC_QUANTITY; index++)
  3368. {
  3369. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3370. {
  3371. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3372. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3373. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3374. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3375. goto end;
  3376. }
  3377. }
  3378. }// END FOR AC ELSE
  3379. //The reservationId does NOT match the reservationId
  3380. sendCancelReservationConfirmation(uuid, comfirmstr);
  3381. end:
  3382. // Fill in ocpp packet uuid
  3383. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3384. return result;
  3385. }
  3386. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3387. {
  3388. mtrace();
  3389. int result = FAIL;
  3390. int gunIndex = 0;
  3391. char sstr[90]={0};
  3392. char typeStr[16]={0};
  3393. char comfirmstr[20];
  3394. int specificId = FALSE;
  3395. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3396. char *loc;
  3397. //int intervalInt = 0;
  3398. int c = 0;
  3399. /*** connectorId ****/
  3400. c = 0;
  3401. loc = strstr(payload, "connectorId");
  3402. memset(sstr ,0, sizeof(sstr) );
  3403. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3404. {
  3405. sstr[c] = loc[strlen("connectorId")+2+c];
  3406. c++;
  3407. }
  3408. sstr[c] = '\0';
  3409. gunIndex = atoi(sstr);
  3410. /***type ****/
  3411. loc = strstr(payload, "type");
  3412. memset(sstr ,0, sizeof(sstr) );
  3413. c = 0;
  3414. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3415. {
  3416. sstr[c] = loc[3+strlen("type")+c];
  3417. c++;
  3418. }
  3419. sstr[c] = '\0';
  3420. strcpy(typeStr, sstr);
  3421. if(gunIndex != 0)
  3422. {
  3423. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3424. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3425. }
  3426. else
  3427. {
  3428. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3429. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3430. }
  3431. memset(comfirmstr, 0, sizeof comfirmstr);
  3432. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3433. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3434. {
  3435. specificId = TRUE;
  3436. }
  3437. if(specificId == FALSE)
  3438. goto end;
  3439. if(gunIndex != 0)
  3440. {
  3441. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3442. }
  3443. else
  3444. {
  3445. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3446. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3447. }
  3448. /*
  3449. enum _SYSTEM_STATUS
  3450. {
  3451. S_BOOTING = 0,
  3452. S_IDLE, = 1
  3453. S_AUTHORIZING, =2
  3454. S_REASSIGN_CHECK, =3
  3455. S_REASSIGN, =4
  3456. S_PRECHARGE, =5
  3457. S_PREPARING_FOR_EV, =6
  3458. S_PREPARING_FOR_EVSE, =7
  3459. S_CHARGING, =8
  3460. S_TERMINATING, =9
  3461. S_COMPLETE, =10
  3462. S_ALARM, =11
  3463. S_FAULT =12
  3464. }
  3465. */
  3466. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3467. {
  3468. //check Transaction active
  3469. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3470. {
  3471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3472. {
  3473. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3474. {
  3475. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3476. {
  3477. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3478. }
  3479. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3480. {
  3481. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3482. }
  3483. else
  3484. {
  3485. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3486. }
  3487. goto end;
  3488. }
  3489. }//END FOR CHAdeMO_QUANTITY
  3490. for (int index = 0; index < CCS_QUANTITY; index++)
  3491. {
  3492. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3493. {
  3494. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3495. {
  3496. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3497. }
  3498. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3499. {
  3500. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3501. }
  3502. else
  3503. {
  3504. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3505. }
  3506. goto end;
  3507. }
  3508. }//END FOR CCS_QUANTITY
  3509. for (int index = 0; index < GB_QUANTITY; index++)
  3510. {
  3511. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3512. {
  3513. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3514. {
  3515. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3516. }
  3517. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3518. {
  3519. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3520. }
  3521. else
  3522. {
  3523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3524. }
  3525. goto end;
  3526. }
  3527. }// END FOR GB_QUANTITY
  3528. }
  3529. else
  3530. {
  3531. for (int index = 0; index < AC_QUANTITY; index++)
  3532. {
  3533. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3534. {
  3535. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3536. {
  3537. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3538. }
  3539. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3540. {
  3541. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3542. }
  3543. else
  3544. {
  3545. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3546. }
  3547. goto end;
  3548. }
  3549. }//END FOR AC_QUANTITY
  3550. }// END FOR AC ELSE
  3551. }//END FOR AvailabilityTypeStr[Inoperative]
  3552. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3553. {
  3554. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3555. //check Transaction active
  3556. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3557. {
  3558. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3559. {
  3560. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3561. {
  3562. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3563. goto end;
  3564. }
  3565. }//END FOR CHAdeMO_QUANTITY
  3566. for (int index = 0; index < CCS_QUANTITY; index++)
  3567. {
  3568. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3569. {
  3570. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3571. goto end;
  3572. }
  3573. }//END FOR CCS_QUANTITY
  3574. for (int index = 0; index < GB_QUANTITY; index++)
  3575. {
  3576. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3577. {
  3578. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3579. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3580. goto end;
  3581. }
  3582. }// END FOR GB_QUANTITY
  3583. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3584. }
  3585. else
  3586. {
  3587. for (int index = 0; index < AC_QUANTITY; index++)
  3588. {
  3589. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3590. {
  3591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3592. goto end;
  3593. }
  3594. }//END FOR CHAdeMO_QUANTITY
  3595. }//END FOR AC ELSE
  3596. }//END FOR AvailabilityTypeStr[Operative]
  3597. end:
  3598. if(gunIndex != 0)
  3599. {
  3600. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3601. }
  3602. else
  3603. {
  3604. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3605. }
  3606. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3607. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3608. return result;
  3609. }
  3610. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3611. {
  3612. mtrace();
  3613. int result = FAIL;
  3614. char sstr[100]={0};
  3615. char keystr[40]={0};
  3616. char valuestr[16]={0};
  3617. char *loc;
  3618. int c = 0;
  3619. char comfirmstr[20];
  3620. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3621. /***key ****/
  3622. loc = strstr(payload, "key");
  3623. memset(sstr ,0, sizeof(sstr) );
  3624. c = 0;
  3625. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3626. {
  3627. sstr[c] = loc[3+strlen("key")+c];
  3628. c++;
  3629. }
  3630. sstr[c] = '\0';
  3631. strcpy(keystr, sstr);
  3632. /***value ****/
  3633. loc = strstr(payload, "value");
  3634. memset(sstr ,0, sizeof(sstr) );
  3635. c = 0;
  3636. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3637. {
  3638. sstr[c] = loc[3+strlen("value")+c];
  3639. c++;
  3640. }
  3641. sstr[c] = '\0';
  3642. strcpy(valuestr, sstr);
  3643. if((uuid==NULL) || (payload ==NULL) )
  3644. {
  3645. #ifdef Debug
  3646. DEBUG_INFO("payload is null\n");
  3647. #endif
  3648. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3649. }
  3650. else
  3651. {
  3652. int status = setKeyValue(keystr, valuestr);
  3653. switch(status)
  3654. {
  3655. case ConfigurationStatus_Accepted:
  3656. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3657. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3658. break;
  3659. case ConfigurationStatus_Rejected:
  3660. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3661. break;
  3662. case RebootRequired:
  3663. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3664. break;
  3665. case NotSupported:
  3666. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3667. break;
  3668. default:
  3669. break;
  3670. }
  3671. }
  3672. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3673. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3674. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3675. return result;
  3676. }
  3677. int handleClearCacheRequest(char *uuid, char *payload)
  3678. {
  3679. mtrace();
  3680. int result = FAIL;
  3681. char comfirmstr[20];
  3682. int fd;
  3683. char rmFileCmd[100]={0};
  3684. struct stat stats;
  3685. DEBUG_ERROR("handle ClearCacheRequest\n");
  3686. stat("../Storage/OCPP", &stats);
  3687. // Check for directory existence
  3688. if (S_ISDIR(stats.st_mode) == 1)
  3689. {
  3690. //DEBUG_ERROR("\n OCPP directory exist \n");
  3691. }
  3692. else
  3693. {
  3694. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3695. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3696. system(rmFileCmd);
  3697. }
  3698. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  3699. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3700. {
  3701. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3702. }
  3703. else
  3704. {
  3705. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3706. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3707. if(log == NULL)
  3708. {
  3709. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3710. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3711. goto end;
  3712. }
  3713. else
  3714. {
  3715. fclose(log);
  3716. }
  3717. }
  3718. fd = open(AuthorizationCache_JSON,O_RDWR);
  3719. if(fd < 0)
  3720. {
  3721. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3722. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3723. }
  3724. else
  3725. {
  3726. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3727. //* 清空?�件 */
  3728. ftruncate(fd,0);
  3729. //* ?�新设置?�件?�移??*/
  3730. lseek(fd,0,SEEK_SET);
  3731. close(fd);
  3732. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3733. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3734. }
  3735. end:
  3736. sendClearCacheConfirmation(uuid, comfirmstr);
  3737. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3738. return result;
  3739. }
  3740. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3741. {
  3742. mtrace();
  3743. int result = FAIL;
  3744. int resultRename;
  3745. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3746. char chargingProfilePurposeStr[26]={0};
  3747. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3748. char tempchargingProfilePurposeStr[26]={0};
  3749. char sstr[160]={0};//sstr[200]={ 0 };
  3750. char str[100]={0};
  3751. int c = 0;
  3752. //int i = 0;
  3753. //char * pch;
  3754. char *loc;
  3755. char fname[200];
  3756. char comfirmstr[20]={0};
  3757. char word[1000]={0};
  3758. int clearflag = FALSE;
  3759. int chargingProfileIdIsNULL = FALSE;
  3760. int connectorIsNULL = FALSE;
  3761. int chargingProfilePurposeIsNULL = FALSE;
  3762. int stackLevelIsNULL = FALSE;
  3763. FILE *fptr1, *fptr2;
  3764. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3765. int n_chargingProfile=0;
  3766. char sLineWord[1060]={0};
  3767. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3768. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3769. //***id ****/
  3770. c = 0;
  3771. loc = strstr(payload, "id");
  3772. memset(sstr ,0, sizeof(sstr) );
  3773. if(loc == NULL)
  3774. {
  3775. chargingProfileIdIsNULL = TRUE;
  3776. }
  3777. else
  3778. {
  3779. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3780. {
  3781. sstr[c] = loc[strlen("id")+2+c];
  3782. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3783. c++;
  3784. }
  3785. sstr[c] = '\0';
  3786. chargingProfileIdInt = atoi(sstr);
  3787. }
  3788. //***connectorId ****/
  3789. c=0;
  3790. loc = strstr(payload, "connectorId");
  3791. memset(sstr ,0, sizeof(sstr) );
  3792. if(loc == NULL)
  3793. {
  3794. connectorIsNULL = TRUE;
  3795. }
  3796. else
  3797. {
  3798. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3799. {
  3800. sstr[c] = loc[strlen("connectorId")+2+c];
  3801. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3802. c++;
  3803. }
  3804. sstr[c] = '\0';
  3805. connectorIdInt = atoi(sstr);
  3806. }
  3807. //***chargingProfilePurpose ****/
  3808. loc = strstr(payload, "chargingProfilePurpose");
  3809. memset(sstr ,0, sizeof(sstr) );
  3810. c = 0;
  3811. if(loc == NULL)
  3812. {
  3813. chargingProfilePurposeIsNULL = TRUE;
  3814. }
  3815. else
  3816. {
  3817. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3818. {
  3819. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3820. c++;
  3821. }
  3822. sstr[c] = '\0';
  3823. strcpy(chargingProfilePurposeStr, sstr);
  3824. }
  3825. //***stackLevel ****/
  3826. c=0;
  3827. loc = strstr(payload, "stackLevel");
  3828. memset(sstr ,0, sizeof(sstr) );
  3829. if(loc == NULL)
  3830. {
  3831. stackLevelIsNULL = TRUE;
  3832. }
  3833. else
  3834. {
  3835. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3836. {
  3837. sstr[c] = loc[strlen("stackLevel")+2+c];
  3838. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3839. c++;
  3840. }
  3841. sstr[c] = '\0';
  3842. stackLevelInt = atoi(sstr);
  3843. }
  3844. if(connectorIsNULL == FALSE)
  3845. {
  3846. switch(connectorIdInt)
  3847. {
  3848. case 0:
  3849. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3850. {
  3851. strcpy(fname, ChargePointMaxProfile_JSON);
  3852. }
  3853. // else
  3854. // {
  3855. // strcpy(fname, TxDefaultProfile_0_JSON);
  3856. // }
  3857. break;
  3858. case 1:
  3859. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3860. {
  3861. strcpy(fname, TxDefaultProfile_1_JSON);
  3862. }
  3863. // else
  3864. // {
  3865. // strcpy(fname, TxProfile_1_JSON);
  3866. // }
  3867. break;
  3868. case 2:
  3869. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3870. {
  3871. strcpy(fname, TxDefaultProfile_2_JSON);
  3872. }
  3873. // else
  3874. // {
  3875. // strcpy(fname, TxProfile_2_JSON);
  3876. // }
  3877. break;
  3878. default:
  3879. strcpy(fname, ChargePointMaxProfile_JSON );
  3880. break;
  3881. }
  3882. }
  3883. else
  3884. {
  3885. strcpy(fname, ChargePointMaxProfile_JSON );
  3886. }
  3887. fptr1 = fopen(fname, "r");
  3888. if (!fptr1)
  3889. {
  3890. //file not exist
  3891. DEBUG_ERROR("Unable to open the input file!!\n");
  3892. fptr1 = fopen(fname, "w+");
  3893. }
  3894. fclose(fptr1);
  3895. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3896. {
  3897. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3898. goto end;
  3899. }
  3900. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3901. {
  3902. //clear the whole contents of a file in C
  3903. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3904. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3905. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3906. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3907. fclose(fopen(TxProfile_1_JSON, "w"));
  3908. fclose(fopen(TxProfile_2_JSON, "w"));
  3909. #if 0
  3910. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3911. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3912. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3913. #endif
  3914. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3915. }
  3916. else
  3917. {
  3918. fptr1 = fopen(fname, "r");
  3919. fptr2 = fopen(temp, "w+");
  3920. while(fscanf(fptr1, "%s", word) != EOF)
  3921. {
  3922. //DEBUG_INFO("word=%s\n",word);
  3923. if(strcmp(word, "chargingProfileId") == 0)
  3924. {
  3925. n_chargingProfile = n_chargingProfile + 1;
  3926. DEBUG_INFO("chargingProfileId Found\n");
  3927. }
  3928. }
  3929. rewind(fptr1);
  3930. //search Charging Profile Element
  3931. //int i= 0;
  3932. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3933. {
  3934. //*************************tempconnectorIdInt*********************************/
  3935. loc = strstr(sLineWord, "connectorId");
  3936. c = 0;
  3937. memset(sstr ,0, sizeof(sstr) );
  3938. while (loc[strlen("connectorId")+2+c] != ',')
  3939. {
  3940. sstr[c] = loc[strlen("connectorId")+2+c];
  3941. c++;
  3942. }
  3943. sstr[c] = '\0';
  3944. tempconnectorIdInt = atoi(sstr);
  3945. //chargingProfileId
  3946. c = 0;
  3947. loc = strstr(sLineWord, "chargingProfileId");
  3948. memset(sstr ,0, sizeof(sstr) );
  3949. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3950. {
  3951. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3952. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3953. c++;
  3954. }
  3955. sstr[c] = '\0';
  3956. tempchargingProfileIdInt = atoi(sstr);
  3957. //stackLevel
  3958. c = 0;
  3959. loc = strstr(sLineWord, "stackLevel");
  3960. memset(sstr ,0, sizeof(sstr) );
  3961. while (loc[strlen("stackLevel")+2+c] != ',')
  3962. {
  3963. sstr[c] = loc[strlen("stackLevel")+2+c];
  3964. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3965. c++;
  3966. }
  3967. sstr[c] = '\0';
  3968. tempstackLevelInt = atoi(sstr);
  3969. c = 0;
  3970. loc = strstr(sLineWord, "chargingProfilePurpose");
  3971. memset(sstr ,0, sizeof(sstr) );
  3972. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3973. {
  3974. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3975. c++;
  3976. }
  3977. sstr[c] = '\0';
  3978. strcpy(tempchargingProfilePurposeStr, sstr);
  3979. if(chargingProfileIdIsNULL == FALSE)
  3980. {
  3981. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3982. {
  3983. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3984. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3985. clearflag = TRUE;
  3986. continue;
  3987. }
  3988. else
  3989. {
  3990. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3991. //json_object_array_add(newHeatMap, jsonitem);
  3992. fprintf(fptr2, sLineWord);//writing data into file
  3993. }
  3994. }
  3995. else
  3996. {
  3997. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3998. {
  3999. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  4000. {
  4001. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4002. clearflag = TRUE;
  4003. continue;
  4004. }
  4005. }
  4006. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4007. {
  4008. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  4009. {
  4010. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  4011. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  4012. {
  4013. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4014. clearflag = TRUE;
  4015. continue;
  4016. }
  4017. }
  4018. }
  4019. else
  4020. {
  4021. //json_object_array_add(newHeatMap, jsonitem);
  4022. fprintf(fptr2, sLineWord);//writing data into file
  4023. }
  4024. }
  4025. memset(sLineWord, 0, sizeof sLineWord);
  4026. }
  4027. if(clearflag == FALSE)
  4028. {
  4029. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4030. goto end;
  4031. }
  4032. fclose(fptr1);
  4033. fclose(fptr2);
  4034. sprintf(str,"rm -f %s",fname);
  4035. system(str);
  4036. resultRename = rename(temp, fname);
  4037. if(resultRename == 0)
  4038. {
  4039. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4040. }
  4041. else
  4042. {
  4043. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4044. }
  4045. }
  4046. end:
  4047. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4048. return result;
  4049. }
  4050. int handleDataTransferRequest(char *uuid, char *payload)
  4051. {
  4052. mtrace();
  4053. int result = FAIL;
  4054. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4055. char tempvendorId[255]={0};
  4056. char tempmessageId[50]={0};
  4057. char tempdata[50]={0};
  4058. char sstr[160]={0};//sstr[200]={ 0 };
  4059. char message[80]={0};
  4060. int c = 0;
  4061. char *loc;
  4062. DEBUG_INFO("handle DataTransferRequest\n");
  4063. if((uuid != NULL) && (payload != NULL))
  4064. {
  4065. //===============================
  4066. // vendorId
  4067. //===============================
  4068. c = 0;
  4069. loc = strstr(payload, "vendorId");
  4070. while (loc[strlen("vendorId")+3+c] != '\"')
  4071. {
  4072. sstr[c] = loc[strlen("vendorId")+3+c];
  4073. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4074. c++;
  4075. }
  4076. sstr[c] = '\0';
  4077. strcpy(tempvendorId,sstr);
  4078. //===============================
  4079. // messageId
  4080. //===============================
  4081. memset(sstr ,0, sizeof(sstr) );
  4082. c = 0;
  4083. loc = strstr(payload, "messageId");
  4084. while (loc[strlen("messageId")+3+c] != '\"')
  4085. {
  4086. sstr[c] = loc[strlen("messageId")+3+c];
  4087. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4088. c++;
  4089. }
  4090. sstr[c] = '\0';
  4091. strcpy(tempmessageId,sstr);
  4092. //===============================
  4093. // data
  4094. //===============================
  4095. memset(sstr ,0, sizeof(sstr) );
  4096. c = 0;
  4097. loc = strstr(payload, "data");
  4098. printf("loc=%s\n",loc);
  4099. while (loc[strlen("data")+3+c] != '\"')
  4100. {
  4101. sstr[c] = loc[strlen("data")+3+c];
  4102. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4103. c++;
  4104. }
  4105. sstr[c] = '\0';
  4106. strcpy(tempdata,sstr);
  4107. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4108. }
  4109. else
  4110. {
  4111. char guid[37]={0};
  4112. random_uuid(guid);
  4113. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4114. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4115. }
  4116. LWS_Send(message);
  4117. return result;
  4118. }
  4119. #if 0
  4120. long long diff_tm(struct tm *a, struct tm *b) {
  4121. return a->tm_sec - b->tm_sec
  4122. + 60LL * (a->tm_min - b->tm_min)
  4123. + 3600LL * (a->tm_hour - b->tm_hour)
  4124. + 86400LL * (a->tm_yday - b->tm_yday)
  4125. + (a->tm_year - 70) * 31536000LL
  4126. - (a->tm_year - 69) / 4 * 86400LL
  4127. + (a->tm_year - 1) / 100 * 86400LL
  4128. - (a->tm_year + 299) / 400 * 86400LL
  4129. - (b->tm_year - 70) * 31536000LL
  4130. + (b->tm_year - 69) / 4 * 86400LL
  4131. - (b->tm_year - 1) / 100 * 86400LL
  4132. + (b->tm_year + 299) /400 * 86400LL;
  4133. }
  4134. #endif
  4135. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4136. {
  4137. mtrace();
  4138. int result = FAIL;
  4139. int connectorIdInt, durationInt;
  4140. char chargingRateUnitStr[4]={0};
  4141. //int tempconnectorIdInt,
  4142. int tempdurationInt;
  4143. float tempminChargingRateFloat = 0.0;
  4144. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4145. int tempStartPeriodInt=0;
  4146. float tempLimitInt=0.0;//0.1;
  4147. int tempNumberPhasesInt=0;
  4148. char fname[200];
  4149. char comfirmstr[20];
  4150. //float totallimit =0.0;
  4151. float MinChargingRate =0.0;
  4152. double diff_t;
  4153. struct tm tp;
  4154. //int clearflag = FALSE;
  4155. FILE *fptr1;//, *fptr2;
  4156. //char temp[] = "../Storage/OCPP/temp.json";
  4157. int c = 0;
  4158. //int i = 0;
  4159. char * pch;
  4160. char *loc;
  4161. char sstr[200]={ 0 };
  4162. int n_chargingProfile = 0;
  4163. int n_SchedulePeriods = 0;
  4164. char SchedulePeriodList[10][200]={0};
  4165. char sLineWord[800]={0};
  4166. //int n_periods = 0;
  4167. char word[1000]={0};
  4168. int confirmPeriods = 0;
  4169. struct StructProfile ChargePointMaxProfile;
  4170. struct StructProfile TxDefaultProfile;
  4171. struct StructProfile TxProfile;
  4172. struct StructProfile TxDefaultProfiletemp[2]={0};
  4173. int TxDefaultProfileFileIsNull=FALSE;
  4174. int ChargePointMaxProfileIsNull=FALSE;
  4175. int TxProfileIsNull=FALSE;
  4176. int CompositeSceduleIndex = 0;
  4177. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4178. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4179. memset(&TxProfile,0,sizeof(struct StructProfile));
  4180. DEBUG_INFO("handleGetCompositeScheduleRequest 1\n");
  4181. c=0;
  4182. loc = strstr(payload, "connectorId");
  4183. memset(sstr ,0, sizeof(sstr) );
  4184. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4185. {
  4186. sstr[c] = loc[strlen("connectorId")+2+c];
  4187. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4188. c++;
  4189. }
  4190. sstr[c] = '\0';
  4191. connectorIdInt = atoi(sstr);
  4192. c=0;
  4193. loc = strstr(payload, "duration");
  4194. memset(sstr ,0, sizeof(sstr) );
  4195. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4196. {
  4197. sstr[c] = loc[strlen("duration")+2+c];
  4198. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4199. c++;
  4200. }
  4201. sstr[c] = '\0';
  4202. durationInt = atoi(sstr);
  4203. c = 0;
  4204. loc = strstr(payload, "chargingRateUnit");
  4205. memset(sstr ,0, sizeof(sstr) );
  4206. if(loc == NULL)
  4207. {
  4208. }
  4209. else
  4210. {
  4211. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4212. {
  4213. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4214. c++;
  4215. }
  4216. sstr[c] = '\0';
  4217. strcpy(chargingRateUnitStr, sstr);
  4218. }
  4219. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4220. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4221. DEBUG_INFO("handleGetCompositeScheduleRequest 2\n");
  4222. if(connectorIdInt==0) // connectorId is 0
  4223. {
  4224. //******************************ChargePointMaxProfile*****************************************************/
  4225. strcpy(fname, ChargePointMaxProfile_JSON );
  4226. char word[30]={0};
  4227. char sLineWord[1060]={0};
  4228. int n_chargingProfile=0;
  4229. ChargePointMaxProfileIsNull=TRUE;
  4230. if((access(fname,F_OK))!=-1)
  4231. {
  4232. fptr1 = fopen(fname, "r");
  4233. int c;
  4234. c = fgetc(fptr1);
  4235. //DEBUG_INFO("c:%d\n",c);
  4236. rewind(fptr1);
  4237. if(c == EOF)
  4238. {
  4239. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4240. ChargePointMaxProfileIsNull=TRUE;
  4241. fclose(fptr1);
  4242. }
  4243. else
  4244. {
  4245. ChargePointMaxProfileIsNull=FALSE;
  4246. while(fscanf(fptr1, "%s", word) != EOF)
  4247. {
  4248. if(strcmp(word, "chargingProfileId") == 0)
  4249. {
  4250. n_chargingProfile = n_chargingProfile + 1;
  4251. printf("Found\n");
  4252. }
  4253. }
  4254. rewind(fptr1);
  4255. //search Charging Profile Element
  4256. int i= 0;
  4257. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4258. #if 0
  4259. /***********connectorId****************/
  4260. c = 0;
  4261. loc = strstr(sLineWord, "connectorId");
  4262. // printf("loc=%s\n",loc);
  4263. memset(sstr ,0, sizeof(sstr) );
  4264. while (loc[strlen("connectorId")+2+c] != ',')
  4265. {
  4266. sstr[c] = loc[strlen("connectorId")+2+c];
  4267. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4268. c++;
  4269. }
  4270. sstr[c] = '\0';
  4271. tempconnectorIdInt = atoi(sstr);
  4272. #endif
  4273. //***********validFrom**************/
  4274. c = 0;
  4275. loc = strstr(sLineWord, "validFrom");
  4276. //DEBUG_INFO("loc=%s\n",loc);
  4277. memset(sstr ,0, sizeof(sstr) );
  4278. if(loc != NULL)
  4279. {
  4280. while (loc[3+strlen("validFrom")+c] != '\"')
  4281. {
  4282. sstr[c] = loc[3+strlen("validFrom")+c];
  4283. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4284. c++;
  4285. }
  4286. sstr[c] = '\0';
  4287. DEBUG_INFO("validFrom=%s\n",sstr);
  4288. strcpy(tempvalidFromStr,sstr);
  4289. }
  4290. else
  4291. {
  4292. strcpy(tempvalidFromStr,"");
  4293. }
  4294. //**********startSchedule**********/
  4295. c = 0;
  4296. loc = strstr(sLineWord, "startSchedule");
  4297. //DEBUG_INFO("loc=%s\n",loc);
  4298. memset(sstr ,0, sizeof(sstr) );
  4299. while (loc[3+strlen("startSchedule")+c] != '\"')
  4300. {
  4301. sstr[c] = loc[3+strlen("startSchedule")+c];
  4302. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4303. c++;
  4304. }
  4305. sstr[c] = '\0';
  4306. strcpy(tempstartScheduleStr, sstr);
  4307. //**********startSchedule**********/
  4308. c = 0;
  4309. loc = strstr(sLineWord, "chargingRateUnit");
  4310. memset(sstr ,0, sizeof(sstr) );
  4311. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4312. {
  4313. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4314. c++;
  4315. }
  4316. sstr[c] = '\0';
  4317. strcpy(tempchargingRateUnitStr, sstr);
  4318. //**********minChargingRate*******/
  4319. c = 0;
  4320. loc = strstr(sLineWord, "minChargingRate");
  4321. //printf("loc=%s\n",loc);
  4322. if(loc != NULL)
  4323. {
  4324. memset(sstr ,0, sizeof(sstr) );
  4325. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4326. {
  4327. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4328. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4329. c++;
  4330. }
  4331. sstr[c] = '\0';
  4332. tempminChargingRateFloat = atof(sstr);
  4333. }
  4334. else
  4335. {
  4336. tempminChargingRateFloat = 0.0;
  4337. }
  4338. //
  4339. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4340. tp.tm_isdst = -1;
  4341. time_t utc = mktime(&tp);
  4342. // current time
  4343. time_t t = time(NULL);
  4344. diff_t = difftime(t, utc);
  4345. //parsing strings to words
  4346. i = 0;
  4347. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4348. loc = loc+3+strlen("chargingSchedulePeriod");
  4349. pch = strtok(loc ,"{");
  4350. while (pch != NULL)
  4351. {
  4352. strcpy(SchedulePeriodList[i], pch);
  4353. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4354. //printf ("%s\n",pch);
  4355. pch = strtok (NULL, "{");
  4356. i = i + 1;
  4357. }
  4358. n_SchedulePeriods = i;
  4359. for(int i=0;i<n_SchedulePeriods;i++)
  4360. {
  4361. //*************startPeriod****************/
  4362. c = 0;
  4363. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4364. memset(sstr ,0, sizeof(sstr) );
  4365. while (loc[strlen("startPeriod")+2+c] != ',')
  4366. {
  4367. sstr[c] = loc[strlen("startPeriod")+2+c];
  4368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4369. c++;
  4370. }
  4371. sstr[c] = '\0';
  4372. tempStartPeriodInt = atoi(sstr);
  4373. //*************limit****************/
  4374. c = 0;
  4375. loc = strstr(SchedulePeriodList[i], "limit");
  4376. memset(sstr ,0, sizeof(sstr) );
  4377. while (loc[strlen("limit")+2+c] != ',')
  4378. {
  4379. sstr[c] = loc[strlen("limit")+2+c];
  4380. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4381. c++;
  4382. }
  4383. sstr[c] = '\0';
  4384. tempLimitInt = atof(sstr);
  4385. //*************numberPhases****************/
  4386. c = 0;
  4387. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4388. memset(sstr ,0, sizeof(sstr) );
  4389. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4390. {
  4391. sstr[c] = loc[strlen("numberPhases")+2+c];
  4392. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4393. c++;
  4394. }
  4395. sstr[c] = '\0';
  4396. tempNumberPhasesInt = atoi(sstr);
  4397. ChargePointMaxProfile.Duration = durationInt;
  4398. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4399. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4400. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4401. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4402. }
  4403. if(MinChargingRate < tempminChargingRateFloat)
  4404. MinChargingRate = tempminChargingRateFloat;
  4405. }
  4406. }// End of file ChargingProfile
  4407. } //THE END OF ACCESS ChargePointMaxProfile
  4408. //******************************TxDefaultProfile***********************************************/
  4409. strcpy(fname, TxDefaultProfile_0_JSON);
  4410. memset(word, 0, 30);
  4411. memset(sLineWord, 0, 1060);
  4412. //char word[30]={0};
  4413. //char sLineWord[1060]={0};
  4414. n_chargingProfile=0;
  4415. TxDefaultProfileFileIsNull=TRUE;
  4416. if((access(fname,F_OK))!=-1)
  4417. {
  4418. fptr1 = fopen(fname, "r");
  4419. c = 0;
  4420. c = fgetc(fptr1);
  4421. //DEBUG_INFO("c:%d\n",c);
  4422. rewind(fptr1);
  4423. if(c == EOF)
  4424. {
  4425. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4426. TxDefaultProfileFileIsNull=TRUE;
  4427. fclose(fptr1);
  4428. }
  4429. else
  4430. {
  4431. TxDefaultProfileFileIsNull=FALSE;
  4432. while(fscanf(fptr1, "%s", word) != EOF)
  4433. {
  4434. if(strcmp(word, "chargingProfileId") == 0)
  4435. {
  4436. n_chargingProfile = n_chargingProfile + 1;
  4437. printf("Found\n");
  4438. }
  4439. }
  4440. rewind(fptr1);
  4441. //search Charging Profile Element
  4442. int i= 0;
  4443. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4444. #if 0
  4445. /***********connectorId****************/
  4446. c = 0;
  4447. loc = strstr(sLineWord, "connectorId");
  4448. // printf("loc=%s\n",loc);
  4449. memset(sstr ,0, sizeof(sstr) );
  4450. while (loc[strlen("connectorId")+2+c] != ',')
  4451. {
  4452. sstr[c] = loc[strlen("connectorId")+2+c];
  4453. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4454. c++;
  4455. }
  4456. sstr[c] = '\0';
  4457. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4458. tempconnectorIdInt = atoi(sstr);
  4459. #endif
  4460. //***********validFrom**************/
  4461. c = 0;
  4462. loc = strstr(sLineWord, "validFrom");
  4463. //DEBUG_INFO("loc=%s\n",loc);
  4464. memset(sstr ,0, sizeof(sstr) );
  4465. if(loc != NULL)
  4466. {
  4467. while (loc[3+strlen("validFrom")+c] != '\"')
  4468. {
  4469. sstr[c] = loc[3+strlen("validFrom")+c];
  4470. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4471. c++;
  4472. }
  4473. sstr[c] = '\0';
  4474. DEBUG_INFO("validFrom=%s\n",sstr);
  4475. strcpy(tempvalidFromStr,sstr);
  4476. }
  4477. else
  4478. {
  4479. strcpy(tempvalidFromStr,"");
  4480. }
  4481. //**********startSchedule**********/
  4482. c = 0;
  4483. loc = strstr(sLineWord, "startSchedule");
  4484. //DEBUG_INFO("loc=%s\n",loc);
  4485. memset(sstr ,0, sizeof(sstr) );
  4486. while (loc[3+strlen("startSchedule")+c] != '\"')
  4487. {
  4488. sstr[c] = loc[3+strlen("startSchedule")+c];
  4489. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4490. c++;
  4491. }
  4492. sstr[c] = '\0';
  4493. strcpy(tempstartScheduleStr, sstr);
  4494. DEBUG_INFO(" debug 3-1\n");
  4495. //**********startSchedule**********/
  4496. c = 0;
  4497. loc = strstr(sLineWord, "chargingRateUnit");
  4498. memset(sstr ,0, sizeof(sstr) );
  4499. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4500. {
  4501. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4502. c++;
  4503. }
  4504. sstr[c] = '\0';
  4505. strcpy(tempchargingRateUnitStr, sstr);
  4506. //**********minChargingRate*******/
  4507. c = 0;
  4508. loc = strstr(sLineWord, "minChargingRate");
  4509. //printf("loc=%s\n",loc);
  4510. if(loc != NULL)
  4511. {
  4512. memset(sstr ,0, sizeof(sstr) );
  4513. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4514. {
  4515. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4516. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4517. c++;
  4518. }
  4519. sstr[c] = '\0';
  4520. tempminChargingRateFloat = atof(sstr);
  4521. }
  4522. else
  4523. {
  4524. tempminChargingRateFloat = 0.0;
  4525. }
  4526. //
  4527. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4528. tp.tm_isdst = -1;
  4529. time_t utc = mktime(&tp);
  4530. // current time
  4531. time_t t = time(NULL);
  4532. diff_t = difftime(t, utc);
  4533. //parsing strings to words
  4534. i = 0;
  4535. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4536. loc = loc+3+strlen("chargingSchedulePeriod");
  4537. pch = strtok(loc ,"{");
  4538. while (pch != NULL)
  4539. {
  4540. strcpy(SchedulePeriodList[i], pch);
  4541. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4542. //printf ("%s\n",pch);
  4543. pch = strtok (NULL, "{");
  4544. i = i + 1;
  4545. }
  4546. n_SchedulePeriods = i;
  4547. for(int i=0;i<n_SchedulePeriods;i++)
  4548. {
  4549. //*************startPeriod****************/
  4550. c = 0;
  4551. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4552. memset(sstr ,0, sizeof(sstr) );
  4553. while (loc[strlen("startPeriod")+2+c] != ',')
  4554. {
  4555. sstr[c] = loc[strlen("startPeriod")+2+c];
  4556. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4557. c++;
  4558. }
  4559. sstr[c] = '\0';
  4560. tempStartPeriodInt = atoi(sstr);
  4561. //*************limit****************/
  4562. c = 0;
  4563. loc = strstr(SchedulePeriodList[i], "limit");
  4564. memset(sstr ,0, sizeof(sstr) );
  4565. while (loc[strlen("limit")+2+c] != ',')
  4566. {
  4567. sstr[c] = loc[strlen("limit")+2+c];
  4568. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4569. c++;
  4570. }
  4571. sstr[c] = '\0';
  4572. tempLimitInt = atof(sstr);
  4573. //*************numberPhases****************/
  4574. c = 0;
  4575. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4576. memset(sstr ,0, sizeof(sstr) );
  4577. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4578. {
  4579. sstr[c] = loc[strlen("numberPhases")+2+c];
  4580. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4581. c++;
  4582. }
  4583. sstr[c] = '\0';
  4584. tempNumberPhasesInt = atoi(sstr);
  4585. TxDefaultProfile.Duration = durationInt;
  4586. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4587. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4588. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4589. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4590. }
  4591. if(MinChargingRate < tempminChargingRateFloat)
  4592. MinChargingRate = tempminChargingRateFloat;
  4593. }
  4594. }
  4595. }// the end of ACCESS TxDefaultProfile
  4596. // Composite Schedule
  4597. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4598. {
  4599. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4600. {
  4601. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4602. {
  4603. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4604. }
  4605. else
  4606. {
  4607. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4608. }
  4609. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4610. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4611. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4612. }
  4613. }
  4614. //* Define temporary variables */
  4615. struct tm *gtime;
  4616. time_t now;
  4617. char buf[28];
  4618. /* Read the current system time */
  4619. time(&now);
  4620. /* Convert the system time to GMT (now UTC) */
  4621. gtime = gmtime(&now);
  4622. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4623. // make .conf
  4624. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4625. //MaxChargingProfilesInstalled is 10
  4626. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4627. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4628. //nPeriod = 1;
  4629. if(chargingRateUnitStr[0] != 0)
  4630. {
  4631. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4632. }
  4633. else
  4634. {
  4635. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4636. }
  4637. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4638. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4639. confirmPeriods = 1;
  4640. }
  4641. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4642. {
  4643. //*****************************ChargePointMaxProfile******************************************/
  4644. DEBUG_INFO("handleGetCompositeScheduleRequest 3\n");
  4645. strcpy(fname, ChargePointMaxProfile_JSON);
  4646. ChargePointMaxProfileIsNull=TRUE;
  4647. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4648. {
  4649. fptr1 = fopen(fname, "r");
  4650. int c;
  4651. c = fgetc(fptr1);
  4652. //DEBUG_INFO("c:%d\n",c);
  4653. rewind(fptr1);
  4654. if(c == EOF)
  4655. {
  4656. DEBUG_INFO("\n End of file reached.");
  4657. ChargePointMaxProfileIsNull=TRUE;
  4658. fclose(fptr1);
  4659. }
  4660. else
  4661. {
  4662. ChargePointMaxProfileIsNull=FALSE;
  4663. while(fscanf(fptr1, "%s", word) != EOF)
  4664. {
  4665. if(strcmp(word, "chargingProfileId") == 0)
  4666. {
  4667. n_chargingProfile = n_chargingProfile + 1;
  4668. }
  4669. }
  4670. rewind(fptr1);
  4671. //search Charging Profile Element
  4672. int i = 0;
  4673. int j = 0;
  4674. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4675. #if 0
  4676. /***********connectorId****************/
  4677. c = 0;
  4678. loc = strstr(sLineWord, "connectorId");
  4679. memset(sstr ,0, sizeof(sstr) );
  4680. while (loc[strlen("connectorId")+2+c] != ',')
  4681. {
  4682. sstr[c] = loc[strlen("connectorId")+2+c];
  4683. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4684. c++;
  4685. }
  4686. sstr[c] = '\0';
  4687. tempconnectorIdInt = atoi(sstr);
  4688. #endif
  4689. //***********validFrom**************/
  4690. c = 0;
  4691. loc = strstr(sLineWord, "validFrom");
  4692. if(loc != NULL)
  4693. {
  4694. memset(sstr ,0, sizeof(sstr) );
  4695. while (loc[3+strlen("validFrom")+c] != '\"')
  4696. {
  4697. sstr[c] = loc[3+strlen("validFrom")+c];
  4698. c++;
  4699. }
  4700. sstr[c] = '\0';
  4701. strcpy(tempvalidFromStr,sstr);
  4702. }
  4703. else
  4704. {
  4705. strcpy(tempvalidFromStr,"");
  4706. }
  4707. //***********validFrom**************/
  4708. c = 0;
  4709. loc = strstr(sLineWord, "duration");
  4710. if(loc != NULL)
  4711. {
  4712. memset(sstr ,0, sizeof(sstr) );
  4713. while (loc[2+strlen("duration")+c] != ',')
  4714. {
  4715. sstr[c] = loc[2+strlen("duration")+c];
  4716. c++;
  4717. }
  4718. sstr[c] = '\0';
  4719. tempdurationInt = atoi(sstr);
  4720. }
  4721. else
  4722. {
  4723. tempdurationInt = 0;
  4724. }
  4725. //**********startSchedule**********/
  4726. c = 0;
  4727. loc = strstr(sLineWord, "startSchedule");
  4728. memset(sstr ,0, sizeof(sstr) );
  4729. while (loc[3+strlen("startSchedule")+c] != '\"')
  4730. {
  4731. sstr[c] = loc[3+strlen("startSchedule")+c];
  4732. c++;
  4733. }
  4734. sstr[c] = '\0';
  4735. strcpy(tempstartScheduleStr, sstr);
  4736. //**********startSchedule**********/
  4737. c = 0;
  4738. loc = strstr(sLineWord, "chargingRateUnit");
  4739. memset(sstr ,0, sizeof(sstr) );
  4740. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4741. {
  4742. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4743. c++;
  4744. }
  4745. sstr[c] = '\0';
  4746. strcpy(tempchargingRateUnitStr, sstr);
  4747. //**********minChargingRate*******/
  4748. c = 0;
  4749. loc = strstr(sLineWord, "minChargingRate");
  4750. if(loc != NULL)
  4751. {
  4752. memset(sstr ,0, sizeof(sstr) );
  4753. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4754. {
  4755. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4756. c++;
  4757. }
  4758. sstr[c] = '\0';
  4759. tempminChargingRateFloat = atof(sstr);
  4760. }
  4761. else
  4762. {
  4763. tempminChargingRateFloat = 0.0;
  4764. }
  4765. //
  4766. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4767. tp.tm_isdst = -1;
  4768. time_t utc = mktime(&tp);
  4769. time_t t = time(NULL);
  4770. diff_t = difftime(t, utc);
  4771. DEBUG_INFO("diff_t=%f\n",diff_t);
  4772. DEBUG_INFO(" debug 5 -1\n");
  4773. //parsing strings to words
  4774. i = 0;
  4775. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4776. loc = loc+3+strlen("chargingSchedulePeriod");
  4777. pch = strtok(loc ,"{");
  4778. while (pch != NULL)
  4779. {
  4780. strcpy(SchedulePeriodList[i], pch);
  4781. pch = strtok (NULL, "{");
  4782. i = i + 1;
  4783. }
  4784. n_SchedulePeriods = i;
  4785. for(int i=0;i<n_SchedulePeriods;i++)
  4786. {
  4787. //*************startPeriod****************/
  4788. c = 0;
  4789. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4790. memset(sstr ,0, sizeof(sstr) );
  4791. while (loc[strlen("startPeriod")+2+c] != ',')
  4792. {
  4793. sstr[c] = loc[strlen("startPeriod")+2+c];
  4794. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4795. c++;
  4796. }
  4797. sstr[c] = '\0';
  4798. tempStartPeriodInt = atoi(sstr);
  4799. //*************limit****************/
  4800. c = 0;
  4801. loc = strstr(SchedulePeriodList[i], "limit");
  4802. memset(sstr ,0, sizeof(sstr) );
  4803. while (loc[strlen("limit")+2+c] != ',')
  4804. {
  4805. sstr[c] = loc[strlen("limit")+2+c];
  4806. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4807. c++;
  4808. }
  4809. sstr[c] = '\0';
  4810. tempLimitInt = atof(sstr);
  4811. //*************numberPhases****************/
  4812. c = 0;
  4813. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4814. memset(sstr ,0, sizeof(sstr) );
  4815. while (loc[strlen("numberPhases")+2+c] != '}')
  4816. {
  4817. sstr[c] = loc[strlen("numberPhases")+2+c];
  4818. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4819. c++;
  4820. }
  4821. sstr[c] = '\0';
  4822. tempNumberPhasesInt = atoi(sstr);
  4823. if(j == 0)
  4824. {
  4825. ChargePointMaxProfile.Duration = tempdurationInt;
  4826. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4827. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4828. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4829. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4830. }
  4831. }
  4832. if(MinChargingRate < tempminChargingRateFloat)
  4833. {
  4834. MinChargingRate = tempminChargingRateFloat;
  4835. }
  4836. if(confirmPeriods < n_SchedulePeriods)
  4837. {
  4838. confirmPeriods = n_SchedulePeriods;
  4839. }
  4840. j = j + 1;
  4841. }
  4842. fclose(fptr1);
  4843. }
  4844. }// the end of access file ChargePointMaxProfile
  4845. //****************************TxDefaultProfile************************************************/
  4846. switch(connectorIdInt)
  4847. {
  4848. case 0:
  4849. break;
  4850. case 1:
  4851. strcpy(fname, TxDefaultProfile_1_JSON );
  4852. break;
  4853. case 2:
  4854. strcpy(fname, TxDefaultProfile_2_JSON );
  4855. break;
  4856. default:
  4857. strcpy(fname, TxDefaultProfile_1_JSON );
  4858. break;
  4859. }
  4860. TxDefaultProfileFileIsNull=TRUE;
  4861. if((access(fname,F_OK))!=-1)
  4862. {
  4863. DEBUG_INFO("handleGetCompositeScheduleRequest 4\n");
  4864. fptr1 = fopen(fname, "r");
  4865. c = 0;
  4866. c = fgetc(fptr1);
  4867. //DEBUG_INFO("c:%d\n",c);
  4868. rewind(fptr1);
  4869. if(c == EOF)
  4870. {
  4871. DEBUG_INFO("\n End of file reached.");
  4872. TxDefaultProfileFileIsNull=TRUE;
  4873. fclose(fptr1);
  4874. }
  4875. else
  4876. {
  4877. TxDefaultProfileFileIsNull=FALSE;
  4878. while(fscanf(fptr1, "%s", word) != EOF)
  4879. {
  4880. if(strcmp(word, "chargingProfileId") == 0)
  4881. {
  4882. n_chargingProfile = n_chargingProfile + 1;
  4883. }
  4884. }
  4885. rewind(fptr1);
  4886. //search Charging Profile Element
  4887. int i = 0;
  4888. int j = 0;
  4889. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4890. #if 0
  4891. /***********connectorId****************/
  4892. c = 0;
  4893. loc = strstr(sLineWord, "connectorId");
  4894. memset(sstr ,0, sizeof(sstr) );
  4895. while (loc[strlen("connectorId")+2+c] != ',')
  4896. {
  4897. sstr[c] = loc[strlen("connectorId")+2+c];
  4898. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4899. c++;
  4900. }
  4901. sstr[c] = '\0';
  4902. tempconnectorIdInt = atoi(sstr);
  4903. #endif
  4904. //***********validFrom**************/
  4905. c = 0;
  4906. loc = strstr(sLineWord, "validFrom");
  4907. if(loc != NULL)
  4908. {
  4909. memset(sstr ,0, sizeof(sstr) );
  4910. while (loc[3+strlen("validFrom")+c] != '\"')
  4911. {
  4912. sstr[c] = loc[3+strlen("validFrom")+c];
  4913. c++;
  4914. }
  4915. sstr[c] = '\0';
  4916. strcpy(tempvalidFromStr,sstr);
  4917. }
  4918. else
  4919. {
  4920. strcpy(tempvalidFromStr,"");
  4921. }
  4922. DEBUG_INFO("handleGetCompositeScheduleRequest 5\n");
  4923. //***********validFrom**************/
  4924. c = 0;
  4925. loc = strstr(sLineWord, "duration");
  4926. if(loc != NULL)
  4927. {
  4928. memset(sstr ,0, sizeof(sstr) );
  4929. while (loc[2+strlen("duration")+c] != ',')
  4930. {
  4931. sstr[c] = loc[2+strlen("duration")+c];
  4932. c++;
  4933. }
  4934. sstr[c] = '\0';
  4935. tempdurationInt = atoi(sstr);
  4936. }
  4937. else
  4938. {
  4939. tempdurationInt = 0;
  4940. }
  4941. DEBUG_INFO("handleGetCompositeScheduleRequest 6\n");
  4942. //**********startSchedule**********/
  4943. c = 0;
  4944. loc = strstr(sLineWord, "startSchedule");
  4945. memset(sstr ,0, sizeof(sstr) );
  4946. while (loc[3+strlen("startSchedule")+c] != '\"')
  4947. {
  4948. sstr[c] = loc[3+strlen("startSchedule")+c];
  4949. c++;
  4950. }
  4951. sstr[c] = '\0';
  4952. strcpy(tempstartScheduleStr, sstr);
  4953. //**********startSchedule**********/
  4954. c = 0;
  4955. loc = strstr(sLineWord, "chargingRateUnit");
  4956. memset(sstr ,0, sizeof(sstr) );
  4957. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4958. {
  4959. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4960. c++;
  4961. }
  4962. sstr[c] = '\0';
  4963. strcpy(tempchargingRateUnitStr, sstr);
  4964. //**********minChargingRate*******/
  4965. c = 0;
  4966. loc = strstr(sLineWord, "minChargingRate");
  4967. if(loc != NULL)
  4968. {
  4969. memset(sstr ,0, sizeof(sstr) );
  4970. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4971. {
  4972. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4973. c++;
  4974. }
  4975. sstr[c] = '\0';
  4976. tempminChargingRateFloat = atof(sstr);
  4977. }
  4978. else
  4979. {
  4980. tempminChargingRateFloat = 0.0;
  4981. }
  4982. DEBUG_INFO("handleGetCompositeScheduleRequest 7\n");
  4983. //
  4984. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4985. tp.tm_isdst = -1;
  4986. time_t utc = mktime(&tp);
  4987. time_t t = time(NULL);
  4988. diff_t = difftime(t, utc);
  4989. DEBUG_INFO("diff_t=%f\n",diff_t);
  4990. DEBUG_INFO(" debug 5 -1\n");
  4991. //parsing strings to words
  4992. i = 0;
  4993. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4994. loc = loc+3+strlen("chargingSchedulePeriod");
  4995. pch = strtok(loc ,"{");
  4996. while (pch != NULL)
  4997. {
  4998. strcpy(SchedulePeriodList[i], pch);
  4999. pch = strtok (NULL, "{");
  5000. i = i + 1;
  5001. }
  5002. n_SchedulePeriods = i;
  5003. DEBUG_INFO("handleGetCompositeScheduleRequest 8\n");
  5004. for(int i=0;i<n_SchedulePeriods;i++)
  5005. {
  5006. //*************startPeriod****************/
  5007. c = 0;
  5008. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5009. memset(sstr ,0, sizeof(sstr) );
  5010. while (loc[strlen("startPeriod")+2+c] != ',')
  5011. {
  5012. sstr[c] = loc[strlen("startPeriod")+2+c];
  5013. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5014. c++;
  5015. }
  5016. sstr[c] = '\0';
  5017. tempStartPeriodInt = atoi(sstr);
  5018. //*************limit****************/
  5019. c = 0;
  5020. loc = strstr(SchedulePeriodList[i], "limit");
  5021. memset(sstr ,0, sizeof(sstr) );
  5022. while (loc[strlen("limit")+2+c] != ',')
  5023. {
  5024. sstr[c] = loc[strlen("limit")+2+c];
  5025. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5026. c++;
  5027. }
  5028. sstr[c] = '\0';
  5029. tempLimitInt = atof(sstr);
  5030. //*************numberPhases****************/
  5031. c = 0;
  5032. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5033. memset(sstr ,0, sizeof(sstr) );
  5034. while (loc[strlen("numberPhases")+2+c] != '}')
  5035. {
  5036. sstr[c] = loc[strlen("numberPhases")+2+c];
  5037. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5038. c++;
  5039. }
  5040. sstr[c] = '\0';
  5041. tempNumberPhasesInt = atoi(sstr);
  5042. if(j == 0)
  5043. {
  5044. TxDefaultProfile.Duration = tempdurationInt;
  5045. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5046. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5047. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5048. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5049. }
  5050. else
  5051. {
  5052. //other stack level charging Profile
  5053. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5054. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5055. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5056. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5057. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5058. }
  5059. }
  5060. if(MinChargingRate < tempminChargingRateFloat)
  5061. MinChargingRate = tempminChargingRateFloat;
  5062. if(confirmPeriods < n_SchedulePeriods)
  5063. confirmPeriods = n_SchedulePeriods;
  5064. j = j + 1;
  5065. }
  5066. fclose(fptr1);
  5067. //Stacking Charging Profiles
  5068. for(int l=0; l <(j-1) ;l++)
  5069. {
  5070. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5071. {
  5072. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5073. {
  5074. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5075. {
  5076. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5077. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5078. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5079. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5080. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5081. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5082. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5083. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5084. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5085. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5086. }
  5087. else
  5088. {
  5089. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5090. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5091. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5092. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5093. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5094. }
  5095. }
  5096. }
  5097. }
  5098. //end of Stacking Charging Profiles
  5099. }
  5100. }// the end of ACCESS TxDefaultProfile
  5101. DEBUG_INFO("handleGetCompositeScheduleRequest 9\n");
  5102. //****************************TxProfile************************************************/
  5103. switch(connectorIdInt)
  5104. {
  5105. case 0:
  5106. break;
  5107. case 1:
  5108. strcpy(fname, TxProfile_1_JSON );
  5109. break;
  5110. case 2:
  5111. strcpy(fname, TxProfile_2_JSON );
  5112. break;
  5113. default:
  5114. strcpy(fname, TxProfile_1_JSON );
  5115. break;
  5116. }
  5117. TxProfileIsNull=TRUE;
  5118. if((access(fname,F_OK))!=-1)
  5119. {
  5120. fptr1 = fopen(fname, "r");
  5121. c = 0;
  5122. c = fgetc(fptr1);
  5123. //DEBUG_INFO("c:%d\n",c);
  5124. rewind(fptr1);
  5125. if(c == EOF)
  5126. {
  5127. DEBUG_INFO("\n End of file reached.");
  5128. TxProfileIsNull=TRUE;
  5129. fclose(fptr1);
  5130. }
  5131. else
  5132. {
  5133. TxProfileIsNull=FALSE;
  5134. while(fscanf(fptr1, "%s", word) != EOF)
  5135. {
  5136. if(strcmp(word, "chargingProfileId") == 0)
  5137. {
  5138. n_chargingProfile = n_chargingProfile + 1;
  5139. }
  5140. }
  5141. rewind(fptr1);
  5142. //search Charging Profile Element
  5143. int i= 0;
  5144. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5145. #if 0
  5146. /***********connectorId****************/
  5147. c = 0;
  5148. loc = strstr(sLineWord, "connectorId");
  5149. memset(sstr ,0, sizeof(sstr) );
  5150. while (loc[strlen("connectorId")+2+c] != ',')
  5151. {
  5152. sstr[c] = loc[strlen("connectorId")+2+c];
  5153. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5154. c++;
  5155. }
  5156. sstr[c] = '\0';
  5157. tempconnectorIdInt = atoi(sstr);
  5158. #endif
  5159. //***********validFrom**************/
  5160. c = 0;
  5161. loc = strstr(sLineWord, "validFrom");
  5162. if(loc != NULL)
  5163. {
  5164. memset(sstr ,0, sizeof(sstr) );
  5165. while (loc[3+strlen("validFrom")+c] != '\"')
  5166. {
  5167. sstr[c] = loc[3+strlen("validFrom")+c];
  5168. c++;
  5169. }
  5170. sstr[c] = '\0';
  5171. strcpy(tempvalidFromStr,sstr);
  5172. }
  5173. else
  5174. {
  5175. strcpy(tempvalidFromStr,"");
  5176. }
  5177. //**********startSchedule**********/
  5178. c = 0;
  5179. loc = strstr(sLineWord, "startSchedule");
  5180. memset(sstr ,0, sizeof(sstr) );
  5181. while (loc[3+strlen("startSchedule")+c] != '\"')
  5182. {
  5183. sstr[c] = loc[3+strlen("startSchedule")+c];
  5184. c++;
  5185. }
  5186. sstr[c] = '\0';
  5187. strcpy(tempstartScheduleStr, sstr);
  5188. //**********startSchedule**********/
  5189. c = 0;
  5190. loc = strstr(sLineWord, "chargingRateUnit");
  5191. memset(sstr ,0, sizeof(sstr) );
  5192. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5193. {
  5194. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5195. c++;
  5196. }
  5197. sstr[c] = '\0';
  5198. strcpy(tempchargingRateUnitStr, sstr);
  5199. //**********minChargingRate*******/
  5200. c = 0;
  5201. loc = strstr(sLineWord, "minChargingRate");
  5202. if(loc != NULL)
  5203. {
  5204. memset(sstr ,0, sizeof(sstr) );
  5205. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5206. {
  5207. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5208. c++;
  5209. }
  5210. sstr[c] = '\0';
  5211. tempminChargingRateFloat = atof(sstr);
  5212. }
  5213. else
  5214. {
  5215. tempminChargingRateFloat = 0.0;
  5216. }
  5217. //
  5218. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5219. tp.tm_isdst = -1;
  5220. time_t utc = mktime(&tp);
  5221. time_t t = time(NULL);
  5222. diff_t = difftime(t, utc);
  5223. DEBUG_INFO("diff_t=%f\n",diff_t);
  5224. //parsing strings to words
  5225. i = 0;
  5226. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5227. loc = loc+3+strlen("chargingSchedulePeriod");
  5228. pch = strtok(loc ,"{");
  5229. while (pch != NULL)
  5230. {
  5231. strcpy(SchedulePeriodList[i], pch);
  5232. pch = strtok (NULL, "{");
  5233. i = i + 1;
  5234. }
  5235. n_SchedulePeriods = i;
  5236. for(int i=0;i<n_SchedulePeriods;i++)
  5237. {
  5238. //*************startPeriod****************/
  5239. c = 0;
  5240. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5241. memset(sstr ,0, sizeof(sstr) );
  5242. while (loc[strlen("startPeriod")+2+c] != ',')
  5243. {
  5244. sstr[c] = loc[strlen("startPeriod")+2+c];
  5245. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5246. c++;
  5247. }
  5248. sstr[c] = '\0';
  5249. tempStartPeriodInt = atoi(sstr);
  5250. //*************limit****************/
  5251. c = 0;
  5252. loc = strstr(SchedulePeriodList[i], "limit");
  5253. memset(sstr ,0, sizeof(sstr) );
  5254. while (loc[strlen("limit")+2+c] != ',')
  5255. {
  5256. sstr[c] = loc[strlen("limit")+2+c];
  5257. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5258. c++;
  5259. }
  5260. sstr[c] = '\0';
  5261. tempLimitInt = atof(sstr);
  5262. //*************numberPhases****************/
  5263. c = 0;
  5264. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5265. memset(sstr ,0, sizeof(sstr) );
  5266. while (loc[strlen("numberPhases")+2+c] != '}')
  5267. {
  5268. sstr[c] = loc[strlen("numberPhases")+2+c];
  5269. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5270. c++;
  5271. }
  5272. sstr[c] = '\0';
  5273. tempNumberPhasesInt = atoi(sstr);
  5274. TxProfile.Duration = durationInt;
  5275. TxProfile.TotalPeriod = n_SchedulePeriods;
  5276. TxProfile.Period[i].Limit = tempLimitInt;
  5277. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5278. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5279. }
  5280. if(MinChargingRate < tempminChargingRateFloat)
  5281. MinChargingRate = tempminChargingRateFloat;
  5282. if(confirmPeriods < n_SchedulePeriods)
  5283. confirmPeriods = n_SchedulePeriods;
  5284. }
  5285. fclose(fptr1);
  5286. }
  5287. }// the end of ACCESS TxProfile
  5288. DEBUG_INFO("handleGetCompositeScheduleRequest 10\n");
  5289. //CompositeSchedule
  5290. int period=0;
  5291. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5292. {
  5293. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5294. {
  5295. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5296. {
  5297. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5298. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5299. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5300. period = period + 1;
  5301. }
  5302. else
  5303. {
  5304. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5305. {
  5306. }
  5307. else
  5308. {
  5309. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5310. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5311. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5312. period = period + 1;
  5313. }
  5314. }
  5315. }
  5316. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5317. {
  5318. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5319. {
  5320. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5321. {
  5322. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5323. }
  5324. else
  5325. {
  5326. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5327. }
  5328. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5329. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5330. period = period + 1;
  5331. }
  5332. }
  5333. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5334. {
  5335. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5336. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5337. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5338. period = period + 1;
  5339. }
  5340. }
  5341. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5342. {
  5343. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5344. {
  5345. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5346. {
  5347. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5348. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5349. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5350. period = period + 1;
  5351. }
  5352. else
  5353. {
  5354. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5355. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5356. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5357. period = period + 1;
  5358. }
  5359. }
  5360. }
  5361. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5362. {
  5363. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5364. {
  5365. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5366. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5367. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5368. period = period + 1;
  5369. }
  5370. }
  5371. confirmPeriods = period;
  5372. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5373. //* Define temporary variables */
  5374. struct tm *gtime;
  5375. time_t now;
  5376. char buf[28];
  5377. //* Read the current system time */
  5378. time(&now);
  5379. //* Convert the system time to GMT (now UTC) */
  5380. gtime = gmtime(&now);
  5381. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5382. // make .conf
  5383. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5384. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5385. //DEBUG_INFO(" debug 11\n");
  5386. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5387. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5388. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5389. }
  5390. else
  5391. {
  5392. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5393. }
  5394. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5395. return result;
  5396. }
  5397. int handleGetConfigurationRequest(char *uuid, char *payload)
  5398. {
  5399. mtrace();
  5400. int result = FAIL;
  5401. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5402. //struct json_object *jsonitem;
  5403. int MaxKeySupported = 0;
  5404. int n_keys = 0;
  5405. char requestKey[43][50]={0};
  5406. char search[]="[";
  5407. char sstr[500]={ 0 };
  5408. //int pos;
  5409. int l, c = 0;
  5410. int i = 0;
  5411. char *delim = "\",\"";
  5412. char * pch;
  5413. char *loc = strstr(payload, search);
  5414. //********************* Parsing String ***********************************/
  5415. if(loc == NULL) {
  5416. DEBUG_INFO("no key match in Configuration \n");
  5417. }
  5418. else {
  5419. //pos = loc - payload;
  5420. l = strlen(loc)-4;
  5421. while (c < l)
  5422. {
  5423. sstr[c] = loc[c+2];
  5424. c++;
  5425. }
  5426. sstr[c] = '\0';
  5427. //parsing strings to words
  5428. pch = strtok(sstr,delim);
  5429. if(pch == NULL)
  5430. {
  5431. strcpy(requestKey[0], sstr);
  5432. }
  5433. else
  5434. {
  5435. while (pch != NULL)
  5436. {
  5437. strcpy(requestKey[i], pch);
  5438. pch = strtok (NULL, delim);
  5439. i = i + 1;
  5440. }
  5441. n_keys = i;
  5442. }
  5443. }
  5444. UnknownKeynum = 0;
  5445. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5446. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5447. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5448. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5449. if(n_keys != 0)
  5450. {
  5451. for(int i=0;i<n_keys;i++)
  5452. {
  5453. getKeyValue(requestKey[i]);
  5454. //json_object_put(jsonitem);
  5455. }
  5456. }
  5457. else
  5458. {
  5459. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5460. getKeyValue("");
  5461. }
  5462. processUnkownKey();
  5463. sendGetConfigurationConfirmation(uuid);
  5464. return result;
  5465. }
  5466. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5467. {
  5468. mtrace();
  5469. int result = FAIL;
  5470. //void *ret; //
  5471. char fnamePlusPath[50]="";
  5472. char fname[16]="";
  5473. pthread_t t; // pthread 變數
  5474. time_t rawtime;
  5475. struct tm * timeinfo;
  5476. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5477. system("exec /root/logPackTools 'log' 6");
  5478. //char buffer [128];
  5479. time (&rawtime);
  5480. //printf("%ld\n", rawtime);
  5481. timeinfo = localtime (&rawtime);
  5482. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5483. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5484. if((access(fnamePlusPath,F_OK))!=-1)
  5485. {
  5486. DEBUG_INFO("fnamePlusPath exist.\n");
  5487. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5488. }
  5489. else
  5490. {
  5491. DEBUG_INFO("fnamePlusPath not exist!\n");
  5492. }
  5493. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5494. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5495. pthread_join(t, NULL/*&ret*/);
  5496. return result;
  5497. }
  5498. void* GetDiagnosticsProcess(void* data)
  5499. {
  5500. mtrace();
  5501. int retriesInt=0, retryIntervalInt=0;
  5502. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5503. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5504. 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};
  5505. int port=0;
  5506. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5507. char fname[16]="";
  5508. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5509. int c = 0;
  5510. char *loc;
  5511. int isSuccess = FALSE;
  5512. char ftpbuf[200]={0};
  5513. //char temp[100]={0};
  5514. char * pch;
  5515. // [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"}]
  5516. char *str = (char*) data; // ?��?輸入資�?
  5517. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5518. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5519. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5520. //****************location*******************/
  5521. c = 0;
  5522. memset(sstr ,0, sizeof(sstr) );
  5523. loc = strstr(str, "location");
  5524. while (loc[3+strlen("location")+c] != '\"')
  5525. {
  5526. sstr[c] = loc[3+strlen("location")+c];
  5527. c++;
  5528. }
  5529. sstr[c] = '\0';
  5530. strcpy(locationstr,sstr);
  5531. if(strcmp(locationstr,"")==0)
  5532. {
  5533. DEBUG_INFO("location is <Empty>!\n");
  5534. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5535. goto end;
  5536. }
  5537. //****************retries*******************/
  5538. c = 0;
  5539. loc = strstr(str, "retries");
  5540. if(loc == NULL)
  5541. {
  5542. retriesIsNULL = TRUE;
  5543. }
  5544. else
  5545. {
  5546. while (loc[strlen("retries")+2+c] != ',')
  5547. {
  5548. sstr[c] = loc[strlen("retries")+2+c];
  5549. c++;
  5550. }
  5551. sstr[c] = '\0';
  5552. retriesInt = atoi(sstr);
  5553. }
  5554. if(retriesIsNULL == TRUE)
  5555. {
  5556. retriesInt = 0;
  5557. }
  5558. //****************retryInterval*******************/
  5559. c = 0;
  5560. loc = strstr(str, "retryInterval");
  5561. if(loc == NULL)
  5562. {
  5563. retryIntervalIsNULL = TRUE;
  5564. }
  5565. else
  5566. {
  5567. while (loc[strlen("retryInterval")+2+c] != ',')
  5568. {
  5569. sstr[c] = loc[strlen("retryInterval")+2+c];
  5570. c++;
  5571. }
  5572. sstr[c] = '\0';
  5573. retryIntervalInt = atoi(sstr);
  5574. }
  5575. //****************startTime*******************/
  5576. c = 0;
  5577. memset(sstr ,0, sizeof(sstr) );
  5578. loc = strstr(str, "startTime");
  5579. if(loc == NULL)
  5580. {
  5581. startTimeIsNULL = TRUE;
  5582. }
  5583. else
  5584. {
  5585. while (loc[3+strlen("startTime")+c] != '\"')
  5586. {
  5587. sstr[c] = loc[3+strlen("startTime")+c];
  5588. c++;
  5589. }
  5590. sstr[c] = '\0';
  5591. strcpy(startTimestr,sstr);
  5592. }
  5593. //****************stopTime*******************/
  5594. c = 0;
  5595. memset(sstr ,0, sizeof(sstr) );
  5596. loc = strstr(str, "stopTime");
  5597. if(loc == NULL)
  5598. {
  5599. stopTimeIsNULL = TRUE;
  5600. }
  5601. else
  5602. {
  5603. while (loc[3+strlen("stopTime")+c] != '\"')
  5604. {
  5605. sstr[c] = loc[3+strlen("stopTime")+c];
  5606. c++;
  5607. }
  5608. sstr[c] = '\0';
  5609. strcpy(stopTimestr,sstr);
  5610. }
  5611. memset(protocol, 0, sizeof(protocol));
  5612. memset(user, 0, sizeof(user) );
  5613. memset(password, 0, sizeof(password));
  5614. memset(host, 0, sizeof(host));
  5615. memset(path, 0, sizeof(path));
  5616. memset(ftppath, 0, sizeof(ftppath));
  5617. memset(host1, 0, sizeof(host1));
  5618. memset(path1, 0, sizeof(path1));
  5619. /*location: ftp://user:password@host:port/path*/
  5620. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5621. // protocol, user, password, host, &port, path);
  5622. #if 0 // remove for temporally
  5623. //zip files in /Storage
  5624. system("exec /root/logPackTools 'log' 6");
  5625. #endif
  5626. // system("exec /root/Module_WebService 'log' 6");
  5627. time_t rawtime;
  5628. struct tm * timeinfo;
  5629. //char buffer [128];
  5630. time (&rawtime);
  5631. //printf("%ld\n", rawtime);
  5632. timeinfo = localtime (&rawtime);
  5633. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5634. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5635. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5636. if((access(fnamePlusPath,F_OK))!=-1)
  5637. {
  5638. DEBUG_INFO("fnamePlusPath exist.\n");
  5639. }
  5640. else
  5641. {
  5642. DEBUG_INFO("fnamePlusPath not exist!\n");
  5643. goto end;
  5644. }
  5645. pch=strchr(locationstr,'@');
  5646. if(pch==NULL)
  5647. {
  5648. sscanf(locationstr,
  5649. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5650. protocol, host, &port, path);
  5651. strcpy(user,"anonymous");
  5652. strcpy(password,"");
  5653. }
  5654. else
  5655. {
  5656. DEBUG_INFO("pch=%s\n", pch);
  5657. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5658. protocol, user, password, host, &port, path);
  5659. }
  5660. if(strcmp(protocol,"ftp")!=0)
  5661. {
  5662. DEBUG_INFO("protocol is not ftp!\n");
  5663. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5664. goto end;
  5665. }
  5666. sscanf(host,"%[^/]%s",host1, path1);
  5667. sprintf(ftppath,"%s", path1);
  5668. DEBUG_INFO("protocol =%s\n",protocol);
  5669. DEBUG_INFO("user =%s\n",user);
  5670. DEBUG_INFO("password =%s\n",password);
  5671. DEBUG_INFO("host1 =%s\n",host1);
  5672. DEBUG_INFO("port =%d\n",port);
  5673. DEBUG_INFO("path1 =%s\n",path1);
  5674. DEBUG_INFO("ftppath=%s\n",ftppath);
  5675. int ftppathlen=strlen(ftppath);
  5676. int i=1;
  5677. char filenametemp[50];
  5678. while(i < ftppathlen)
  5679. {
  5680. int len=ftppathlen-i;
  5681. if(ftppath[len]== 47) // '/' ascll code: 47
  5682. {
  5683. DEBUG_INFO("find '/' all right\n");
  5684. break;
  5685. }
  5686. i=i+1;
  5687. }
  5688. memset(filenametemp, 0, sizeof(filenametemp));
  5689. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5690. filenametemp[i+1] = 0;
  5691. //httpDownLoadFile(host, ftppath, fname);
  5692. memset(ftpbuf, 0, sizeof(ftpbuf));
  5693. if(port == 0)
  5694. port = 21;
  5695. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5696. do{
  5697. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5698. sleep(retryIntervalInt);
  5699. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5700. if(!isSuccess)
  5701. {
  5702. //BulldogUtil.sleepMs(interval*1000);
  5703. DEBUG_INFO("Diagnostics fail.\n");
  5704. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5705. }
  5706. else
  5707. {
  5708. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5709. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5710. //isUpdateRequest = TRUE;
  5711. }
  5712. end:
  5713. // json_object_put(obj);
  5714. DiagnosticsStatusNotificationStatus = 0; //Idle
  5715. pthread_exit(NULL/*(void *) fname*/); // ?��?子執行�?
  5716. }
  5717. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5718. {
  5719. mtrace();
  5720. int result = FAIL;
  5721. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5722. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5723. {
  5724. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5725. localversion = -1;
  5726. }
  5727. else
  5728. {
  5729. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5730. OCPP_getListVerion();
  5731. }
  5732. //from db.OCPP_getListVerion
  5733. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5734. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5735. sendGetLocalListVersionConfirmation(uuid,"");
  5736. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5737. return result;
  5738. }
  5739. int handleRemoteStartRequest(char *uuid, char *payload)
  5740. {
  5741. mtrace();
  5742. int result = FAIL;
  5743. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5744. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5745. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5746. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5747. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5748. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5749. int chargingSchedulePeriodCount = 0;
  5750. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5751. int c = 0;
  5752. char *loc;
  5753. char comfirmstr[20]={0};
  5754. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5755. if(server_pending == TRUE)
  5756. {
  5757. return 0;
  5758. }
  5759. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5760. //**********connectorId****************/
  5761. c = 0;
  5762. memset(sstr ,0, sizeof(sstr) );
  5763. loc = strstr(payload, "connectorId");
  5764. if(loc == NULL)
  5765. {
  5766. connectorIdIsNULL = TRUE;
  5767. }
  5768. else
  5769. {
  5770. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5771. {
  5772. sstr[c] = loc[strlen("connectorId")+2+c];
  5773. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5774. c++;
  5775. }
  5776. sstr[c] = '\0';
  5777. connectorIdInt = atoi(sstr);
  5778. }
  5779. if(connectorIdIsNULL == TRUE) // need to discussion
  5780. {
  5781. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5782. goto end;
  5783. }
  5784. //****************idTag*******************/
  5785. c = 0;
  5786. memset(sstr ,0, sizeof(sstr) );
  5787. loc = strstr(payload, "idTag");
  5788. while (loc[3+strlen("idTag")+c] != '\"')
  5789. {
  5790. sstr[c] = loc[3+strlen("idTag")+c];
  5791. c++;
  5792. }
  5793. sstr[c] = '\0';
  5794. strcpy(idTagstr,sstr);
  5795. //****************chargingProfile*******************/
  5796. c = 0;
  5797. memset(sstr ,0, sizeof(sstr) );
  5798. loc = strstr(payload, "chargingProfile");
  5799. if(loc == NULL)
  5800. {
  5801. chargingProfileIsNULL = TRUE;
  5802. }
  5803. else
  5804. {
  5805. //****************chargingProfileId*******************/
  5806. c=0;
  5807. loc = strstr(payload, "chargingProfileId");
  5808. memset(sstr ,0, sizeof(sstr) );
  5809. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5810. {
  5811. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5812. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5813. c++;
  5814. }
  5815. sstr[c] = '\0';
  5816. chargingProfileIdInt = atoi(sstr);
  5817. //****************transactionId*******************/
  5818. loc = strstr(payload, "transactionId");
  5819. if(loc == NULL)
  5820. {
  5821. transactionIdIsNULL = TRUE;
  5822. }
  5823. else
  5824. {
  5825. c=0;
  5826. memset(sstr ,0, sizeof(sstr) );
  5827. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5828. {
  5829. sstr[c] = loc[strlen("transactionId")+2+c];
  5830. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5831. c++;
  5832. }
  5833. sstr[c] = '\0';
  5834. transactionIdInt = atoi(sstr);
  5835. }
  5836. //****************stackLevel*******************/
  5837. c=0;
  5838. loc = strstr(payload, "stackLevel");
  5839. memset(sstr ,0, sizeof(sstr) );
  5840. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5841. {
  5842. sstr[c] = loc[strlen("stackLevel")+2+c];
  5843. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5844. c++;
  5845. }
  5846. sstr[c] = '\0';
  5847. stackLevelInt = atoi(sstr);
  5848. //****************chargingProfilePurpose*******************/
  5849. c = 0;
  5850. memset(sstr ,0, sizeof(sstr) );
  5851. loc = strstr(payload, "chargingProfilePurpose");
  5852. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5853. {
  5854. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5855. c++;
  5856. }
  5857. sstr[c] = '\0';
  5858. strcpy(chargingProfilePurposestr,sstr);
  5859. //****************chargingProfileKind*******************/
  5860. c = 0;
  5861. memset(sstr ,0, sizeof(sstr) );
  5862. loc = strstr(payload, "chargingProfileKind");
  5863. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5864. {
  5865. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5866. c++;
  5867. }
  5868. sstr[c] = '\0';
  5869. strcpy(chargingProfileKindstr,sstr);
  5870. //****************recurrencyKind*******************/
  5871. loc = strstr(payload, "recurrencyKind");
  5872. if(loc == NULL)
  5873. {
  5874. recurrencyKindIsNULL = TRUE;
  5875. }
  5876. else
  5877. {
  5878. c = 0;
  5879. memset(sstr ,0, sizeof(sstr) );
  5880. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5881. {
  5882. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5883. c++;
  5884. }
  5885. sstr[c] = '\0';
  5886. strcpy(recurrencyKindstr,sstr);
  5887. }
  5888. //****************validFrom*******************/
  5889. loc = strstr(payload, "validFrom");
  5890. if(loc == NULL)
  5891. {
  5892. validFromIsNULL = TRUE;
  5893. }
  5894. else
  5895. {
  5896. c = 0;
  5897. memset(sstr ,0, sizeof(sstr) );
  5898. while (loc[3+strlen("validFrom")+c] != '\"')
  5899. {
  5900. sstr[c] = loc[3+strlen("validFrom")+c];
  5901. c++;
  5902. }
  5903. sstr[c] = '\0';
  5904. strcpy(validFromstr,sstr);
  5905. }
  5906. //****************validTo*******************/
  5907. loc = strstr(payload, "validTo");
  5908. if(loc == NULL)
  5909. {
  5910. validToIsNULL = TRUE;
  5911. }
  5912. else
  5913. {
  5914. c = 0;
  5915. memset(sstr ,0, sizeof(sstr) );
  5916. while (loc[3+strlen("validTo")+c] != '\"')
  5917. {
  5918. sstr[c] = loc[3+strlen("validTo")+c];
  5919. c++;
  5920. }
  5921. sstr[c] = '\0';
  5922. strcpy(validTostr,sstr);
  5923. }
  5924. //****************chargingSchedule*******************/
  5925. loc = strstr(payload, "chargingSchedule");
  5926. if(loc != NULL)
  5927. {
  5928. //****************duration*******************/
  5929. loc = strstr(payload, "duration");
  5930. if(loc == NULL)
  5931. {
  5932. durationIsNULL = TRUE;
  5933. }
  5934. else
  5935. {
  5936. c=0;
  5937. memset(sstr ,0, sizeof(sstr) );
  5938. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5939. {
  5940. sstr[c] = loc[strlen("duration")+2+c];
  5941. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5942. c++;
  5943. }
  5944. sstr[c] = '\0';
  5945. durationInt = atoi(sstr);
  5946. }
  5947. //****************startSchedule******************/
  5948. loc = strstr(payload, "startSchedule");
  5949. if(loc == NULL)
  5950. {
  5951. startScheduleIsNULL = TRUE;
  5952. }
  5953. else
  5954. {
  5955. c = 0;
  5956. memset(sstr ,0, sizeof(sstr) );
  5957. while (loc[3+strlen("startSchedule")+c] != '\"')
  5958. {
  5959. sstr[c] = loc[3+strlen("startSchedule")+c];
  5960. c++;
  5961. }
  5962. sstr[c] = '\0';
  5963. strcpy(startSchedulestr,sstr);
  5964. }
  5965. //****************chargingRateUnit*******************/
  5966. c = 0;
  5967. memset(sstr ,0, sizeof(sstr) );
  5968. loc = strstr(payload, "chargingRateUnit");
  5969. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5970. {
  5971. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5972. c++;
  5973. }
  5974. sstr[c] = '\0';
  5975. strcpy(chargingRateUnitstr,sstr);
  5976. //****************minChargingRate*******************/
  5977. loc = strstr(payload, "minChargingRate");
  5978. if(loc == NULL)
  5979. {
  5980. minChargingRateIsNULL = TRUE;
  5981. }
  5982. else
  5983. {
  5984. c=0;
  5985. memset(sstr ,0, sizeof(sstr) );
  5986. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5987. {
  5988. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5989. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5990. c++;
  5991. }
  5992. sstr[c] = '\0';
  5993. minChargingRateflaot = atof(sstr);
  5994. }
  5995. //****************chargingSchedulePeriod count*******************/
  5996. int what_len = strlen("startPeriod");
  5997. char *where = payload;
  5998. while ((where = strstr(where, "startPeriod"))) {
  5999. where += what_len;
  6000. chargingSchedulePeriodCount++;
  6001. }
  6002. where = payload;
  6003. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6004. {
  6005. //****************startPeriod*******************/
  6006. c=0;
  6007. loc = strstr(where, "startPeriod");
  6008. memset(sstr ,0, sizeof(sstr) );
  6009. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6010. {
  6011. sstr[c] = loc[strlen("startPeriod")+2+c];
  6012. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6013. c++;
  6014. }
  6015. sstr[c] = '\0';
  6016. startPeriodInt[periodNums] = atoi(sstr);
  6017. //****************limit*******************/
  6018. c=0;
  6019. loc = strstr(where, "limit");
  6020. memset(sstr ,0, sizeof(sstr) );
  6021. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6022. {
  6023. sstr[c] = loc[strlen("limit")+2+c];
  6024. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6025. c++;
  6026. }
  6027. sstr[c] = '\0';
  6028. limitflaot[periodNums] = atof(sstr);
  6029. //****************numberPhases*******************/
  6030. loc = strstr(where, "numberPhases");
  6031. if(loc == NULL)
  6032. {
  6033. numberPhasesIsNULL = TRUE;
  6034. }
  6035. else
  6036. {
  6037. c=0;
  6038. memset(sstr ,0, sizeof(sstr) );
  6039. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6040. {
  6041. sstr[c] = loc[strlen("numberPhases")+2+c];
  6042. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6043. c++;
  6044. }
  6045. sstr[c] = '\0';
  6046. numberPhasesInt[periodNums] = atoi(sstr);
  6047. }
  6048. where = loc;
  6049. }
  6050. }
  6051. }
  6052. /*
  6053. enum _SYSTEM_STATUS
  6054. {
  6055. S_BOOTING = 0,
  6056. S_IDLE, = 1
  6057. S_AUTHORIZING, =2
  6058. S_REASSIGN_CHECK, =3
  6059. S_REASSIGN, =4
  6060. S_PRECHARGE, =5
  6061. S_PREPARING_FOR_EV, =6
  6062. S_PREPARING_FOR_EVSE, =7
  6063. S_CHARGING, =8
  6064. S_TERMINATING, =9
  6065. S_COMPLETE, =10
  6066. S_ALARM, =11
  6067. S_FAULT =12
  6068. }
  6069. */
  6070. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6071. {
  6072. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6073. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6074. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6075. //check Transaction active
  6076. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6077. {
  6078. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6079. {
  6080. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6081. {
  6082. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6083. {
  6084. //Reserved
  6085. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6086. }
  6087. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6088. {
  6089. //Reserved
  6090. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6091. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6092. goto end;
  6093. }
  6094. else
  6095. {
  6096. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6097. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6098. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6099. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6100. {
  6101. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6102. goto end;
  6103. }
  6104. }//END FOR ELSE
  6105. }
  6106. }// END FOR CHAdeMO_QUANTITY
  6107. for (int index = 0; index < CCS_QUANTITY; index++)
  6108. {
  6109. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6110. {
  6111. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6112. {
  6113. //Reserved
  6114. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6115. }
  6116. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6117. {
  6118. //Reserved
  6119. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6120. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6121. goto end;
  6122. }
  6123. else
  6124. {
  6125. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6126. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6127. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6128. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6129. {
  6130. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6131. goto end;
  6132. }
  6133. }// END FOR ELSE
  6134. }
  6135. }// END FOR CCS_QUANTITY
  6136. for (int index = 0; index < GB_QUANTITY; index++)
  6137. {
  6138. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6139. {
  6140. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6141. {
  6142. //Reserved
  6143. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6144. }
  6145. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6146. {
  6147. //Reserved
  6148. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6149. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6150. goto end;
  6151. }
  6152. else
  6153. {
  6154. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6155. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6156. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6157. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6158. {
  6159. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6160. goto end;
  6161. }
  6162. }// END FOR ELSE
  6163. }
  6164. } // END FOR GB_QUANTITY
  6165. }
  6166. else
  6167. {
  6168. for (int index = 0; index < AC_QUANTITY; index++)
  6169. {
  6170. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6171. {
  6172. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6173. {
  6174. //Reserved
  6175. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6176. }
  6177. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6178. {
  6179. //Reserved
  6180. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6181. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6182. goto end;
  6183. }
  6184. else
  6185. {
  6186. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6187. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6188. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6189. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6190. {
  6191. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6192. goto end;
  6193. }
  6194. }//END FOR ELSE
  6195. }
  6196. }// END FOR AC_QUANTITY
  6197. }
  6198. if(chargingProfileIsNULL == FALSE)
  6199. {
  6200. //ChargingProfile
  6201. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6202. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6203. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6204. if(recurrencyKindIsNULL == FALSE) //OPTION
  6205. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6206. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6207. if(transactionIdIsNULL == FALSE) // OPTION
  6208. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6209. if(validFromIsNULL == FALSE) // OPTION
  6210. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6211. if(validToIsNULL == FALSE) //OPTION
  6212. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6213. //ChargingSchedule
  6214. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6215. if(durationIsNULL == FALSE) //OPTION
  6216. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6217. if(minChargingRateIsNULL == FALSE) //OPTION
  6218. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6219. if(startScheduleIsNULL == FALSE) //OPTION
  6220. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6221. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6222. {
  6223. //ChargingSchedulePeriod
  6224. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6225. if(numberPhasesIsNULL == FALSE)
  6226. {
  6227. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6228. }
  6229. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6230. }
  6231. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6232. {
  6233. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6234. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6235. }
  6236. else
  6237. {
  6238. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6239. }
  6240. }
  6241. else
  6242. {
  6243. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6244. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6245. }
  6246. }
  6247. else
  6248. {
  6249. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6250. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6251. }
  6252. end:
  6253. if(connectorIdIsNULL == FALSE)
  6254. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6255. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6256. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6257. //OCPP send RemoteStartConfirmation by first.
  6258. sendRemoteStartConfirmation(uuid, comfirmstr);
  6259. return result;
  6260. }
  6261. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6262. {
  6263. mtrace();
  6264. int result = FAIL;
  6265. int match = FALSE;
  6266. int GunNO = 0;
  6267. int transactionIdInt=0;
  6268. int transactionIdIsNULL= FALSE;
  6269. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6270. int c = 0;
  6271. char *loc;
  6272. char comfirmstr[20];
  6273. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6274. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6275. if(server_pending == TRUE)
  6276. {
  6277. return 0;
  6278. }
  6279. c=0;
  6280. loc = strstr(payload, "transactionId");
  6281. if(loc == NULL)
  6282. {
  6283. transactionIdIsNULL= TRUE;
  6284. }
  6285. else
  6286. {
  6287. memset(sstr ,0, sizeof(sstr) );
  6288. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6289. {
  6290. sstr[c] = loc[strlen("transactionId")+2+c];
  6291. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6292. c++;
  6293. }
  6294. sstr[c] = '\0';
  6295. transactionIdInt = atoi(sstr);
  6296. }
  6297. if(transactionIdIsNULL == FALSE)
  6298. {
  6299. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6300. {
  6301. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6302. {
  6303. //check Transaction active
  6304. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6305. {
  6306. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6307. {
  6308. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6309. {
  6310. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6311. {
  6312. match = TRUE;
  6313. GunNO = gun_index;
  6314. }
  6315. }
  6316. }// END FOR CHAdeMO_QUANTITY
  6317. for (int index = 0; index < CCS_QUANTITY; index++)
  6318. {
  6319. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6320. {
  6321. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6322. {
  6323. match = TRUE;
  6324. GunNO = gun_index;
  6325. }
  6326. }
  6327. }// END FOR CCS_QUANTITY
  6328. for (int index = 0; index < GB_QUANTITY; index++)
  6329. {
  6330. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6331. {
  6332. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6333. {
  6334. match = TRUE;
  6335. GunNO = gun_index;
  6336. }
  6337. }
  6338. }// END FOR GB_QUANTITY
  6339. }
  6340. else
  6341. {
  6342. for (int index = 0; index < AC_QUANTITY; index++)
  6343. {
  6344. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6345. {
  6346. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6347. {
  6348. match = TRUE;
  6349. GunNO = gun_index;
  6350. }
  6351. }
  6352. }// END FOR CHAdeMO_QUANTITY
  6353. }// END FOR AC ELSE
  6354. }// CHECK IF ResponseTransactionId == transactionIdInt
  6355. }//END FOR
  6356. if( match == TRUE)
  6357. {
  6358. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6359. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6360. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6361. }
  6362. else
  6363. {
  6364. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6365. }
  6366. }
  6367. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6368. return result;
  6369. }
  6370. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6371. {
  6372. mtrace();
  6373. int result = FAIL;
  6374. int connectorIdInt=0, reservationIdInt=0;
  6375. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6376. char comfirmstr[20]={0};
  6377. char sstr[180]={ 0 };
  6378. int c = 0;
  6379. char *loc;
  6380. //char *ptr;
  6381. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6382. //***(1)connectorId ****/
  6383. c=0;
  6384. loc = strstr(payload, "connectorId");
  6385. memset(sstr ,0, sizeof(sstr) );
  6386. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6387. {
  6388. sstr[c] = loc[strlen("connectorId")+2+c];
  6389. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6390. c++;
  6391. }
  6392. sstr[c] = '\0';
  6393. connectorIdInt = atoi(sstr);
  6394. //***(2)expiryDate ****/
  6395. loc = strstr(payload, "expiryDate");
  6396. memset(sstr ,0, sizeof(sstr) );
  6397. c = 0;
  6398. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6399. {
  6400. sstr[c] = loc[3+strlen("expiryDate")+c];
  6401. c++;
  6402. }
  6403. sstr[c] = '\0';
  6404. strcpy(expiryDatestr, sstr);
  6405. //***(3)idTag ****/
  6406. loc = strstr(payload, "idTag");
  6407. memset(sstr ,0, sizeof(sstr) );
  6408. c = 0;
  6409. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6410. {
  6411. sstr[c] = loc[3+strlen("idTag")+c];
  6412. c++;
  6413. }
  6414. sstr[c] = '\0';
  6415. strcpy(idTagstr, sstr);
  6416. //***(4)parentIdTag ****/
  6417. loc = strstr(payload, "parentIdTag");
  6418. memset(sstr ,0, sizeof(sstr) );
  6419. c = 0;
  6420. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6421. {
  6422. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6423. c++;
  6424. }
  6425. sstr[c] = '\0';
  6426. strcpy(parentIdTagstr, sstr);
  6427. //***(5)reservationId ****/
  6428. c=0;
  6429. loc = strstr(payload, "reservationId");
  6430. memset(sstr ,0, sizeof(sstr) );
  6431. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6432. {
  6433. sstr[c] = loc[strlen("reservationId")+2+c];
  6434. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6435. c++;
  6436. }
  6437. sstr[c] = '\0';
  6438. reservationIdInt = atoi(sstr);
  6439. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6440. /*
  6441. enum _SYSTEM_STATUS
  6442. {
  6443. S_BOOTING = 0,
  6444. S_IDLE, = 1
  6445. S_AUTHORIZING, =2
  6446. S_REASSIGN_CHECK, =3
  6447. S_REASSIGN, =4
  6448. S_PRECHARGE, =5
  6449. S_PREPARING_FOR_EV, =6
  6450. S_PREPARING_FOR_EVSE, =7
  6451. S_CHARGING, =8
  6452. S_TERMINATING, =9
  6453. S_COMPLETE, =10
  6454. S_ALARM, =11
  6455. S_FAULT =12
  6456. }
  6457. */
  6458. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6459. {
  6460. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6461. goto end;
  6462. }
  6463. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6464. {
  6465. //check Transaction active
  6466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6467. {
  6468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6469. {
  6470. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6471. {
  6472. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6473. {
  6474. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6475. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6476. {
  6477. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6478. {
  6479. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6481. }
  6482. 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'))
  6483. {
  6484. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6485. }
  6486. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6487. {
  6488. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6489. }
  6490. else
  6491. {
  6492. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6493. }
  6494. }
  6495. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6496. {
  6497. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6498. }
  6499. }
  6500. else
  6501. {
  6502. //replace reservation
  6503. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6504. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6505. }
  6506. }
  6507. } // END FOR CHAdeMO_QUANTITY
  6508. for (int index = 0; index < CCS_QUANTITY; index++)
  6509. {
  6510. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6511. {
  6512. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6513. {
  6514. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6515. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6516. {
  6517. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6518. {
  6519. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6520. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6521. }
  6522. 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'))
  6523. {
  6524. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6525. }
  6526. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6527. {
  6528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6529. }
  6530. else
  6531. {
  6532. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6533. }
  6534. }
  6535. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6536. {
  6537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6538. }
  6539. }
  6540. else
  6541. {
  6542. //replace reservation
  6543. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6544. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6545. }
  6546. }
  6547. } // END FOR CCS_QUANTITY
  6548. for (int index = 0; index < GB_QUANTITY; index++)
  6549. {
  6550. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6551. {
  6552. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6553. {
  6554. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6555. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6556. {
  6557. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6558. {
  6559. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6560. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6561. }
  6562. 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'))
  6563. {
  6564. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6565. }
  6566. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6567. {
  6568. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6569. }
  6570. else
  6571. {
  6572. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6573. }
  6574. }
  6575. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6576. {
  6577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6578. }
  6579. }
  6580. else
  6581. {
  6582. //replace reservation
  6583. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6584. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6585. }
  6586. }
  6587. }// END FOR GB_QUANTITY
  6588. }
  6589. else
  6590. {
  6591. for (int index = 0; index < AC_QUANTITY; index++)
  6592. {
  6593. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6594. {
  6595. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6596. {
  6597. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6598. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6599. {
  6600. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6601. {
  6602. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6604. }
  6605. 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'))
  6606. {
  6607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6608. }
  6609. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6610. {
  6611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6612. }
  6613. else
  6614. {
  6615. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6616. }
  6617. }
  6618. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6619. {
  6620. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6621. }
  6622. }
  6623. else
  6624. {
  6625. //replace reservation
  6626. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6628. }
  6629. }
  6630. } // END FOR AC_QUANTITY
  6631. }//END FOR AC ELSE
  6632. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6633. }
  6634. else if(connectorIdInt == 0)
  6635. {
  6636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6637. {
  6638. //check Transaction active
  6639. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6640. {
  6641. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6642. {
  6643. 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'))
  6644. {
  6645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6646. goto end;
  6647. }
  6648. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6649. {
  6650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6651. goto end;
  6652. }
  6653. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6654. {
  6655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6656. goto end;
  6657. }
  6658. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6659. {
  6660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6661. goto end;
  6662. }
  6663. }
  6664. }// END FOR CHAdeMO_QUANTITY
  6665. for (int index = 0; index < CCS_QUANTITY; index++)
  6666. {
  6667. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6668. {
  6669. 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'))
  6670. {
  6671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6672. }
  6673. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6674. {
  6675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6676. }
  6677. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6678. {
  6679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6680. }
  6681. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6682. {
  6683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6684. }
  6685. }
  6686. } // END FOR CCS_QUANTITY
  6687. for (int index = 0; index < GB_QUANTITY; index++)
  6688. {
  6689. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6690. {
  6691. 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'))
  6692. {
  6693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6694. }
  6695. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6696. {
  6697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6698. }
  6699. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6700. {
  6701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6702. }
  6703. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6704. {
  6705. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6706. }
  6707. }
  6708. } // END FOR GB_QUANTITY
  6709. }
  6710. else
  6711. {
  6712. for (int index = 0; index < AC_QUANTITY; index++)
  6713. {
  6714. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6715. {
  6716. 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'))
  6717. {
  6718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6719. goto end;
  6720. }
  6721. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6722. {
  6723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6724. goto end;
  6725. }
  6726. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6727. {
  6728. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6729. goto end;
  6730. }
  6731. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6732. {
  6733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6734. goto end;
  6735. }
  6736. }
  6737. }// END FOR AC_QUANTITY
  6738. }
  6739. //The connectorId is 0
  6740. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6741. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6742. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6743. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6744. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6745. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6746. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6747. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6748. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6749. result = TRUE;
  6750. return result;
  6751. }
  6752. else
  6753. {
  6754. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6755. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6756. }
  6757. if(strcmp(comfirmstr,"Accepted") == 0)
  6758. {
  6759. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6760. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6761. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6762. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6763. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6764. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6765. result = TRUE;
  6766. return result;
  6767. }
  6768. end:
  6769. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6770. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6771. return result;
  6772. }
  6773. int handleResetRequest(char *uuid, char *payload)
  6774. {
  6775. mtrace();
  6776. int result = FAIL;
  6777. char sstr[10]={0};
  6778. char typestr[10]={0};
  6779. char comfirmstr[20]={0};
  6780. int c = 0;
  6781. char *loc;
  6782. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6783. DEBUG_INFO("handleResetRequest ...\n");
  6784. loc = strstr(payload, "type");
  6785. memset(sstr ,0, sizeof(sstr) );
  6786. c = 0;
  6787. while (loc[3+strlen("type")+c] != '\"')
  6788. {
  6789. sstr[c] = loc[3+strlen("type")+c];
  6790. c++;
  6791. }
  6792. sstr[c] = '\0';
  6793. strcpy(typestr,sstr);
  6794. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6795. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6796. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6797. {
  6798. //check Transaction active
  6799. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6800. {
  6801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6802. {
  6803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6804. {
  6805. //0: unplug, 1: Plug-in
  6806. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6807. }
  6808. }
  6809. for (int index = 0; index < CCS_QUANTITY; index++)
  6810. {
  6811. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6812. {
  6813. //0: unplug, 1: Plug-in
  6814. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6815. }
  6816. }
  6817. for (int index = 0; index < GB_QUANTITY; index++)
  6818. {
  6819. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6820. {
  6821. //0: unplug, 1: Plug-in
  6822. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6823. }
  6824. }
  6825. }
  6826. else
  6827. {
  6828. for (int index = 0; index < AC_QUANTITY; index++)
  6829. {
  6830. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6831. {
  6832. //0: unplug, 1: Plug-in
  6833. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6834. }
  6835. }
  6836. }// END FOR AC ELSE
  6837. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6838. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6839. result = TRUE;
  6840. return result;
  6841. }
  6842. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6843. {
  6844. //check Transaction active
  6845. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6846. {
  6847. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6848. {
  6849. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6850. {
  6851. //0: unplug, 1: Plug-in
  6852. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6853. }
  6854. }
  6855. for (int index = 0; index < CCS_QUANTITY; index++)
  6856. {
  6857. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6858. {
  6859. //0: unplug, 1: Plug-in
  6860. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6861. }
  6862. }
  6863. for (int index = 0; index < GB_QUANTITY; index++)
  6864. {
  6865. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6866. {
  6867. //0: unplug, 1: Plug-in
  6868. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6869. }
  6870. }
  6871. }
  6872. else
  6873. {
  6874. for (int index = 0; index < AC_QUANTITY; index++)
  6875. {
  6876. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6877. {
  6878. //0: unplug, 1: Plug-in
  6879. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6880. }
  6881. }
  6882. }// END FOR AC ELSE
  6883. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6884. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6885. result = TRUE;
  6886. return result;
  6887. }
  6888. else
  6889. {
  6890. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6891. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6892. goto errorend;
  6893. }
  6894. errorend:
  6895. sendResetConfirmation(uuid, comfirmstr);
  6896. return result;
  6897. }
  6898. int handleSendLocalListRequest(char *uuid, char *payload)
  6899. {
  6900. mtrace();
  6901. int result = FAIL;
  6902. int listVersionInt;
  6903. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6904. char listsearch[]="listVersion";
  6905. char updateTypesearch[]="updateType";
  6906. char localAuthorizationListsearch[]="localAuthorizationList";
  6907. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6908. char CardList[500][160]={0};
  6909. char updateTypestr[15]={0};
  6910. char idTagstr[20]={0};
  6911. char parentIdTag[20]={0};
  6912. char expiryDate[30]={0};
  6913. char idTagstatus[16]={0};
  6914. int c = 0;
  6915. int i = 0;
  6916. char *delim1 = "}";
  6917. char * pch;
  6918. char *loc;
  6919. //char *ptr;
  6920. char comfirmstr[20];
  6921. //int n_localAuthorizations = 0;
  6922. int checkState_Faulted = FALSE;
  6923. DEBUG_INFO("handleSendLocalListRequest\n");
  6924. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6925. {
  6926. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6927. goto end;
  6928. }
  6929. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6930. {
  6931. //check Charge Point state
  6932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6933. {
  6934. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6935. {
  6936. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6937. }
  6938. }
  6939. for (int index = 0; index < CCS_QUANTITY; index++)
  6940. {
  6941. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6942. {
  6943. checkState_Faulted = TRUE; //OCPP Status
  6944. }
  6945. }
  6946. for (int index = 0; index < GB_QUANTITY; index++)
  6947. {
  6948. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6949. {
  6950. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6951. }
  6952. }
  6953. }
  6954. else
  6955. {
  6956. //check Charge Point state
  6957. for (int index = 0; index < AC_QUANTITY; index++)
  6958. {
  6959. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6960. {
  6961. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6962. }
  6963. }
  6964. }// END FOR AC ELSE
  6965. if(checkState_Faulted == TRUE)
  6966. {
  6967. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6968. goto end;
  6969. }
  6970. //listVersion
  6971. c = 0;
  6972. loc = strstr(payload, listsearch);
  6973. while (loc[strlen("listVersion")+2+c] != ',')
  6974. {
  6975. sstr[c] = loc[strlen("listVersion")+2+c];
  6976. c++;
  6977. }
  6978. sstr[c] = '\0';
  6979. listVersionInt = atoi(sstr);
  6980. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6981. //updateType
  6982. loc = strstr(payload, updateTypesearch);
  6983. c = 0;
  6984. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6985. {
  6986. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6987. c++;
  6988. }
  6989. sstr[c] = '\0';
  6990. strcpy(updateTypestr, sstr);
  6991. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6992. //localAuthorizationList
  6993. memset(sstr ,0, sizeof(sstr) );
  6994. loc = strstr(payload, localAuthorizationListsearch);
  6995. if(loc != NULL) // localAuthorizationList is not NULL
  6996. {
  6997. //Check UpdateType
  6998. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6999. {
  7000. //Local list full update
  7001. printf("Local list full update.\n");
  7002. OCPP_cleanLocalList();
  7003. }
  7004. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7005. {
  7006. //Local list different update
  7007. printf("Local list different update.\n");
  7008. OCPP_getListVerion();
  7009. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7010. {
  7011. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7012. goto end;
  7013. }
  7014. }
  7015. else
  7016. {
  7017. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7018. goto end;
  7019. }
  7020. c = 0;
  7021. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7022. {
  7023. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7024. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7025. c++;
  7026. }
  7027. sstr[c] = '\0';
  7028. //parsing strings to words
  7029. i = 0;
  7030. pch = strtok(sstr,delim1);
  7031. while (pch != NULL)
  7032. {
  7033. strcpy(CardList[i], pch);
  7034. pch = strtok (NULL, delim1);
  7035. i = i + 1;
  7036. }
  7037. //local Authorizations List Numbers
  7038. //n_localAuthorizations = i;
  7039. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7040. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7041. c= 0;
  7042. while(c < i)
  7043. {
  7044. //Search "IdToken"
  7045. memset(sstr ,0, sizeof(sstr) );
  7046. loc = strstr(CardList[c], "idTag");
  7047. int j = 0;
  7048. while (loc[3+strlen("idTag")+j] != '\"')
  7049. {
  7050. sstr[j] = loc[3+strlen("idTag")+j];
  7051. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7052. j++;
  7053. }
  7054. sstr[j] = '\0';
  7055. strcpy(idTagstr, sstr);
  7056. //Search "expiryDate"
  7057. memset(sstr ,0, sizeof(sstr) );
  7058. loc = strstr(CardList[c], "expiryDate");
  7059. j = 0;
  7060. while (loc[3+strlen("expiryDate")+j] != '\"')
  7061. {
  7062. sstr[j] = loc[3+strlen("expiryDate")+j];
  7063. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7064. j++;
  7065. }
  7066. sstr[j] = '\0';
  7067. strcpy(expiryDate, sstr);
  7068. //Search "parentIdTag"
  7069. memset(sstr ,0, sizeof(sstr) );
  7070. loc = strstr(CardList[c], "parentIdTag");
  7071. j = 0;
  7072. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7073. {
  7074. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7075. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7076. j++;
  7077. }
  7078. sstr[j] = '\0';
  7079. strcpy(parentIdTag, sstr);
  7080. //Search "status"
  7081. memset(sstr ,0, sizeof(sstr) );
  7082. loc = strstr(CardList[c], "status");
  7083. j = 0;
  7084. while (loc[3+strlen("status")+j] != '\"')
  7085. {
  7086. sstr[j] = loc[3+strlen("status")+j];
  7087. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7088. j++;
  7089. }
  7090. sstr[j] = '\0';
  7091. strcpy(idTagstatus, sstr);
  7092. OCPP_getIdTag(idTagstr);
  7093. //OCPP_getIdTag("test"); For Test
  7094. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7095. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7096. {
  7097. //Local list full update
  7098. DEBUG_INFO("Local list full update.\n");
  7099. // update list
  7100. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7101. OCPP_get_TableAuthlocalAllData();
  7102. }
  7103. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7104. {
  7105. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7106. {
  7107. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7108. }
  7109. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7110. {
  7111. OCPP_deleteIdTag(idTagstr);
  7112. }
  7113. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7114. {
  7115. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7116. }
  7117. }
  7118. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7119. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7120. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7121. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7122. c++;
  7123. }
  7124. }
  7125. else
  7126. {
  7127. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7128. {
  7129. //Local list different update
  7130. DEBUG_INFO("Local list different update.\n");
  7131. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7132. goto end;
  7133. }
  7134. }
  7135. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7136. end:
  7137. sendSendLocalListConfirmation(uuid, comfirmstr);
  7138. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7139. #if 0
  7140. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7141. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7142. #endif
  7143. return result;
  7144. }
  7145. /*
  7146. enum _SYSTEM_STATUS
  7147. {
  7148. S_BOOTING = 0,
  7149. S_IDLE, =1
  7150. S_AUTHORIZING, =2
  7151. S_REASSIGN_CHECK, =3
  7152. S_REASSIGN, =4
  7153. S_PRECHARGE, =5
  7154. S_PREPARING_FOR_EV, =6
  7155. S_PREPARING_FOR_EVSE, =7
  7156. S_CHARGING, =8
  7157. S_TERMINATING, =9
  7158. S_COMPLETE, =10
  7159. S_ALARM, =11
  7160. S_FAULT =12
  7161. };
  7162. */
  7163. #define MAX 200
  7164. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7165. {
  7166. mtrace();
  7167. int result = FAIL;
  7168. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7169. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7170. char chargingProfilePurposeStr[30]={0};
  7171. char chargingProfileKindStr[16]={0};
  7172. char recurrencyKindStr[10]={0};
  7173. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7174. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7175. int chargingSchedulePeriodCount = 0;
  7176. //int updateflag = FALSE;
  7177. char comfirmstr[20]={0};
  7178. int meet= FALSE;
  7179. char sstr[10]={0};
  7180. int c = 0;
  7181. char *loc;
  7182. FILE *fptr1;//, *fptr2;
  7183. //int lno=0;//, linectr = 0;
  7184. //int modifyflag = FALSE;
  7185. char filename[MAX]={0};
  7186. char tempfile[] = "../Storage/OCPP/temp.json";
  7187. int resultRename=0;
  7188. char rmFileCmd[50]={0};
  7189. char tempchargingProfilePurposeStr[30]={0};
  7190. //[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}}}]
  7191. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7192. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7193. //*********************connectorId***************************/
  7194. loc = strstr(payload, "connectorId");
  7195. c = 0;
  7196. memset(sstr ,0, sizeof(sstr) );
  7197. while (loc[strlen("connectorId")+2+c] != ',')
  7198. {
  7199. sstr[c] = loc[strlen("connectorId")+2+c];
  7200. c++;
  7201. }
  7202. sstr[c] = '\0';
  7203. connectorIdInt = atoi(sstr);
  7204. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7205. {
  7206. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7207. }
  7208. else
  7209. {
  7210. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7211. }
  7212. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7213. //*********************chargingProfileId***************************/
  7214. loc = strstr(payload, "chargingProfileId");
  7215. c = 0;
  7216. memset(sstr ,0, sizeof(sstr) );
  7217. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7218. {
  7219. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7220. c++;
  7221. }
  7222. sstr[c] = '\0';
  7223. chargingProfileIdInt = atoi(sstr);
  7224. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7225. {
  7226. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7227. }
  7228. else
  7229. {
  7230. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7231. }
  7232. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7233. //*********************transactionId***************************/
  7234. loc = strstr(payload, "transactionId");
  7235. if(loc != NULL)
  7236. {
  7237. c = 0;
  7238. memset(sstr ,0, sizeof(sstr) );
  7239. while (loc[strlen("transactionId")+2+c] != ',')
  7240. {
  7241. sstr[c] = loc[strlen("transactionId")+2+c];
  7242. c++;
  7243. }
  7244. sstr[c] = '\0';
  7245. transactionIdInt = atoi(sstr);
  7246. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7247. {
  7248. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7249. }
  7250. else
  7251. {
  7252. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7253. }
  7254. }
  7255. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7256. //*********************stackLevel***************************/
  7257. loc = strstr(payload, "stackLevel");
  7258. c = 0;
  7259. memset(sstr ,0, sizeof(sstr) );
  7260. while (loc[strlen("stackLevel")+2+c] != ',')
  7261. {
  7262. sstr[c] = loc[strlen("stackLevel")+2+c];
  7263. c++;
  7264. }
  7265. sstr[c] = '\0';
  7266. stackLevelInt = atoi(sstr);
  7267. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7268. {
  7269. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7270. }
  7271. else
  7272. {
  7273. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7274. }
  7275. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7276. //*********************chargingProfilePurpose***************************/
  7277. loc = strstr(payload, "chargingProfilePurpose");
  7278. c = 0;
  7279. memset(sstr ,0, sizeof(sstr) );
  7280. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7281. {
  7282. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7283. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7284. c++;
  7285. }
  7286. sstr[c] = '\0';
  7287. strcpy(chargingProfilePurposeStr,sstr);
  7288. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7289. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7290. {
  7291. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7292. }
  7293. else
  7294. {
  7295. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7296. }
  7297. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7298. //*********************chargingProfileKind***************************/
  7299. loc = strstr(payload, "chargingProfileKind");
  7300. c = 0;
  7301. memset(sstr ,0, sizeof(sstr) );
  7302. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7303. {
  7304. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7305. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7306. c++;
  7307. }
  7308. sstr[c] = '\0';
  7309. strcpy(chargingProfileKindStr,sstr);
  7310. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7311. {
  7312. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7313. }
  7314. else
  7315. {
  7316. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7317. }
  7318. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7319. //*********************recurrencyKind***************************/
  7320. loc = strstr(payload, "recurrencyKind");
  7321. if(loc != NULL)
  7322. {
  7323. c = 0;
  7324. memset(sstr ,0, sizeof(sstr) );
  7325. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7326. {
  7327. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7328. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7329. c++;
  7330. }
  7331. sstr[c] = '\0';
  7332. strcpy(recurrencyKindStr,sstr);
  7333. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7334. {
  7335. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7336. }
  7337. else
  7338. {
  7339. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7340. }
  7341. }
  7342. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7343. //*********************validFrom***************************/
  7344. loc = strstr(payload, "validFrom");
  7345. if(loc != NULL)
  7346. {
  7347. c = 0;
  7348. memset(sstr ,0, sizeof(sstr) );
  7349. while (loc[3+strlen("validFrom")+c] != '\"')
  7350. {
  7351. sstr[c] = loc[3+strlen("validFrom")+c];
  7352. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7353. c++;
  7354. }
  7355. sstr[c] = '\0';
  7356. strcpy(validFromStr,sstr);
  7357. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7358. {
  7359. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7360. }
  7361. else
  7362. {
  7363. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7364. }
  7365. }
  7366. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7367. //*********************validTo***************************/
  7368. loc = strstr(payload, "validTo");
  7369. if(loc != NULL)
  7370. {
  7371. c = 0;
  7372. memset(sstr ,0, sizeof(sstr) );
  7373. while (loc[3+strlen("validTo")+c] != '\"')
  7374. {
  7375. sstr[c] = loc[3+strlen("validTo")+c];
  7376. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7377. c++;
  7378. }
  7379. sstr[c] = '\0';
  7380. strcpy(validToStr,sstr);
  7381. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7382. {
  7383. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7384. }
  7385. else
  7386. {
  7387. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7388. }
  7389. }
  7390. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7391. //*********************duration***************************/
  7392. loc = strstr(payload, "duration");
  7393. if(loc != NULL)
  7394. {
  7395. c = 0;
  7396. memset(sstr ,0, sizeof(sstr) );
  7397. while (loc[strlen("duration")+2+c] != ',')
  7398. {
  7399. sstr[c] = loc[strlen("duration")+2+c];
  7400. c++;
  7401. }
  7402. sstr[c] = '\0';
  7403. durationInt = atoi(sstr);
  7404. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7405. {
  7406. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7407. }
  7408. else
  7409. {
  7410. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7411. }
  7412. }
  7413. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7414. //*********************startSchedule***************************/
  7415. loc = strstr(payload, "startSchedule");
  7416. if(loc != NULL)
  7417. {
  7418. c = 0;
  7419. memset(sstr ,0, sizeof(sstr) );
  7420. while (loc[3+strlen("startSchedule")+c] != '\"')
  7421. {
  7422. sstr[c] = loc[3+strlen("startSchedule")+c];
  7423. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7424. c++;
  7425. }
  7426. sstr[c] = '\0';
  7427. strcpy(startScheduleStr,sstr);
  7428. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7429. {
  7430. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7431. }
  7432. else
  7433. {
  7434. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7435. }
  7436. }
  7437. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7438. //*********************chargingRateUnit***************************/
  7439. loc = strstr(payload, "chargingRateUnit");
  7440. if(loc != NULL)
  7441. {
  7442. c = 0;
  7443. memset(sstr ,0, sizeof(sstr) );
  7444. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7445. {
  7446. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7447. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7448. c++;
  7449. }
  7450. sstr[c] = '\0';
  7451. strcpy(chargingRateUnitStr,sstr);
  7452. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7453. {
  7454. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7455. }
  7456. else
  7457. {
  7458. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7459. }
  7460. }
  7461. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7462. //****************chargingSchedulePeriod count start*******************/
  7463. int what_len = strlen("startPeriod");
  7464. char *where = payload;
  7465. if (what_len)
  7466. while ((where = strstr(where, "startPeriod"))) {
  7467. where += what_len;
  7468. chargingSchedulePeriodCount++;
  7469. }
  7470. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7471. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7472. where = payload;
  7473. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7474. {
  7475. //****************startPeriod*******************/
  7476. c=0;
  7477. loc = strstr(where, "startPeriod");
  7478. memset(sstr ,0, sizeof(sstr) );
  7479. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7480. {
  7481. sstr[c] = loc[strlen("startPeriod")+2+c];
  7482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7483. c++;
  7484. }
  7485. sstr[c] = '\0';
  7486. startPeriodInt[periodNums] = atoi(sstr);
  7487. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7488. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7489. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7490. {
  7491. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7492. }
  7493. else
  7494. {
  7495. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7496. }
  7497. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7498. //****************limit*******************/
  7499. c=0;
  7500. loc = strstr(where, "limit");
  7501. memset(sstr ,0, sizeof(sstr) );
  7502. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7503. {
  7504. sstr[c] = loc[strlen("limit")+2+c];
  7505. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7506. c++;
  7507. }
  7508. sstr[c] = '\0';
  7509. limitflaot[periodNums] = atof(sstr);
  7510. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7511. {
  7512. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7513. }
  7514. else
  7515. {
  7516. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7517. }
  7518. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7519. //****************numberPhases*******************/
  7520. loc = strstr(where, "numberPhases");
  7521. if(loc != NULL)
  7522. {
  7523. c=0;
  7524. memset(sstr ,0, sizeof(sstr) );
  7525. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7526. {
  7527. sstr[c] = loc[strlen("numberPhases")+2+c];
  7528. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7529. c++;
  7530. }
  7531. sstr[c] = '\0';
  7532. numberPhasesInt[periodNums] = atoi(sstr);
  7533. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7534. {
  7535. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7536. }
  7537. else
  7538. {
  7539. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7540. }
  7541. }
  7542. where = loc;
  7543. }
  7544. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7545. //****************chargingSchedulePeriod count end*******************/
  7546. //*********************minChargingRate***************************/
  7547. loc = strstr(payload, "minChargingRate");
  7548. if(loc != NULL)
  7549. {
  7550. c = 0;
  7551. memset(sstr ,0, sizeof(sstr) );
  7552. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7553. {
  7554. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7555. c++;
  7556. }
  7557. sstr[c] = '\0';
  7558. minChargingRateFloat = atof(sstr);
  7559. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7560. {
  7561. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7562. }
  7563. else
  7564. {
  7565. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7566. }
  7567. }
  7568. DEBUG_INFO("\n\n Replace a specific line in a text file with a new text :\n");
  7569. DEBUG_INFO("-------------------------------------------------------------\n");
  7570. DEBUG_INFO(" Input the file name to be opened : ");
  7571. //fgets(fname, MAX, stdin);
  7572. //fname[strlen(fname) - 1] = '\0';
  7573. #if 0
  7574. switch(connectorIdInt)
  7575. {
  7576. case 0:
  7577. strcpy(filename, ChargingProfile_0_JSON );
  7578. break;
  7579. case 1:
  7580. strcpy(filename, ChargingProfile_1_JSON );
  7581. break;
  7582. case 2:
  7583. strcpy(filename, ChargingProfile_2_JSON );
  7584. break;
  7585. default:
  7586. strcpy(filename, ChargingProfile_0_JSON );
  7587. break;
  7588. }
  7589. fptr1 = fopen(filename, "r");
  7590. if (!fptr1)
  7591. {
  7592. //file not exist
  7593. DEBUG_INFO("Unable to open the input file!!\n");
  7594. fptr1 = fopen(filename, "w+");
  7595. }
  7596. fclose(fptr1);
  7597. #endif
  7598. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7599. //DEBUG_INFO(" ChargingProfilePurposeTypeStr[TxProfile]=%s\n", ChargingProfilePurposeTypeStr[TxProfile]);
  7600. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7601. {
  7602. //printf("set chargingProfile 1-2\n");
  7603. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7604. if(connectorIdInt != 0)
  7605. {
  7606. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7607. goto end;
  7608. }
  7609. strcpy(filename, ChargePointMaxProfile_JSON );
  7610. fptr1 = fopen(filename, "r");
  7611. if (!fptr1)
  7612. {
  7613. //file not exist
  7614. DEBUG_INFO("Unable to open the input file!!\n");
  7615. fptr1 = fopen(filename, "w+");
  7616. }
  7617. fclose(fptr1);
  7618. }
  7619. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7620. {
  7621. //printf("set chargingProfile 1-3\n");
  7622. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7623. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7624. {
  7625. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7626. goto end;
  7627. }
  7628. switch(connectorIdInt)
  7629. {
  7630. case 0:
  7631. strcpy(filename, TxDefaultProfile_0_JSON );
  7632. break;
  7633. case 1:
  7634. strcpy(filename, TxDefaultProfile_1_JSON );
  7635. break;
  7636. case 2:
  7637. strcpy(filename, TxDefaultProfile_2_JSON );
  7638. break;
  7639. default:
  7640. strcpy(filename, TxDefaultProfile_0_JSON );
  7641. break;
  7642. }
  7643. fptr1 = fopen(filename, "r");
  7644. if (!fptr1)
  7645. {
  7646. //file not exist
  7647. DEBUG_INFO("Unable to open the input file!!\n");
  7648. fptr1 = fopen(filename, "w+");
  7649. }
  7650. fclose(fptr1);
  7651. }
  7652. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7653. {
  7654. //printf("set chargingProfile 1-4\n");
  7655. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7656. //check Transaction active
  7657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7658. {
  7659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7660. {
  7661. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7662. {
  7663. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7664. {
  7665. meet = TRUE;
  7666. break;
  7667. }
  7668. }
  7669. }
  7670. }
  7671. for (int index = 0; index < CCS_QUANTITY; index++)
  7672. {
  7673. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7674. {
  7675. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7676. {
  7677. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7678. {
  7679. meet = TRUE;
  7680. break;
  7681. }
  7682. }
  7683. }
  7684. }
  7685. for (int index = 0; index < GB_QUANTITY; index++)
  7686. {
  7687. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7688. {
  7689. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7690. {
  7691. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7692. {
  7693. meet = TRUE;
  7694. break;
  7695. }
  7696. }
  7697. }
  7698. }
  7699. if(meet == FALSE)
  7700. {
  7701. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7702. goto end;
  7703. }
  7704. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7705. {
  7706. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7707. goto end;
  7708. }
  7709. switch(connectorIdInt)
  7710. {
  7711. case 0:
  7712. break;
  7713. case 1:
  7714. strcpy(filename, TxProfile_1_JSON);
  7715. break;
  7716. case 2:
  7717. strcpy(filename, TxProfile_2_JSON);
  7718. break;
  7719. default:
  7720. strcpy(filename, TxProfile_1_JSON);
  7721. break;
  7722. }
  7723. fptr1 = fopen(filename, "r");
  7724. if (!fptr1)
  7725. {
  7726. //file not exist
  7727. DEBUG_INFO("Unable to open the input file!!\n");
  7728. fptr1 = fopen(filename, "w+");
  7729. }
  7730. fclose(fptr1);
  7731. }
  7732. //**********************************Write to File********************************************************/
  7733. FILE *infile;
  7734. FILE *outfile;
  7735. // open file for writing
  7736. infile = fopen (filename, "r");
  7737. outfile = fopen (tempfile, "w");
  7738. int d =0;
  7739. d = fgetc(infile);
  7740. DEBUG_INFO("d:%d\n",d);
  7741. rewind(infile);
  7742. //*检测到文件结束标识返回1,否则返回0。*/
  7743. if(d == EOF)
  7744. {
  7745. DEBUG_INFO("ChargingProfile content is NULL\n");
  7746. fprintf(outfile,"[%s]\n",payload);
  7747. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7748. fclose(infile);
  7749. fclose(outfile);
  7750. sprintf(rmFileCmd,"rm -f %s",filename);
  7751. system(rmFileCmd);
  7752. resultRename = rename(tempfile, filename);
  7753. if(resultRename == 0)
  7754. {
  7755. DEBUG_INFO("File chargingProfile renamed successfully");
  7756. }
  7757. else
  7758. {
  7759. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7760. }
  7761. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7762. //system(rmFileCmd);
  7763. }
  7764. else
  7765. {
  7766. char buf[1000]={0};
  7767. while (fgets(buf, sizeof(buf), infile) != NULL)
  7768. {
  7769. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7770. //*************************tempconnectorIdInt*********************************/
  7771. loc = strstr(buf, "connectorId");
  7772. c = 0;
  7773. memset(sstr ,0, sizeof(sstr) );
  7774. while (loc[strlen("connectorId")+2+c] != ',')
  7775. {
  7776. sstr[c] = loc[strlen("connectorId")+2+c];
  7777. c++;
  7778. }
  7779. sstr[c] = '\0';
  7780. tempconnectorIdInt = atoi(sstr);
  7781. //*************************tempchargingProfileIdInt*********************************/
  7782. loc = strstr(buf, "chargingProfileId");
  7783. c = 0;
  7784. memset(sstr ,0, sizeof(sstr) );
  7785. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7786. {
  7787. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7788. c++;
  7789. }
  7790. sstr[c] = '\0';
  7791. tempchargingProfileIdInt = atoi(sstr);
  7792. //*************************tempstackLevelInt*********************************/
  7793. loc = strstr(buf, "stackLevel");
  7794. c = 0;
  7795. memset(sstr ,0, sizeof(sstr) );
  7796. while (loc[strlen("stackLevel")+2+c] != ',')
  7797. {
  7798. sstr[c] = loc[strlen("stackLevel")+2+c];
  7799. c++;
  7800. }
  7801. sstr[c] = '\0';
  7802. tempstackLevelInt = atoi(sstr);
  7803. //*************************tempchargingProfilePurposeStr*********************************/
  7804. loc = strstr(payload, "chargingProfilePurpose");
  7805. c = 0;
  7806. memset(sstr ,0, sizeof(sstr) );
  7807. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7808. {
  7809. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7810. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7811. c++;
  7812. }
  7813. sstr[c] = '\0';
  7814. strcpy(tempchargingProfilePurposeStr,sstr);
  7815. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7816. {
  7817. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7818. {
  7819. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7820. fprintf(outfile,"[%s]\n",payload);
  7821. }
  7822. else
  7823. {
  7824. //DEBUG_INFO("update set chargingProfile to file -1\n");
  7825. if(tempstackLevelInt < stackLevelInt)
  7826. {
  7827. //DEBUG_INFO("update set chargingProfile to file -2\n");
  7828. fprintf(outfile,"[%s]\n",payload);
  7829. fprintf(outfile,"[%s]\n",buf);
  7830. }
  7831. else
  7832. {
  7833. fprintf(outfile,"[%s]\n",buf);
  7834. fprintf(outfile,"[%s]\n",payload);
  7835. }
  7836. }
  7837. DEBUG_INFO("update set chargingProfile to file\n");
  7838. }
  7839. else
  7840. {
  7841. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7842. {
  7843. fprintf(outfile,"[%s]\n",payload);
  7844. fprintf(outfile,"[%s]\n",buf);
  7845. }
  7846. else if(tempstackLevelInt < stackLevelInt)
  7847. {
  7848. fprintf(outfile,"[%s]\n",payload);
  7849. fprintf(outfile,"[%s]\n",buf);
  7850. }
  7851. else
  7852. {
  7853. fprintf(outfile,"[%s]\n",buf);
  7854. fprintf(outfile,"[%s]\n",payload);
  7855. }
  7856. fprintf(outfile,"[%s]\n",buf);
  7857. DEBUG_INFO("add set chargingProfile to file\n");
  7858. }
  7859. } // end of while loop
  7860. fclose(infile);
  7861. fclose(outfile);
  7862. sprintf(rmFileCmd,"rm -f %s",filename);
  7863. system(rmFileCmd);
  7864. resultRename = rename(tempfile, filename);
  7865. if(resultRename == 0)
  7866. {
  7867. DEBUG_INFO("File chargingProfile renamed successfully");
  7868. }
  7869. else
  7870. {
  7871. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7872. }
  7873. result = TRUE;
  7874. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7875. }
  7876. end:
  7877. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7878. return result;
  7879. return result;
  7880. }
  7881. int handleTriggerMessageRequest(char *uuid, char *payload)
  7882. {
  7883. mtrace();
  7884. int result = FAIL;
  7885. int connectorIdIsNULL = FALSE;
  7886. int connectorIdInt =0;
  7887. char sstr[40]={0};
  7888. char requestedMessagestr[40]={0};
  7889. char comfirmstr[20]={0};
  7890. int c = 0;
  7891. char *loc;
  7892. DEBUG_INFO("handleTriggerMessageRequest\n");
  7893. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7894. c = 0;
  7895. loc = strstr(payload, "requestedMessage");
  7896. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7897. {
  7898. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7899. c++;
  7900. }
  7901. sstr[c] = '\0';
  7902. strcpy(requestedMessagestr, sstr);
  7903. c = 0;
  7904. loc = strstr(payload, "connectorId");
  7905. if(loc == NULL)
  7906. {
  7907. connectorIdIsNULL = TRUE;
  7908. }
  7909. else
  7910. {
  7911. memset(sstr ,0, sizeof(sstr) );
  7912. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7913. {
  7914. sstr[c] = loc[strlen("connectorId")+2+c];
  7915. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7916. c++;
  7917. }
  7918. sstr[c] = '\0';
  7919. connectorIdInt = atoi(sstr);
  7920. }
  7921. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7922. {
  7923. //connectorIdInt = json_object_get_int(connectorId);
  7924. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7925. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7926. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7927. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7928. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7929. }
  7930. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7931. {
  7932. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7933. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7934. return TRUE;
  7935. }
  7936. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7937. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7938. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7939. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7940. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7941. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7942. {
  7943. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7944. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7945. return TRUE;
  7946. }
  7947. else
  7948. {
  7949. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7950. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7951. }
  7952. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7953. {
  7954. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  7955. {
  7956. FirmwareStatusNotificationStatus = 3;
  7957. }
  7958. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7959. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7960. }
  7961. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7962. {
  7963. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7964. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7965. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7966. }
  7967. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7968. {
  7969. sendBootNotificationRequest();
  7970. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7971. }
  7972. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7973. {
  7974. sendHeartbeatRequest(connectorIdInt);
  7975. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7976. }
  7977. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7978. {
  7979. if(connectorIdIsNULL == FALSE)
  7980. {
  7981. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7982. {
  7983. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7984. sendMeterValuesRequest(connectorIdInt -1);
  7985. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7986. }
  7987. }
  7988. else
  7989. {
  7990. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7991. {
  7992. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  7993. sendMeterValuesRequest(idx);
  7994. }
  7995. }
  7996. }
  7997. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  7998. {
  7999. if(connectorIdIsNULL == FALSE)
  8000. {
  8001. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8002. {
  8003. sendStatusNotificationRequest(connectorIdInt -1);
  8004. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8005. }
  8006. }
  8007. else
  8008. {
  8009. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8010. sendStatusNotificationRequest(idx);
  8011. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8012. }
  8013. }
  8014. return result;
  8015. }
  8016. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8017. {
  8018. mtrace();
  8019. int result = FAIL;
  8020. char sstr[6]={0};
  8021. int connectorIdInt =0;
  8022. char comfirmstr[20]={0};
  8023. int c = 0;
  8024. char *loc;
  8025. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8026. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8027. c = 0;
  8028. loc = strstr(payload, "connectorId");
  8029. memset(sstr ,0, sizeof(sstr) );
  8030. while (loc[strlen("connectorId")+2+c] != '}')
  8031. {
  8032. sstr[c] = loc[strlen("connectorId")+2+c];
  8033. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8034. c++;
  8035. }
  8036. sstr[c] = '\0';
  8037. connectorIdInt = atoi(sstr);
  8038. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8039. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8040. {
  8041. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8042. goto end;
  8043. }
  8044. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8045. {
  8046. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8047. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8048. goto end;
  8049. }
  8050. else
  8051. {
  8052. //check Transaction active
  8053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8054. {
  8055. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8056. {
  8057. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8058. {
  8059. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8060. }
  8061. }
  8062. for (int index = 0; index < CCS_QUANTITY; index++)
  8063. {
  8064. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8065. {
  8066. //stop Transaction
  8067. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8068. }
  8069. }
  8070. for (int index = 0; index < GB_QUANTITY; index++)
  8071. {
  8072. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8073. {
  8074. //stop Transaction
  8075. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8076. }
  8077. }
  8078. }
  8079. else
  8080. {
  8081. for (int index = 0; index < AC_QUANTITY; index++)
  8082. {
  8083. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8084. {
  8085. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8086. }
  8087. }
  8088. }// END FOR AC ELSE
  8089. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8090. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8091. result = TRUE;
  8092. return result;
  8093. }
  8094. end:
  8095. //json_object_put(obj); --- remove temporally
  8096. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8097. return result;
  8098. }
  8099. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8100. {
  8101. mtrace();
  8102. int result = FAIL;
  8103. pthread_t t;
  8104. sendUpdateFirmwareConfirmation(uuid);
  8105. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8106. ////pthread_join(t, NULL); //
  8107. pthread_detach(t);
  8108. //sendUpdateFirmwareConfirmation(uuid);
  8109. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8110. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8111. return result;
  8112. }
  8113. void *UpdateFirmwareProcess(void *data)
  8114. {
  8115. mtrace();
  8116. int retriesInt =0, retryIntervalInt=0;
  8117. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8118. int port=0;
  8119. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8120. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8121. //char comfirmstr[20];
  8122. int isSuccess = 0;
  8123. char ftpbuf[200];
  8124. char temp[100];
  8125. char * pch;
  8126. int retriesISNULL=FALSE;
  8127. int retryInterval=FALSE;
  8128. int c = 0;
  8129. //int i = 0;
  8130. char *loc;
  8131. char sstr[300]={ 0 };
  8132. char *str = (char*) data; // ?��?輸入資�?
  8133. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8134. //***************location **************/
  8135. loc = strstr(str, "location");
  8136. memset(sstr ,0, sizeof(sstr) );
  8137. c = 0;
  8138. while (loc[3+strlen("location")+c] != '\"')
  8139. {
  8140. sstr[c] = loc[3+strlen("location")+c];
  8141. c++;
  8142. }
  8143. sstr[c] = '\0';
  8144. strcpy(locationstr, sstr);
  8145. //***************retries**************/
  8146. c = 0;
  8147. loc = strstr(str, "retries");
  8148. if(loc == NULL)
  8149. {
  8150. retriesISNULL=TRUE;
  8151. }
  8152. else
  8153. {
  8154. memset(sstr ,0, sizeof(sstr) );
  8155. while (loc[strlen("retries")+2+c] != ',')
  8156. {
  8157. sstr[c] = loc[strlen("retries")+2+c];
  8158. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8159. c++;
  8160. }
  8161. sstr[c] = '\0';
  8162. }
  8163. if(retriesISNULL == FALSE)
  8164. {
  8165. retriesInt = atoi(sstr);
  8166. }
  8167. //***************retrieveDate **************/
  8168. loc = strstr(str, "retrieveDate");
  8169. memset(sstr ,0, sizeof(sstr) );
  8170. c = 0;
  8171. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8172. {
  8173. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8174. c++;
  8175. }
  8176. sstr[c] = '\0';
  8177. strcpy(retrieveDatestr, sstr);
  8178. //***************retryInterval **************/
  8179. c = 0;
  8180. loc = strstr(str, "retryInterval");
  8181. memset(sstr ,0, sizeof(sstr) );
  8182. if(loc == NULL)
  8183. {
  8184. retryInterval=TRUE;
  8185. }
  8186. else
  8187. {
  8188. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8189. {
  8190. sstr[c] = loc[strlen("retryInterval")+2+c];
  8191. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8192. c++;
  8193. }
  8194. sstr[c] = '\0';
  8195. }
  8196. if(retryInterval==FALSE)
  8197. {
  8198. retryIntervalInt = atoi(sstr);
  8199. }
  8200. memset(ftppath, 0, sizeof(ftppath));
  8201. memset(path, 0, sizeof(path));
  8202. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8203. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8204. if(strncmp(locationstr,"http", 4) == 0)
  8205. {
  8206. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8207. protocol, host, path);
  8208. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8209. // protocol, user, password, host, path);
  8210. sprintf(ftppath,"/%s", path);
  8211. DEBUG_INFO("protocol =%s\n",protocol);
  8212. DEBUG_INFO("host =%s\n",host);
  8213. DEBUG_INFO("path =%s\n",path);
  8214. DEBUG_INFO("ftppath=%s\n",ftppath);
  8215. int ftppathlen=strlen(ftppath);
  8216. int i=1;
  8217. char filenametemp[50];
  8218. while(i < ftppathlen)
  8219. {
  8220. int len=ftppathlen-i;
  8221. if(ftppath[len]== 47) // '/' ascll code: 47
  8222. {
  8223. DEBUG_INFO("compare '/' all right\n");
  8224. break;
  8225. }
  8226. i=i+1;
  8227. }
  8228. memset(filenametemp, 0, sizeof(filenametemp));
  8229. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8230. filenametemp[i+1] = 0;
  8231. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8232. do{
  8233. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8234. sleep(retryIntervalInt);
  8235. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8236. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8237. if(!isSuccess)
  8238. {
  8239. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8240. }
  8241. else
  8242. {
  8243. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8244. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8245. isUpdateRequest = TRUE;
  8246. }
  8247. }
  8248. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8249. {
  8250. memset(ftpbuf, 0, sizeof(ftpbuf));
  8251. memset(temp, 0, sizeof(temp));
  8252. DEBUG_INFO("locationstr=%s\n",locationstr);
  8253. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8254. int ftppathlen=strlen(ftpbuf);
  8255. int i=1;
  8256. char filenametemp[50];
  8257. while(i < ftppathlen)
  8258. {
  8259. int len=ftppathlen-i;
  8260. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8261. {
  8262. DEBUG_INFO(" compare '/' all right\n");
  8263. break;
  8264. }
  8265. i=i+1;
  8266. }
  8267. memset(filenametemp, 0, sizeof(filenametemp));
  8268. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8269. filenametemp[i+1] = 0;
  8270. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8271. pch=strchr(temp,'@');
  8272. if(pch==NULL)
  8273. {
  8274. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8275. protocol, host, &port, path);
  8276. strcpy(user,"anonymous");
  8277. strcpy(password,"");
  8278. }
  8279. else
  8280. {
  8281. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8282. protocol, user, password, host, &port, path);
  8283. }
  8284. sscanf(host,"%[^/]%s",host1, path1);
  8285. sprintf(ftppath,"%s", path1);
  8286. DEBUG_INFO("protocol =%s\n",protocol);
  8287. DEBUG_INFO("user =%s\n",user);
  8288. DEBUG_INFO("password =%s\n",password);
  8289. DEBUG_INFO("host1 =%s\n",host1);
  8290. DEBUG_INFO("port =%d\n",port);
  8291. DEBUG_INFO("path1 =%s\n",path1);
  8292. DEBUG_INFO("ftppath=%s\n",ftppath);
  8293. //ftpFile(host, user, password, port, ftppath, fname);
  8294. //download firmware pthred
  8295. if(port == 0)
  8296. {
  8297. port = 21;
  8298. }
  8299. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8300. do{
  8301. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8302. sleep(retryIntervalInt);
  8303. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8304. if(!isSuccess)
  8305. {
  8306. //BulldogUtil.sleepMs(interval*1000);
  8307. DEBUG_INFO("Update firmware request and download file fail.\n");
  8308. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8309. }
  8310. else
  8311. {
  8312. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8313. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8314. isUpdateRequest = TRUE;
  8315. }
  8316. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8317. }
  8318. else
  8319. {
  8320. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8321. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8322. }
  8323. pthread_exit(NULL);
  8324. }
  8325. //==========================================
  8326. // Handle server response routine
  8327. //==========================================
  8328. void handleAuthorizeResponse(char *payload, int gun_index)
  8329. {
  8330. mtrace();
  8331. char expiryDatestr[30]={0};
  8332. char parentIdTagstr[20]={0};
  8333. char statusstr[20]={0};
  8334. char expiryDatestrtemp[30]={0};
  8335. char parentIdTagstrtemp[20]={0};
  8336. char IdTagstrtemp[20]={0};
  8337. char statusstrtemp[20]={0};
  8338. int expiryDateISNULL=FALSE;
  8339. int parentIdTagISNULL=FALSE;
  8340. char sstr[160]={ 0 };
  8341. char* filename = AuthorizationCache_JSON;
  8342. char tempfile[] = "../Storage/OCPP/temp.json";
  8343. int c = 0;
  8344. char *loc;
  8345. int resultRename=0;
  8346. int responseIdTagInfoAsZero= 0;
  8347. char rmFileCmd[50]={0};
  8348. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8349. //***********expiryDate*************/
  8350. loc = strstr(payload, "expiryDate");
  8351. memset(sstr ,0, sizeof(sstr) );
  8352. c = 0;
  8353. if(loc == NULL)
  8354. {
  8355. expiryDateISNULL = TRUE;
  8356. }
  8357. else
  8358. {
  8359. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8360. {
  8361. sstr[c] = loc[3+strlen("expiryDate")+c];
  8362. c++;
  8363. }
  8364. sstr[c] = '\0';
  8365. strcpy(expiryDatestr, sstr);
  8366. }
  8367. //***********parentIdTag*************/
  8368. loc = strstr(payload, "parentIdTag");
  8369. memset(sstr ,0, sizeof(sstr) );
  8370. c = 0;
  8371. if(loc == NULL)
  8372. {
  8373. parentIdTagISNULL = TRUE;
  8374. }
  8375. else
  8376. {
  8377. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8378. {
  8379. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8380. c++;
  8381. }
  8382. sstr[c] = '\0';
  8383. strcpy(parentIdTagstr, sstr);
  8384. }
  8385. //***********status*************/
  8386. loc = strstr(payload, "status");
  8387. memset(sstr ,0, sizeof(sstr) );
  8388. c = 0;
  8389. while (loc[3+strlen("status")+c] != '\"')
  8390. {
  8391. sstr[c] = loc[3+strlen("status")+c];
  8392. c++;
  8393. }
  8394. sstr[c] = '\0';
  8395. strcpy(statusstr, sstr);
  8396. //#ifdef SystemLogMessage
  8397. // if(expiryDateISNULL == FALSE)
  8398. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8399. // if(parentIdTagISNULL == FALSE)
  8400. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8401. // DEBUG_INFO("status: %s\n", statusstr);
  8402. //#endif
  8403. if(expiryDateISNULL == FALSE)
  8404. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8405. if(parentIdTagISNULL == FALSE)
  8406. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8407. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8408. //Update idTag information to authorization cache if supproted
  8409. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8410. {
  8411. if((access(filename,F_OK))!=-1)
  8412. {
  8413. DEBUG_INFO("AuthorizationCache exist.\n");
  8414. }
  8415. else
  8416. {
  8417. DEBUG_INFO("AuthorizationCache not exist\n");
  8418. FILE *log = fopen(filename, "w+");
  8419. if(log == NULL)
  8420. {
  8421. DEBUG_INFO("log is NULL\n");
  8422. goto out;
  8423. }
  8424. else
  8425. {
  8426. fclose(log);
  8427. }
  8428. }
  8429. FILE *infile;
  8430. FILE *outfile;
  8431. // open file for writing
  8432. infile = fopen (filename, "r");
  8433. outfile = fopen (tempfile, "w");
  8434. //*检测到文件结束标识返回1,否则返回0。*/
  8435. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8436. int c;
  8437. c = fgetc(infile);
  8438. //DEBUG_INFO("c:%d\n",c);
  8439. rewind(infile);
  8440. if(c == EOF)
  8441. {
  8442. DEBUG_INFO("Orignal File is NULL\n");
  8443. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8444. {
  8445. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8446. }
  8447. else
  8448. {
  8449. strcpy(expiryDatestrtemp, "");
  8450. }
  8451. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8452. {
  8453. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8454. }
  8455. else
  8456. {
  8457. //write Authorize IdTag
  8458. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8459. }
  8460. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8461. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8462. fclose(infile);
  8463. fclose(outfile);
  8464. sprintf(rmFileCmd,"rm -f %s",filename);
  8465. system(rmFileCmd);
  8466. resultRename = rename(tempfile, filename);
  8467. if(resultRename == 0)
  8468. {
  8469. DEBUG_INFO("File renamed successfully");
  8470. }
  8471. else
  8472. {
  8473. DEBUG_INFO("Error: unable to rename the file");
  8474. }
  8475. }
  8476. else
  8477. {
  8478. char buf[160]={0};
  8479. //DEBUG_INFO("Orignal File is not NULL\n");
  8480. while (fgets(buf, sizeof(buf), infile) != NULL)
  8481. {
  8482. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8483. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8484. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8485. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8486. memset(statusstr, 0, sizeof(statusstrtemp));
  8487. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8488. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8489. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8490. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8491. //------------------IdTag-----------------------
  8492. loc = strstr(buf, "idTag");
  8493. memset(sstr ,0, sizeof(sstr) );
  8494. c = 0;
  8495. while (loc[3+strlen("idTag")+c] != '\"')
  8496. {
  8497. sstr[c] = loc[3+strlen("idTag")+c];
  8498. c++;
  8499. }
  8500. sstr[c] = '\0';
  8501. strcpy(IdTagstrtemp,sstr);
  8502. //*********************expiryDate***************/
  8503. loc = strstr(buf, "expiryDate");
  8504. memset(sstr ,0, sizeof(sstr) );
  8505. c = 0;
  8506. while (loc[3+strlen("expiryDate")+c] != '\"')
  8507. {
  8508. sstr[c] = loc[3+strlen("expiryDate")+c];
  8509. c++;
  8510. }
  8511. sstr[c] = '\0';
  8512. strcpy(expiryDatestr,sstr);
  8513. //*********************parentIdTag***************/
  8514. loc = strstr(buf, "parentIdTag");
  8515. memset(sstr ,0, sizeof(sstr) );
  8516. c = 0;
  8517. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8518. {
  8519. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8520. c++;
  8521. }
  8522. sstr[c] = '\0';
  8523. strcpy(parentIdTagstr,sstr);
  8524. //*********************status***************/
  8525. loc = strstr(buf, "status");
  8526. memset(sstr ,0, sizeof(sstr) );
  8527. c = 0;
  8528. while (loc[3+strlen("status")+c] != '\"')
  8529. {
  8530. sstr[c] = loc[3+strlen("status")+c];
  8531. c++;
  8532. }
  8533. sstr[c] = '\0';
  8534. strcpy(statusstr,sstr);
  8535. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8536. {
  8537. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8538. responseIdTagInfoAsZero = 1;
  8539. }
  8540. else
  8541. {
  8542. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8543. }
  8544. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8545. {
  8546. //modify item
  8547. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8548. {
  8549. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8550. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8551. }
  8552. else
  8553. {
  8554. strcpy(expiryDatestrtemp, "");
  8555. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8556. }
  8557. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8558. {
  8559. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8560. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8561. }
  8562. else
  8563. {
  8564. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8565. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8566. }
  8567. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8568. }
  8569. else
  8570. {
  8571. //wrie original item
  8572. strcpy(expiryDatestrtemp, expiryDatestr);
  8573. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8574. strcpy(statusstrtemp, statusstr);
  8575. }
  8576. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8577. }
  8578. fclose(infile);
  8579. fclose(outfile);
  8580. sprintf(rmFileCmd,"rm -f %s",filename);
  8581. system(rmFileCmd);
  8582. resultRename = rename(tempfile, filename);
  8583. if(resultRename == 0)
  8584. {
  8585. DEBUG_INFO("File renamed successfully");
  8586. }
  8587. else
  8588. {
  8589. DEBUG_INFO("Error: unable to rename the file");
  8590. }
  8591. }
  8592. }
  8593. out:
  8594. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8595. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8596. authorizeRetryTimes = 0;
  8597. }
  8598. void handleBootNotificationResponse(char *payload, int gun_index)
  8599. {
  8600. mtrace();
  8601. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8602. char statusStr[12]={0};
  8603. char currentTimeStr[30]={0};
  8604. char *loc;
  8605. int intervalInt = 0;
  8606. int c = 0;
  8607. //double diff_t;
  8608. struct tm tp;
  8609. char buf[28]={0};
  8610. char timebuf[50]={0};
  8611. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8612. //*** interval ****/
  8613. c = 0;
  8614. loc = strstr(payload, "interval");
  8615. //printf("loc=%s\n",loc);
  8616. memset(sstr ,0, sizeof(sstr) );
  8617. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8618. {
  8619. sstr[c] = loc[strlen("interval")+2+c];
  8620. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8621. c++;
  8622. }
  8623. sstr[c] = '\0';
  8624. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8625. intervalInt = atoi(sstr);
  8626. //***status ****/
  8627. loc = strstr(payload, "status");
  8628. memset(sstr ,0, sizeof(sstr) );
  8629. c = 0;
  8630. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8631. {
  8632. sstr[c] = loc[3+strlen("status")+c];
  8633. c++;
  8634. }
  8635. sstr[c] = '\0';
  8636. strcpy(statusStr, sstr);
  8637. //***currentTime ****/
  8638. loc = strstr(payload, "currentTime");
  8639. //printf("loc=%s\n",loc);
  8640. memset(sstr ,0, sizeof(sstr) );
  8641. c = 0;
  8642. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8643. {
  8644. sstr[c] = loc[3+strlen("currentTime")+c];
  8645. c++;
  8646. }
  8647. sstr[c] = '\0';
  8648. strcpy(currentTimeStr, sstr);
  8649. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8650. HeartBeatWaitTime = BootNotificationInterval;
  8651. //#ifdef SystemLogMessage
  8652. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8653. // DEBUG_INFO("interval: %d\n", intervalInt);
  8654. // DEBUG_INFO("status: %s\n", statusStr);
  8655. //#endif
  8656. //write back to ShmOCPP16Data->BootNotification
  8657. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8658. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8659. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8660. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8661. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8662. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8663. {
  8664. server_sign = TRUE;
  8665. server_pending =FALSE;
  8666. }
  8667. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8668. {
  8669. server_pending = TRUE;
  8670. }
  8671. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8672. tp.tm_isdst = -1;
  8673. //time_t utc = mktime(&tp);
  8674. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8675. memset(timebuf, 0, sizeof timebuf);
  8676. sprintf(timebuf,"date -s '%s'",buf);
  8677. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8678. system(timebuf);
  8679. //==============================================
  8680. // RTC sync
  8681. //==============================================
  8682. system("/sbin/hwclock -w --systohc");
  8683. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8684. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8685. }
  8686. void handleDataTransferResponse(char *payload, int gun_index)
  8687. {
  8688. char sstr[160]={0};//sstr[200]={ 0 };
  8689. int c = 0;
  8690. char *loc;
  8691. DEBUG_INFO("handleDataTransferResponse ...\n");
  8692. loc = strstr(payload, "status");
  8693. printf("loc=%s\n",loc);
  8694. c = 0;
  8695. while (loc[3+strlen("status")+c] != '\"')
  8696. {
  8697. sstr[c] = loc[3+strlen("status")+c];
  8698. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8699. c++;
  8700. }
  8701. sstr[c] = '\0';
  8702. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8703. //#ifdef SystemLogMessage
  8704. //DEBUG_INFO("data: %s\n", payload);
  8705. //#endif
  8706. }
  8707. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8708. {
  8709. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8710. //struct json_object *obj;
  8711. // obj = json_tokener_parse(payload);
  8712. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8713. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8714. //No fields are defined.
  8715. }
  8716. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8717. {
  8718. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8719. //struct json_object *obj;
  8720. // obj = json_tokener_parse(payload);
  8721. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8722. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8723. //No fields are defined.
  8724. }
  8725. void handleHeartbeatResponse(char *payload, int gun_index)
  8726. {
  8727. mtrace();
  8728. //double diff_t;
  8729. struct tm tp;
  8730. char buf[28]={0};
  8731. char timebuf[50]={0};
  8732. char sstr[30]={ 0 };
  8733. int c = 0;
  8734. char *loc;
  8735. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8736. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8737. c = 0;
  8738. loc = strstr(payload, "currentTime");
  8739. memset(sstr ,0, sizeof(sstr) );
  8740. while (loc[3+strlen("currentTime")+c] != '\"')
  8741. {
  8742. sstr[c] = loc[3+strlen("currentTime")+c];
  8743. c++;
  8744. }
  8745. sstr[c] = '\0';
  8746. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8747. // #ifdef SystemLogMessage
  8748. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8749. // #endif
  8750. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8751. tp.tm_isdst = -1;
  8752. //time_t utc = mktime(&tp);
  8753. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8754. memset(timebuf, 0, sizeof timebuf);
  8755. sprintf(timebuf,"date -s '%s'",buf);
  8756. system(timebuf);
  8757. //==============================================
  8758. // RTC sync
  8759. //==============================================
  8760. system("/sbin/hwclock -w --systohc");
  8761. if(FirstHeartBeat == 0)
  8762. {
  8763. FirstHeartBeat = 1;
  8764. }
  8765. HeartBeatWithNOResponse = 0;
  8766. }
  8767. void handleMeterValuesResponse(char *payload, int gun_index)
  8768. {
  8769. mtrace();
  8770. //struct json_object *obj;
  8771. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8772. //No fields are defined.
  8773. }
  8774. void handleStartTransactionResponse(char *payload, int gun_index)
  8775. {
  8776. mtrace();
  8777. char sstr[30]={ 0 };
  8778. int c = 0;
  8779. char *loc;
  8780. int transactionIdInt = 0;
  8781. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8782. DEBUG_INFO("handleStartTransactionResponse\n");
  8783. //****************expiryDate********************/
  8784. loc = strstr(payload, "expiryDate");
  8785. if(loc == NULL)
  8786. {
  8787. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8788. }
  8789. else
  8790. {
  8791. c = 0;
  8792. memset(sstr ,0, sizeof(sstr) );
  8793. while (loc[3+strlen("expiryDate")+c] != '\"')
  8794. {
  8795. sstr[c] = loc[3+strlen("expiryDate")+c];
  8796. c++;
  8797. }
  8798. sstr[c] = '\0';
  8799. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8800. }
  8801. //****************parentIdTag********************/
  8802. loc = strstr(payload, "parentIdTag");
  8803. if(loc == NULL)
  8804. {
  8805. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8806. }
  8807. else
  8808. {
  8809. c = 0;
  8810. memset(sstr ,0, sizeof(sstr) );
  8811. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8812. {
  8813. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8814. c++;
  8815. }
  8816. sstr[c] = '\0';
  8817. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8818. }
  8819. //****************status********************/
  8820. loc = strstr(payload, "status");
  8821. if(loc == NULL)
  8822. {
  8823. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8824. }
  8825. else
  8826. {
  8827. c = 0;
  8828. memset(sstr ,0, sizeof(sstr) );
  8829. while (loc[3+strlen("status")+c] != '\"')
  8830. {
  8831. sstr[c] = loc[3+strlen("status")+c];
  8832. c++;
  8833. }
  8834. sstr[c] = '\0';
  8835. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8836. }
  8837. //****************transactionId********************/
  8838. c=0;
  8839. loc = strstr(payload, "transactionId");
  8840. memset(sstr ,0, sizeof(sstr) );
  8841. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8842. {
  8843. sstr[c] = loc[strlen("transactionId")+2+c];
  8844. c++;
  8845. }
  8846. sstr[c] = '\0';
  8847. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8848. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8849. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8850. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8851. #ifdef SystemLogMessage
  8852. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8853. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8854. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8855. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8856. #endif
  8857. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8858. {
  8859. //add Charging Record
  8860. SettingChargingRecord(gun_index, transactionIdInt);
  8861. }
  8862. }
  8863. void handleStatusNotificationResponse(char *payload, int gun_index)
  8864. {
  8865. mtrace();
  8866. printf("handleStatusNotificationResponse\n");
  8867. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8868. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8869. }
  8870. void handleStopTransactionnResponse(char *payload, int gun_index)
  8871. {
  8872. mtrace();
  8873. char sstr[30]={ 0 };
  8874. int c = 0;
  8875. char *loc;
  8876. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8877. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8878. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8879. loc = strstr(payload, "idTagInfo");
  8880. //***********************idTagInfo************************/
  8881. if(loc != NULL)
  8882. {
  8883. //***********************expiryDate************************/
  8884. loc = strstr(payload, "expiryDate");
  8885. if(loc != NULL)
  8886. {
  8887. memset(sstr ,0, sizeof(sstr) );
  8888. c = 0;
  8889. while (loc[3+strlen("expiryDate")+c] != '\"')
  8890. {
  8891. sstr[c] = loc[3+strlen("expiryDate")+c];
  8892. c++;
  8893. }
  8894. sstr[c] = '\0';
  8895. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8896. }
  8897. //***********************parentIdTag************************/
  8898. loc = strstr(payload, "parentIdTag");
  8899. if(loc != NULL)
  8900. {
  8901. memset(sstr ,0, sizeof(sstr) );
  8902. c = 0;
  8903. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8904. {
  8905. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8906. c++;
  8907. }
  8908. sstr[c] = '\0';
  8909. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8910. }
  8911. //***********************status************************/
  8912. loc = strstr(payload, "status");
  8913. memset(sstr ,0, sizeof(sstr) );
  8914. c = 0;
  8915. while (loc[3+strlen("status")+c] != '\"')
  8916. {
  8917. sstr[c] = loc[3+strlen("status")+c];
  8918. c++;
  8919. }
  8920. sstr[c] = '\0';
  8921. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8922. }
  8923. #ifdef SystemLogMessage
  8924. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8925. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8926. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8927. #endif
  8928. }
  8929. //==========================================
  8930. // Handle Error routine
  8931. //==========================================
  8932. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8933. {
  8934. mtrace();
  8935. #ifdef SystemLogMessage
  8936. DEBUG_INFO("errorCode: %s\n", errorCode);
  8937. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8938. DEBUG_INFO("errorDetails: %s\n", payload);
  8939. #endif
  8940. }
  8941. //===============================================
  8942. // Common routine
  8943. //===============================================
  8944. int initialConfigurationTable(void)
  8945. {
  8946. printf("initialConfigurationTable \n");
  8947. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8948. /*Core Profile*/
  8949. //AllowOfflineTxForUnknownId
  8950. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8951. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8954. //AuthorizationCacheEnabled
  8955. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8958. //AuthorizeRemoteTxRequests
  8959. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8962. //BlinkRepeat
  8963. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8966. //ClockAlignedDataInterval
  8967. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8970. //ConnectionTimeOut
  8971. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8974. //GetConfigurationMaxKeys
  8975. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  8978. // HeartbeatInterval
  8979. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  8980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  8981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  8982. // LightIntensity
  8983. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  8984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  8985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  8986. // LocalAuthorizeOffline
  8987. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  8988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  8989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  8990. // LocalPreAuthorize
  8991. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  8992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  8993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  8994. // MaxEnergyOnInvalidId
  8995. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  8996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  8997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  8998. // MeterValuesAlignedData
  8999. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9002. // MeterValuesAlignedDataMaxLength
  9003. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9006. // MeterValuesSampledData
  9007. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9010. // MeterValuesSampledDataMaxLength
  9011. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9014. // MeterValueSampleInterval
  9015. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9018. // MinimumStatusDuration
  9019. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9022. // NumberOfConnectors
  9023. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  9026. // ResetRetries
  9027. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9030. // ConnectorPhaseRotation
  9031. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  9034. // ConnectorPhaseRotationMaxLength
  9035. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9038. // StopTransactionOnEVSideDisconnect
  9039. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9042. // StopTransactionOnInvalidId
  9043. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9046. // StopTxnAlignedData
  9047. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9050. // StopTxnAlignedDataMaxLength
  9051. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9054. // StopTxnSampledData
  9055. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9058. // StopTxnSampledDataMaxLength
  9059. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9062. // SupportedFeatureProfiles
  9063. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9066. // SupportedFeatureProfilesMaxLength
  9067. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9070. // TransactionMessageAttempts
  9071. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9074. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9075. // TransactionMessageRetryInterval
  9076. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9079. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9080. // UnlockConnectorOnEVSideDisconnect
  9081. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9084. // WebSocketPingInterval
  9085. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9088. //* Local Auth List Management Profile*/
  9089. #if 0
  9090. //For OCTT Test Case
  9091. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9094. #endif
  9095. #if 1
  9096. //LocalAuthListEnabled
  9097. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9100. #endif
  9101. //LocalAuthListMaxLength
  9102. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9105. //SendLocalListMaxLength
  9106. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9109. //ReserveConnectorZeroSupported
  9110. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9113. //* Smart Charging Profile */
  9114. //ChargeProfileMaxStackLevel
  9115. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9118. // ChargingScheduleAllowedChargingRateUnit
  9119. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9122. // ChargingScheduleMaxPeriods
  9123. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9126. // ConnectorSwitch3to1PhaseSupported
  9127. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9130. // MaxChargingProfilesInstalled
  9131. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9134. return 0;
  9135. }
  9136. void getKeyValue(char *keyReq)
  9137. {
  9138. int isEmpty = FALSE;
  9139. int isKnowKey = FALSE;
  9140. //int unKnowIndex = 0;
  9141. DEBUG_INFO("getKeyValue \n");
  9142. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9143. isEmpty = TRUE;
  9144. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9145. {
  9146. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9149. {
  9150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9151. }
  9152. else
  9153. {
  9154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9155. }
  9156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9157. isKnowKey = TRUE;
  9158. }
  9159. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9160. {
  9161. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9164. {
  9165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9166. }
  9167. else
  9168. {
  9169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9170. }
  9171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9172. isKnowKey = TRUE;
  9173. }
  9174. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9175. {
  9176. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9179. {
  9180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9181. }
  9182. else
  9183. {
  9184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9185. }
  9186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9187. isKnowKey = TRUE;
  9188. }
  9189. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9190. {
  9191. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9194. {
  9195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9196. }
  9197. else
  9198. {
  9199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9200. }
  9201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9202. isKnowKey = TRUE;
  9203. }
  9204. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9205. {
  9206. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9209. {
  9210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9211. }
  9212. else
  9213. {
  9214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9215. }
  9216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9217. isKnowKey = TRUE;
  9218. }
  9219. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9220. {
  9221. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9223. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9224. {
  9225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9226. }
  9227. else
  9228. {
  9229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9230. }
  9231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9232. isKnowKey = TRUE;
  9233. }
  9234. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9235. {
  9236. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9239. {
  9240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9241. }
  9242. else
  9243. {
  9244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9245. }
  9246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9247. isKnowKey = TRUE;
  9248. }
  9249. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9250. {
  9251. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9254. {
  9255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9256. }
  9257. else
  9258. {
  9259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9260. }
  9261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9262. isKnowKey = TRUE;
  9263. }
  9264. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9265. {
  9266. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9269. {
  9270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9271. }
  9272. else
  9273. {
  9274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9275. }
  9276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9277. isKnowKey = TRUE;
  9278. }
  9279. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9280. {
  9281. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9284. {
  9285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9286. }
  9287. else
  9288. {
  9289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9290. }
  9291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9292. isKnowKey = TRUE;
  9293. }
  9294. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9295. {
  9296. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9298. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9299. {
  9300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9301. }
  9302. else
  9303. {
  9304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9305. }
  9306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9307. isKnowKey = TRUE;
  9308. }
  9309. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9310. {
  9311. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9314. {
  9315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9316. }
  9317. else
  9318. {
  9319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9320. }
  9321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9322. isKnowKey = TRUE;
  9323. }
  9324. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9325. {
  9326. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9329. {
  9330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9331. }
  9332. else
  9333. {
  9334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9335. }
  9336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9337. isKnowKey = TRUE;
  9338. }
  9339. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9340. {
  9341. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9344. {
  9345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9346. }
  9347. else
  9348. {
  9349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9350. }
  9351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9352. isKnowKey = TRUE;
  9353. }
  9354. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9355. {
  9356. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9358. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9359. {
  9360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9361. }
  9362. else
  9363. {
  9364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9365. }
  9366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9367. isKnowKey = TRUE;
  9368. }
  9369. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9370. {
  9371. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9374. {
  9375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9376. }
  9377. else
  9378. {
  9379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9380. }
  9381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9382. isKnowKey = TRUE;
  9383. }
  9384. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9385. {
  9386. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9388. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9389. {
  9390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9391. }
  9392. else
  9393. {
  9394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9395. }
  9396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9397. isKnowKey = TRUE;
  9398. }
  9399. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9400. {
  9401. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9403. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9404. {
  9405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9406. }
  9407. else
  9408. {
  9409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9410. }
  9411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9412. isKnowKey = TRUE;
  9413. }
  9414. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9415. {
  9416. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9418. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9419. {
  9420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9421. }
  9422. else
  9423. {
  9424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9425. }
  9426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9427. isKnowKey = TRUE;
  9428. }
  9429. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9430. {
  9431. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9433. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9434. {
  9435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9436. }
  9437. else
  9438. {
  9439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9440. }
  9441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9442. isKnowKey = TRUE;
  9443. }
  9444. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9445. {
  9446. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9448. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9449. {
  9450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9451. }
  9452. else
  9453. {
  9454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9455. }
  9456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9457. isKnowKey = TRUE;
  9458. }
  9459. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9460. {
  9461. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9464. {
  9465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9466. }
  9467. else
  9468. {
  9469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9470. }
  9471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9472. isKnowKey = TRUE;
  9473. }
  9474. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9475. {
  9476. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9479. {
  9480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9481. }
  9482. else
  9483. {
  9484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9485. }
  9486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9487. isKnowKey = TRUE;
  9488. }
  9489. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9490. {
  9491. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9494. {
  9495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9496. }
  9497. else
  9498. {
  9499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9500. }
  9501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9502. isKnowKey = TRUE;
  9503. }
  9504. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9505. {
  9506. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9508. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9509. {
  9510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9511. }
  9512. else
  9513. {
  9514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9515. }
  9516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9517. isKnowKey = TRUE;
  9518. }
  9519. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9520. {
  9521. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9523. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9524. {
  9525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9526. }
  9527. else
  9528. {
  9529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9530. }
  9531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9532. isKnowKey = TRUE;
  9533. }
  9534. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9535. {
  9536. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9538. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9539. {
  9540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9541. }
  9542. else
  9543. {
  9544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9545. }
  9546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9547. isKnowKey = TRUE;
  9548. }
  9549. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9550. {
  9551. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9553. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9554. {
  9555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9556. }
  9557. else
  9558. {
  9559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9560. }
  9561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9562. isKnowKey = TRUE;
  9563. }
  9564. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9565. {
  9566. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9568. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9569. {
  9570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9571. }
  9572. else
  9573. {
  9574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9575. }
  9576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9577. isKnowKey = TRUE;
  9578. }
  9579. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9580. {
  9581. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9584. {
  9585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9586. }
  9587. else
  9588. {
  9589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9590. }
  9591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9592. isKnowKey = TRUE;
  9593. }
  9594. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9595. {
  9596. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9598. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9599. {
  9600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9601. }
  9602. else
  9603. {
  9604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9605. }
  9606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9607. isKnowKey = TRUE;
  9608. }
  9609. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9610. {
  9611. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9613. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9614. {
  9615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9616. }
  9617. else
  9618. {
  9619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9620. }
  9621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9622. isKnowKey = TRUE;
  9623. }
  9624. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9625. {
  9626. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9629. {
  9630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9631. }
  9632. else
  9633. {
  9634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9635. }
  9636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9637. isKnowKey = TRUE;
  9638. }
  9639. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9640. {
  9641. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9643. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9644. {
  9645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9646. }
  9647. else
  9648. {
  9649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9650. }
  9651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9652. isKnowKey = TRUE;
  9653. }
  9654. #if 0
  9655. //For OCTT Test Case
  9656. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9657. {
  9658. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9660. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9661. {
  9662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9663. }
  9664. else
  9665. {
  9666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9667. }
  9668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9669. isKnowKey = TRUE;
  9670. }
  9671. #endif
  9672. #if 1
  9673. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9674. {
  9675. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9677. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9678. {
  9679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9680. }
  9681. else
  9682. {
  9683. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9684. }
  9685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9686. isKnowKey = TRUE;
  9687. }
  9688. #endif
  9689. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9690. {
  9691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9693. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9694. {
  9695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9696. }
  9697. else
  9698. {
  9699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9700. }
  9701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9702. isKnowKey = TRUE;
  9703. }
  9704. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9705. {
  9706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9708. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9709. {
  9710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9711. }
  9712. else
  9713. {
  9714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9715. }
  9716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9717. isKnowKey = TRUE;
  9718. }
  9719. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9720. {
  9721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9723. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9724. {
  9725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9726. }
  9727. else
  9728. {
  9729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9730. }
  9731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9732. isKnowKey = TRUE;
  9733. }
  9734. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9735. {
  9736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9738. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9739. {
  9740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9741. }
  9742. else
  9743. {
  9744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9745. }
  9746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9747. isKnowKey = TRUE;
  9748. }
  9749. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9750. {
  9751. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9753. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9754. {
  9755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9756. }
  9757. else
  9758. {
  9759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9760. }
  9761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9762. isKnowKey = TRUE;
  9763. }
  9764. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9765. {
  9766. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9768. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9769. {
  9770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9771. }
  9772. else
  9773. {
  9774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9775. }
  9776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9777. isKnowKey = TRUE;
  9778. }
  9779. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9780. {
  9781. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9783. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9784. {
  9785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9786. }
  9787. else
  9788. {
  9789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9790. }
  9791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9792. isKnowKey = TRUE;
  9793. }
  9794. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9795. {
  9796. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9798. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9799. {
  9800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9801. }
  9802. else
  9803. {
  9804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9805. }
  9806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9807. isKnowKey = TRUE;
  9808. }
  9809. //=========================================================
  9810. if(!isEmpty && !isKnowKey)
  9811. {
  9812. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9813. strcpy(unknownkey[UnknownKeynum], keyReq);
  9814. UnknownKeynum = UnknownKeynum + 1;
  9815. }
  9816. }
  9817. void processUnkownKey(void)
  9818. {
  9819. DEBUG_INFO("processUnkownKey\n");
  9820. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9821. for(int index=0; index < UnknownKeynum; index++)
  9822. {
  9823. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9824. {
  9825. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9826. }
  9827. }
  9828. }
  9829. int setKeyValue(char *key, char *value)
  9830. {
  9831. int isSuccess = NotSupported;
  9832. int check_ascii=0;
  9833. #ifdef Debug
  9834. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9835. #endif
  9836. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9837. {
  9838. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9839. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9840. {
  9841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9842. isSuccess = ConfigurationStatus_Accepted;
  9843. }
  9844. else
  9845. {
  9846. isSuccess = ConfigurationStatus_Rejected;
  9847. }
  9848. }
  9849. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9850. {
  9851. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9853. {
  9854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9855. isSuccess = ConfigurationStatus_Accepted;
  9856. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9857. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9858. }
  9859. else
  9860. {
  9861. isSuccess = ConfigurationStatus_Rejected;
  9862. }
  9863. }
  9864. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9865. {
  9866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9867. {
  9868. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9870. isSuccess = ConfigurationStatus_Accepted;
  9871. }
  9872. else
  9873. {
  9874. isSuccess = ConfigurationStatus_Rejected;
  9875. }
  9876. }
  9877. if(strcmp(key, "BlinkRepeat") == 0)
  9878. {
  9879. //Charger.BlinkRepeat = Integer.parseInt(value);
  9880. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9881. {
  9882. check_ascii = value[0];
  9883. if( (check_ascii < 48) || (check_ascii > 57) )
  9884. {
  9885. isSuccess = ConfigurationStatus_Rejected;
  9886. }
  9887. else
  9888. {
  9889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9890. isSuccess = ConfigurationStatus_Accepted;
  9891. }
  9892. }
  9893. else
  9894. {
  9895. isSuccess = ConfigurationStatus_Rejected;
  9896. }
  9897. }
  9898. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9899. {
  9900. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9901. {
  9902. check_ascii = value[0];
  9903. if( (check_ascii < 48) || (check_ascii > 57) )
  9904. {
  9905. isSuccess = ConfigurationStatus_Rejected;
  9906. }
  9907. else
  9908. {
  9909. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9911. isSuccess = ConfigurationStatus_Accepted;
  9912. }
  9913. }
  9914. else
  9915. {
  9916. isSuccess = ConfigurationStatus_Rejected;
  9917. }
  9918. }
  9919. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9920. {
  9921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9922. {
  9923. check_ascii = value[0];
  9924. if( (check_ascii < 48) || (check_ascii > 57) )
  9925. {
  9926. isSuccess = ConfigurationStatus_Rejected;
  9927. }
  9928. else
  9929. {
  9930. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9932. isSuccess = ConfigurationStatus_Accepted;
  9933. }
  9934. }
  9935. else
  9936. {
  9937. isSuccess = ConfigurationStatus_Rejected;
  9938. }
  9939. }
  9940. if(strcmp(key, "HeartbeatInterval") == 0)
  9941. {
  9942. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9943. {
  9944. check_ascii = value[0];
  9945. if( (check_ascii < 48) || (check_ascii > 57) )
  9946. {
  9947. isSuccess = ConfigurationStatus_Rejected;
  9948. }
  9949. else
  9950. {
  9951. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9952. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9953. HeartBeatWaitTime = atoi(value);
  9954. isSuccess = ConfigurationStatus_Accepted;
  9955. }
  9956. }
  9957. else
  9958. {
  9959. isSuccess = ConfigurationStatus_Rejected;
  9960. }
  9961. }
  9962. if(strcmp(key, "LightIntensity") == 0)
  9963. {
  9964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9965. {
  9966. check_ascii = value[0];
  9967. if( (check_ascii < 48) || (check_ascii > 57) )
  9968. {
  9969. isSuccess = ConfigurationStatus_Rejected;
  9970. }
  9971. else
  9972. {
  9973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9974. isSuccess = ConfigurationStatus_Accepted;
  9975. }
  9976. }
  9977. else
  9978. {
  9979. isSuccess = ConfigurationStatus_Rejected;
  9980. }
  9981. }
  9982. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  9983. {
  9984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9985. {
  9986. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9987. isSuccess = ConfigurationStatus_Accepted;
  9988. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9989. }
  9990. else
  9991. {
  9992. isSuccess = ConfigurationStatus_Rejected;
  9993. }
  9994. }
  9995. if(strcmp(key, "LocalPreAuthorize") == 0)
  9996. {
  9997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9998. {
  9999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10000. isSuccess = ConfigurationStatus_Accepted;
  10001. }
  10002. else
  10003. {
  10004. isSuccess = ConfigurationStatus_Rejected;
  10005. }
  10006. }
  10007. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10008. {
  10009. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10010. {
  10011. check_ascii = value[0];
  10012. if( (check_ascii < 48) || (check_ascii > 57) )
  10013. {
  10014. isSuccess = ConfigurationStatus_Rejected;
  10015. }
  10016. else
  10017. {
  10018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10019. isSuccess = ConfigurationStatus_Accepted;
  10020. }
  10021. }
  10022. else
  10023. {
  10024. isSuccess = ConfigurationStatus_Rejected;
  10025. }
  10026. }
  10027. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10028. {
  10029. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10030. {
  10031. //int valueLength = strlen(value);
  10032. for(int i = 0; value[i]; i++){
  10033. value[i] = tolower(value[i]);
  10034. }
  10035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10036. isSuccess = ConfigurationStatus_Accepted;
  10037. }
  10038. else
  10039. {
  10040. isSuccess = ConfigurationStatus_Rejected;
  10041. }
  10042. }
  10043. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10044. {
  10045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10046. {
  10047. //int valueLength = strlen(value);
  10048. for(int i = 0; value[i]; i++){
  10049. value[i] = tolower(value[i]);
  10050. }
  10051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10052. isSuccess = ConfigurationStatus_Accepted;
  10053. }
  10054. else
  10055. {
  10056. isSuccess = ConfigurationStatus_Rejected;
  10057. }
  10058. }
  10059. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10060. {
  10061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10062. {
  10063. check_ascii = value[0];
  10064. if( (check_ascii < 48) || (check_ascii > 57) )
  10065. {
  10066. isSuccess = ConfigurationStatus_Rejected;
  10067. }
  10068. else
  10069. {
  10070. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10072. isSuccess = ConfigurationStatus_Accepted;
  10073. }
  10074. #ifdef Debug
  10075. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10076. #endif
  10077. }
  10078. else
  10079. {
  10080. isSuccess = ConfigurationStatus_Rejected;
  10081. #ifdef Debug
  10082. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10083. #endif
  10084. }
  10085. }
  10086. if(strcmp(key, "MinimumStatusDuration") == 0)
  10087. {
  10088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10089. {
  10090. check_ascii = value[0];
  10091. if( (check_ascii < 48) || (check_ascii > 57) )
  10092. {
  10093. isSuccess = ConfigurationStatus_Rejected;
  10094. }
  10095. else
  10096. {
  10097. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10099. isSuccess = ConfigurationStatus_Accepted;
  10100. }
  10101. }
  10102. else
  10103. {
  10104. isSuccess = ConfigurationStatus_Rejected;
  10105. }
  10106. }
  10107. if(strcmp(key, "ResetRetries") == 0)
  10108. {
  10109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10110. {
  10111. check_ascii = value[0];
  10112. if( (check_ascii < 48) || (check_ascii > 57) )
  10113. {
  10114. isSuccess = ConfigurationStatus_Rejected;
  10115. }
  10116. else
  10117. {
  10118. //Charger.ResetRetries = Integer.parseInt(value);
  10119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10120. isSuccess = ConfigurationStatus_Accepted;
  10121. }
  10122. }
  10123. else
  10124. {
  10125. isSuccess = ConfigurationStatus_Rejected;
  10126. }
  10127. }
  10128. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10129. {
  10130. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10131. {
  10132. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10133. //int valueLength = strlen(value);
  10134. for(int i = 0; value[i]; i++){
  10135. value[i] = tolower(value[i]);
  10136. }
  10137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10138. isSuccess = ConfigurationStatus_Accepted;
  10139. }
  10140. else
  10141. {
  10142. isSuccess = ConfigurationStatus_Rejected;
  10143. }
  10144. }
  10145. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10146. {
  10147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10148. {
  10149. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10151. isSuccess = ConfigurationStatus_Accepted;
  10152. }
  10153. else
  10154. {
  10155. isSuccess = ConfigurationStatus_Rejected;
  10156. }
  10157. }
  10158. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10159. {
  10160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10161. {
  10162. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10164. isSuccess = ConfigurationStatus_Accepted;
  10165. }
  10166. else
  10167. {
  10168. isSuccess = ConfigurationStatus_Rejected;
  10169. }
  10170. }
  10171. if(strcmp(key, "StopTxnAlignedData") == 0)
  10172. {
  10173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10174. {
  10175. //Charger.StopTxnAlignedData = value.toLowerCase();
  10176. //int valueLength = strlen(value);
  10177. for(int i = 0; value[i]; i++){
  10178. value[i] = tolower(value[i]);
  10179. }
  10180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10181. isSuccess = ConfigurationStatus_Accepted;
  10182. }
  10183. else
  10184. {
  10185. isSuccess = ConfigurationStatus_Rejected;
  10186. }
  10187. }
  10188. if(strcmp(key, "StopTxnSampledData") == 0)
  10189. {
  10190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10191. {
  10192. //Charger.StopTxnSampledData = value.toLowerCase();
  10193. //int valueLength = strlen(value);
  10194. for(int i = 0; value[i]; i++){
  10195. value[i] = tolower(value[i]);
  10196. }
  10197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10198. isSuccess = ConfigurationStatus_Accepted;
  10199. }
  10200. else
  10201. {
  10202. isSuccess = ConfigurationStatus_Rejected;
  10203. }
  10204. }
  10205. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10206. {
  10207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10208. {
  10209. check_ascii = value[0];
  10210. if( (check_ascii < 48) || (check_ascii > 57) )
  10211. {
  10212. isSuccess = ConfigurationStatus_Rejected;
  10213. }
  10214. else
  10215. {
  10216. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10218. TransactionMessageAttemptsValue = atoi(value);
  10219. isSuccess = ConfigurationStatus_Accepted;
  10220. }
  10221. }
  10222. else
  10223. {
  10224. isSuccess = ConfigurationStatus_Rejected;
  10225. }
  10226. }
  10227. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10228. {
  10229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10230. {
  10231. check_ascii = value[0];
  10232. if( (check_ascii < 48) || (check_ascii > 57) )
  10233. {
  10234. isSuccess = ConfigurationStatus_Rejected;
  10235. }
  10236. else
  10237. {
  10238. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10240. TransactionMessageRetryIntervalValue = atoi(value);
  10241. isSuccess = ConfigurationStatus_Accepted;
  10242. }
  10243. }
  10244. else
  10245. {
  10246. isSuccess = ConfigurationStatus_Rejected;
  10247. }
  10248. }
  10249. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10250. {
  10251. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10252. {
  10253. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10255. isSuccess = ConfigurationStatus_Accepted;
  10256. }
  10257. else
  10258. {
  10259. isSuccess = ConfigurationStatus_Rejected;
  10260. }
  10261. }
  10262. if(strcmp(key, "WebSocketPingInterval") == 0)
  10263. {
  10264. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10265. {
  10266. check_ascii = value[0];
  10267. if( (check_ascii < 48) || (check_ascii > 57) )
  10268. {
  10269. isSuccess = ConfigurationStatus_Rejected;
  10270. }
  10271. else
  10272. {
  10273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10274. isSuccess = ConfigurationStatus_Accepted;
  10275. }
  10276. }
  10277. else
  10278. {
  10279. isSuccess = ConfigurationStatus_Rejected;
  10280. }
  10281. }
  10282. #if 0
  10283. //For OCPP Test Case
  10284. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10285. {
  10286. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10287. {
  10288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10289. isSuccess = ConfigurationStatus_Accepted;
  10290. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10291. }
  10292. else
  10293. {
  10294. isSuccess = ConfigurationStatus_Rejected;
  10295. }
  10296. }
  10297. #endif
  10298. #if 1
  10299. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10300. {
  10301. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10302. {
  10303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10304. isSuccess = ConfigurationStatus_Accepted;
  10305. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10306. }
  10307. else
  10308. {
  10309. isSuccess = ConfigurationStatus_Rejected;
  10310. }
  10311. }
  10312. #endif
  10313. return isSuccess;
  10314. }
  10315. int updateSetting(char *key, char *value)
  10316. {
  10317. mtrace();
  10318. int isSuccess = FALSE;
  10319. char string[1000]={0}, buffer[1000]={0};
  10320. char strtemp[50]={0};
  10321. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10322. int pos, c = 0;
  10323. char *loc;
  10324. int pos1=0;
  10325. FILE *f = fopen("/var/www/settings1", "r");
  10326. if(f == NULL)
  10327. {
  10328. #ifdef Debug
  10329. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10330. #endif
  10331. return isSuccess;
  10332. }
  10333. fseek(f, 0, SEEK_END);
  10334. long fsize = ftell(f);
  10335. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10336. fread(string, 1, fsize, f);
  10337. fclose(f);
  10338. string[fsize] = 0;
  10339. loc = strstr(string, key);
  10340. if(loc != NULL)
  10341. {
  10342. DEBUG_INFO("key exist!\n");
  10343. pos = loc - string-1;
  10344. f = fopen("/var/www/settings1", "w");
  10345. strncpy(buffer, string, pos);
  10346. fprintf(f, "%s", buffer);
  10347. memset(sstr ,0, sizeof(sstr) );
  10348. c = 0;
  10349. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10350. {
  10351. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10352. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10353. c++;
  10354. }
  10355. sstr[c] = '\0';
  10356. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10357. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10358. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10359. memset(buffer ,0, sizeof(buffer) );
  10360. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10361. //printf("buffer=%s",buffer);
  10362. fprintf(f, "%s", buffer);
  10363. fclose(f);
  10364. }
  10365. else
  10366. {
  10367. printf("key not exist!\n");
  10368. f = fopen("/var/www/settings1", "w+");
  10369. fputs(string, f);
  10370. fseek(f, -1, SEEK_CUR);
  10371. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10372. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10373. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10374. fclose(f);
  10375. }
  10376. isSuccess = TRUE;
  10377. return isSuccess;
  10378. }
  10379. int TransactionMessageAttemptsGet(void)
  10380. {
  10381. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10382. }
  10383. int FirstHeartBeatResponse(void)
  10384. {
  10385. return FirstHeartBeat;
  10386. }
  10387. int TransactionMessageRetryIntervalGet(void)
  10388. {
  10389. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10390. }
  10391. #define SA struct sockaddr
  10392. #define MAXBUF 1024
  10393. //static int m_socket_data;
  10394. //static int sockfd;
  10395. int ReadHttpStatus(int sock){
  10396. //char c;
  10397. char buff[1024]="",*ptr=buff+1;
  10398. int bytes_received, status;
  10399. DEBUG_INFO("Begin Response ..\n");
  10400. while((bytes_received = recv(sock, ptr, 1, 0))){
  10401. if(bytes_received==-1){
  10402. perror("ReadHttpStatus");
  10403. exit(1);
  10404. }
  10405. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10406. ptr++;
  10407. }
  10408. *ptr=0;
  10409. ptr=buff+1;
  10410. sscanf(ptr,"%*s %d ", &status);
  10411. DEBUG_INFO("%s\n",ptr);
  10412. DEBUG_INFO("status=%d\n",status);
  10413. DEBUG_INFO("End Response ..\n");
  10414. return (bytes_received>0)?status:0;
  10415. }
  10416. //the only filed that it parsed is 'Content-Length'
  10417. int ParseHeader(int sock){
  10418. //char c;
  10419. char buff[1024]="",*ptr=buff+4;
  10420. int bytes_received;
  10421. DEBUG_INFO("Begin HEADER ..\n");
  10422. while((bytes_received = recv(sock, ptr, 1, 0))){
  10423. if(bytes_received==-1){
  10424. perror("Parse Header");
  10425. exit(1);
  10426. }
  10427. if(
  10428. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10429. (ptr[-1]=='\r') && (*ptr=='\n' )
  10430. ) break;
  10431. ptr++;
  10432. }
  10433. *ptr=0;
  10434. ptr=buff+4;
  10435. //printf("%s",ptr);
  10436. if(bytes_received){
  10437. ptr=strstr(ptr,"Content-Length:");
  10438. if(ptr){
  10439. sscanf(ptr,"%*s %d",&bytes_received);
  10440. }else
  10441. bytes_received=-1; //unknown size
  10442. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10443. }
  10444. DEBUG_INFO("End HEADER ..\n");
  10445. return bytes_received ;
  10446. }
  10447. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10448. {
  10449. char rmFileCmd[100]={0};
  10450. char FilePath[100]={0};
  10451. char ftpbuf[200];
  10452. int systemresult;
  10453. DEBUG_INFO("filename=%s\n",filename);
  10454. DEBUG_INFO("url=%s\n",url);
  10455. sprintf(FilePath,"../mnt/%s",filename);
  10456. if((access(FilePath,F_OK))!=-1)
  10457. {
  10458. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10459. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10460. system(rmFileCmd);
  10461. }
  10462. memset(ftpbuf, 0, sizeof(ftpbuf));
  10463. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10464. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10465. systemresult = system(ftpbuf);
  10466. DEBUG_INFO("systemresult=%d\n",systemresult);
  10467. if(systemresult != 0)
  10468. {
  10469. DEBUG_INFO("http DownLoad error!\n");
  10470. return FALSE;
  10471. }
  10472. return TRUE;
  10473. }
  10474. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10475. {
  10476. char rmFileCmd[100]={0};
  10477. char FilePath[100]={0};
  10478. char ftpbuf[200];
  10479. int systemresult;
  10480. //char temp[100];
  10481. #if 0
  10482. struct hostent* server;
  10483. char *IPbuffer;
  10484. server = gethostbyname(location);
  10485. // To convert an Internet network
  10486. // address into ASCII string
  10487. IPbuffer = inet_ntoa(*((struct in_addr*)
  10488. server->h_addr_list[0]));
  10489. #endif
  10490. sprintf(FilePath,"../mnt/%s",filename);
  10491. if((access(FilePath,F_OK))!=-1)
  10492. {
  10493. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10494. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10495. system(rmFileCmd);
  10496. }
  10497. memset(ftpbuf, 0, sizeof(ftpbuf));
  10498. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10499. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10500. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10501. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10502. systemresult = system(ftpbuf);
  10503. DEBUG_INFO("systemresult=%d\n",systemresult);
  10504. if(systemresult != 0)
  10505. {
  10506. printf("ftpget error!\n");
  10507. return FALSE;
  10508. }
  10509. return TRUE;
  10510. }
  10511. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10512. {
  10513. struct hostent* server;
  10514. char *IPbuffer;
  10515. char ftpbuf[200];
  10516. int systemresult;
  10517. // To retrieve host information
  10518. server = gethostbyname(location);
  10519. // To convert an Internet network
  10520. // address into ASCII string
  10521. IPbuffer = inet_ntoa(*((struct in_addr*)
  10522. server->h_addr_list[0]));
  10523. memset(ftpbuf, 0, sizeof(ftpbuf));
  10524. /* format : ftpput -u username -p passwd IP target source*/
  10525. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10526. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10527. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10528. systemresult = system(ftpbuf);
  10529. DEBUG_INFO("systemresult=%d\n",systemresult);
  10530. if(systemresult != 0)
  10531. {
  10532. DEBUG_INFO("ftpput error!\n");
  10533. return FALSE;
  10534. }
  10535. return TRUE;
  10536. }
  10537. int SettingChargingRecord(int target, int transactionId)
  10538. {
  10539. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10540. {
  10541. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10542. {
  10543. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10544. {
  10545. addBuff(target, transactionId, 0);
  10546. return TRUE;
  10547. }
  10548. }
  10549. for (int index = 0; index < CCS_QUANTITY; index++)
  10550. {
  10551. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10552. {
  10553. addBuff(target, transactionId, 0);
  10554. return TRUE;
  10555. }
  10556. }
  10557. for (int index = 0; index < GB_QUANTITY; index++)
  10558. {
  10559. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10560. {
  10561. addBuff(target, transactionId, 0);
  10562. return TRUE;
  10563. }
  10564. }
  10565. }
  10566. else
  10567. {
  10568. for (int index = 0; index < AC_QUANTITY; index++)
  10569. {
  10570. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10571. {
  10572. addBuff(target, transactionId, 0);
  10573. return TRUE;
  10574. }
  10575. }
  10576. }
  10577. return FALSE;
  10578. }
  10579. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10580. {
  10581. int isSuccess = FALSE;
  10582. //char *query = NULL;
  10583. sqlite3_stmt *stmt;
  10584. int rc; // return code
  10585. char str[20];
  10586. sprintf(str,"%d",user_id);
  10587. 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 */
  10588. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10589. rc = sqlite3_step(stmt); /* 3 */
  10590. if (rc != SQLITE_DONE) {
  10591. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10592. goto out;
  10593. }
  10594. sqlite3_finalize(stmt);
  10595. // free(query);
  10596. out:
  10597. //----------------------
  10598. // close SQLite database
  10599. //----------------------
  10600. sqlite3_close(db);
  10601. printf("database closed.\n");
  10602. return isSuccess;
  10603. }
  10604. /**
  10605. * Place the contents of the specified file into a memory buffer
  10606. *
  10607. * @param[in] filename The path and name of the file to read
  10608. * @param[out] filebuffer A pointer to the contents in memory
  10609. * @return status 0 success, 1 on failure
  10610. */
  10611. int get_file_contents(const char* filename, char** outbuffer) {
  10612. FILE* file = NULL;
  10613. long filesize;
  10614. const int blocksize = 1;
  10615. size_t readsize;
  10616. char* filebuffer;
  10617. // Open the file
  10618. file = fopen(filename, "r");
  10619. if (NULL == file)
  10620. {
  10621. printf("'%s' not opened\n", filename);
  10622. exit(EXIT_FAILURE);
  10623. }
  10624. // Determine the file size
  10625. fseek(file, 0, SEEK_END);
  10626. filesize = ftell(file);
  10627. rewind (file);
  10628. // Allocate memory for the file contents
  10629. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10630. *outbuffer = filebuffer;
  10631. if (filebuffer == NULL)
  10632. {
  10633. fputs ("malloc out-of-memory", stderr);
  10634. exit(EXIT_FAILURE);
  10635. }
  10636. // Read in the file
  10637. readsize = fread(filebuffer, blocksize, filesize, file);
  10638. if (readsize != filesize)
  10639. {
  10640. fputs ("didn't read file completely",stderr);
  10641. exit(EXIT_FAILURE);
  10642. }
  10643. // Clean exit
  10644. fclose(file);
  10645. return EXIT_SUCCESS;
  10646. }
  10647. static int selectSqlCount = 0;
  10648. static int callback(void *data, int argc, char **argv, char **azColName){
  10649. int i;
  10650. printf("%s: ", (const char*)data);
  10651. selectSqlCount = argc;
  10652. for(i = 0; i<argc; i++){
  10653. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10654. }
  10655. printf("\n");
  10656. return 0;
  10657. }
  10658. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10659. //int i;
  10660. //printf("%s:\n", (const char*)data);
  10661. localversion = argv[5] ? atoi(argv[5]) : 0;
  10662. printf("localversion=%d\n", localversion);
  10663. return 0;
  10664. }
  10665. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10666. //int i;
  10667. //printf("%s:\n", (const char*)data);
  10668. //idTag
  10669. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10670. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10671. //parentIdTag
  10672. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10673. //expir_date
  10674. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10675. //status
  10676. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10677. //version
  10678. idTagQuery.listVersionInt = atoi(argv[5]);
  10679. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10680. return 0;
  10681. }
  10682. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10683. int i;
  10684. //printf("%s:\n", (const char*)data);
  10685. #if 1
  10686. for(i=0; i<argc; i++){
  10687. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10688. }
  10689. //printf("");
  10690. #endif
  10691. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10692. // printf("localversion=%d\n", localversion);
  10693. return 0;
  10694. }
  10695. /** sqlite3_exec的回调。
  10696. *
  10697. * 向控制台打印查询的结果。
  10698. *
  10699. * @param in data 传递给回调函数的数据。
  10700. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10701. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10702. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10703. * @return 状态码。
  10704. */
  10705. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10706. {
  10707. for (int i = 0; i < n_columns; i++)
  10708. {
  10709. DEBUG_INFO("%s/t", col_values[i]);
  10710. }
  10711. DEBUG_INFO("/n");
  10712. return 0;
  10713. }
  10714. void OCPP_getListVerion()
  10715. {
  10716. int rc = 0;
  10717. // const char* data = "Callback function called";
  10718. char sql[100];
  10719. char zErrMsg[100];
  10720. memset(sql, 0, 100);
  10721. memset(zErrMsg, 0, 100);
  10722. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10723. /* Execute SQL statement */
  10724. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10725. DEBUG_INFO("rc=%d\n",rc);
  10726. if( rc != SQLITE_OK ){
  10727. DEBUG_INFO("SQL error: %s", zErrMsg);
  10728. //sqlite3_free(zErrMsg);
  10729. }else{
  10730. DEBUG_INFO("Operation done successfully");
  10731. }
  10732. }
  10733. void OCPP_getIdTag(char *idTag)
  10734. {
  10735. int rc = 0;
  10736. // const char* data = "Callback function called";
  10737. char sql[100];
  10738. char zErrMsg[100];
  10739. memset(sql, 0, 100);
  10740. memset(zErrMsg, 0, 100);
  10741. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10742. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10743. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10744. /* Execute SQL statement */
  10745. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10746. if( rc != SQLITE_OK ){
  10747. DEBUG_INFO("SQL error: %s", zErrMsg);
  10748. //sqlite3_free(zErrMsg);
  10749. }else{
  10750. printf("Operation done successfully");
  10751. }
  10752. //return ver;
  10753. }
  10754. void OCPP_get_TableAuthlocalAllData(void)
  10755. {
  10756. int rc = 0;
  10757. // const char* data = "Callback function called";
  10758. char sql[100];
  10759. char zErrMsg[100];
  10760. memset(sql, 0, 100);
  10761. memset(zErrMsg, 0, 100);
  10762. sprintf(sql,"select * from ocpp_auth_local ");
  10763. /* Execute SQL statement */
  10764. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10765. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10766. if( rc != SQLITE_OK ){
  10767. DEBUG_INFO("SQL error: %s", zErrMsg);
  10768. //sqlite3_free(zErrMsg);
  10769. }else{
  10770. DEBUG_INFO("Operation done successfully");
  10771. }
  10772. //return ver;
  10773. }
  10774. int OCPP_cleanLocalList()
  10775. {
  10776. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10777. char *errMsg = 0;
  10778. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10779. if (SQLITE_OK != rc)
  10780. {
  10781. DEBUG_INFO("%s\n",errMsg);
  10782. return FALSE;
  10783. }
  10784. else
  10785. {
  10786. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10787. }
  10788. return TRUE;
  10789. }
  10790. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10791. {
  10792. int isSuccess = FALSE;
  10793. int ret = 0;
  10794. //const char* data = "Callback function called";
  10795. char sql[200];
  10796. char zErrMsg[100];
  10797. memset(sql, 0, 200);
  10798. memset(zErrMsg, 0, 100);
  10799. 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);
  10800. //* Execute SQL statement */
  10801. //zErrMsg = 0;
  10802. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10803. if( ret != SQLITE_OK ){
  10804. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10805. // free(zErrMsg);
  10806. // free(sql);
  10807. return isSuccess;
  10808. }
  10809. DEBUG_INFO("successfully Insert records created\n");
  10810. isSuccess = TRUE;
  10811. return isSuccess;
  10812. }
  10813. void OCPP_deleteIdTag(char *idTag)
  10814. {
  10815. //int ver = 0;
  10816. //int isSuccess = FALSE;
  10817. int rc = 0;
  10818. char sql[100];
  10819. char zErrMsg[100];
  10820. memset(sql, 0, 100);
  10821. memset(zErrMsg, 0, 100);
  10822. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10823. //* Execute SQL statement */
  10824. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10825. if( rc != SQLITE_OK ){
  10826. DEBUG_INFO("SQL error: %s", zErrMsg);
  10827. //sqlite3_free(zErrMsg);
  10828. }else{
  10829. DEBUG_INFO("Operation done successfully");
  10830. }
  10831. }
  10832. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10833. {
  10834. int isSuccess = FALSE;
  10835. int ret = 0;
  10836. const char* data = "Callback function called";
  10837. char sql[200];
  10838. char zErrMsg[100];
  10839. memset(sql, 0, 200);
  10840. memset(zErrMsg, 0, 100);
  10841. //* selectFromTable */
  10842. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10843. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10844. //* Execute SQL statement */
  10845. selectSqlCount = 0;
  10846. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10847. if( ret != SQLITE_OK ){
  10848. printf("Error SQL: %s\n", zErrMsg);
  10849. }
  10850. printf("successfully select operation done\n");
  10851. memset(sql, 0, 200);
  10852. memset(zErrMsg, 0, 100);
  10853. if(selectSqlCount == 0)
  10854. {
  10855. //Insert
  10856. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
  10857. 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);
  10858. DEBUG_INFO("sql:%s\n", sql);
  10859. //* Execute SQL statement */
  10860. //zErrMsg = 0;
  10861. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10862. if( ret != SQLITE_OK ){
  10863. printf("SQL error: %s\n", zErrMsg);
  10864. return isSuccess;
  10865. }
  10866. DEBUG_INFO("successfully Insert records created\n");
  10867. isSuccess = TRUE;
  10868. }
  10869. else
  10870. {
  10871. //Update
  10872. //* Create merged SQL statement */
  10873. 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);
  10874. /* Execute SQL statement */
  10875. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10876. if( ret != SQLITE_OK ){
  10877. printf("SQL error: %s\n", zErrMsg);
  10878. //sqlite3_free(zErrMsg);
  10879. //sqlite3_free(sql);
  10880. return isSuccess;
  10881. }
  10882. DEBUG_INFO("Successfully operation done \n");
  10883. isSuccess = TRUE;
  10884. }
  10885. return isSuccess;
  10886. }
  10887. char *GetOcppServerURL()
  10888. {
  10889. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10890. memset(OcppHost, 0, sizeof(OcppHost));
  10891. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10892. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  10893. {
  10894. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  10895. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  10896. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10897. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10898. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10899. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10900. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10901. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10902. goto End;
  10903. }
  10904. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  10905. {
  10906. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  10907. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10908. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10909. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10910. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10911. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10912. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10913. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10914. goto End;
  10915. }
  10916. else
  10917. {
  10918. strcpy(OcppHost,"");
  10919. }
  10920. End:
  10921. return OcppHost;
  10922. }
  10923. char *GetOcppPath()
  10924. {
  10925. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  10926. {
  10927. if(OcppTempPath == NULL)
  10928. {
  10929. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10930. }
  10931. else
  10932. {
  10933. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10934. }
  10935. goto End;
  10936. }
  10937. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  10938. {
  10939. if(OcppTempPath == NULL)
  10940. {
  10941. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10942. }
  10943. else
  10944. {
  10945. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10946. }
  10947. goto End;
  10948. }
  10949. else
  10950. {
  10951. strcpy(OcppHost,"");
  10952. }
  10953. End:
  10954. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10955. return OcppPath;
  10956. }
  10957. int GetOcppPort()
  10958. {
  10959. return OcppPort;
  10960. }
  10961. int GetOcppConnStatus(void)
  10962. {
  10963. return ShmOCPP16Data->OcppConnStatus;
  10964. }
  10965. void SetOcppConnStatus(uint8_t status)
  10966. {
  10967. ShmOCPP16Data->OcppConnStatus = status;
  10968. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  10969. if(status == FALSE)
  10970. {
  10971. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10972. {
  10973. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  10974. }
  10975. else
  10976. {
  10977. SystemInitial = AC_QUANTITY;
  10978. }
  10979. }
  10980. }
  10981. int GetHeartBeatWithNOResponse(void)
  10982. {
  10983. return HeartBeatWithNOResponse;
  10984. }
  10985. void SetHeartBeatWithNOResponse(void)
  10986. {
  10987. HeartBeatWithNOResponse = 0;
  10988. }
  10989. int InternetDisconnect(void)
  10990. {
  10991. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  10992. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  10993. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  10994. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  10995. }
  10996. #if 0
  10997. void Send(struct json_object *message)
  10998. {
  10999. printf("Send -1 \n");
  11000. printf("message=%s\n",json_object_to_json_string(message));
  11001. LWS_Send(json_object_to_json_string(message));
  11002. }
  11003. #endif
  11004. void LWS_Send(char * str)
  11005. {
  11006. #if 1
  11007. //=====================================================
  11008. // Check InternetConn 0: disconnected, 1: connected
  11009. //====================================================
  11010. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  11011. {
  11012. DEBUG_INFO("\n offline now !!!\n");
  11013. return;
  11014. }
  11015. #endif
  11016. pthread_mutex_lock(&lock);
  11017. memset(SendBuffer,0,SendBufLen);
  11018. sprintf((char *)SendBuffer, "%s", str);
  11019. pthread_mutex_unlock(&lock);
  11020. lws_callback_on_writable(wsi_client);
  11021. lws_service(context, 10000);//timeout_ms
  11022. //usleep(10000); // 等�??��?微�?
  11023. //DEBUG_INFO("Send message end\n");
  11024. }