MessageHandler.c 521 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669
  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[2600]={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 StartTransaction transactionId variables
  115. //===============================
  116. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  117. //===============================
  118. // OCPP other variables
  119. //===============================
  120. int isUpdateRequest = FALSE;
  121. static int HeartBeatWaitTime = 10;
  122. static int FirstHeartBeat = 0;
  123. static int FirmwareStatusNotificationStatus = 3; // Idle
  124. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  125. static char CurrentChargingProfileScheduleStr[30]={0};
  126. //========================================
  127. // OCPP status/previous related variables
  128. //========================================
  129. static int GunStatusInterval = 10;
  130. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  131. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  132. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  133. static int GbPreviousSystemStatus[GB_QUANTITY];
  134. static int AcPreviousSystemStatus[AC_QUANTITY];
  135. int TransactionMessageAttemptsValue = 0;
  136. int TransactionMessageRetryIntervalValue = 0;
  137. static struct OCPPAuthLocalElemet
  138. {
  139. int listVersionInt;
  140. char idTagstr[20];
  141. char parentIdTag[20];
  142. char expiryDate[30];
  143. char idTagstatus[16];
  144. }idTagQuery;
  145. //=============================================
  146. // OCPP HeartBeat Response Not Receive Counts
  147. //============================================
  148. static int HeartBeatWithNOResponse = 0;
  149. static int HeartBeatCount = 0;
  150. extern struct lws *wsi_client;
  151. extern struct lws_context *context;
  152. #if 0
  153. extern unsigned char *SendBuffer;
  154. #endif
  155. extern unsigned char SendBuffer[4096];
  156. extern int SendBufLen;
  157. //extern map_t hashMap;
  158. //extern data_struct_t* mapItem; --- remove for temporally
  159. //extern data_struct_t mapItem[0];
  160. extern char *random_uuid( char buf[37] );
  161. extern void split(char **arr, char *str, const char *del);
  162. extern pthread_mutex_t mutex1;
  163. extern struct Charger_Info Charger;
  164. extern sqlite3 *db;
  165. int TransactionMessageAttemptsGet(void);
  166. int TransactionMessageRetryIntervalGet(void);
  167. int GetOcppConnStatus(void);
  168. void SetOcppConnStatus(uint8_t status);
  169. int updateSetting(char *key, char *value);
  170. int setKeyValue(char *key, char *value);
  171. void OCPP_get_TableAuthlocalAllData(void);
  172. void processUnkownKey(void);
  173. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  174. struct StructOCPPMeterValue
  175. {
  176. unsigned char TimeStamp[28];
  177. struct StructSampledValue SampledValue[10];
  178. };
  179. struct ClientTime
  180. {
  181. unsigned int Heartbeat;
  182. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  183. unsigned int StartTransaction;
  184. unsigned int StopTransaction;
  185. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  186. }clientTime;
  187. typedef union
  188. {
  189. //Operations Initiated by Central System
  190. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  191. struct
  192. {
  193. //CsMsgValue[0]
  194. unsigned char StatusNotificationReq :1; //bit 0,
  195. unsigned char StatusNotificationConf :1; //bit 0,
  196. unsigned char :6; //bit 2~7
  197. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  198. }CpinitiateMsg;
  199. CpinitiateMsg cpinitateMsg;
  200. //==========================================
  201. // Init all Enumeration & Mapping String
  202. //==========================================
  203. /*ChargePointErrorCode*/
  204. typedef enum {
  205. ConnectorLockFailure,
  206. EVCommunicationError,
  207. GroundFailure,
  208. HighTemperature,
  209. InternalError,
  210. LocalListConflict,
  211. NoError,
  212. OtherError,
  213. OverCurrentFailure,
  214. OverVoltage,
  215. PowerMeterFailure,
  216. PowerSwitchFailure,
  217. ReaderFailure,
  218. ResetFailure,
  219. UnderVoltage,
  220. WeakSignal
  221. } ChargePointErrorCode;
  222. #if 0
  223. static char *ChargePointErrorCodeStr[] = {
  224. MACROSTR(ConnectorLockFailure),
  225. MACROSTR(EVCommunicationError),
  226. MACROSTR(GroundFailure),
  227. MACROSTR(HighTemperature),
  228. MACROSTR(InternalError),
  229. MACROSTR(LocalListConflict),
  230. MACROSTR(NoError),
  231. MACROSTR(OtherError),
  232. MACROSTR(OverCurrentFailure),
  233. MACROSTR(OverVoltage),
  234. MACROSTR(PowerMeterFailure),
  235. MACROSTR(PowerSwitchFailure),
  236. MACROSTR(ReaderFailure),
  237. MACROSTR(ResetFailure),
  238. MACROSTR(UnderVoltage),
  239. MACROSTR(WeakSignal)
  240. };
  241. #endif
  242. /*ChargePointStatus*/
  243. typedef enum {
  244. Available =0,
  245. Preparing,
  246. Charging,
  247. SuspendedEVSE,
  248. SuspendedEV,
  249. Finishing,
  250. Reserved,
  251. Unavailable,
  252. Faulted
  253. } ChargePointStatus;
  254. static char * ChargePointStatusStr[] = {
  255. MACROSTR(Available),
  256. MACROSTR(Preparing),
  257. MACROSTR(Charging),
  258. MACROSTR(SuspendedEVSE),
  259. MACROSTR(SuspendedEV),
  260. MACROSTR(Finishing),
  261. MACROSTR(Reserved),
  262. MACROSTR(Unavailable),
  263. MACROSTR(Faulted)
  264. };
  265. /*AvailabilityType*/
  266. typedef enum {
  267. RegistrationStatus_Accepted,
  268. RegistrationStatus_Pending,
  269. RegistrationStatus_Rejected
  270. } RegistrationStatus;
  271. static char *RegistrationStatusStr[] = {
  272. MACROSTR(Accepted),
  273. MACROSTR(Pending),
  274. MACROSTR(Rejected)
  275. };
  276. /*AvailabilityType*/
  277. typedef enum {
  278. Inoperative,
  279. Operative
  280. } AvailabilityType;
  281. static char *AvailabilityTypeStr[] = {
  282. MACROSTR(Inoperative),
  283. MACROSTR(Operative)
  284. };
  285. /*AvailabilityStatus*/
  286. typedef enum {
  287. Accepted,
  288. Rejected,
  289. Scheduled
  290. } AvailabilityStatus;
  291. static char *AvailabilityStatusStr[] = {
  292. MACROSTR(Accepted),
  293. MACROSTR(Rejected),
  294. MACROSTR(Scheduled)
  295. };
  296. /*ConfigurationStatus*/
  297. typedef enum {
  298. ConfigurationStatus_Accepted,
  299. ConfigurationStatus_Rejected,
  300. RebootRequired,
  301. NotSupported
  302. } ConfigurationStatus;
  303. static char *ConfigurationStatusStr[] = {
  304. MACROSTR(Accepted),
  305. MACROSTR(Rejected),
  306. MACROSTR(RebootRequired),
  307. MACROSTR(NotSupported)
  308. };
  309. /*ClearCacheStatus*/
  310. typedef enum {
  311. ClearCacheStatus_Accepted,
  312. ClearCacheStatus_Rejected
  313. } ClearCacheStatus;
  314. static char *ClearCacheStatusStr[] = {
  315. MACROSTR(Accepted),
  316. MACROSTR(Rejected)
  317. };
  318. /*ChargingProfilePurposeType*/
  319. typedef enum {
  320. ChargePointMaxProfile,
  321. TxDefaultProfile,
  322. TxProfile
  323. } ChargingProfilePurposeType;
  324. static char *ChargingProfilePurposeTypeStr[] = {
  325. MACROSTR(ChargePointMaxProfile),
  326. MACROSTR(TxDefaultProfile),
  327. MACROSTR(TxProfile)
  328. };
  329. /*ChargingProfileStatus*/
  330. typedef enum {
  331. ChargingProfileStatus_Accepted,
  332. ChargingProfileStatus_Rejected,
  333. ChargingProfileStatus_NotSupported
  334. } ChargingProfileStatus;
  335. static char *ChargingProfileStatusStr[] = {
  336. MACROSTR(Accepted),
  337. MACROSTR(Rejected),
  338. MACROSTR(NotSupported)
  339. };
  340. /*ClearChargingProfileStatus*/
  341. typedef enum {
  342. ClearChargingProfileStatus_Accepted,
  343. ClearChargingProfileStatus_Unknown
  344. } ClearChargingProfileStatus;
  345. static char *ClearChargingProfileStatusStr[] = {
  346. MACROSTR(Accepted),
  347. MACROSTR(Unknown)
  348. };
  349. /*GetCompositeScheduleStatus*/
  350. typedef enum {
  351. GetCompositeScheduleStatus_Accepted,
  352. GetCompositeScheduleStatus_Rejected
  353. } GetCompositeScheduleStatus;
  354. static char *GetCompositeScheduleStatusStr[] = {
  355. MACROSTR(Accepted),
  356. MACROSTR(Rejected)
  357. };
  358. /*ChargingRateUnitType*/
  359. typedef enum {
  360. ChargingRateUnitType_W,
  361. ChargingRateUnitType_A
  362. } ChargingRateUnitType;
  363. /*AuthorizationStatus*/
  364. typedef enum {
  365. AuthorizationStatus_Accepted ,
  366. AuthorizationStatus_Blocked ,
  367. AuthorizationStatus_Expired ,
  368. AuthorizationStatus_Invalid ,
  369. AuthorizationStatus_ConcurrentTx
  370. } AuthorizationStatus;
  371. /*UpdateType*/
  372. typedef enum {
  373. Differential ,
  374. Full
  375. } UpdateType;
  376. static char *UpdateTypeStr[] = {
  377. MACROSTR(Differential),
  378. MACROSTR(Full)
  379. };
  380. /*UpdateStatus*/
  381. typedef enum {
  382. UpdateStatus_Accepted ,
  383. UpdateStatus_Failed ,
  384. UpdateStatus_NotSupported ,
  385. UpdateStatus_VersionMismatch
  386. } UpdateStatus;
  387. static char *UpdateStatusStr[] = {
  388. MACROSTR(Accepted),
  389. MACROSTR(Failed),
  390. MACROSTR(NotSupported),
  391. MACROSTR(VersionMismatch)
  392. };
  393. /*RemoteStartStopStatus*/
  394. typedef enum {
  395. RemoteStartStopStatus_Accepted,
  396. RemoteStartStopStatus_Rejected
  397. } RemoteStartStopStatus;
  398. static char *RemoteStartStopStatusStr[] = {
  399. MACROSTR(Accepted),
  400. MACROSTR(Rejected)
  401. };
  402. /*ReservationStatus*/
  403. typedef enum {
  404. ReservationStatus_Accepted,
  405. ReservationStatus_Faulted,
  406. ReservationStatus_Occupied,
  407. ReservationStatus_Rejected,
  408. ReservationStatus_Unavailable
  409. } ReservationStatus;
  410. static char *ReservationStatusStr[] = {
  411. MACROSTR(Accepted),
  412. MACROSTR(Faulted),
  413. MACROSTR(Occupied),
  414. MACROSTR(Rejected),
  415. MACROSTR(Unavailable)
  416. };
  417. /*ResetType*/
  418. typedef enum {
  419. Hard,
  420. Soft
  421. } ResetType;
  422. static char *ResetTypeStr[] = {
  423. MACROSTR(Hard),
  424. MACROSTR(Soft)
  425. };
  426. /*ResetStatus*/
  427. typedef enum {
  428. ResetStatus_Accepted,
  429. ResetStatus_Rejected
  430. } ResetStatus;
  431. static char *ResetStatusStr[] = {
  432. MACROSTR(Accepted),
  433. MACROSTR(Rejected)
  434. };
  435. /*DiagnosticsStatus*/
  436. typedef enum {
  437. DiagnosticsStatus_Idle,
  438. DiagnosticsStatus_Uploaded,
  439. DiagnosticsStatus_UploadFailed,
  440. DiagnosticsStatus_Uploading
  441. } DiagnosticsStatus;
  442. static char * DiagnosticsStatusStr[] = {
  443. MACROSTR(Idle),
  444. MACROSTR(Uploaded),
  445. MACROSTR(UploadFailed),
  446. MACROSTR(Uploading)
  447. };
  448. /*FirmwareStatus*/
  449. typedef enum {
  450. FirmwareStatus_Downloaded,
  451. FirmwareStatus_DownloadFailed,
  452. FirmwareStatus_Downloading,
  453. FirmwareStatus_Idle,
  454. FirmwareStatus_InstallationFailed,
  455. FirmwareStatus_Installing,
  456. FirmwareStatus_Installed
  457. } FirmwareStatus;
  458. static char * FirmwareStatusStr[] = {
  459. MACROSTR(Downloaded),
  460. MACROSTR(DownloadFailed),
  461. MACROSTR(Downloading),
  462. MACROSTR(Idle),
  463. MACROSTR(InstallationFailed),
  464. MACROSTR(Installing),
  465. MACROSTR(Installed)
  466. };
  467. /*MessageTrigger*/
  468. typedef enum {
  469. BootNotification,
  470. DiagnosticsStatusNotification,
  471. FirmwareStatusNotification,
  472. Heartbeat,
  473. MeterValues,
  474. StatusNotification
  475. } MessageTrigger;
  476. static char * MessageTriggerStr[] = {
  477. MACROSTR(BootNotification),
  478. MACROSTR(DiagnosticsStatusNotification),
  479. MACROSTR(FirmwareStatusNotification),
  480. MACROSTR(Heartbeat),
  481. MACROSTR(MeterValues),
  482. MACROSTR(StatusNotification)
  483. };
  484. /*TriggerMessageStatus*/
  485. typedef enum {
  486. TriggerMessageStatus_Accepted ,
  487. TriggerMessageStatus_Rejected ,
  488. TriggerMessageStatus_NotImplemented
  489. } TriggerMessageStatus;
  490. static char * TriggerMessageStatusStr[] = {
  491. MACROSTR(Accepted),
  492. MACROSTR(Rejected),
  493. MACROSTR(NotImplemented)
  494. };
  495. /*UnlockStatus*/
  496. typedef enum {
  497. Unlocked,
  498. UnlockFailed,
  499. UnlockStatus_NotSupported
  500. } UnlockStatus;
  501. static char * UnlockStatusStr[] = {
  502. MACROSTR(Unlocked),
  503. MACROSTR(UnlockFailed),
  504. MACROSTR(NotSupported)
  505. };
  506. /*StopTransactionReason*/
  507. typedef enum {
  508. EmergencyStop,
  509. EVDisconnected,
  510. HardReset,
  511. Local,
  512. Other,
  513. PowerLoss,
  514. Reboot,
  515. Remote,
  516. SoftReset,
  517. UnlockCommand,
  518. DeAuthorized
  519. } StopTransactionReason;
  520. static char * StopTransactionReasonStr[] = {
  521. MACROSTR(EmergencyStop),
  522. MACROSTR(EVDisconnected),
  523. MACROSTR(HardReset),
  524. MACROSTR(Local),
  525. MACROSTR(Other),
  526. MACROSTR(PowerLoss),
  527. MACROSTR(Reboot),
  528. MACROSTR(Remote),
  529. MACROSTR(SoftReset),
  530. MACROSTR(UnlockCommand),
  531. MACROSTR(DeAuthorized)
  532. };
  533. /*CancelReservationStatus*/
  534. typedef enum {
  535. CancelReservationStatus_Accepted,
  536. CancelReservationStatus_Rejected
  537. } CancelReservationStatus;
  538. static char * CancelReservationStatusStr[] = {
  539. MACROSTR(Accepted),
  540. MACROSTR(Rejected)
  541. };
  542. /*ReadingContext*/
  543. typedef enum {
  544. ReadingContext_Interruption_Begin,
  545. ReadingContext_Interruption_End,
  546. ReadingContext_Other,
  547. ReadingContext_Sample_Clock,
  548. ReadingContext_Sample_Periodic ,
  549. ReadingContext_Transaction_Begin ,
  550. ReadingContext_Transaction_End,
  551. ReadingContext_Trigger
  552. } ReadingContext;
  553. static char * ReadingContextStr[] = {
  554. MACROSTR(Interruption.Begin),
  555. MACROSTR(Interruption.End),
  556. MACROSTR(Other),
  557. MACROSTR(Sample.Clock),
  558. MACROSTR(Sample.Periodic),
  559. MACROSTR(Transaction.Begin),
  560. MACROSTR(Transaction.End),
  561. MACROSTR(Trigger)
  562. };
  563. /*ValueFormat*/
  564. typedef enum {
  565. Raw,
  566. SignedData
  567. } ValueFormat;
  568. static char * ValueFormatStr[] = {
  569. MACROSTR(Raw),
  570. MACROSTR(SignedData)
  571. };
  572. /*Measurand*/
  573. typedef enum {
  574. Current_Export ,
  575. Current_Import,
  576. Current_Offered,
  577. Energy_Active_Export_Register,
  578. Energy_Active_Import_Register,
  579. Energy_Reactive_Export_Register,
  580. Energy_Reactive_Import_Register,
  581. Energy_Active_Export_Interval,
  582. Energy_Active_Import_Interval,
  583. Energy_Reactive_Export_Interval,
  584. Energy_Reactive_Import_Interval,
  585. Frequency,
  586. Power_Active_Export ,
  587. Power_Active_Import,
  588. Power_Factor,
  589. Power_Offered,
  590. Power_Reactive_Export,
  591. Power_Reactive_Import,
  592. RPM,
  593. SoC,
  594. Temperature ,
  595. Voltage
  596. } Measurand;
  597. static char * MeasurandStr[] = {
  598. MACROSTR(Current.Export),
  599. MACROSTR(Current.Import),
  600. MACROSTR(Current.Offered),
  601. MACROSTR(Energy.Active.Export.Register),
  602. MACROSTR(Energy.Active.Import.Register),
  603. MACROSTR(Energy.Reactive.Export.Register),
  604. MACROSTR(Energy.Reactive.Import.Register),
  605. MACROSTR(Energy.Active.Export.Interval),
  606. MACROSTR(Energy.Active.Import.Interval),
  607. MACROSTR(Energy.Reactive.Export.Interval),
  608. MACROSTR(Energy.Reactive.Import.Interval),
  609. MACROSTR(Frequency),
  610. MACROSTR(Power.Active.Export),
  611. MACROSTR(Power.Active.Import),
  612. MACROSTR(Power.Factor),
  613. MACROSTR(Power.Offered),
  614. MACROSTR(Power.Reactive.ExportMACROSTR),
  615. MACROSTR(Power.Reactive.Import),
  616. MACROSTR(RPM),
  617. MACROSTR(SoC),
  618. MACROSTR(Temperature),
  619. MACROSTR(Voltage)
  620. };
  621. /*Location*/
  622. typedef enum {
  623. Location_Body,
  624. Location_Cable,
  625. Location_EV,
  626. Location_Inlet ,
  627. Location_Outlet
  628. } Location;
  629. static char * LocationStr[] = {
  630. MACROSTR(Body),
  631. MACROSTR(Cable),
  632. MACROSTR(EV),
  633. MACROSTR(Inlet),
  634. MACROSTR(Outlet)
  635. };
  636. /*Phase*/
  637. typedef enum {
  638. L1,
  639. L2,
  640. L3,
  641. N,
  642. L1_N,
  643. L2_N,
  644. L3_N,
  645. L1_L2,
  646. L2_L3,
  647. L3_L1
  648. } Phase;
  649. static char * PhaseStr[] = {
  650. MACROSTR(L1),
  651. MACROSTR(L2),
  652. MACROSTR(L3),
  653. MACROSTR(N),
  654. MACROSTR(L1-N),
  655. MACROSTR(L2-N),
  656. MACROSTR(L3-N),
  657. MACROSTR(L1-L2),
  658. MACROSTR(L2-L3),
  659. MACROSTR(L3-L1)
  660. };
  661. /*UnitOfMeasure*/
  662. typedef enum {
  663. UnitOfMeasure_Wh,
  664. UnitOfMeasure_kWh ,
  665. UnitOfMeasure_varh ,
  666. UnitOfMeasure_kvarh ,
  667. UnitOfMeasure_W ,
  668. UnitOfMeasure_kW ,
  669. UnitOfMeasure_VA ,
  670. UnitOfMeasure_kVA ,
  671. UnitOfMeasure_var ,
  672. UnitOfMeasure_kvar ,
  673. UnitOfMeasure_A ,
  674. UnitOfMeasure_V ,
  675. UnitOfMeasure_Celsius ,
  676. UnitOfMeasure_Fahrenheit ,
  677. UnitOfMeasure_K ,
  678. UnitOfMeasure_Percent
  679. } UnitOfMeasure;
  680. static char * UnitOfMeasureStr[] = {
  681. MACROSTR(Wh),
  682. MACROSTR(kWh),
  683. MACROSTR(varh),
  684. MACROSTR(kvarh),
  685. MACROSTR(W),
  686. MACROSTR(kW),
  687. MACROSTR(VA),
  688. MACROSTR(kVA),
  689. MACROSTR(var),
  690. MACROSTR(kvar),
  691. MACROSTR(A),
  692. MACROSTR(V),
  693. MACROSTR(Celsius),
  694. MACROSTR(Fahrenheit),
  695. MACROSTR(K),
  696. MACROSTR(Percent)
  697. };
  698. #if 0
  699. /*Configuration enum*/
  700. enum CoreProfile {
  701. AllowOfflineTxForUnknownId=0,
  702. AuthorizationCacheEnabled,
  703. AuthorizeRemoteTxRequests,
  704. BlinkRepeat,
  705. ClockAlignedDataInterval,
  706. ConnectionTimeOut,
  707. GetConfigurationMaxKeys,
  708. HeartbeatInterval,
  709. LightIntensity,
  710. LocalAuthorizeOffline,
  711. LocalPreAuthorize,
  712. MaxEnergyOnInvalidId,
  713. MeterValuesAlignedData,
  714. MeterValuesAlignedDataMaxLength,
  715. MeterValuesSampledData,
  716. MeterValuesSampledDataMaxLength,
  717. MeterValueSampleInterval,
  718. MinimumStatusDuration,
  719. NumberOfConnectors,
  720. ResetRetries,
  721. ConnectorPhaseRotation,
  722. ConnectorPhaseRotationMaxLength,
  723. StopTransactionOnEVSideDisconnect,
  724. StopTransactionOnInvalidId,
  725. StopTxnAlignedData,
  726. StopTxnAlignedDataMaxLength,
  727. StopTxnSampledData,
  728. StopTxnSampledDataMaxLength,
  729. SupportedFeatureProfiles,
  730. SupportedFeatureProfilesMaxLength,
  731. TransactionMessageAttempts,
  732. TransactionMessageRetryInterval,
  733. UnlockConnectorOnEVSideDisconnect,
  734. WebSocketPingInterval,
  735. _CoreProfile_CNT
  736. };
  737. #endif
  738. enum LocalAuthListManagementProfile{
  739. LocalAuthListEnabled=0,
  740. LocalAuthListMaxLength,
  741. SendLocalListMaxLength,
  742. _LocalAuthListManagementProfile_CNT
  743. };
  744. enum ReservationProfile{
  745. ReserveConnectorZeroSupported
  746. };
  747. enum SmartChargingProfile{
  748. ChargeProfileMaxStackLevel,
  749. ChargingScheduleAllowedChargingRateUnit,
  750. ChargingScheduleMaxPeriods,
  751. ConnectorSwitch3to1PhaseSupported,
  752. MaxChargingProfilesInstalled
  753. };
  754. enum ChargerSystemStatus{
  755. ChargerSystemStatus_Booting,
  756. ChargerSystemStatus_Idle,
  757. ChargerSystemStatus_Authorizing,
  758. ChargerSystemStatus_Preparing,
  759. ChargerSystemStatus_Charging,
  760. ChargerSystemStatus_Terminating,
  761. ChargerSystemStatus_Alarm,
  762. ChargerSystemStatus_Fault
  763. };
  764. enum GetConfigurationKey {
  765. GetConfiguration_AllowOfflineTxForUnknownId=0,
  766. GetConfiguration_AuthorizationCacheEnabled,
  767. GetConfiguration_AuthorizeRemoteTxRequests,
  768. GetConfiguration_BlinkRepeat,
  769. GetConfiguration_ClockAlignedDataInterval,
  770. GetConfiguration_ConnectionTimeOut,
  771. GetConfiguration_GetConfigurationMaxKeys,
  772. GetConfiguration_HeartbeatInterval,
  773. GetConfiguration_LightIntensity,
  774. GetConfiguration_LocalAuthorizeOffline,
  775. GetConfiguration_LocalPreAuthorize,
  776. GetConfiguration_MaxEnergyOnInvalidId,
  777. GetConfiguration_MeterValuesAlignedData,
  778. GetConfiguration_MeterValuesAlignedDataMaxLength,
  779. GetConfiguration_MeterValuesSampledData,
  780. GetConfiguration_MeterValuesSampledDataMaxLength,
  781. GetConfiguration_MeterValueSampleInterval,
  782. GetConfiguration_MinimumStatusDuration,
  783. GetConfiguration_NumberOfConnectors,
  784. GetConfiguration_ResetRetries,
  785. GetConfiguration_ConnectorPhaseRotation,
  786. GetConfiguration_ConnectorPhaseRotationMaxLength,
  787. GetConfiguration_StopTransactionOnEVSideDisconnect,
  788. GetConfiguration_StopTransactionOnInvalidId,
  789. GetConfiguration_StopTxnAlignedData,
  790. GetConfiguration_StopTxnAlignedDataMaxLength,
  791. GetConfiguration_StopTxnSampledData,
  792. GetConfiguration_StopTxnSampledDataMaxLength,
  793. GetConfiguration_SupportedFeatureProfiles,
  794. GetConfiguration_SupportedFeatureProfilesMaxLength,
  795. GetConfiguration_TransactionMessageAttempts,
  796. GetConfiguration_TransactionMessageRetryInterval,
  797. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  798. GetConfiguration_WebSocketPingInterval,
  799. GetConfiguration_LocalAuthListEnabled,
  800. GetConfiguration_LocalAuthListMaxLength,
  801. GetConfiguration_SendLocalListMaxLength,
  802. GetConfiguration_ReserveConnectorZeroSupported,
  803. GetConfiguration_ChargeProfileMaxStackLevel,
  804. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  805. GetConfiguration_ChargingScheduleMaxPeriods,
  806. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  807. GetConfiguration_MaxChargingProfilesInstalled,
  808. };
  809. //GetConfiguration Array
  810. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  811. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  812. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  813. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  814. //==========================================
  815. // Init all share memory
  816. //==========================================
  817. int InitShareMemory()
  818. {
  819. int result = PASS;
  820. int MeterSMId;
  821. //printf("1\n");
  822. //creat ShmSysConfigAndInfo
  823. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  824. {
  825. #ifdef SystemLogMessage
  826. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  827. #endif
  828. result = FAIL;
  829. }
  830. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  831. {
  832. #ifdef SystemLogMessage
  833. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  834. #endif
  835. result = FAIL;
  836. }
  837. else
  838. {}
  839. //printf("2\n");
  840. //creat ShmStatusCodeData
  841. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  842. {
  843. #ifdef SystemLogMessage
  844. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  845. #endif
  846. result = FAIL;
  847. }
  848. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  849. {
  850. #ifdef SystemLogMessage
  851. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  852. #endif
  853. result = FAIL;
  854. }
  855. else
  856. {}
  857. //printf("3\n");
  858. //creat ShmPsuData
  859. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  860. {
  861. #ifdef SystemLogMessage
  862. DEBUG_ERROR("shmget ShmPsuData NG\n");
  863. #endif
  864. result = FAIL;
  865. }
  866. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  867. {
  868. #ifdef SystemLogMessage
  869. DEBUG_ERROR("shmat ShmPsuData NG\n");
  870. #endif
  871. result = FAIL;
  872. }
  873. else
  874. {}
  875. //creat ShmOCPP16Data
  876. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  877. {
  878. #ifdef SystemLogMessage
  879. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  880. #endif
  881. result = FAIL;
  882. }
  883. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  884. {
  885. #ifdef SystemLogMessage
  886. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  887. #endif
  888. result = FAIL;
  889. }
  890. else
  891. {}
  892. /****************************** For Initial Settings************************************************/
  893. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  894. //memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY));
  895. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  896. {
  897. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  898. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  899. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  900. }
  901. // Charger PRE_SYS_MODE
  902. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  903. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  904. clientTime.Heartbeat=time((time_t*)NULL);
  905. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  906. {
  907. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  908. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  909. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  910. }
  911. //HeartBeatWaitTime = 10;
  912. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  913. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  914. // allocate Configuration memory address
  915. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  916. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  917. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  918. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  920. {
  921. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  922. DEBUG_INFO("DC ...\n");
  923. }
  924. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  925. {
  926. SystemInitial = AC_QUANTITY;
  927. DEBUG_INFO("AC ...\n");
  928. }
  929. //Status Setting
  930. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  931. {
  932. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  933. }
  934. for (int index = 0; index < CCS_QUANTITY; index++)
  935. {
  936. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  937. }
  938. for (int index = 0; index < GB_QUANTITY; index++)
  939. {
  940. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  941. }
  942. for (int index = 0; index < AC_QUANTITY; index++)
  943. {
  944. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  945. }
  946. //memset(unknownkey, 0, 10);
  947. return result;
  948. }
  949. int ProcessShareMemory()
  950. {
  951. if(InitShareMemory() == FAIL)
  952. {
  953. #ifdef SystemLogMessage
  954. DEBUG_ERROR("InitShareMemory NG\n");
  955. #endif
  956. if(ShmStatusCodeData!=NULL)
  957. {
  958. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  959. }
  960. sleep(5);
  961. return FAIL;
  962. }
  963. return PASS;
  964. }
  965. //---------------------------------------------
  966. // new:
  967. // enum SYSTEM_STATUS
  968. // {
  969. // SYS_MODE_BOOTING = 0,
  970. // SYS_MODE_IDLE = 1,
  971. // SYS_MODE_AUTHORIZING = 2,
  972. // SYS_MODE_PREPARING = 3,
  973. // SYS_MODE_CHARGING = 4,
  974. // SYS_MODE_TERMINATING = 5,
  975. // SYS_MODE_ALARM = 6,
  976. // SYS_MODE_FAULT = 7,
  977. // SYS_MODE_RESERVATION = 8,
  978. // SYS_MODE_BOOKING = 9,
  979. // SYS_MODE_MAINTAIN = 10,
  980. // SYS_MODE_DEBUG = 11,
  981. // SYS_MODE_REASSIGN_CHECK = 12,
  982. // SYS_MODE_REASSIGN = 13,
  983. // SYS_MODE_PRECHARGE = 14,
  984. // SYS_MODE_PREPARING_EV = 15,
  985. // SYS_MODE_PREPARING_EVSE = 16,
  986. // SYS_MODE_COMPLETE = 17
  987. // };
  988. //
  989. // old:
  990. // enum _SYSTEM_STATUS
  991. // {
  992. // S_BOOTING = 0,
  993. // S_IDLE, =1
  994. // S_AUTHORIZING, =2
  995. // S_REASSIGN_CHECK, =3
  996. // S_REASSIGN, =4
  997. // S_PRECHARGE, =5
  998. // S_PREPARING_FOR_EV, =6
  999. // S_PREPARING_FOR_EVSE, =7
  1000. // S_CHARGING, =8
  1001. // S_TERMINATING, =9
  1002. // S_COMPLETE, =10
  1003. // S_ALARM, =11
  1004. // S_FAULT =12
  1005. // };
  1006. //
  1007. //-----------------------------------------
  1008. void CheckSystemValue(void)
  1009. {
  1010. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1011. int IdleModeCnt = 0;
  1012. char filenmae[100]={0};
  1013. char str[100]={0};
  1014. //===============================
  1015. // send Heartbeat
  1016. //===============================
  1017. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1018. {
  1019. //parameter for test
  1020. sendHeartbeatRequest(0);
  1021. //==============================================
  1022. // Reset Waiting Time
  1023. //==============================================
  1024. clientTime.Heartbeat=time((time_t*)NULL);
  1025. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1026. }
  1027. //==============================================
  1028. // Update firmware request
  1029. //==============================================
  1030. if(isUpdateRequest == TRUE )
  1031. {
  1032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1033. {
  1034. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1035. {
  1036. //check SystemStatus
  1037. /*************************DC*******************************/
  1038. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1039. {
  1040. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1041. {
  1042. IdleModeCnt = IdleModeCnt + 1;
  1043. }
  1044. }
  1045. for (int index = 0; index < CCS_QUANTITY; index++)
  1046. {
  1047. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1048. {
  1049. IdleModeCnt = IdleModeCnt + 1;
  1050. }
  1051. }
  1052. for (int index = 0; index < GB_QUANTITY; index++)
  1053. {
  1054. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1055. {
  1056. IdleModeCnt = IdleModeCnt + 1;
  1057. }
  1058. }
  1059. }
  1060. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1061. {
  1062. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1063. isUpdateRequest = FALSE;
  1064. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1065. }
  1066. }
  1067. else
  1068. {
  1069. /*************************AC*******************************/
  1070. for (int index = 0; index < AC_QUANTITY; index++)
  1071. {
  1072. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1073. {
  1074. IdleModeCnt = IdleModeCnt + 1;
  1075. }
  1076. }
  1077. if(IdleModeCnt == AC_QUANTITY)
  1078. {
  1079. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1080. isUpdateRequest = FALSE;
  1081. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1082. }
  1083. }
  1084. }
  1085. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1086. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1087. {
  1088. //===============================
  1089. // CSU Trigger Reset Conf
  1090. //===============================
  1091. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1092. {
  1093. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1094. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1095. {
  1096. server_sign = FALSE;
  1097. }
  1098. }
  1099. //===============================
  1100. // CSU Trigger Authorize Request
  1101. //===============================
  1102. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1103. {
  1104. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1105. {
  1106. sendAuthorizeRequest(0);
  1107. authorizeRetryTimes = authorizeRetryTimes + 1;
  1108. // authenrequest = TRUE
  1109. if(authorizeRetryTimes < 3)
  1110. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1111. }
  1112. }
  1113. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1114. {
  1115. authorizeRetryTimes = 0;
  1116. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1117. server_sign = FALSE;
  1118. }
  1119. //===============================
  1120. // CSU Trigger Smart Charging Profilw
  1121. //===============================
  1122. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1123. {
  1124. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1125. GetChargingProfileRequest(gun_index);
  1126. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1127. }
  1128. //==============================================
  1129. // Charger start transaction
  1130. //==============================================
  1131. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1132. {
  1133. sendStartTransactionRequest(gun_index);
  1134. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1135. clientTime.StartTransaction = time((time_t*)NULL);
  1136. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1137. }
  1138. //==============================================
  1139. // Charger stop transaction
  1140. //==============================================
  1141. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1142. {
  1143. sendStopTransactionRequest(gun_index);
  1144. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1145. clientTime.StopTransaction = time((time_t*)NULL);
  1146. }
  1147. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1148. //==============================================
  1149. // Charger status report
  1150. //==============================================
  1151. /* Check Mode Change */
  1152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1153. {
  1154. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1155. {
  1156. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1157. {
  1158. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1159. {
  1160. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1161. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1162. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1163. statusModeChage[gun_index] = TRUE;
  1164. }
  1165. }
  1166. }
  1167. for (int index = 0; index < CCS_QUANTITY; index++)
  1168. {
  1169. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1170. {
  1171. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1172. {
  1173. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1174. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1175. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1176. statusModeChage[gun_index] = TRUE;
  1177. }
  1178. }
  1179. }
  1180. for (int index = 0; index < GB_QUANTITY; index++)
  1181. {
  1182. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1183. {
  1184. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1185. {
  1186. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1187. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1188. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1189. statusModeChage[gun_index] = TRUE;
  1190. }
  1191. }
  1192. }
  1193. }
  1194. else //AC
  1195. {
  1196. for (int index = 0; index < AC_QUANTITY; index++)
  1197. {
  1198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1199. {
  1200. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1201. {
  1202. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1203. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1204. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1205. statusModeChage[gun_index] = TRUE;
  1206. }
  1207. }
  1208. }// END OF FOR
  1209. }// END OF ELSE
  1210. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1211. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1212. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1213. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1214. {
  1215. if(SystemInitial != 0)
  1216. SystemInitial = SystemInitial -1;
  1217. //GunStatusInterval= GunStatusInterval* gun_index;
  1218. sendStatusNotificationRequest(gun_index);
  1219. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1220. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1221. statusModeChage[gun_index] = FALSE;
  1222. //sleep(30); // sleep for 30 seconds
  1223. }
  1224. //==============================================
  1225. // Meter report
  1226. //==============================================
  1227. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1228. {
  1229. //check Transaction active
  1230. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1231. {
  1232. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1233. {
  1234. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1235. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1236. {
  1237. meterValueSend[gun_index] =1;
  1238. }
  1239. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1240. {
  1241. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1242. if((access(filenmae,F_OK))!=-1)
  1243. {
  1244. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1245. sprintf(str,"rm -f %s",filenmae);
  1246. system(str);
  1247. }
  1248. }
  1249. }// End for CHAdeMO
  1250. for (int index = 0; index < CCS_QUANTITY; index++)
  1251. {
  1252. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1253. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1254. {
  1255. meterValueSend[gun_index] =1;
  1256. }
  1257. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1258. {
  1259. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1260. if((access(filenmae,F_OK))!=-1)
  1261. {
  1262. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1263. sprintf(str,"rm -f %s",filenmae);
  1264. system(str);
  1265. }
  1266. }
  1267. } // End for CCS
  1268. for (int index = 0; index < GB_QUANTITY; index++)
  1269. {
  1270. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1271. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1272. {
  1273. meterValueSend[gun_index] =1;
  1274. }
  1275. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1276. {
  1277. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1278. if((access(filenmae,F_OK))!=-1)
  1279. {
  1280. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1281. sprintf(str,"rm -f %s",filenmae);
  1282. system(str);
  1283. }
  1284. }
  1285. }// End for GB
  1286. }
  1287. else
  1288. {
  1289. for (int index = 0; index < AC_QUANTITY; index++)
  1290. {
  1291. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1292. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1293. {
  1294. meterValueSend[gun_index] =1;
  1295. }
  1296. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1297. {
  1298. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1299. if((access(filenmae,F_OK))!=-1)
  1300. {
  1301. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1302. sprintf(str,"rm -f %s",filenmae);
  1303. system(str);
  1304. }
  1305. }
  1306. }//End for AC
  1307. }//END OF ELSE
  1308. // sleep(1);
  1309. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1310. if(meterValueSend[gun_index] == 1)
  1311. sendMeterValuesRequest(gun_index);
  1312. }
  1313. //==============================================
  1314. // Check Connector reserved
  1315. //==============================================
  1316. //===============================
  1317. // Check if Reserve is expired
  1318. //===============================
  1319. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1320. {
  1321. double diff_t;
  1322. struct tm tp;
  1323. // current time
  1324. time_t t = time(NULL);
  1325. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1326. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1327. tp.tm_isdst = -1;
  1328. time_t utc = mktime(&tp);
  1329. diff_t = difftime(utc, t);
  1330. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1331. if(diff_t <= 0)
  1332. {
  1333. DEBUG_INFO("reserve expired !!! \n");
  1334. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1335. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1336. }
  1337. #if 0
  1338. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1339. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1340. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1341. {
  1342. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1343. }
  1344. else
  1345. {
  1346. //check Transaction active
  1347. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1348. {
  1349. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1350. {
  1351. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1352. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1353. {
  1354. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1355. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1356. {
  1357. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1358. }
  1359. }
  1360. }
  1361. for (int index = 0; index < CCS_QUANTITY; index++)
  1362. {
  1363. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1364. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1365. {
  1366. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1367. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1368. {
  1369. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1370. }
  1371. }
  1372. }
  1373. for (int index = 0; index < GB_QUANTITY; index++)
  1374. {
  1375. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1376. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1377. {
  1378. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1379. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1380. {
  1381. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1382. }
  1383. }
  1384. }
  1385. }
  1386. else //AC
  1387. {
  1388. for (int index = 0; index < AC_QUANTITY; index++)
  1389. {
  1390. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1391. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1392. {
  1393. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1394. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1395. {
  1396. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1397. }
  1398. }
  1399. }
  1400. }// END OF ELSE
  1401. }// END OF check Transaction active
  1402. #endif
  1403. }//END OF Check if Reserve is expired
  1404. //==========================================
  1405. // csu trigger FirmwareStatusNotificationReq
  1406. //==========================================
  1407. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1408. {
  1409. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1410. }
  1411. //==========================================
  1412. // csu trigger CancelReservationConf
  1413. //==========================================
  1414. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1415. {
  1416. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1417. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1418. }
  1419. //==========================================
  1420. // csu trigger ChangeAvailabilityConf
  1421. //==========================================
  1422. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1423. {
  1424. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1425. }
  1426. //==========================================
  1427. // csu trigger UnlockConnectorConf
  1428. //==========================================
  1429. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1430. {
  1431. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1432. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1433. }
  1434. //==========================================
  1435. // csu trigger ReserveNowConf
  1436. //==========================================
  1437. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1438. {
  1439. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1440. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1441. }
  1442. //==========================================
  1443. // csu trigger DataTransferReq
  1444. //==========================================
  1445. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1446. {
  1447. sendDataTransferRequest(gun_index);
  1448. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1449. }
  1450. }
  1451. }
  1452. //==========================================
  1453. // send request routine
  1454. //==========================================
  1455. int sendAuthorizeRequest(int gun_index)
  1456. {
  1457. mtrace();
  1458. int result = FAIL;
  1459. char message[100]={0};
  1460. char guid[37];
  1461. char tempdata[65]={0};
  1462. DEBUG_INFO("sendAuthorizeRequest \n");
  1463. //Local Authorize
  1464. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1465. {
  1466. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1467. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1468. {
  1469. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1470. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1471. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1472. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1473. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1474. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1475. authorizeRetryTimes = 0;
  1476. return result;
  1477. }
  1478. else
  1479. {
  1480. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1481. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1482. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1483. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1484. result = PASS;
  1485. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1486. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1487. authorizeRetryTimes = 0;
  1488. return result;
  1489. }
  1490. }
  1491. //initailize struct Authorize
  1492. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1493. //get data from shared memory
  1494. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1495. random_uuid(guid);
  1496. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1497. LWS_Send(message);
  1498. sprintf(tempdata, "Authorize,%d", gun_index);
  1499. if(hashmap_operation(0, guid, tempdata) == 1)
  1500. {
  1501. result = PASS;
  1502. DEBUG_ERROR("Authorize mapItem pass\n");
  1503. }
  1504. //#ifdef SystemLogMessage
  1505. //DEBUG_INFO(">>>>>Authorize request\n");
  1506. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1507. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1508. //#endif
  1509. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1510. return result;
  1511. }
  1512. int sendBootNotificationRequest(void)
  1513. {
  1514. mtrace();
  1515. int result = FAIL;
  1516. char message[500]={0}, payload[700]={0};
  1517. char guid[37]={0};
  1518. char tempdata[65]={0};
  1519. int IsGunCharging = FALSE;
  1520. //check Transaction active
  1521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1522. {
  1523. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1524. {
  1525. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1526. {
  1527. IsGunCharging = TRUE;
  1528. }
  1529. }
  1530. for (int index = 0; index < CCS_QUANTITY; index++)
  1531. {
  1532. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1533. {
  1534. IsGunCharging = TRUE;
  1535. }
  1536. }
  1537. for (int index = 0; index < GB_QUANTITY; index++)
  1538. {
  1539. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1540. {
  1541. IsGunCharging = TRUE;
  1542. }
  1543. }
  1544. }
  1545. else
  1546. {
  1547. for (int index = 0; index < AC_QUANTITY; index++)
  1548. {
  1549. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1550. {
  1551. IsGunCharging = TRUE;
  1552. }
  1553. }
  1554. }
  1555. if(IsGunCharging == TRUE)
  1556. {
  1557. server_sign = TRUE;
  1558. return result;
  1559. }
  1560. // Fill BootNotification fields
  1561. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1562. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1563. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1564. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1565. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1566. ShmOCPP16Data->ChargeBoxId
  1567. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1568. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1569. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1570. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1571. ,ShmOCPP16Data->BootNotification.CpIccid
  1572. ,ShmOCPP16Data->BootNotification.CpImsi
  1573. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1574. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1575. random_uuid(guid);
  1576. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1577. LWS_Send(message);
  1578. sprintf(tempdata, "BootNotification,0");
  1579. 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*/)
  1580. {
  1581. result = PASS;
  1582. }
  1583. memset(queuedata, 0, sizeof(queuedata));
  1584. strcpy(queuedata,message);
  1585. HeartBeatCount = 0;
  1586. //#ifdef SystemLogMessage
  1587. //DEBUG_INFO(">>>>>BootNotification request\n");
  1588. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1589. //#endif
  1590. return result;
  1591. }
  1592. int sendDataTransferRequest(int gun_index)
  1593. {
  1594. mtrace();
  1595. char message[1000]={0};
  1596. char guid[37]={0};
  1597. char tempdata[65]={0};
  1598. int result = FAIL;
  1599. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1600. random_uuid(guid);
  1601. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1602. MESSAGE_TYPE_CALL,
  1603. guid,
  1604. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1605. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1606. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1607. LWS_Send(message);
  1608. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1609. 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*/)
  1610. {
  1611. result = PASS;
  1612. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1613. }
  1614. //#ifdef SystemLogMessage
  1615. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1616. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1617. //#endif
  1618. return result;
  1619. }
  1620. int sendDiagnosticsStatusNotificationRequest(char *status)
  1621. {
  1622. mtrace();
  1623. int result = FAIL;
  1624. char message[110]={0};
  1625. char guid[37]={0};
  1626. char tempdata[65]={0};
  1627. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1628. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1629. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1630. random_uuid(guid);
  1631. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1632. LWS_Send(message);
  1633. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1634. if(hashmap_operation(0, guid, tempdata) == 1)
  1635. {
  1636. result = PASS;
  1637. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1638. }
  1639. //#ifdef SystemLogMessage
  1640. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1641. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1642. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1643. //#endif
  1644. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1645. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1646. //record status
  1647. if(strcmp(status,"Idle")==0)
  1648. {
  1649. DiagnosticsStatusNotificationStatus = 0;
  1650. }
  1651. else if(strcmp(status,"Uploaded")==0)
  1652. {
  1653. DiagnosticsStatusNotificationStatus = 1;
  1654. }
  1655. else if(strcmp(status,"UploadFailed")==0)
  1656. {
  1657. DiagnosticsStatusNotificationStatus = 2;
  1658. }
  1659. else if(strcmp(status,"Uploading")==0)
  1660. {
  1661. DiagnosticsStatusNotificationStatus = 3;
  1662. }
  1663. return result;
  1664. }
  1665. int sendFirmwareStatusNotificationRequest(char *status)
  1666. {
  1667. mtrace();
  1668. int result = FAIL;
  1669. char message[110]={0};
  1670. char guid[37]={0};
  1671. char tempdata[65]={0};
  1672. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1673. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1674. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1675. random_uuid(guid);
  1676. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1677. LWS_Send(message);
  1678. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1679. 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*/)
  1680. {
  1681. result = PASS;
  1682. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1683. }
  1684. //#ifdef SystemLogMessage
  1685. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1686. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1687. //#endif
  1688. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1689. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1690. //record status
  1691. if(strcmp(status,"Downloaded")==0)
  1692. {
  1693. FirmwareStatusNotificationStatus = 0;
  1694. }
  1695. else if(strcmp(status,"DownloadFailed")==0)
  1696. {
  1697. FirmwareStatusNotificationStatus = 1;
  1698. }
  1699. else if(strcmp(status,"Downloading")==0)
  1700. {
  1701. FirmwareStatusNotificationStatus = 2;
  1702. }
  1703. else if(strcmp(status,"Idle")==0)
  1704. {
  1705. FirmwareStatusNotificationStatus = 3;
  1706. }
  1707. else if(strcmp(status,"InstallationFailed")==0)
  1708. {
  1709. FirmwareStatusNotificationStatus = 4;
  1710. }
  1711. else if(strcmp(status,"Installing")==0)
  1712. {
  1713. FirmwareStatusNotificationStatus = 5;
  1714. }
  1715. else if(strcmp(status,"Installed")==0)
  1716. {
  1717. FirmwareStatusNotificationStatus = 6;
  1718. }
  1719. return result;
  1720. }
  1721. int sendHeartbeatRequest(int gun_index)
  1722. {
  1723. mtrace();
  1724. int result = FAIL;
  1725. char message[80]={0};
  1726. char guid[37]={0};
  1727. char tempdata[65]={0};
  1728. random_uuid(guid);
  1729. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1730. , MESSAGE_TYPE_CALL
  1731. , guid );
  1732. LWS_Send(message);
  1733. sprintf(tempdata, "Heartbeat,%d", 0);
  1734. 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*/)
  1735. {
  1736. result = PASS;
  1737. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1738. }
  1739. return result;
  1740. }
  1741. int sendStartTransactionRequest(int gun_index)
  1742. {
  1743. mtrace();
  1744. int result = FAIL;
  1745. char message[250]={0};
  1746. char guid[37]={0};
  1747. struct timeval tmnow;
  1748. struct tm *tm;
  1749. char buf[28];//, usec_buf[6];
  1750. char tempdata[65]={0};
  1751. DEBUG_INFO("sendStartTransactionRequest...");
  1752. gettimeofday(&tmnow, NULL);
  1753. time_t t;
  1754. t = time(NULL);
  1755. /*UTC time and date*/
  1756. tm = gmtime(&t);
  1757. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1758. #if 0 // remove temporally
  1759. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1760. strcat(buf,".");
  1761. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1762. strcat(buf,usec_buf);
  1763. #endif
  1764. //printf("Start Charging Time :%s",buf);
  1765. // set value
  1766. //if(ShmOCPP16Data->OcppConnStatus == 1 )
  1767. //{
  1768. //memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1769. //}
  1770. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1771. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1772. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1773. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1774. {
  1775. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1776. {
  1777. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1778. {
  1779. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1780. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1781. }
  1782. }
  1783. for (int index = 0; index < CCS_QUANTITY; index++)
  1784. {
  1785. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1786. {
  1787. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1788. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1789. }
  1790. }
  1791. for (int index = 0; index < GB_QUANTITY; index++)
  1792. {
  1793. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1794. {
  1795. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1796. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1797. }
  1798. }
  1799. }
  1800. else
  1801. {
  1802. for (int index = 0; index < AC_QUANTITY; index++)
  1803. {
  1804. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1805. {
  1806. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1807. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1808. }
  1809. }
  1810. }//END OF ELSE
  1811. random_uuid(guid);
  1812. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1813. , MESSAGE_TYPE_CALL
  1814. , guid
  1815. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1816. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1817. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1818. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1819. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1820. LWS_Send(message);
  1821. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1822. 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*/)
  1823. {
  1824. result = PASS;
  1825. }
  1826. strcpy(queuedata, message);
  1827. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1828. //#ifdef SystemLogMessage
  1829. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1830. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1831. //#endif
  1832. return result;
  1833. }
  1834. int sendStatusNotificationRequest(int gun_index)
  1835. {
  1836. mtrace();
  1837. int result = FAIL;
  1838. char message[600]={0};
  1839. char guid[37];
  1840. int currentStatus = 0;
  1841. struct timeval tmnow;
  1842. struct tm *tm;
  1843. char buf[28];//, usec_buf[6];
  1844. char tempdata[65]={0};
  1845. gettimeofday(&tmnow, NULL);
  1846. time_t t;
  1847. t = time(NULL);
  1848. /*UTC time and date*/
  1849. tm = gmtime(&t);
  1850. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1851. #if 0 // remove temporally
  1852. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1853. strcat(buf,".");
  1854. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1855. strcat(buf,usec_buf);
  1856. #endif
  1857. printf("%s",buf);
  1858. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1859. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1860. // it's option
  1861. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1862. /*
  1863. enum _SYSTEM_STATUS
  1864. {
  1865. S_BOOTING = 0,
  1866. S_IDLE, = 1
  1867. S_AUTHORIZING, =2
  1868. S_REASSIGN_CHECK, =3
  1869. S_REASSIGN, =4
  1870. S_PRECHARGE, =5
  1871. S_PREPARING_FOR_EV, =6
  1872. S_PREPARING_FOR_EVSE, =7
  1873. S_CHARGING, =8
  1874. S_TERMINATING, =9
  1875. S_COMPLETE, =10
  1876. S_ALARM, =11
  1877. S_FAULT =12
  1878. }
  1879. */
  1880. //check Transaction active
  1881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1882. {
  1883. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1884. {
  1885. //printf("gun_index=%d\n",gun_index);
  1886. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1887. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1888. {
  1889. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1890. currentStatus = 0; //OCPP Status
  1891. }
  1892. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1893. {
  1894. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1895. currentStatus = 1; //OCPP Status
  1896. }
  1897. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1898. {
  1899. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1900. currentStatus = 2; //OCPP Status
  1901. }
  1902. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1903. {
  1904. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1905. currentStatus = 5; //OCPP Status
  1906. }
  1907. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1908. {
  1909. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1910. currentStatus = 4; //OCPP Status
  1911. }
  1912. 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) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE) )) //S_TERMINATING ---> Unavailable
  1913. {
  1914. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1915. currentStatus = 7; //OCPP Status: Unavailable
  1916. }
  1917. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1918. {
  1919. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1920. currentStatus = 8; //OCPP Status: Faulted
  1921. }
  1922. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1923. {
  1924. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1925. currentStatus = 6; //OCPP Status: Reserved
  1926. }
  1927. }//end of for CHAdeMO_QUANTITY
  1928. for (int index = 0; index < CCS_QUANTITY; index++)
  1929. {
  1930. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1931. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1932. {
  1933. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1934. currentStatus = 0; //OCPP Status
  1935. }
  1936. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1937. {
  1938. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1939. currentStatus = 1; //OCPP Status
  1940. }
  1941. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1942. {
  1943. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1944. currentStatus = 2; //OCPP Status
  1945. }
  1946. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1947. {
  1948. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1949. currentStatus = 5; //OCPP Status
  1950. }
  1951. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1952. {
  1953. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1954. currentStatus = 4; //OCPP Status
  1955. }
  1956. 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) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE) )) //S_TERMINATING ---> Unavailable
  1957. {
  1958. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1959. currentStatus = 7; //OCPP Status
  1960. }
  1961. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1962. {
  1963. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1964. currentStatus = 8; //OCPP Status
  1965. }
  1966. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1967. {
  1968. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1969. currentStatus = 6; //OCPP Status
  1970. }
  1971. }
  1972. for (int index = 0; index < GB_QUANTITY; index++)
  1973. {
  1974. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1975. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1976. {
  1977. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1978. currentStatus = 0; //OCPP Status
  1979. }
  1980. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1981. {
  1982. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1983. currentStatus = 1; //OCPP Status
  1984. }
  1985. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1986. {
  1987. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1988. currentStatus = 2; //OCPP Status
  1989. }
  1990. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1991. {
  1992. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1993. currentStatus = 5; //OCPP Status
  1994. }
  1995. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1996. {
  1997. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1998. currentStatus = 4; //OCPP Status
  1999. }
  2000. 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) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE))) //S_TERMINATING ---> Unavailable
  2001. {
  2002. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2003. currentStatus = 7; //OCPP Status: Unavailable
  2004. }
  2005. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2006. {
  2007. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2008. currentStatus = 8; //OCPP Status: Faulted
  2009. }
  2010. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2011. {
  2012. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2013. currentStatus = 6; //OCPP Status: Faulted
  2014. }
  2015. }
  2016. }
  2017. else
  2018. {
  2019. for (int index = 0; index < AC_QUANTITY; index++)
  2020. {
  2021. //printf("gun_index=%d\n",gun_index);
  2022. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2023. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2024. {
  2025. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2026. currentStatus = 0; //OCPP Status
  2027. }
  2028. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2029. {
  2030. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2031. currentStatus = 1; //OCPP Status
  2032. }
  2033. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2034. {
  2035. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2036. currentStatus = 2; //OCPP Status
  2037. }
  2038. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2039. {
  2040. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2041. currentStatus = 5; //OCPP Status
  2042. }
  2043. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2044. {
  2045. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2046. currentStatus = 4; //OCPP Status
  2047. }
  2048. 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) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE) )) //S_TERMINATING ---> Unavailable
  2049. {
  2050. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2051. currentStatus = 7; //OCPP Status: Unavailable
  2052. }
  2053. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2054. {
  2055. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2056. currentStatus = 8; //OCPP Status: Faulted
  2057. }
  2058. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2059. {
  2060. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2061. currentStatus = 6; //OCPP Status: Reserved
  2062. }
  2063. }//end of for AC_QUANTITY
  2064. }//END OF ELSE
  2065. //it's option
  2066. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2067. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2068. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2069. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2070. random_uuid(guid);
  2071. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2072. , MESSAGE_TYPE_CALL
  2073. , guid
  2074. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2075. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2076. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2077. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2078. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2079. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2080. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2081. LWS_Send(message);
  2082. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2083. 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*/)
  2084. {
  2085. //DEBUG_ERROR("statusNotification mapitem pass");
  2086. result = PASS;
  2087. }
  2088. //#ifdef SystemLogMessage
  2089. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2090. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2091. //#endif
  2092. return result;
  2093. }
  2094. int sendStopTransactionRequest(int gun_index)
  2095. {
  2096. mtrace();
  2097. int result = FAIL;
  2098. //char message[1500]={0};
  2099. char guid[37]={0};
  2100. char tempdata[65]={0};
  2101. //int idx_sample=0;
  2102. DEBUG_ERROR("sendStopTransactionRequest \n");
  2103. memset(queuedata, 0, sizeof(queuedata));
  2104. //ENERGY_ACTIVE_IMPORT_REGISTER
  2105. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2106. {
  2107. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2108. {
  2109. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2110. {
  2111. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2112. //Check Status
  2113. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2114. {
  2115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2116. }
  2117. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2118. }
  2119. }// END OF CHAdeMO_QUANTITY
  2120. for (int index = 0; index < CCS_QUANTITY; index++)
  2121. {
  2122. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2123. {
  2124. //for test
  2125. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2126. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2127. //Check Status
  2128. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2129. {
  2130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2131. }
  2132. else
  2133. {
  2134. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2135. }
  2136. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2137. }
  2138. }// END OF CCS_QUANTITY
  2139. for (int index = 0; index < GB_QUANTITY; index++)
  2140. {
  2141. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2142. {
  2143. // for test
  2144. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2145. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2146. //Check Status
  2147. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2148. {
  2149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2150. }
  2151. else
  2152. {
  2153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2154. }
  2155. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2156. }
  2157. }// END OF GB_QUANTITY
  2158. }
  2159. else
  2160. {
  2161. for (int index = 0; index < AC_QUANTITY; index++)
  2162. {
  2163. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2164. {
  2165. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2166. //Check Status
  2167. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2168. {
  2169. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2170. }
  2171. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2172. }
  2173. }// END OF AC_QUANTITY
  2174. }//END OF ELSE
  2175. //Stop Transaction Time
  2176. struct timeval tmnow;
  2177. struct tm *tm;
  2178. char buf[28];//, usec_buf[6];
  2179. gettimeofday(&tmnow, NULL);
  2180. time_t t;
  2181. t = time(NULL);
  2182. /*UTC time and date*/
  2183. tm = gmtime(&t);
  2184. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2185. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2187. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2188. random_uuid(guid);
  2189. /***********************************transactionData******************************************************/
  2190. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2191. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2192. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2193. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2194. //=================================
  2195. // Transaction_Begin
  2196. //=================================
  2197. // Energy.Active.Export.Interval
  2198. //idx_sample=0;
  2199. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Export_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2204. {
  2205. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2206. }
  2207. else
  2208. {
  2209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2210. }
  2211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2213. //=================================
  2214. // Transaction_End
  2215. //=================================
  2216. //Current.Export
  2217. //idx_sample=1;
  2218. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2219. {
  2220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2221. {
  2222. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2223. {
  2224. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2225. }
  2226. }
  2227. for (int index = 0; index < CCS_QUANTITY; index++)
  2228. {
  2229. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2230. {
  2231. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2232. }
  2233. }
  2234. for (int index = 0; index < GB_QUANTITY; index++)
  2235. {
  2236. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2237. {
  2238. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2239. }
  2240. }
  2241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2242. }
  2243. else
  2244. {
  2245. for (int index = 0; index < AC_QUANTITY; index++)
  2246. {
  2247. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2248. {
  2249. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2250. }
  2251. }
  2252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2253. }// END FOR AC ELSE
  2254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2255. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2257. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2260. //Energy.Active.Export.Interval
  2261. //idx_sample=2;
  2262. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2263. {
  2264. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2265. {
  2266. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2267. {
  2268. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2269. }
  2270. }
  2271. for (int index = 0; index < CCS_QUANTITY; index++)
  2272. {
  2273. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2274. {
  2275. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2276. }
  2277. }
  2278. for (int index = 0; index < GB_QUANTITY; index++)
  2279. {
  2280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2281. {
  2282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2283. }
  2284. }
  2285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2286. }
  2287. else
  2288. {
  2289. for (int index = 0; index < AC_QUANTITY; index++)
  2290. {
  2291. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2292. {
  2293. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2294. }
  2295. }
  2296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2297. }// END FOR AC ELSE
  2298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2299. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2300. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2301. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2304. //Power.Active.Export
  2305. //idx_sample=3;
  2306. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2307. {
  2308. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2309. {
  2310. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2311. {
  2312. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2313. }
  2314. }
  2315. for (int index = 0; index < CCS_QUANTITY; index++)
  2316. {
  2317. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2318. {
  2319. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2320. }
  2321. }
  2322. for (int index = 0; index < GB_QUANTITY; index++)
  2323. {
  2324. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2325. {
  2326. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2327. }
  2328. }
  2329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2330. }
  2331. else
  2332. {
  2333. for (int index = 0; index < AC_QUANTITY; index++)
  2334. {
  2335. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2336. {
  2337. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2338. }
  2339. }
  2340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2341. }// END FOR AC ELSE
  2342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2344. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2345. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2348. //Voltage
  2349. //idx_sample=4;
  2350. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2351. {
  2352. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2353. {
  2354. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2355. {
  2356. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2357. }
  2358. }
  2359. for (int index = 0; index < CCS_QUANTITY; index++)
  2360. {
  2361. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2362. {
  2363. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2364. }
  2365. }
  2366. for (int index = 0; index < GB_QUANTITY; index++)
  2367. {
  2368. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2369. {
  2370. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2371. }
  2372. }
  2373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2374. }
  2375. else
  2376. {
  2377. for (int index = 0; index < AC_QUANTITY; index++)
  2378. {
  2379. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2380. {
  2381. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2382. }
  2383. }
  2384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2385. }// END FOR AC ELSE
  2386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2389. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2392. //SoC
  2393. //idx_sample=5;
  2394. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2395. {
  2396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2397. {
  2398. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2399. {
  2400. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2401. }
  2402. }
  2403. for (int index = 0; index < CCS_QUANTITY; index++)
  2404. {
  2405. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2406. {
  2407. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2408. }
  2409. }
  2410. for (int index = 0; index < GB_QUANTITY; index++)
  2411. {
  2412. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2413. {
  2414. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2415. }
  2416. }
  2417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2423. } // END FOR DC CASE
  2424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2425. {
  2426. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" } ] } ] } ]"
  2427. ,MESSAGE_TYPE_CALL
  2428. ,guid
  2429. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2430. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2431. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2432. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2433. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2434. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2435. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2436. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2437. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2438. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2439. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2440. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2441. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2442. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2443. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2444. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2445. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2446. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2447. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2448. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2449. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2450. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2451. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2452. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2453. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2454. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2455. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2456. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2457. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2458. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2459. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2460. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2461. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2462. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2463. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2464. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2465. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2466. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2467. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2468. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2469. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2470. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2471. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2472. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2473. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2474. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2475. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2476. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2477. );
  2478. }
  2479. else
  2480. {
  2481. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" },{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" } ] } ] } ]"
  2482. ,MESSAGE_TYPE_CALL
  2483. ,guid
  2484. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2485. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2486. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2487. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2488. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2489. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2490. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2491. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2492. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2493. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2494. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2495. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2496. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2497. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2498. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2499. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2500. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2501. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2502. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2503. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2504. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2505. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2506. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2507. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2508. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2509. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2510. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2511. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2512. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2513. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2514. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2515. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2516. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2517. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2518. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2519. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2520. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2521. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2522. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2523. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2524. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2525. );
  2526. }
  2527. LWS_Send(queuedata);
  2528. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2529. if(hashmap_operation(0, guid, tempdata) == 1)
  2530. {
  2531. result = PASS;
  2532. DEBUG_INFO("StopTransaction mapitem pass\n");
  2533. }
  2534. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2535. //for test
  2536. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2537. return result;
  2538. }
  2539. int sendMeterValuesRequest(int gun_index)
  2540. {
  2541. mtrace();
  2542. int result = FAIL;
  2543. // char message[1500]={0};
  2544. char guid[37]={0};
  2545. //int idx_sample=0;
  2546. //int length = 0;
  2547. char tempdata[65]={0};
  2548. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2549. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2550. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2551. {
  2552. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2553. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2554. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2555. return result;
  2556. }
  2557. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2558. {
  2559. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2560. }
  2561. memset(queuedata, 0, sizeof(queuedata));
  2562. //set value
  2563. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2564. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2565. random_uuid(guid);
  2566. //UTC Date time
  2567. struct timeval tmnow;
  2568. struct tm *tm;
  2569. char buf[28];//, usec_buf[6];
  2570. gettimeofday(&tmnow, NULL);
  2571. time_t t;
  2572. t = time(NULL);
  2573. /*UTC time and date*/
  2574. tm = gmtime(&t);
  2575. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2576. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2577. //idx_sample=0;
  2578. //********************************(1)Current.Export************************************************/
  2579. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2580. {
  2581. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2582. {
  2583. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2584. {
  2585. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2586. }
  2587. }
  2588. for (int index = 0; index < CCS_QUANTITY; index++)
  2589. {
  2590. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2591. {
  2592. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2593. }
  2594. }
  2595. for (int index = 0; index < GB_QUANTITY; index++)
  2596. {
  2597. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2598. {
  2599. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2600. }
  2601. }
  2602. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2603. }
  2604. else
  2605. {
  2606. for (int index = 0; index < AC_QUANTITY; index++)
  2607. {
  2608. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2609. {
  2610. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2611. }
  2612. }
  2613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2614. }// END FOR AC ELSE
  2615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2618. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2619. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2620. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2621. //idx_sample=1;
  2622. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2623. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2624. {
  2625. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2626. {
  2627. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2628. {
  2629. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2630. }
  2631. }
  2632. for (int index = 0; index < CCS_QUANTITY; index++)
  2633. {
  2634. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2635. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2636. {
  2637. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2638. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2639. }
  2640. }
  2641. for (int index = 0; index < GB_QUANTITY; index++)
  2642. {
  2643. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2644. {
  2645. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2646. }
  2647. }
  2648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2649. }
  2650. else
  2651. {
  2652. for (int index = 0; index < AC_QUANTITY; index++)
  2653. {
  2654. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2655. {
  2656. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2657. }
  2658. }
  2659. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2660. }//END FOR AC ELSE
  2661. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2662. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2664. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2666. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2667. //idx_sample=2;
  2668. //********************************(4)Power.Active.Export************************************************/
  2669. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2670. {
  2671. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2672. {
  2673. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2674. {
  2675. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2676. }
  2677. }
  2678. for (int index = 0; index < CCS_QUANTITY; index++)
  2679. {
  2680. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2681. {
  2682. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2683. }
  2684. }
  2685. for (int index = 0; index < GB_QUANTITY; index++)
  2686. {
  2687. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2688. {
  2689. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2690. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2691. }
  2692. }
  2693. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2694. }
  2695. else
  2696. {
  2697. for (int index = 0; index < AC_QUANTITY; index++)
  2698. {
  2699. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2700. {
  2701. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2702. }
  2703. }
  2704. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2705. }// END FOR AC ELSE
  2706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2709. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2711. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2712. //idx_sample=3;
  2713. //***********************************************(5)VOLTAGE******************************************************/
  2714. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2715. {
  2716. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2717. {
  2718. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2719. {
  2720. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2721. }
  2722. }
  2723. for (int index = 0; index < CCS_QUANTITY; index++)
  2724. {
  2725. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2726. {
  2727. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2728. }
  2729. }
  2730. for (int index = 0; index < GB_QUANTITY; index++)
  2731. {
  2732. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2733. {
  2734. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2735. }
  2736. }
  2737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2738. }
  2739. else
  2740. {
  2741. for (int index = 0; index < AC_QUANTITY; index++)
  2742. {
  2743. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2744. {
  2745. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2746. }
  2747. }
  2748. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2749. }//END FOR AC ELSE
  2750. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2751. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2752. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2753. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2754. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2755. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2757. {
  2758. //idx_sample=4;
  2759. //sampledValue = NULL;
  2760. //***********************************************(6)SOC******************************************************/
  2761. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2762. {
  2763. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2764. {
  2765. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2766. }
  2767. }
  2768. for (int index = 0; index < CCS_QUANTITY; index++)
  2769. {
  2770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2771. {
  2772. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2773. }
  2774. }
  2775. for (int index = 0; index < GB_QUANTITY; index++)
  2776. {
  2777. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2778. {
  2779. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2780. }
  2781. }
  2782. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2783. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2784. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2785. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2786. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2787. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2788. }
  2789. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2790. {
  2791. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2792. ,MESSAGE_TYPE_CALL
  2793. ,guid
  2794. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2795. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2796. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2832. );
  2833. }
  2834. else
  2835. {
  2836. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  2837. ,MESSAGE_TYPE_CALL
  2838. ,guid
  2839. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2840. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2841. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2842. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2843. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2844. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2845. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2846. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2847. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2848. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2849. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2850. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2851. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2852. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2853. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2854. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2855. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2856. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2857. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2858. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2859. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2860. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2861. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2862. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2863. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2864. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2865. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2866. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2867. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2868. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2869. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2870. );
  2871. }
  2872. LWS_Send(queuedata);
  2873. // Put request guid to hash map
  2874. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2875. 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*/)
  2876. {
  2877. result = PASS;
  2878. DEBUG_INFO("MeterValues mapitem pass\n");
  2879. }
  2880. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2881. return result;
  2882. }
  2883. //==========================================
  2884. // send confirm routine
  2885. //==========================================
  2886. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2887. {
  2888. mtrace();
  2889. int result = FAIL;
  2890. char message[100]={0};
  2891. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2892. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2893. LWS_Send(message);
  2894. result = TRUE;
  2895. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2896. return result;
  2897. }
  2898. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2899. {
  2900. mtrace();
  2901. int result = FAIL;
  2902. char message[100]={0};
  2903. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2904. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2905. LWS_Send(message);
  2906. result = TRUE;
  2907. return result;
  2908. }
  2909. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2910. {
  2911. mtrace();
  2912. int result = FAIL;
  2913. char message[100]={0};
  2914. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2915. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2916. LWS_Send(message);
  2917. result = TRUE;
  2918. return result;
  2919. }
  2920. int sendClearCacheConfirmation(char *uuid,char *payload)
  2921. {
  2922. mtrace();
  2923. int result = FAIL;
  2924. char message[500]={0};
  2925. // int count = 0;
  2926. // int gun_index = 0;
  2927. // char guid[37];
  2928. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2929. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2930. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2931. LWS_Send(message);
  2932. return result;
  2933. }
  2934. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2935. {
  2936. mtrace();
  2937. int result = FAIL;
  2938. char message[500]={0};
  2939. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2940. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2941. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2942. LWS_Send(message);
  2943. return result;
  2944. }
  2945. int sendDataTransferConfirmation(char *uuid,char *payload)
  2946. {
  2947. mtrace();
  2948. char statusStr[20]={0};
  2949. char dataStr[10]={0};
  2950. char sstr[20]={0};
  2951. int c = 0;
  2952. char *loc;
  2953. int result = FAIL;
  2954. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2955. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2956. /**********************status**************************/
  2957. loc = strstr(payload, "status");
  2958. memset(sstr ,0, sizeof(sstr) );
  2959. c = 0;
  2960. while (loc[3+strlen("status")+c] != '\"')
  2961. {
  2962. sstr[c] = loc[3+strlen("status")+c];
  2963. c++;
  2964. }
  2965. sstr[c] = '\0';
  2966. strcpy(statusStr, sstr);
  2967. /**********************data**************************/
  2968. loc = strstr(payload, "data");
  2969. memset(sstr ,0, sizeof(sstr) );
  2970. c = 0;
  2971. while (loc[3+strlen("data")+c] != '\"')
  2972. {
  2973. sstr[c] = loc[3+strlen("data")+c];
  2974. c++;
  2975. }
  2976. sstr[c] = '\0';
  2977. strcpy(dataStr, sstr);
  2978. return result;
  2979. }
  2980. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2981. {
  2982. mtrace();
  2983. int result = FAIL;
  2984. char message[1000]={0};
  2985. double diff_f = 0.0;
  2986. int diff_i = 0;
  2987. int diffSeconds = 0;
  2988. struct tm tp;
  2989. int TimeZero = FALSE;
  2990. int CompositeScheduleIndex = 0;
  2991. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2992. #if 0
  2993. if(connectorIdInt > 0)
  2994. {
  2995. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2996. {
  2997. TimeZero = TRUE;
  2998. }
  2999. else
  3000. {
  3001. strptime((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  3002. }
  3003. }
  3004. else
  3005. {
  3006. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  3007. {
  3008. TimeZero = TRUE;
  3009. }
  3010. else
  3011. {
  3012. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  3013. }
  3014. }
  3015. DEBUG_INFO("ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule=%s\n",ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule);
  3016. #endif
  3017. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  3018. {
  3019. TimeZero = TRUE;
  3020. }
  3021. else
  3022. {
  3023. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3024. }
  3025. if(TimeZero == FALSE)
  3026. {
  3027. tp.tm_isdst = -1;
  3028. time_t utc = mktime(&tp);
  3029. time_t t = time(NULL);
  3030. diff_f = difftime(t, utc);
  3031. diff_i = (int)diff_f;
  3032. diffSeconds = diff_i % 86400;//86400 seconds/day
  3033. }
  3034. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3035. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3036. #if 0 //remove temporally
  3037. 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}"
  3038. ,MESSAGE_TYPE_CALLRESULT
  3039. ,uuid
  3040. ,payload
  3041. ,connectorIdInt
  3042. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3043. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3044. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3045. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3046. #endif
  3047. if(nPeriod == 0)
  3048. {
  3049. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3050. ,MESSAGE_TYPE_CALLRESULT
  3051. ,uuid
  3052. ,payload
  3053. ,connectorIdInt
  3054. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3055. }
  3056. else
  3057. {
  3058. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3059. ,MESSAGE_TYPE_CALLRESULT
  3060. ,uuid
  3061. ,payload
  3062. ,connectorIdInt
  3063. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3064. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3065. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3066. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3067. int len = nPeriod;
  3068. //Last Period StartPriod is less than diffSeconds
  3069. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  3070. {
  3071. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3072. , 0
  3073. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3074. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3075. }
  3076. else
  3077. {
  3078. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3079. {
  3080. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  3081. {
  3082. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3083. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3084. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3085. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3086. }
  3087. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  3088. {
  3089. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3090. , (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)) //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
  3091. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3092. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3093. }
  3094. }
  3095. }
  3096. sprintf(message + strlen(message), "]}}]");
  3097. }
  3098. LWS_Send(message);
  3099. result = TRUE;
  3100. return result;
  3101. }
  3102. int sendGetConfigurationConfirmation(char *uuid)
  3103. {
  3104. mtrace();
  3105. int result = FAIL;
  3106. int MaxKeySupported = 0;
  3107. int sentConfigurationNumber= 0;
  3108. int sentunConfigurationNumber= 0;
  3109. char message[4000]={0};
  3110. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3111. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3112. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3113. ,MESSAGE_TYPE_CALLRESULT
  3114. ,uuid );
  3115. //configuration key
  3116. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3117. {
  3118. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3119. {
  3120. if (sentConfigurationNumber == 0)
  3121. {
  3122. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3123. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3124. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3125. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3126. }
  3127. else
  3128. {
  3129. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3130. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3131. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3132. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3133. }
  3134. sentConfigurationNumber = sentConfigurationNumber + 1;
  3135. }
  3136. }
  3137. sprintf(message + strlen(message), "]");
  3138. if(UnknownKeynum != 0)
  3139. {
  3140. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3141. //unkown key
  3142. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3143. {
  3144. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3145. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3146. if(sentunConfigurationNumber == 0)
  3147. {
  3148. sprintf(message + strlen(message), "\"%s\""
  3149. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3150. }
  3151. else
  3152. {
  3153. sprintf(message + strlen(message), ",\"%s\""
  3154. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3155. }
  3156. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3157. }
  3158. sprintf(message + strlen(message), "]");
  3159. }
  3160. sprintf(message + strlen(message), "} ]");
  3161. LWS_Send(message);
  3162. #if 0
  3163. printf("error 1-0\n");
  3164. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3165. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3166. #endif
  3167. return result;
  3168. }
  3169. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3170. {
  3171. mtrace();
  3172. int result = FAIL;
  3173. char message[400]={0};
  3174. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3175. if(strcmp(payload,"")==0)
  3176. {
  3177. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3178. }
  3179. else
  3180. {
  3181. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3182. }
  3183. LWS_Send(message);
  3184. result = TRUE;
  3185. return result;
  3186. }
  3187. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3188. {
  3189. mtrace();
  3190. int result = FAIL;
  3191. char message[80]={0};
  3192. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3193. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3194. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3195. LWS_Send(message);
  3196. result = TRUE;
  3197. return result;
  3198. }
  3199. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3200. {
  3201. mtrace();
  3202. int result = FAIL;
  3203. char message[80]={0};
  3204. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3205. DEBUG_ERROR("handleRemoteStartRequest ...\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 sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3212. {
  3213. mtrace();
  3214. int result = FAIL;
  3215. char message[80]={0};
  3216. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3217. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  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 sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3224. {
  3225. mtrace();
  3226. int result = FAIL;
  3227. char message[80]={0};
  3228. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3229. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3230. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3231. LWS_Send(message);
  3232. result = TRUE;
  3233. return result;
  3234. }
  3235. int sendResetConfirmation(char *uuid,char *payload)
  3236. {
  3237. mtrace();
  3238. int result = FAIL;
  3239. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3240. char message[80]={0};
  3241. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3242. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3243. LWS_Send(message);
  3244. result = TRUE;
  3245. return result;
  3246. }
  3247. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3248. {
  3249. mtrace();
  3250. int result = FAIL;
  3251. char message[500]={0};
  3252. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3253. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3254. LWS_Send(message);
  3255. result = TRUE;
  3256. return result;
  3257. }
  3258. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3259. {
  3260. mtrace();
  3261. int result = FAIL;
  3262. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3263. char message[80]={0};
  3264. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3265. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3266. LWS_Send(message);
  3267. result = TRUE;
  3268. return result;
  3269. }
  3270. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3271. {
  3272. mtrace();
  3273. int result = FAIL;
  3274. char message[80]={0};
  3275. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3276. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3277. LWS_Send(message);
  3278. result = TRUE;
  3279. return result;
  3280. }
  3281. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3282. {
  3283. mtrace();
  3284. int result = FAIL;
  3285. char message[80]={0};
  3286. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3287. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3288. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3289. LWS_Send(message);
  3290. result = TRUE;
  3291. return result;
  3292. }
  3293. int sendUpdateFirmwareConfirmation(char *uuid)
  3294. {
  3295. mtrace();
  3296. int result = FAIL;
  3297. char message[60]={0};
  3298. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3299. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3300. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3301. LWS_Send(message);
  3302. result = TRUE;
  3303. return result;
  3304. }
  3305. //==========================================
  3306. // send CallError routine
  3307. //==========================================
  3308. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3309. {
  3310. mtrace();
  3311. //int result = FAIL;
  3312. char message[220]={0};
  3313. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3314. #ifdef SystemLogMessage
  3315. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3316. uniqueId, action, errorCode, errorDescription);
  3317. #endif
  3318. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3319. LWS_Send(message);
  3320. //result = TRUE;
  3321. }
  3322. //==========================================
  3323. // Handle server request routine Start
  3324. //==========================================
  3325. #define GUN_NUM 1
  3326. int handleCancelReservationRequest(char *uuid, char *payload)
  3327. {
  3328. mtrace();
  3329. int result = FAIL;
  3330. int gunNO = 0;
  3331. int reservationIdInt =0;
  3332. char comfirmstr[20];
  3333. int c = 0;
  3334. char *loc;
  3335. char sstr[100]={0};
  3336. DEBUG_INFO("handle CancelReservationRequest\n");
  3337. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3338. c = 0;
  3339. loc = strstr(payload, "reservationId");
  3340. memset(sstr ,0, sizeof(sstr) );
  3341. while (loc[strlen("reservationId")+2+c] != '}')
  3342. {
  3343. sstr[c] = loc[strlen("reservationId")+2+c];
  3344. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3345. c++;
  3346. }
  3347. sstr[c] = '\0';
  3348. reservationIdInt = atoi(sstr);
  3349. memset(comfirmstr, 0, sizeof comfirmstr);
  3350. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3351. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3352. //check Transaction active
  3353. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3354. {
  3355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3356. {
  3357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3358. {
  3359. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3360. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3361. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3362. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3363. goto end;
  3364. }
  3365. }
  3366. for (int index = 0; index < CCS_QUANTITY; index++)
  3367. {
  3368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3369. {
  3370. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3371. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3372. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3373. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3374. goto end;
  3375. }
  3376. }
  3377. for (int index = 0; index < GB_QUANTITY; index++)
  3378. {
  3379. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3380. {
  3381. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3382. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3383. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3384. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3385. goto end;
  3386. }
  3387. }
  3388. }
  3389. else
  3390. {
  3391. for (int index = 0; index < AC_QUANTITY; index++)
  3392. {
  3393. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3394. {
  3395. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3396. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3397. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3398. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3399. goto end;
  3400. }
  3401. }
  3402. }// END FOR AC ELSE
  3403. //The reservationId does NOT match the reservationId
  3404. sendCancelReservationConfirmation(uuid, comfirmstr);
  3405. end:
  3406. // Fill in ocpp packet uuid
  3407. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3408. return result;
  3409. }
  3410. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3411. {
  3412. mtrace();
  3413. int result = FAIL;
  3414. int gunIndex = 0;
  3415. char sstr[90]={0};
  3416. char typeStr[16]={0};
  3417. char comfirmstr[20];
  3418. int specificId = FALSE;
  3419. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3420. char *loc;
  3421. //int intervalInt = 0;
  3422. int c = 0;
  3423. /*** connectorId ****/
  3424. c = 0;
  3425. loc = strstr(payload, "connectorId");
  3426. memset(sstr ,0, sizeof(sstr) );
  3427. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3428. {
  3429. sstr[c] = loc[strlen("connectorId")+2+c];
  3430. c++;
  3431. }
  3432. sstr[c] = '\0';
  3433. gunIndex = atoi(sstr);
  3434. /***type ****/
  3435. loc = strstr(payload, "type");
  3436. memset(sstr ,0, sizeof(sstr) );
  3437. c = 0;
  3438. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3439. {
  3440. sstr[c] = loc[3+strlen("type")+c];
  3441. c++;
  3442. }
  3443. sstr[c] = '\0';
  3444. strcpy(typeStr, sstr);
  3445. if(gunIndex != 0)
  3446. {
  3447. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3448. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3449. }
  3450. else
  3451. {
  3452. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3453. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3454. }
  3455. memset(comfirmstr, 0, sizeof comfirmstr);
  3456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3457. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3458. {
  3459. specificId = TRUE;
  3460. }
  3461. if(specificId == FALSE)
  3462. goto end;
  3463. if(gunIndex != 0)
  3464. {
  3465. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3466. }
  3467. else
  3468. {
  3469. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3470. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3471. }
  3472. /*
  3473. enum _SYSTEM_STATUS
  3474. {
  3475. S_BOOTING = 0,
  3476. S_IDLE, = 1
  3477. S_AUTHORIZING, =2
  3478. S_REASSIGN_CHECK, =3
  3479. S_REASSIGN, =4
  3480. S_PRECHARGE, =5
  3481. S_PREPARING_FOR_EV, =6
  3482. S_PREPARING_FOR_EVSE, =7
  3483. S_CHARGING, =8
  3484. S_TERMINATING, =9
  3485. S_COMPLETE, =10
  3486. S_ALARM, =11
  3487. S_FAULT =12
  3488. }
  3489. */
  3490. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3491. {
  3492. //check Transaction active
  3493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3494. {
  3495. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3496. {
  3497. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3498. {
  3499. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3500. {
  3501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3502. }
  3503. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3504. {
  3505. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3506. }
  3507. else
  3508. {
  3509. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3510. }
  3511. goto end;
  3512. }
  3513. }//END FOR CHAdeMO_QUANTITY
  3514. for (int index = 0; index < CCS_QUANTITY; index++)
  3515. {
  3516. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3517. {
  3518. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3519. {
  3520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3521. }
  3522. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3523. {
  3524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3525. }
  3526. else
  3527. {
  3528. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3529. }
  3530. goto end;
  3531. }
  3532. }//END FOR CCS_QUANTITY
  3533. for (int index = 0; index < GB_QUANTITY; index++)
  3534. {
  3535. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3536. {
  3537. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3538. {
  3539. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3540. }
  3541. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3542. {
  3543. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3544. }
  3545. else
  3546. {
  3547. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3548. }
  3549. goto end;
  3550. }
  3551. }// END FOR GB_QUANTITY
  3552. }
  3553. else
  3554. {
  3555. for (int index = 0; index < AC_QUANTITY; index++)
  3556. {
  3557. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3558. {
  3559. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3560. {
  3561. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3562. }
  3563. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3564. {
  3565. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3566. }
  3567. else
  3568. {
  3569. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3570. }
  3571. goto end;
  3572. }
  3573. }//END FOR AC_QUANTITY
  3574. }// END FOR AC ELSE
  3575. }//END FOR AvailabilityTypeStr[Inoperative]
  3576. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3577. {
  3578. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3579. //check Transaction active
  3580. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3581. {
  3582. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3583. {
  3584. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3585. {
  3586. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3587. goto end;
  3588. }
  3589. }//END FOR CHAdeMO_QUANTITY
  3590. for (int index = 0; index < CCS_QUANTITY; index++)
  3591. {
  3592. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3593. {
  3594. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3595. goto end;
  3596. }
  3597. }//END FOR CCS_QUANTITY
  3598. for (int index = 0; index < GB_QUANTITY; index++)
  3599. {
  3600. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3601. {
  3602. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3603. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3604. goto end;
  3605. }
  3606. }// END FOR GB_QUANTITY
  3607. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3608. }
  3609. else
  3610. {
  3611. for (int index = 0; index < AC_QUANTITY; index++)
  3612. {
  3613. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3614. {
  3615. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3616. goto end;
  3617. }
  3618. }//END FOR CHAdeMO_QUANTITY
  3619. }//END FOR AC ELSE
  3620. }//END FOR AvailabilityTypeStr[Operative]
  3621. end:
  3622. if(gunIndex != 0)
  3623. {
  3624. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3625. }
  3626. else
  3627. {
  3628. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3629. }
  3630. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3631. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3632. return result;
  3633. }
  3634. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3635. {
  3636. mtrace();
  3637. int result = FAIL;
  3638. char sstr[100]={0};
  3639. char keystr[40]={0};
  3640. char valuestr[16]={0};
  3641. char *loc;
  3642. int c = 0;
  3643. char comfirmstr[20];
  3644. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3645. /***key ****/
  3646. loc = strstr(payload, "key");
  3647. memset(sstr ,0, sizeof(sstr) );
  3648. c = 0;
  3649. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3650. {
  3651. sstr[c] = loc[3+strlen("key")+c];
  3652. c++;
  3653. }
  3654. sstr[c] = '\0';
  3655. strcpy(keystr, sstr);
  3656. /***value ****/
  3657. loc = strstr(payload, "value");
  3658. memset(sstr ,0, sizeof(sstr) );
  3659. c = 0;
  3660. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3661. {
  3662. sstr[c] = loc[3+strlen("value")+c];
  3663. c++;
  3664. }
  3665. sstr[c] = '\0';
  3666. strcpy(valuestr, sstr);
  3667. if((uuid==NULL) || (payload ==NULL) )
  3668. {
  3669. #ifdef Debug
  3670. DEBUG_INFO("payload is null\n");
  3671. #endif
  3672. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3673. }
  3674. else
  3675. {
  3676. int status = setKeyValue(keystr, valuestr);
  3677. switch(status)
  3678. {
  3679. case ConfigurationStatus_Accepted:
  3680. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3681. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3682. break;
  3683. case ConfigurationStatus_Rejected:
  3684. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3685. break;
  3686. case RebootRequired:
  3687. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3688. break;
  3689. case NotSupported:
  3690. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3691. break;
  3692. default:
  3693. break;
  3694. }
  3695. }
  3696. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3697. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3698. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3699. return result;
  3700. }
  3701. int handleClearCacheRequest(char *uuid, char *payload)
  3702. {
  3703. mtrace();
  3704. int result = FAIL;
  3705. char comfirmstr[20];
  3706. int fd;
  3707. char rmFileCmd[100]={0};
  3708. struct stat stats;
  3709. DEBUG_ERROR("handle ClearCacheRequest\n");
  3710. stat("../Storage/OCPP", &stats);
  3711. // Check for directory existence
  3712. if (S_ISDIR(stats.st_mode) == 1)
  3713. {
  3714. //DEBUG_ERROR("\n OCPP directory exist \n");
  3715. }
  3716. else
  3717. {
  3718. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3719. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3720. system(rmFileCmd);
  3721. }
  3722. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3723. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3724. {
  3725. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3726. }
  3727. else
  3728. {
  3729. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3730. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3731. if(log == NULL)
  3732. {
  3733. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3734. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3735. goto end;
  3736. }
  3737. else
  3738. {
  3739. fclose(log);
  3740. }
  3741. }
  3742. fd = open(AuthorizationCache_JSON,O_RDWR);
  3743. if(fd < 0)
  3744. {
  3745. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3746. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3747. }
  3748. else
  3749. {
  3750. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3751. //* 清空? 件 */
  3752. ftruncate(fd,0);
  3753. //* ? 新设置? 件? 移??*/
  3754. lseek(fd,0,SEEK_SET);
  3755. close(fd);
  3756. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3757. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3758. }
  3759. end:
  3760. sendClearCacheConfirmation(uuid, comfirmstr);
  3761. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3762. return result;
  3763. }
  3764. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3765. {
  3766. mtrace();
  3767. int result = FAIL;
  3768. int resultRename;
  3769. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3770. char chargingProfilePurposeStr[26]={0};
  3771. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3772. char tempchargingProfilePurposeStr[26]={0};
  3773. char sstr[160]={0};//sstr[200]={ 0 };
  3774. char str[100]={0};
  3775. int c = 0;
  3776. //int i = 0;
  3777. //char * pch;
  3778. char *loc;
  3779. char fname[200];
  3780. char comfirmstr[20]={0};
  3781. char word[1000]={0};
  3782. int clearflag = FALSE;
  3783. int chargingProfileIdIsNULL = FALSE;
  3784. int connectorIsNULL = FALSE;
  3785. int chargingProfilePurposeIsNULL = FALSE;
  3786. int stackLevelIsNULL = FALSE;
  3787. FILE *fptr1, *fptr2;
  3788. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3789. int n_chargingProfile=0;
  3790. char sLineWord[1060]={0};
  3791. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3792. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3793. //***id ****/
  3794. c = 0;
  3795. loc = strstr(payload, "id");
  3796. memset(sstr ,0, sizeof(sstr) );
  3797. if(loc == NULL)
  3798. {
  3799. chargingProfileIdIsNULL = TRUE;
  3800. }
  3801. else
  3802. {
  3803. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3804. {
  3805. sstr[c] = loc[strlen("id")+2+c];
  3806. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3807. c++;
  3808. }
  3809. sstr[c] = '\0';
  3810. chargingProfileIdInt = atoi(sstr);
  3811. }
  3812. //***connectorId ****/
  3813. c=0;
  3814. loc = strstr(payload, "connectorId");
  3815. memset(sstr ,0, sizeof(sstr) );
  3816. if(loc == NULL)
  3817. {
  3818. connectorIsNULL = TRUE;
  3819. }
  3820. else
  3821. {
  3822. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3823. {
  3824. sstr[c] = loc[strlen("connectorId")+2+c];
  3825. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3826. c++;
  3827. }
  3828. sstr[c] = '\0';
  3829. connectorIdInt = atoi(sstr);
  3830. }
  3831. //***chargingProfilePurpose ****/
  3832. loc = strstr(payload, "chargingProfilePurpose");
  3833. memset(sstr ,0, sizeof(sstr) );
  3834. c = 0;
  3835. if(loc == NULL)
  3836. {
  3837. chargingProfilePurposeIsNULL = TRUE;
  3838. }
  3839. else
  3840. {
  3841. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3842. {
  3843. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3844. c++;
  3845. }
  3846. sstr[c] = '\0';
  3847. strcpy(chargingProfilePurposeStr, sstr);
  3848. }
  3849. //***stackLevel ****/
  3850. c=0;
  3851. loc = strstr(payload, "stackLevel");
  3852. memset(sstr ,0, sizeof(sstr) );
  3853. if(loc == NULL)
  3854. {
  3855. stackLevelIsNULL = TRUE;
  3856. }
  3857. else
  3858. {
  3859. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3860. {
  3861. sstr[c] = loc[strlen("stackLevel")+2+c];
  3862. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3863. c++;
  3864. }
  3865. sstr[c] = '\0';
  3866. stackLevelInt = atoi(sstr);
  3867. }
  3868. if(connectorIsNULL == FALSE)
  3869. {
  3870. switch(connectorIdInt)
  3871. {
  3872. case 0:
  3873. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3874. {
  3875. strcpy(fname, ChargePointMaxProfile_JSON);
  3876. }
  3877. // else
  3878. // {
  3879. // strcpy(fname, TxDefaultProfile_0_JSON);
  3880. // }
  3881. break;
  3882. case 1:
  3883. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3884. {
  3885. strcpy(fname, TxDefaultProfile_1_JSON);
  3886. }
  3887. // else
  3888. // {
  3889. // strcpy(fname, TxProfile_1_JSON);
  3890. // }
  3891. break;
  3892. case 2:
  3893. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3894. {
  3895. strcpy(fname, TxDefaultProfile_2_JSON);
  3896. }
  3897. // else
  3898. // {
  3899. // strcpy(fname, TxProfile_2_JSON);
  3900. // }
  3901. break;
  3902. default:
  3903. strcpy(fname, ChargePointMaxProfile_JSON );
  3904. break;
  3905. }
  3906. }
  3907. else
  3908. {
  3909. strcpy(fname, ChargePointMaxProfile_JSON );
  3910. }
  3911. fptr1 = fopen(fname, "r");
  3912. if (!fptr1)
  3913. {
  3914. //file not exist
  3915. DEBUG_ERROR("Unable to open the input file!!\n");
  3916. fptr1 = fopen(fname, "w+");
  3917. }
  3918. fclose(fptr1);
  3919. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3920. {
  3921. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3922. goto end;
  3923. }
  3924. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3925. {
  3926. //clear the whole contents of a file in C
  3927. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3928. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3929. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3930. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3931. fclose(fopen(TxProfile_1_JSON, "w"));
  3932. fclose(fopen(TxProfile_2_JSON, "w"));
  3933. #if 0
  3934. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3935. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3936. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3937. #endif
  3938. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3939. }
  3940. else
  3941. {
  3942. fptr1 = fopen(fname, "r");
  3943. fptr2 = fopen(temp, "w+");
  3944. while(fscanf(fptr1, "%s", word) != EOF)
  3945. {
  3946. //DEBUG_INFO("word=%s\n",word);
  3947. if(strcmp(word, "chargingProfileId") == 0)
  3948. {
  3949. n_chargingProfile = n_chargingProfile + 1;
  3950. DEBUG_INFO("chargingProfileId Found\n");
  3951. }
  3952. }
  3953. rewind(fptr1);
  3954. //search Charging Profile Element
  3955. //int i= 0;
  3956. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3957. {
  3958. //*************************tempconnectorIdInt*********************************/
  3959. loc = strstr(sLineWord, "connectorId");
  3960. c = 0;
  3961. memset(sstr ,0, sizeof(sstr) );
  3962. while (loc[strlen("connectorId")+2+c] != ',')
  3963. {
  3964. sstr[c] = loc[strlen("connectorId")+2+c];
  3965. c++;
  3966. }
  3967. sstr[c] = '\0';
  3968. tempconnectorIdInt = atoi(sstr);
  3969. //chargingProfileId
  3970. c = 0;
  3971. loc = strstr(sLineWord, "chargingProfileId");
  3972. memset(sstr ,0, sizeof(sstr) );
  3973. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3974. {
  3975. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3976. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3977. c++;
  3978. }
  3979. sstr[c] = '\0';
  3980. tempchargingProfileIdInt = atoi(sstr);
  3981. //stackLevel
  3982. c = 0;
  3983. loc = strstr(sLineWord, "stackLevel");
  3984. memset(sstr ,0, sizeof(sstr) );
  3985. while (loc[strlen("stackLevel")+2+c] != ',')
  3986. {
  3987. sstr[c] = loc[strlen("stackLevel")+2+c];
  3988. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3989. c++;
  3990. }
  3991. sstr[c] = '\0';
  3992. tempstackLevelInt = atoi(sstr);
  3993. c = 0;
  3994. loc = strstr(sLineWord, "chargingProfilePurpose");
  3995. memset(sstr ,0, sizeof(sstr) );
  3996. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3997. {
  3998. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3999. c++;
  4000. }
  4001. sstr[c] = '\0';
  4002. strcpy(tempchargingProfilePurposeStr, sstr);
  4003. if(chargingProfileIdIsNULL == FALSE)
  4004. {
  4005. if(tempchargingProfileIdInt == chargingProfileIdInt)
  4006. {
  4007. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  4008. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4009. clearflag = TRUE;
  4010. continue;
  4011. }
  4012. else
  4013. {
  4014. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  4015. //json_object_array_add(newHeatMap, jsonitem);
  4016. fprintf(fptr2, sLineWord);//writing data into file
  4017. }
  4018. }
  4019. else
  4020. {
  4021. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  4022. {
  4023. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  4024. {
  4025. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4026. clearflag = TRUE;
  4027. continue;
  4028. }
  4029. }
  4030. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4031. {
  4032. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  4033. {
  4034. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  4035. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  4036. {
  4037. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4038. clearflag = TRUE;
  4039. continue;
  4040. }
  4041. }
  4042. }
  4043. else
  4044. {
  4045. //json_object_array_add(newHeatMap, jsonitem);
  4046. fprintf(fptr2, sLineWord);//writing data into file
  4047. }
  4048. }
  4049. memset(sLineWord, 0, sizeof sLineWord);
  4050. }
  4051. if(clearflag == FALSE)
  4052. {
  4053. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4054. goto end;
  4055. }
  4056. fclose(fptr1);
  4057. fclose(fptr2);
  4058. sprintf(str,"rm -f %s",fname);
  4059. system(str);
  4060. resultRename = rename(temp, fname);
  4061. if(resultRename == 0)
  4062. {
  4063. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4064. }
  4065. else
  4066. {
  4067. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4068. }
  4069. }
  4070. end:
  4071. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4072. return result;
  4073. }
  4074. int handleDataTransferRequest(char *uuid, char *payload)
  4075. {
  4076. mtrace();
  4077. int result = FAIL;
  4078. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4079. char tempvendorId[255]={0};
  4080. char tempmessageId[50]={0};
  4081. char tempdata[50]={0};
  4082. char sstr[160]={0};//sstr[200]={ 0 };
  4083. char message[80]={0};
  4084. int c = 0;
  4085. char *loc;
  4086. DEBUG_INFO("handle DataTransferRequest\n");
  4087. if((uuid != NULL) && (payload != NULL))
  4088. {
  4089. //===============================
  4090. // vendorId
  4091. //===============================
  4092. c = 0;
  4093. loc = strstr(payload, "vendorId");
  4094. while (loc[strlen("vendorId")+3+c] != '\"')
  4095. {
  4096. sstr[c] = loc[strlen("vendorId")+3+c];
  4097. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4098. c++;
  4099. }
  4100. sstr[c] = '\0';
  4101. strcpy(tempvendorId,sstr);
  4102. //===============================
  4103. // messageId
  4104. //===============================
  4105. memset(sstr ,0, sizeof(sstr) );
  4106. c = 0;
  4107. loc = strstr(payload, "messageId");
  4108. while (loc[strlen("messageId")+3+c] != '\"')
  4109. {
  4110. sstr[c] = loc[strlen("messageId")+3+c];
  4111. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4112. c++;
  4113. }
  4114. sstr[c] = '\0';
  4115. strcpy(tempmessageId,sstr);
  4116. //===============================
  4117. // data
  4118. //===============================
  4119. memset(sstr ,0, sizeof(sstr) );
  4120. c = 0;
  4121. loc = strstr(payload, "data");
  4122. printf("loc=%s\n",loc);
  4123. while (loc[strlen("data")+3+c] != '\"')
  4124. {
  4125. sstr[c] = loc[strlen("data")+3+c];
  4126. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4127. c++;
  4128. }
  4129. sstr[c] = '\0';
  4130. strcpy(tempdata,sstr);
  4131. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4132. }
  4133. else
  4134. {
  4135. char guid[37]={0};
  4136. random_uuid(guid);
  4137. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4138. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4139. }
  4140. LWS_Send(message);
  4141. return result;
  4142. }
  4143. #if 0
  4144. long long diff_tm(struct tm *a, struct tm *b) {
  4145. return a->tm_sec - b->tm_sec
  4146. + 60LL * (a->tm_min - b->tm_min)
  4147. + 3600LL * (a->tm_hour - b->tm_hour)
  4148. + 86400LL * (a->tm_yday - b->tm_yday)
  4149. + (a->tm_year - 70) * 31536000LL
  4150. - (a->tm_year - 69) / 4 * 86400LL
  4151. + (a->tm_year - 1) / 100 * 86400LL
  4152. - (a->tm_year + 299) / 400 * 86400LL
  4153. - (b->tm_year - 70) * 31536000LL
  4154. + (b->tm_year - 69) / 4 * 86400LL
  4155. - (b->tm_year - 1) / 100 * 86400LL
  4156. + (b->tm_year + 299) /400 * 86400LL;
  4157. }
  4158. #endif
  4159. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4160. {
  4161. mtrace();
  4162. int result = FAIL;
  4163. int connectorIdInt, durationInt;
  4164. char chargingRateUnitStr[4]={0};
  4165. //int tempconnectorIdInt,
  4166. int tempdurationInt;
  4167. float tempminChargingRateFloat = 0.0;
  4168. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4169. int tempStartPeriodInt=0;
  4170. float tempLimitInt=0.0;//0.1;
  4171. int tempNumberPhasesInt=0;
  4172. char fname[200];
  4173. char comfirmstr[20];
  4174. //float totallimit =0.0;
  4175. float MinChargingRate =0.0;
  4176. //double diff_t;
  4177. //struct tm tp;
  4178. FILE *fptr1;
  4179. int c = 0;
  4180. //int i = 0;
  4181. char * pch;
  4182. char *loc;
  4183. char sstr[200]={ 0 };
  4184. int n_chargingProfile = 0;
  4185. int n_SchedulePeriods = 0;
  4186. char SchedulePeriodList[10][200]={0};
  4187. char sLineWord[800]={0};
  4188. //int n_periods = 0;
  4189. char word[1000]={0};
  4190. int confirmPeriods = 0;
  4191. struct StructProfile ChargePointMaxProfile;
  4192. struct StructProfile TxDefaultProfile;
  4193. struct StructProfile TxProfile;
  4194. struct StructProfile TxDefaultProfiletemp[2]={0};
  4195. int TxDefaultProfileFileIsNull=FALSE;
  4196. int ChargePointMaxProfileIsNull=FALSE;
  4197. int TxProfileIsNull=FALSE;
  4198. int CompositeSceduleIndex = 0;
  4199. char ChargePointMaxProfileScheduleStr[30]={0};
  4200. char TxDefaultProfileScheduleStr[30]={0};
  4201. char TxProfileScheduleStr[30]={0};
  4202. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4203. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4204. memset(&TxProfile,0,sizeof(struct StructProfile));
  4205. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4206. c=0;
  4207. loc = strstr(payload, "connectorId");
  4208. memset(sstr ,0, sizeof(sstr) );
  4209. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4210. {
  4211. sstr[c] = loc[strlen("connectorId")+2+c];
  4212. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4213. c++;
  4214. }
  4215. sstr[c] = '\0';
  4216. connectorIdInt = atoi(sstr);
  4217. c=0;
  4218. loc = strstr(payload, "duration");
  4219. memset(sstr ,0, sizeof(sstr) );
  4220. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4221. {
  4222. sstr[c] = loc[strlen("duration")+2+c];
  4223. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4224. c++;
  4225. }
  4226. sstr[c] = '\0';
  4227. durationInt = atoi(sstr);
  4228. c = 0;
  4229. loc = strstr(payload, "chargingRateUnit");
  4230. memset(sstr ,0, sizeof(sstr) );
  4231. if(loc == NULL)
  4232. {
  4233. }
  4234. else
  4235. {
  4236. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4237. {
  4238. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4239. c++;
  4240. }
  4241. sstr[c] = '\0';
  4242. strcpy(chargingRateUnitStr, sstr);
  4243. }
  4244. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4245. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4246. if(connectorIdInt==0) // connectorId is 0
  4247. {
  4248. //******************************ChargePointMaxProfile*****************************************************/
  4249. strcpy(fname, ChargePointMaxProfile_JSON );
  4250. char word[30]={0};
  4251. char sLineWord[1060]={0};
  4252. int n_chargingProfile=0;
  4253. ChargePointMaxProfileIsNull=TRUE;
  4254. if((access(fname,F_OK))!=-1)
  4255. {
  4256. fptr1 = fopen(fname, "r");
  4257. int c;
  4258. c = fgetc(fptr1);
  4259. //DEBUG_INFO("c:%d\n",c);
  4260. rewind(fptr1);
  4261. if(c == EOF)
  4262. {
  4263. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4264. ChargePointMaxProfileIsNull=TRUE;
  4265. fclose(fptr1);
  4266. }
  4267. else
  4268. {
  4269. ChargePointMaxProfileIsNull=FALSE;
  4270. while(fscanf(fptr1, "%s", word) != EOF)
  4271. {
  4272. if(strcmp(word, "chargingProfileId") == 0)
  4273. {
  4274. n_chargingProfile = n_chargingProfile + 1;
  4275. printf("Found\n");
  4276. }
  4277. }
  4278. rewind(fptr1);
  4279. //search Charging Profile Element
  4280. int i= 0;
  4281. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4282. #if 0
  4283. /***********connectorId****************/
  4284. c = 0;
  4285. loc = strstr(sLineWord, "connectorId");
  4286. // printf("loc=%s\n",loc);
  4287. memset(sstr ,0, sizeof(sstr) );
  4288. while (loc[strlen("connectorId")+2+c] != ',')
  4289. {
  4290. sstr[c] = loc[strlen("connectorId")+2+c];
  4291. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4292. c++;
  4293. }
  4294. sstr[c] = '\0';
  4295. tempconnectorIdInt = atoi(sstr);
  4296. #endif
  4297. //***********validFrom**************/
  4298. c = 0;
  4299. loc = strstr(sLineWord, "validFrom");
  4300. //DEBUG_INFO("loc=%s\n",loc);
  4301. memset(sstr ,0, sizeof(sstr) );
  4302. if(loc != NULL)
  4303. {
  4304. while (loc[3+strlen("validFrom")+c] != '\"')
  4305. {
  4306. sstr[c] = loc[3+strlen("validFrom")+c];
  4307. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4308. c++;
  4309. }
  4310. sstr[c] = '\0';
  4311. DEBUG_INFO("validFrom=%s\n",sstr);
  4312. strcpy(tempvalidFromStr,sstr);
  4313. }
  4314. else
  4315. {
  4316. strcpy(tempvalidFromStr,"");
  4317. }
  4318. //**********startSchedule**********/
  4319. c = 0;
  4320. loc = strstr(sLineWord, "startSchedule");
  4321. //DEBUG_INFO("loc=%s\n",loc);
  4322. memset(sstr ,0, sizeof(sstr) );
  4323. while (loc[3+strlen("startSchedule")+c] != '\"')
  4324. {
  4325. sstr[c] = loc[3+strlen("startSchedule")+c];
  4326. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4327. c++;
  4328. }
  4329. sstr[c] = '\0';
  4330. strcpy(tempstartScheduleStr, sstr);
  4331. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4332. //**********chargingRateUnit**********/
  4333. c = 0;
  4334. loc = strstr(sLineWord, "chargingRateUnit");
  4335. memset(sstr ,0, sizeof(sstr) );
  4336. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4337. {
  4338. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4339. c++;
  4340. }
  4341. sstr[c] = '\0';
  4342. strcpy(tempchargingRateUnitStr, sstr);
  4343. //**********minChargingRate*******/
  4344. c = 0;
  4345. loc = strstr(sLineWord, "minChargingRate");
  4346. //printf("loc=%s\n",loc);
  4347. if(loc != NULL)
  4348. {
  4349. memset(sstr ,0, sizeof(sstr) );
  4350. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4351. {
  4352. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4353. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4354. c++;
  4355. }
  4356. sstr[c] = '\0';
  4357. tempminChargingRateFloat = atof(sstr);
  4358. }
  4359. else
  4360. {
  4361. tempminChargingRateFloat = 0.0;
  4362. }
  4363. //
  4364. #if 0
  4365. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4366. tp.tm_isdst = -1;
  4367. time_t utc = mktime(&tp);
  4368. // current time
  4369. time_t t = time(NULL);
  4370. #endif
  4371. //diff_t = difftime(t, utc);
  4372. //parsing strings to words
  4373. i = 0;
  4374. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4375. loc = loc+3+strlen("chargingSchedulePeriod");
  4376. pch = strtok(loc ,"{");
  4377. while (pch != NULL)
  4378. {
  4379. strcpy(SchedulePeriodList[i], pch);
  4380. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4381. //printf ("%s\n",pch);
  4382. pch = strtok (NULL, "{");
  4383. i = i + 1;
  4384. }
  4385. n_SchedulePeriods = i;
  4386. for(int i=0;i<n_SchedulePeriods;i++)
  4387. {
  4388. //*************startPeriod****************/
  4389. c = 0;
  4390. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4391. memset(sstr ,0, sizeof(sstr) );
  4392. while (loc[strlen("startPeriod")+2+c] != ',')
  4393. {
  4394. sstr[c] = loc[strlen("startPeriod")+2+c];
  4395. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4396. c++;
  4397. }
  4398. sstr[c] = '\0';
  4399. tempStartPeriodInt = atoi(sstr);
  4400. //*************limit****************/
  4401. c = 0;
  4402. loc = strstr(SchedulePeriodList[i], "limit");
  4403. memset(sstr ,0, sizeof(sstr) );
  4404. while (loc[strlen("limit")+2+c] != ',')
  4405. {
  4406. sstr[c] = loc[strlen("limit")+2+c];
  4407. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4408. c++;
  4409. }
  4410. sstr[c] = '\0';
  4411. tempLimitInt = atof(sstr);
  4412. //*************numberPhases****************/
  4413. c = 0;
  4414. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4415. memset(sstr ,0, sizeof(sstr) );
  4416. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4417. {
  4418. sstr[c] = loc[strlen("numberPhases")+2+c];
  4419. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4420. c++;
  4421. }
  4422. sstr[c] = '\0';
  4423. tempNumberPhasesInt = atoi(sstr);
  4424. ChargePointMaxProfile.Duration = durationInt;
  4425. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4426. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4427. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4428. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4429. }
  4430. if(MinChargingRate < tempminChargingRateFloat)
  4431. MinChargingRate = tempminChargingRateFloat;
  4432. }
  4433. }// End of file ChargingProfile
  4434. } //THE END OF ACCESS ChargePointMaxProfile
  4435. //******************************TxDefaultProfile***********************************************/
  4436. strcpy(fname, TxDefaultProfile_0_JSON);
  4437. memset(word, 0, 30);
  4438. memset(sLineWord, 0, 1060);
  4439. //char word[30]={0};
  4440. //char sLineWord[1060]={0};
  4441. n_chargingProfile=0;
  4442. TxDefaultProfileFileIsNull=TRUE;
  4443. if((access(fname,F_OK))!=-1)
  4444. {
  4445. fptr1 = fopen(fname, "r");
  4446. c = 0;
  4447. c = fgetc(fptr1);
  4448. //DEBUG_INFO("c:%d\n",c);
  4449. rewind(fptr1);
  4450. if(c == EOF)
  4451. {
  4452. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4453. TxDefaultProfileFileIsNull=TRUE;
  4454. fclose(fptr1);
  4455. }
  4456. else
  4457. {
  4458. TxDefaultProfileFileIsNull=FALSE;
  4459. while(fscanf(fptr1, "%s", word) != EOF)
  4460. {
  4461. if(strcmp(word, "chargingProfileId") == 0)
  4462. {
  4463. n_chargingProfile = n_chargingProfile + 1;
  4464. printf("Found\n");
  4465. }
  4466. }
  4467. rewind(fptr1);
  4468. //search Charging Profile Element
  4469. int i= 0;
  4470. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4471. #if 0
  4472. /***********connectorId****************/
  4473. c = 0;
  4474. loc = strstr(sLineWord, "connectorId");
  4475. // printf("loc=%s\n",loc);
  4476. memset(sstr ,0, sizeof(sstr) );
  4477. while (loc[strlen("connectorId")+2+c] != ',')
  4478. {
  4479. sstr[c] = loc[strlen("connectorId")+2+c];
  4480. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4481. c++;
  4482. }
  4483. sstr[c] = '\0';
  4484. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4485. tempconnectorIdInt = atoi(sstr);
  4486. #endif
  4487. //***********validFrom**************/
  4488. c = 0;
  4489. loc = strstr(sLineWord, "validFrom");
  4490. //DEBUG_INFO("loc=%s\n",loc);
  4491. memset(sstr ,0, sizeof(sstr) );
  4492. if(loc != NULL)
  4493. {
  4494. while (loc[3+strlen("validFrom")+c] != '\"')
  4495. {
  4496. sstr[c] = loc[3+strlen("validFrom")+c];
  4497. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4498. c++;
  4499. }
  4500. sstr[c] = '\0';
  4501. DEBUG_INFO("validFrom=%s\n",sstr);
  4502. strcpy(tempvalidFromStr,sstr);
  4503. }
  4504. else
  4505. {
  4506. strcpy(tempvalidFromStr,"");
  4507. }
  4508. //**********startSchedule**********/
  4509. c = 0;
  4510. loc = strstr(sLineWord, "startSchedule");
  4511. //DEBUG_INFO("loc=%s\n",loc);
  4512. memset(sstr ,0, sizeof(sstr) );
  4513. while (loc[3+strlen("startSchedule")+c] != '\"')
  4514. {
  4515. sstr[c] = loc[3+strlen("startSchedule")+c];
  4516. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4517. c++;
  4518. }
  4519. sstr[c] = '\0';
  4520. strcpy(tempstartScheduleStr, sstr);
  4521. strcpy(TxDefaultProfileScheduleStr, sstr);
  4522. DEBUG_INFO(" debug 3-1\n");
  4523. //**********chargingRateUnit**********/
  4524. c = 0;
  4525. loc = strstr(sLineWord, "chargingRateUnit");
  4526. memset(sstr ,0, sizeof(sstr) );
  4527. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4528. {
  4529. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4530. c++;
  4531. }
  4532. sstr[c] = '\0';
  4533. strcpy(tempchargingRateUnitStr, sstr);
  4534. //**********minChargingRate*******/
  4535. c = 0;
  4536. loc = strstr(sLineWord, "minChargingRate");
  4537. //printf("loc=%s\n",loc);
  4538. if(loc != NULL)
  4539. {
  4540. memset(sstr ,0, sizeof(sstr) );
  4541. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4542. {
  4543. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4544. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4545. c++;
  4546. }
  4547. sstr[c] = '\0';
  4548. tempminChargingRateFloat = atof(sstr);
  4549. }
  4550. else
  4551. {
  4552. tempminChargingRateFloat = 0.0;
  4553. }
  4554. #if 0
  4555. //
  4556. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4557. tp.tm_isdst = -1;
  4558. time_t utc = mktime(&tp);
  4559. // current time
  4560. time_t t = time(NULL);
  4561. //diff_t = difftime(t, utc);
  4562. #endif
  4563. //parsing strings to words
  4564. i = 0;
  4565. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4566. loc = loc+3+strlen("chargingSchedulePeriod");
  4567. pch = strtok(loc ,"{");
  4568. while (pch != NULL)
  4569. {
  4570. strcpy(SchedulePeriodList[i], pch);
  4571. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4572. //printf ("%s\n",pch);
  4573. pch = strtok (NULL, "{");
  4574. i = i + 1;
  4575. }
  4576. n_SchedulePeriods = i;
  4577. for(int i=0;i<n_SchedulePeriods;i++)
  4578. {
  4579. //*************startPeriod****************/
  4580. c = 0;
  4581. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4582. memset(sstr ,0, sizeof(sstr) );
  4583. while (loc[strlen("startPeriod")+2+c] != ',')
  4584. {
  4585. sstr[c] = loc[strlen("startPeriod")+2+c];
  4586. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4587. c++;
  4588. }
  4589. sstr[c] = '\0';
  4590. tempStartPeriodInt = atoi(sstr);
  4591. //*************limit****************/
  4592. c = 0;
  4593. loc = strstr(SchedulePeriodList[i], "limit");
  4594. memset(sstr ,0, sizeof(sstr) );
  4595. while (loc[strlen("limit")+2+c] != ',')
  4596. {
  4597. sstr[c] = loc[strlen("limit")+2+c];
  4598. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4599. c++;
  4600. }
  4601. sstr[c] = '\0';
  4602. tempLimitInt = atof(sstr);
  4603. //*************numberPhases****************/
  4604. c = 0;
  4605. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4606. memset(sstr ,0, sizeof(sstr) );
  4607. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4608. {
  4609. sstr[c] = loc[strlen("numberPhases")+2+c];
  4610. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4611. c++;
  4612. }
  4613. sstr[c] = '\0';
  4614. tempNumberPhasesInt = atoi(sstr);
  4615. TxDefaultProfile.Duration = durationInt;
  4616. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4617. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4618. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4619. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4620. }
  4621. if(MinChargingRate < tempminChargingRateFloat)
  4622. MinChargingRate = tempminChargingRateFloat;
  4623. }
  4624. }
  4625. }// the end of ACCESS TxDefaultProfile
  4626. // Composite Schedule
  4627. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4628. {
  4629. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4630. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4631. {
  4632. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4633. {
  4634. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4635. }
  4636. else
  4637. {
  4638. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4639. }
  4640. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4641. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4642. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4643. }
  4644. }
  4645. //* Define temporary variables */
  4646. struct tm *gtime;
  4647. time_t now;
  4648. char buf[28];
  4649. /* Read the current system time */
  4650. time(&now);
  4651. /* Convert the system time to GMT (now UTC) */
  4652. gtime = gmtime(&now);
  4653. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4654. // make .conf
  4655. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4656. //MaxChargingProfilesInstalled is 10
  4657. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4658. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4659. //nPeriod = 1;
  4660. if(chargingRateUnitStr[0] != 0)
  4661. {
  4662. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4663. }
  4664. else
  4665. {
  4666. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4667. }
  4668. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4669. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4670. confirmPeriods = 1;
  4671. }
  4672. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4673. {
  4674. //*****************************ChargePointMaxProfile******************************************/
  4675. strcpy(fname, ChargePointMaxProfile_JSON);
  4676. ChargePointMaxProfileIsNull=TRUE;
  4677. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4678. {
  4679. fptr1 = fopen(fname, "r");
  4680. int c;
  4681. c = fgetc(fptr1);
  4682. //DEBUG_INFO("c:%d\n",c);
  4683. rewind(fptr1);
  4684. if(c == EOF)
  4685. {
  4686. DEBUG_INFO("\n End of file reached.");
  4687. ChargePointMaxProfileIsNull=TRUE;
  4688. fclose(fptr1);
  4689. }
  4690. else
  4691. {
  4692. ChargePointMaxProfileIsNull=FALSE;
  4693. while(fscanf(fptr1, "%s", word) != EOF)
  4694. {
  4695. if(strcmp(word, "chargingProfileId") == 0)
  4696. {
  4697. n_chargingProfile = n_chargingProfile + 1;
  4698. }
  4699. }
  4700. rewind(fptr1);
  4701. //search Charging Profile Element
  4702. int i = 0;
  4703. int j = 0;
  4704. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4705. #if 0
  4706. /***********connectorId****************/
  4707. c = 0;
  4708. loc = strstr(sLineWord, "connectorId");
  4709. memset(sstr ,0, sizeof(sstr) );
  4710. while (loc[strlen("connectorId")+2+c] != ',')
  4711. {
  4712. sstr[c] = loc[strlen("connectorId")+2+c];
  4713. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4714. c++;
  4715. }
  4716. sstr[c] = '\0';
  4717. tempconnectorIdInt = atoi(sstr);
  4718. #endif
  4719. //***********validFrom**************/
  4720. c = 0;
  4721. loc = strstr(sLineWord, "validFrom");
  4722. if(loc != NULL)
  4723. {
  4724. memset(sstr ,0, sizeof(sstr) );
  4725. while (loc[3+strlen("validFrom")+c] != '\"')
  4726. {
  4727. sstr[c] = loc[3+strlen("validFrom")+c];
  4728. c++;
  4729. }
  4730. sstr[c] = '\0';
  4731. strcpy(tempvalidFromStr,sstr);
  4732. }
  4733. else
  4734. {
  4735. strcpy(tempvalidFromStr,"");
  4736. }
  4737. //***********validFrom**************/
  4738. c = 0;
  4739. loc = strstr(sLineWord, "duration");
  4740. if(loc != NULL)
  4741. {
  4742. memset(sstr ,0, sizeof(sstr) );
  4743. while (loc[2+strlen("duration")+c] != ',')
  4744. {
  4745. sstr[c] = loc[2+strlen("duration")+c];
  4746. c++;
  4747. }
  4748. sstr[c] = '\0';
  4749. tempdurationInt = atoi(sstr);
  4750. }
  4751. else
  4752. {
  4753. tempdurationInt = 0;
  4754. }
  4755. //**********startSchedule**********/
  4756. c = 0;
  4757. loc = strstr(sLineWord, "startSchedule");
  4758. memset(sstr ,0, sizeof(sstr) );
  4759. while (loc[3+strlen("startSchedule")+c] != '\"')
  4760. {
  4761. sstr[c] = loc[3+strlen("startSchedule")+c];
  4762. c++;
  4763. }
  4764. sstr[c] = '\0';
  4765. strcpy(tempstartScheduleStr, sstr);
  4766. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4767. //**********chargingRateUnit**********/
  4768. c = 0;
  4769. loc = strstr(sLineWord, "chargingRateUnit");
  4770. memset(sstr ,0, sizeof(sstr) );
  4771. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4772. {
  4773. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4774. c++;
  4775. }
  4776. sstr[c] = '\0';
  4777. strcpy(tempchargingRateUnitStr, sstr);
  4778. //**********minChargingRate*******/
  4779. c = 0;
  4780. loc = strstr(sLineWord, "minChargingRate");
  4781. if(loc != NULL)
  4782. {
  4783. memset(sstr ,0, sizeof(sstr) );
  4784. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4785. {
  4786. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4787. c++;
  4788. }
  4789. sstr[c] = '\0';
  4790. tempminChargingRateFloat = atof(sstr);
  4791. }
  4792. else
  4793. {
  4794. tempminChargingRateFloat = 0.0;
  4795. }
  4796. #if 0
  4797. //
  4798. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4799. tp.tm_isdst = -1;
  4800. time_t utc = mktime(&tp);
  4801. time_t t = time(NULL);
  4802. //diff_t = difftime(t, utc);
  4803. #endif
  4804. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4805. //DEBUG_INFO(" debug 5 -1\n");
  4806. //parsing strings to words
  4807. i = 0;
  4808. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4809. loc = loc+3+strlen("chargingSchedulePeriod");
  4810. pch = strtok(loc ,"{");
  4811. while (pch != NULL)
  4812. {
  4813. strcpy(SchedulePeriodList[i], pch);
  4814. pch = strtok (NULL, "{");
  4815. i = i + 1;
  4816. }
  4817. n_SchedulePeriods = i;
  4818. for(int i=0;i<n_SchedulePeriods;i++)
  4819. {
  4820. //*************startPeriod****************/
  4821. c = 0;
  4822. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4823. memset(sstr ,0, sizeof(sstr) );
  4824. while (loc[strlen("startPeriod")+2+c] != ',')
  4825. {
  4826. sstr[c] = loc[strlen("startPeriod")+2+c];
  4827. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4828. c++;
  4829. }
  4830. sstr[c] = '\0';
  4831. tempStartPeriodInt = atoi(sstr);
  4832. //*************limit****************/
  4833. c = 0;
  4834. loc = strstr(SchedulePeriodList[i], "limit");
  4835. memset(sstr ,0, sizeof(sstr) );
  4836. while (loc[strlen("limit")+2+c] != ',')
  4837. {
  4838. sstr[c] = loc[strlen("limit")+2+c];
  4839. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4840. c++;
  4841. }
  4842. sstr[c] = '\0';
  4843. tempLimitInt = atof(sstr);
  4844. //*************numberPhases****************/
  4845. c = 0;
  4846. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4847. memset(sstr ,0, sizeof(sstr) );
  4848. while (loc[strlen("numberPhases")+2+c] != '}')
  4849. {
  4850. sstr[c] = loc[strlen("numberPhases")+2+c];
  4851. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4852. c++;
  4853. }
  4854. sstr[c] = '\0';
  4855. tempNumberPhasesInt = atoi(sstr);
  4856. if(j == 0)
  4857. {
  4858. ChargePointMaxProfile.Duration = tempdurationInt;
  4859. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4860. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4861. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4862. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4863. }
  4864. }
  4865. if(MinChargingRate < tempminChargingRateFloat)
  4866. {
  4867. MinChargingRate = tempminChargingRateFloat;
  4868. }
  4869. if(confirmPeriods < n_SchedulePeriods)
  4870. {
  4871. confirmPeriods = n_SchedulePeriods;
  4872. }
  4873. j = j + 1;
  4874. }
  4875. fclose(fptr1);
  4876. }
  4877. }// the end of access file ChargePointMaxProfile
  4878. //****************************TxDefaultProfile************************************************/
  4879. switch(connectorIdInt)
  4880. {
  4881. case 0:
  4882. break;
  4883. case 1:
  4884. strcpy(fname, TxDefaultProfile_1_JSON );
  4885. break;
  4886. case 2:
  4887. strcpy(fname, TxDefaultProfile_2_JSON );
  4888. break;
  4889. default:
  4890. strcpy(fname, TxDefaultProfile_1_JSON );
  4891. break;
  4892. }
  4893. TxDefaultProfileFileIsNull=TRUE;
  4894. if((access(fname,F_OK))!=-1)
  4895. {
  4896. fptr1 = fopen(fname, "r");
  4897. c = 0;
  4898. c = fgetc(fptr1);
  4899. //DEBUG_INFO("c:%d\n",c);
  4900. rewind(fptr1);
  4901. if(c == EOF)
  4902. {
  4903. DEBUG_INFO("\n End of file reached.");
  4904. TxDefaultProfileFileIsNull=TRUE;
  4905. fclose(fptr1);
  4906. }
  4907. else
  4908. {
  4909. TxDefaultProfileFileIsNull=FALSE;
  4910. while(fscanf(fptr1, "%s", word) != EOF)
  4911. {
  4912. if(strcmp(word, "chargingProfileId") == 0)
  4913. {
  4914. n_chargingProfile = n_chargingProfile + 1;
  4915. }
  4916. }
  4917. rewind(fptr1);
  4918. //search Charging Profile Element
  4919. int i = 0;
  4920. int j = 0;
  4921. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4922. //DEBUG_INFO(" 1-1\n");
  4923. #if 0
  4924. /***********connectorId****************/
  4925. c = 0;
  4926. loc = strstr(sLineWord, "connectorId");
  4927. memset(sstr ,0, sizeof(sstr) );
  4928. while (loc[strlen("connectorId")+2+c] != ',')
  4929. {
  4930. sstr[c] = loc[strlen("connectorId")+2+c];
  4931. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4932. c++;
  4933. }
  4934. sstr[c] = '\0';
  4935. tempconnectorIdInt = atoi(sstr);
  4936. #endif
  4937. //***********validFrom**************/
  4938. c = 0;
  4939. loc = strstr(sLineWord, "validFrom");
  4940. if(loc != NULL)
  4941. {
  4942. memset(sstr ,0, sizeof(sstr) );
  4943. while (loc[3+strlen("validFrom")+c] != '\"')
  4944. {
  4945. sstr[c] = loc[3+strlen("validFrom")+c];
  4946. c++;
  4947. }
  4948. sstr[c] = '\0';
  4949. strcpy(tempvalidFromStr,sstr);
  4950. }
  4951. else
  4952. {
  4953. strcpy(tempvalidFromStr,"");
  4954. }
  4955. //***********validFrom**************/
  4956. c = 0;
  4957. loc = strstr(sLineWord, "duration");
  4958. if(loc != NULL)
  4959. {
  4960. memset(sstr ,0, sizeof(sstr) );
  4961. while (loc[2+strlen("duration")+c] != ',')
  4962. {
  4963. sstr[c] = loc[2+strlen("duration")+c];
  4964. c++;
  4965. }
  4966. sstr[c] = '\0';
  4967. tempdurationInt = atoi(sstr);
  4968. }
  4969. else
  4970. {
  4971. tempdurationInt = 0;
  4972. }
  4973. //**********startSchedule**********/
  4974. c = 0;
  4975. loc = strstr(sLineWord, "startSchedule");
  4976. memset(sstr ,0, sizeof(sstr) );
  4977. while (loc[3+strlen("startSchedule")+c] != '\"')
  4978. {
  4979. sstr[c] = loc[3+strlen("startSchedule")+c];
  4980. c++;
  4981. }
  4982. sstr[c] = '\0';
  4983. strcpy(tempstartScheduleStr, sstr);
  4984. strcpy(TxDefaultProfileScheduleStr, sstr);
  4985. //**********chargingRateUnit**********/
  4986. c = 0;
  4987. loc = strstr(sLineWord, "chargingRateUnit");
  4988. memset(sstr ,0, sizeof(sstr) );
  4989. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4990. {
  4991. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4992. c++;
  4993. }
  4994. sstr[c] = '\0';
  4995. strcpy(tempchargingRateUnitStr, sstr);
  4996. //**********minChargingRate*******/
  4997. c = 0;
  4998. loc = strstr(sLineWord, "minChargingRate");
  4999. if(loc != NULL)
  5000. {
  5001. memset(sstr ,0, sizeof(sstr) );
  5002. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5003. {
  5004. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5005. c++;
  5006. }
  5007. sstr[c] = '\0';
  5008. tempminChargingRateFloat = atof(sstr);
  5009. }
  5010. else
  5011. {
  5012. tempminChargingRateFloat = 0.0;
  5013. }
  5014. #if 0
  5015. //
  5016. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5017. tp.tm_isdst = -1;
  5018. time_t utc = mktime(&tp);
  5019. time_t t = time(NULL);
  5020. //diff_t = difftime(t, utc);
  5021. #endif
  5022. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5023. //parsing strings to words
  5024. i = 0;
  5025. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5026. loc = loc+3+strlen("chargingSchedulePeriod");
  5027. pch = strtok(loc ,"{");
  5028. while (pch != NULL)
  5029. {
  5030. strcpy(SchedulePeriodList[i], pch);
  5031. pch = strtok (NULL, "{");
  5032. i = i + 1;
  5033. }
  5034. n_SchedulePeriods = i;
  5035. for(int i=0;i<n_SchedulePeriods;i++)
  5036. {
  5037. //*************startPeriod****************/
  5038. c = 0;
  5039. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5040. memset(sstr ,0, sizeof(sstr) );
  5041. while (loc[strlen("startPeriod")+2+c] != ',')
  5042. {
  5043. sstr[c] = loc[strlen("startPeriod")+2+c];
  5044. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5045. c++;
  5046. }
  5047. sstr[c] = '\0';
  5048. tempStartPeriodInt = atoi(sstr);
  5049. //*************limit****************/
  5050. c = 0;
  5051. loc = strstr(SchedulePeriodList[i], "limit");
  5052. memset(sstr ,0, sizeof(sstr) );
  5053. while (loc[strlen("limit")+2+c] != ',')
  5054. {
  5055. sstr[c] = loc[strlen("limit")+2+c];
  5056. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5057. c++;
  5058. }
  5059. sstr[c] = '\0';
  5060. tempLimitInt = atof(sstr);
  5061. //*************numberPhases****************/
  5062. c = 0;
  5063. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5064. memset(sstr ,0, sizeof(sstr) );
  5065. while (loc[strlen("numberPhases")+2+c] != '}')
  5066. {
  5067. sstr[c] = loc[strlen("numberPhases")+2+c];
  5068. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5069. c++;
  5070. }
  5071. sstr[c] = '\0';
  5072. tempNumberPhasesInt = atoi(sstr);
  5073. if(j == 0)
  5074. {
  5075. TxDefaultProfile.Duration = tempdurationInt;
  5076. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5077. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5078. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5079. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5080. }
  5081. else
  5082. {
  5083. //other stack level charging Profile
  5084. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5085. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5086. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5087. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5088. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5089. }
  5090. }
  5091. if(MinChargingRate < tempminChargingRateFloat)
  5092. MinChargingRate = tempminChargingRateFloat;
  5093. if(confirmPeriods < n_SchedulePeriods)
  5094. confirmPeriods = n_SchedulePeriods;
  5095. j = j + 1;
  5096. //DEBUG_INFO(" 1-2\n");
  5097. }
  5098. fclose(fptr1);
  5099. //Stacking Charging Profiles
  5100. for(int l=0; l <(j-1) ;l++)
  5101. {
  5102. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5103. {
  5104. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5105. {
  5106. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5107. {
  5108. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5109. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5110. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5111. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5112. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5113. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5114. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5115. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5116. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5117. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5118. }
  5119. else
  5120. {
  5121. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5122. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5123. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5124. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5125. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5126. }
  5127. }
  5128. }
  5129. }
  5130. //end of Stacking Charging Profiles
  5131. }
  5132. }// the end of ACCESS TxDefaultProfile
  5133. //****************************TxProfile************************************************/
  5134. switch(connectorIdInt)
  5135. {
  5136. case 0:
  5137. break;
  5138. case 1:
  5139. strcpy(fname, TxProfile_1_JSON );
  5140. break;
  5141. case 2:
  5142. strcpy(fname, TxProfile_2_JSON );
  5143. break;
  5144. default:
  5145. strcpy(fname, TxProfile_1_JSON );
  5146. break;
  5147. }
  5148. TxProfileIsNull=TRUE;
  5149. if((access(fname,F_OK))!=-1)
  5150. {
  5151. fptr1 = fopen(fname, "r");
  5152. c = 0;
  5153. c = fgetc(fptr1);
  5154. //DEBUG_INFO("c:%d\n",c);
  5155. rewind(fptr1);
  5156. if(c == EOF)
  5157. {
  5158. DEBUG_INFO("\n End of file reached.");
  5159. TxProfileIsNull=TRUE;
  5160. fclose(fptr1);
  5161. }
  5162. else
  5163. {
  5164. TxProfileIsNull=FALSE;
  5165. while(fscanf(fptr1, "%s", word) != EOF)
  5166. {
  5167. if(strcmp(word, "chargingProfileId") == 0)
  5168. {
  5169. n_chargingProfile = n_chargingProfile + 1;
  5170. }
  5171. }
  5172. rewind(fptr1);
  5173. //search Charging Profile Element
  5174. int i= 0;
  5175. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5176. #if 0
  5177. /***********connectorId****************/
  5178. c = 0;
  5179. loc = strstr(sLineWord, "connectorId");
  5180. memset(sstr ,0, sizeof(sstr) );
  5181. while (loc[strlen("connectorId")+2+c] != ',')
  5182. {
  5183. sstr[c] = loc[strlen("connectorId")+2+c];
  5184. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5185. c++;
  5186. }
  5187. sstr[c] = '\0';
  5188. tempconnectorIdInt = atoi(sstr);
  5189. #endif
  5190. //***********validFrom**************/
  5191. c = 0;
  5192. loc = strstr(sLineWord, "validFrom");
  5193. if(loc != NULL)
  5194. {
  5195. memset(sstr ,0, sizeof(sstr) );
  5196. while (loc[3+strlen("validFrom")+c] != '\"')
  5197. {
  5198. sstr[c] = loc[3+strlen("validFrom")+c];
  5199. c++;
  5200. }
  5201. sstr[c] = '\0';
  5202. strcpy(tempvalidFromStr,sstr);
  5203. }
  5204. else
  5205. {
  5206. strcpy(tempvalidFromStr,"");
  5207. }
  5208. //**********startSchedule**********/
  5209. c = 0;
  5210. loc = strstr(sLineWord, "startSchedule");
  5211. memset(sstr ,0, sizeof(sstr) );
  5212. while (loc[3+strlen("startSchedule")+c] != '\"')
  5213. {
  5214. sstr[c] = loc[3+strlen("startSchedule")+c];
  5215. c++;
  5216. }
  5217. sstr[c] = '\0';
  5218. strcpy(tempstartScheduleStr, sstr);
  5219. strcpy(TxProfileScheduleStr, sstr);
  5220. //**********chargingRateUnit**********/
  5221. c = 0;
  5222. loc = strstr(sLineWord, "chargingRateUnit");
  5223. memset(sstr ,0, sizeof(sstr) );
  5224. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5225. {
  5226. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5227. c++;
  5228. }
  5229. sstr[c] = '\0';
  5230. strcpy(tempchargingRateUnitStr, sstr);
  5231. //**********minChargingRate*******/
  5232. c = 0;
  5233. loc = strstr(sLineWord, "minChargingRate");
  5234. if(loc != NULL)
  5235. {
  5236. memset(sstr ,0, sizeof(sstr) );
  5237. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5238. {
  5239. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5240. c++;
  5241. }
  5242. sstr[c] = '\0';
  5243. tempminChargingRateFloat = atof(sstr);
  5244. }
  5245. else
  5246. {
  5247. tempminChargingRateFloat = 0.0;
  5248. }
  5249. #if 0
  5250. //
  5251. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5252. tp.tm_isdst = -1;
  5253. time_t utc = mktime(&tp);
  5254. time_t t = time(NULL);
  5255. //diff_t = difftime(t, utc);
  5256. #endif
  5257. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5258. //parsing strings to words
  5259. i = 0;
  5260. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5261. loc = loc+3+strlen("chargingSchedulePeriod");
  5262. pch = strtok(loc ,"{");
  5263. while (pch != NULL)
  5264. {
  5265. strcpy(SchedulePeriodList[i], pch);
  5266. pch = strtok (NULL, "{");
  5267. i = i + 1;
  5268. }
  5269. n_SchedulePeriods = i;
  5270. for(int i=0;i<n_SchedulePeriods;i++)
  5271. {
  5272. //*************startPeriod****************/
  5273. c = 0;
  5274. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5275. memset(sstr ,0, sizeof(sstr) );
  5276. while (loc[strlen("startPeriod")+2+c] != ',')
  5277. {
  5278. sstr[c] = loc[strlen("startPeriod")+2+c];
  5279. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5280. c++;
  5281. }
  5282. sstr[c] = '\0';
  5283. tempStartPeriodInt = atoi(sstr);
  5284. //*************limit****************/
  5285. c = 0;
  5286. loc = strstr(SchedulePeriodList[i], "limit");
  5287. memset(sstr ,0, sizeof(sstr) );
  5288. while (loc[strlen("limit")+2+c] != ',')
  5289. {
  5290. sstr[c] = loc[strlen("limit")+2+c];
  5291. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5292. c++;
  5293. }
  5294. sstr[c] = '\0';
  5295. tempLimitInt = atof(sstr);
  5296. //*************numberPhases****************/
  5297. c = 0;
  5298. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5299. memset(sstr ,0, sizeof(sstr) );
  5300. while (loc[strlen("numberPhases")+2+c] != '}')
  5301. {
  5302. sstr[c] = loc[strlen("numberPhases")+2+c];
  5303. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5304. c++;
  5305. }
  5306. sstr[c] = '\0';
  5307. tempNumberPhasesInt = atoi(sstr);
  5308. TxProfile.Duration = durationInt;
  5309. TxProfile.TotalPeriod = n_SchedulePeriods;
  5310. TxProfile.Period[i].Limit = tempLimitInt;
  5311. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5312. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5313. }
  5314. if(MinChargingRate < tempminChargingRateFloat)
  5315. MinChargingRate = tempminChargingRateFloat;
  5316. if(confirmPeriods < n_SchedulePeriods)
  5317. confirmPeriods = n_SchedulePeriods;
  5318. }
  5319. fclose(fptr1);
  5320. }
  5321. }// the end of ACCESS TxProfile
  5322. //CompositeSchedule
  5323. int period=0;
  5324. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5325. {
  5326. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5327. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5328. {
  5329. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5330. {
  5331. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5332. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5333. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5334. period = period + 1;
  5335. }
  5336. else
  5337. {
  5338. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5339. {
  5340. }
  5341. else
  5342. {
  5343. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5344. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5345. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5346. period = period + 1;
  5347. }
  5348. }
  5349. }
  5350. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5351. {
  5352. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5353. {
  5354. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5355. {
  5356. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5357. }
  5358. else
  5359. {
  5360. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5361. }
  5362. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5363. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5364. period = period + 1;
  5365. }
  5366. }
  5367. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5368. {
  5369. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5370. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5371. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5372. period = period + 1;
  5373. }
  5374. }
  5375. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5376. {
  5377. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5378. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5379. {
  5380. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5381. {
  5382. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5383. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5384. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5385. period = period + 1;
  5386. }
  5387. else
  5388. {
  5389. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5390. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5391. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5392. period = period + 1;
  5393. }
  5394. }
  5395. }
  5396. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5397. {
  5398. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5399. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5400. {
  5401. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5402. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5403. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5404. period = period + 1;
  5405. }
  5406. }
  5407. confirmPeriods = period;
  5408. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5409. //* Define temporary variables */
  5410. struct tm *gtime;
  5411. time_t now;
  5412. char buf[28];
  5413. //* Read the current system time */
  5414. time(&now);
  5415. //* Convert the system time to GMT (now UTC) */
  5416. gtime = gmtime(&now);
  5417. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5418. // make .conf
  5419. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5420. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5421. //DEBUG_INFO(" debug 11\n");
  5422. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5423. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5424. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5425. }
  5426. else
  5427. {
  5428. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5429. }
  5430. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5431. return result;
  5432. }
  5433. int handleGetConfigurationRequest(char *uuid, char *payload)
  5434. {
  5435. mtrace();
  5436. int result = FAIL;
  5437. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5438. //struct json_object *jsonitem;
  5439. int MaxKeySupported = 0;
  5440. int n_keys = 0;
  5441. char requestKey[43][50]={0};
  5442. char search[]="[";
  5443. char sstr[500]={ 0 };
  5444. //int pos;
  5445. int l, c = 0;
  5446. int i = 0;
  5447. char *delim = "\",\"";
  5448. char * pch;
  5449. char *loc = strstr(payload, search);
  5450. //********************* Parsing String ***********************************/
  5451. if(loc == NULL) {
  5452. DEBUG_INFO("no key match in Configuration \n");
  5453. }
  5454. else {
  5455. //pos = loc - payload;
  5456. l = strlen(loc)-4;
  5457. while (c < l)
  5458. {
  5459. sstr[c] = loc[c+2];
  5460. c++;
  5461. }
  5462. sstr[c] = '\0';
  5463. //parsing strings to words
  5464. pch = strtok(sstr,delim);
  5465. if(pch == NULL)
  5466. {
  5467. strcpy(requestKey[0], sstr);
  5468. }
  5469. else
  5470. {
  5471. while (pch != NULL)
  5472. {
  5473. strcpy(requestKey[i], pch);
  5474. pch = strtok (NULL, delim);
  5475. i = i + 1;
  5476. }
  5477. n_keys = i;
  5478. }
  5479. }
  5480. UnknownKeynum = 0;
  5481. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5482. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5483. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5484. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5485. if(n_keys != 0)
  5486. {
  5487. for(int i=0;i<n_keys;i++)
  5488. {
  5489. getKeyValue(requestKey[i]);
  5490. //json_object_put(jsonitem);
  5491. }
  5492. }
  5493. else
  5494. {
  5495. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5496. getKeyValue("");
  5497. }
  5498. processUnkownKey();
  5499. sendGetConfigurationConfirmation(uuid);
  5500. return result;
  5501. }
  5502. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5503. {
  5504. mtrace();
  5505. int result = FAIL;
  5506. //void *ret; //
  5507. char fnamePlusPath[50]="";
  5508. char fname[16]="";
  5509. pthread_t t; // pthread 變數
  5510. time_t rawtime;
  5511. struct tm * timeinfo;
  5512. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5513. system("exec /root/logPackTools 'log' 6");
  5514. //char buffer [128];
  5515. time (&rawtime);
  5516. //printf("%ld\n", rawtime);
  5517. timeinfo = localtime (&rawtime);
  5518. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5519. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5520. if((access(fnamePlusPath,F_OK))!=-1)
  5521. {
  5522. DEBUG_INFO("fnamePlusPath exist.\n");
  5523. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5524. }
  5525. else
  5526. {
  5527. DEBUG_INFO("fnamePlusPath not exist!\n");
  5528. }
  5529. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5530. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5531. pthread_join(t, NULL/*&ret*/);
  5532. return result;
  5533. }
  5534. void* GetDiagnosticsProcess(void* data)
  5535. {
  5536. mtrace();
  5537. int retriesInt=0, retryIntervalInt=0;
  5538. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5539. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5540. 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};
  5541. int port=0;
  5542. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5543. char fname[16]="";
  5544. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5545. int c = 0;
  5546. char *loc;
  5547. int isSuccess = FALSE;
  5548. char ftpbuf[200]={0};
  5549. //char temp[100]={0};
  5550. char * pch;
  5551. // [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"}]
  5552. char *str = (char*) data; // ? ?輸入資 ?
  5553. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5554. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5555. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5556. //****************location*******************/
  5557. c = 0;
  5558. memset(sstr ,0, sizeof(sstr) );
  5559. loc = strstr(str, "location");
  5560. while (loc[3+strlen("location")+c] != '\"')
  5561. {
  5562. sstr[c] = loc[3+strlen("location")+c];
  5563. c++;
  5564. }
  5565. sstr[c] = '\0';
  5566. strcpy(locationstr,sstr);
  5567. if(strcmp(locationstr,"")==0)
  5568. {
  5569. DEBUG_INFO("location is <Empty>!\n");
  5570. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5571. goto end;
  5572. }
  5573. //****************retries*******************/
  5574. c = 0;
  5575. loc = strstr(str, "retries");
  5576. if(loc == NULL)
  5577. {
  5578. retriesIsNULL = TRUE;
  5579. }
  5580. else
  5581. {
  5582. while (loc[strlen("retries")+2+c] != ',')
  5583. {
  5584. sstr[c] = loc[strlen("retries")+2+c];
  5585. c++;
  5586. }
  5587. sstr[c] = '\0';
  5588. retriesInt = atoi(sstr);
  5589. }
  5590. if(retriesIsNULL == TRUE)
  5591. {
  5592. retriesInt = 0;
  5593. }
  5594. //****************retryInterval*******************/
  5595. c = 0;
  5596. loc = strstr(str, "retryInterval");
  5597. if(loc == NULL)
  5598. {
  5599. retryIntervalIsNULL = TRUE;
  5600. }
  5601. else
  5602. {
  5603. while (loc[strlen("retryInterval")+2+c] != ',')
  5604. {
  5605. sstr[c] = loc[strlen("retryInterval")+2+c];
  5606. c++;
  5607. }
  5608. sstr[c] = '\0';
  5609. retryIntervalInt = atoi(sstr);
  5610. }
  5611. //****************startTime*******************/
  5612. c = 0;
  5613. memset(sstr ,0, sizeof(sstr) );
  5614. loc = strstr(str, "startTime");
  5615. if(loc == NULL)
  5616. {
  5617. startTimeIsNULL = TRUE;
  5618. }
  5619. else
  5620. {
  5621. while (loc[3+strlen("startTime")+c] != '\"')
  5622. {
  5623. sstr[c] = loc[3+strlen("startTime")+c];
  5624. c++;
  5625. }
  5626. sstr[c] = '\0';
  5627. strcpy(startTimestr,sstr);
  5628. }
  5629. //****************stopTime*******************/
  5630. c = 0;
  5631. memset(sstr ,0, sizeof(sstr) );
  5632. loc = strstr(str, "stopTime");
  5633. if(loc == NULL)
  5634. {
  5635. stopTimeIsNULL = TRUE;
  5636. }
  5637. else
  5638. {
  5639. while (loc[3+strlen("stopTime")+c] != '\"')
  5640. {
  5641. sstr[c] = loc[3+strlen("stopTime")+c];
  5642. c++;
  5643. }
  5644. sstr[c] = '\0';
  5645. strcpy(stopTimestr,sstr);
  5646. }
  5647. memset(protocol, 0, sizeof(protocol));
  5648. memset(user, 0, sizeof(user) );
  5649. memset(password, 0, sizeof(password));
  5650. memset(host, 0, sizeof(host));
  5651. memset(path, 0, sizeof(path));
  5652. memset(ftppath, 0, sizeof(ftppath));
  5653. memset(host1, 0, sizeof(host1));
  5654. memset(path1, 0, sizeof(path1));
  5655. /*location: ftp://user:password@host:port/path*/
  5656. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5657. // protocol, user, password, host, &port, path);
  5658. #if 0 // remove for temporally
  5659. //zip files in /Storage
  5660. system("exec /root/logPackTools 'log' 6");
  5661. #endif
  5662. // system("exec /root/Module_WebService 'log' 6");
  5663. time_t rawtime;
  5664. struct tm * timeinfo;
  5665. //char buffer [128];
  5666. time (&rawtime);
  5667. //printf("%ld\n", rawtime);
  5668. timeinfo = localtime (&rawtime);
  5669. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5670. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5671. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5672. if((access(fnamePlusPath,F_OK))!=-1)
  5673. {
  5674. DEBUG_INFO("fnamePlusPath exist.\n");
  5675. }
  5676. else
  5677. {
  5678. DEBUG_INFO("fnamePlusPath not exist!\n");
  5679. goto end;
  5680. }
  5681. pch=strchr(locationstr,'@');
  5682. if(pch==NULL)
  5683. {
  5684. sscanf(locationstr,
  5685. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5686. protocol, host, &port, path);
  5687. strcpy(user,"anonymous");
  5688. strcpy(password,"");
  5689. }
  5690. else
  5691. {
  5692. DEBUG_INFO("pch=%s\n", pch);
  5693. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5694. protocol, user, password, host, &port, path);
  5695. }
  5696. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5697. {
  5698. DEBUG_INFO("protocol is not ftp/http ! \n");
  5699. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5700. goto end;
  5701. }
  5702. if(strncmp(locationstr,"http", 4) == 0)
  5703. {
  5704. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  5705. protocol, host, path);
  5706. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  5707. // protocol, user, password, host, path);
  5708. sprintf(ftppath,"/%s", path);
  5709. DEBUG_INFO("protocol =%s\n",protocol);
  5710. DEBUG_INFO("host =%s\n",host);
  5711. DEBUG_INFO("path =%s\n",path);
  5712. DEBUG_INFO("ftppath=%s\n",ftppath);
  5713. int ftppathlen=strlen(ftppath);
  5714. int i=1;
  5715. char filenametemp[50];
  5716. while(i < ftppathlen)
  5717. {
  5718. int len=ftppathlen-i;
  5719. if(ftppath[len]== 47) // '/' ascll code: 47
  5720. {
  5721. DEBUG_INFO("compare '/' all right\n");
  5722. break;
  5723. }
  5724. i=i+1;
  5725. }
  5726. memset(filenametemp, 0, sizeof(filenametemp));
  5727. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5728. filenametemp[i+1] = 0;
  5729. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  5730. do{
  5731. isSuccess = httpUploadFile(host, ftppath, filenametemp, locationstr);
  5732. sleep(retryIntervalInt);
  5733. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5734. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  5735. if(!isSuccess)
  5736. {
  5737. //BulldogUtil.sleepMs(interval*1000);
  5738. DEBUG_INFO("Diagnostics fail.\n");
  5739. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5740. }
  5741. else
  5742. {
  5743. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5744. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5745. //isUpdateRequest = TRUE;
  5746. }
  5747. }
  5748. else
  5749. {
  5750. sscanf(host,"%[^/]%s",host1, path1);
  5751. sprintf(ftppath,"%s", path1);
  5752. DEBUG_INFO("protocol =%s\n",protocol);
  5753. DEBUG_INFO("user =%s\n",user);
  5754. DEBUG_INFO("password =%s\n",password);
  5755. DEBUG_INFO("host1 =%s\n",host1);
  5756. DEBUG_INFO("port =%d\n",port);
  5757. DEBUG_INFO("path1 =%s\n",path1);
  5758. DEBUG_INFO("ftppath=%s\n",ftppath);
  5759. int ftppathlen=strlen(ftppath);
  5760. int i=1;
  5761. char filenametemp[50];
  5762. while(i < ftppathlen)
  5763. {
  5764. int len=ftppathlen-i;
  5765. if(ftppath[len]== 47) // '/' ascll code: 47
  5766. {
  5767. DEBUG_INFO("find '/' all right\n");
  5768. break;
  5769. }
  5770. i=i+1;
  5771. }
  5772. memset(filenametemp, 0, sizeof(filenametemp));
  5773. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5774. filenametemp[i+1] = 0;
  5775. memset(ftpbuf, 0, sizeof(ftpbuf));
  5776. if(port == 0)
  5777. port = 21;
  5778. do{
  5779. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5780. sleep(retryIntervalInt);
  5781. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5782. if(!isSuccess)
  5783. {
  5784. //BulldogUtil.sleepMs(interval*1000);
  5785. DEBUG_INFO("Diagnostics fail.\n");
  5786. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5787. }
  5788. else
  5789. {
  5790. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5791. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5792. //isUpdateRequest = TRUE;
  5793. }
  5794. }
  5795. end:
  5796. // json_object_put(obj);
  5797. DiagnosticsStatusNotificationStatus = 0; //Idle
  5798. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5799. }
  5800. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5801. {
  5802. mtrace();
  5803. int result = FAIL;
  5804. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5805. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5806. {
  5807. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5808. localversion = -1;
  5809. }
  5810. else
  5811. {
  5812. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5813. OCPP_getListVerion();
  5814. }
  5815. //from db.OCPP_getListVerion
  5816. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5817. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5818. sendGetLocalListVersionConfirmation(uuid,"");
  5819. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5820. return result;
  5821. }
  5822. int handleRemoteStartRequest(char *uuid, char *payload)
  5823. {
  5824. mtrace();
  5825. int result = FAIL;
  5826. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5827. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5828. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5829. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5830. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5831. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5832. int chargingSchedulePeriodCount = 0;
  5833. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5834. int c = 0;
  5835. char *loc;
  5836. char comfirmstr[20]={0};
  5837. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5838. if(server_pending == TRUE)
  5839. {
  5840. return 0;
  5841. }
  5842. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5843. //**********connectorId****************/
  5844. c = 0;
  5845. memset(sstr ,0, sizeof(sstr) );
  5846. loc = strstr(payload, "connectorId");
  5847. if(loc == NULL)
  5848. {
  5849. connectorIdIsNULL = TRUE;
  5850. }
  5851. else
  5852. {
  5853. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5854. {
  5855. sstr[c] = loc[strlen("connectorId")+2+c];
  5856. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5857. c++;
  5858. }
  5859. sstr[c] = '\0';
  5860. connectorIdInt = atoi(sstr);
  5861. }
  5862. if(connectorIdIsNULL == TRUE) // need to discussion
  5863. {
  5864. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5865. goto end;
  5866. }
  5867. //****************idTag*******************/
  5868. c = 0;
  5869. memset(sstr ,0, sizeof(sstr) );
  5870. loc = strstr(payload, "idTag");
  5871. while (loc[3+strlen("idTag")+c] != '\"')
  5872. {
  5873. sstr[c] = loc[3+strlen("idTag")+c];
  5874. c++;
  5875. }
  5876. sstr[c] = '\0';
  5877. strcpy(idTagstr,sstr);
  5878. //****************chargingProfile*******************/
  5879. c = 0;
  5880. memset(sstr ,0, sizeof(sstr) );
  5881. loc = strstr(payload, "chargingProfile");
  5882. if(loc == NULL)
  5883. {
  5884. chargingProfileIsNULL = TRUE;
  5885. }
  5886. else
  5887. {
  5888. //****************chargingProfileId*******************/
  5889. c=0;
  5890. loc = strstr(payload, "chargingProfileId");
  5891. memset(sstr ,0, sizeof(sstr) );
  5892. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5893. {
  5894. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5895. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5896. c++;
  5897. }
  5898. sstr[c] = '\0';
  5899. chargingProfileIdInt = atoi(sstr);
  5900. //****************transactionId*******************/
  5901. loc = strstr(payload, "transactionId");
  5902. if(loc == NULL)
  5903. {
  5904. transactionIdIsNULL = TRUE;
  5905. }
  5906. else
  5907. {
  5908. c=0;
  5909. memset(sstr ,0, sizeof(sstr) );
  5910. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5911. {
  5912. sstr[c] = loc[strlen("transactionId")+2+c];
  5913. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5914. c++;
  5915. }
  5916. sstr[c] = '\0';
  5917. transactionIdInt = atoi(sstr);
  5918. }
  5919. //****************stackLevel*******************/
  5920. c=0;
  5921. loc = strstr(payload, "stackLevel");
  5922. memset(sstr ,0, sizeof(sstr) );
  5923. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5924. {
  5925. sstr[c] = loc[strlen("stackLevel")+2+c];
  5926. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5927. c++;
  5928. }
  5929. sstr[c] = '\0';
  5930. stackLevelInt = atoi(sstr);
  5931. //****************chargingProfilePurpose*******************/
  5932. c = 0;
  5933. memset(sstr ,0, sizeof(sstr) );
  5934. loc = strstr(payload, "chargingProfilePurpose");
  5935. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5936. {
  5937. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5938. c++;
  5939. }
  5940. sstr[c] = '\0';
  5941. strcpy(chargingProfilePurposestr,sstr);
  5942. //****************chargingProfileKind*******************/
  5943. c = 0;
  5944. memset(sstr ,0, sizeof(sstr) );
  5945. loc = strstr(payload, "chargingProfileKind");
  5946. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5947. {
  5948. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5949. c++;
  5950. }
  5951. sstr[c] = '\0';
  5952. strcpy(chargingProfileKindstr,sstr);
  5953. //****************recurrencyKind*******************/
  5954. loc = strstr(payload, "recurrencyKind");
  5955. if(loc == NULL)
  5956. {
  5957. recurrencyKindIsNULL = TRUE;
  5958. }
  5959. else
  5960. {
  5961. c = 0;
  5962. memset(sstr ,0, sizeof(sstr) );
  5963. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5964. {
  5965. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5966. c++;
  5967. }
  5968. sstr[c] = '\0';
  5969. strcpy(recurrencyKindstr,sstr);
  5970. }
  5971. //****************validFrom*******************/
  5972. loc = strstr(payload, "validFrom");
  5973. if(loc == NULL)
  5974. {
  5975. validFromIsNULL = TRUE;
  5976. }
  5977. else
  5978. {
  5979. c = 0;
  5980. memset(sstr ,0, sizeof(sstr) );
  5981. while (loc[3+strlen("validFrom")+c] != '\"')
  5982. {
  5983. sstr[c] = loc[3+strlen("validFrom")+c];
  5984. c++;
  5985. }
  5986. sstr[c] = '\0';
  5987. strcpy(validFromstr,sstr);
  5988. }
  5989. //****************validTo*******************/
  5990. loc = strstr(payload, "validTo");
  5991. if(loc == NULL)
  5992. {
  5993. validToIsNULL = TRUE;
  5994. }
  5995. else
  5996. {
  5997. c = 0;
  5998. memset(sstr ,0, sizeof(sstr) );
  5999. while (loc[3+strlen("validTo")+c] != '\"')
  6000. {
  6001. sstr[c] = loc[3+strlen("validTo")+c];
  6002. c++;
  6003. }
  6004. sstr[c] = '\0';
  6005. strcpy(validTostr,sstr);
  6006. }
  6007. //****************chargingSchedule*******************/
  6008. loc = strstr(payload, "chargingSchedule");
  6009. if(loc != NULL)
  6010. {
  6011. //****************duration*******************/
  6012. loc = strstr(payload, "duration");
  6013. if(loc == NULL)
  6014. {
  6015. durationIsNULL = TRUE;
  6016. }
  6017. else
  6018. {
  6019. c=0;
  6020. memset(sstr ,0, sizeof(sstr) );
  6021. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6022. {
  6023. sstr[c] = loc[strlen("duration")+2+c];
  6024. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6025. c++;
  6026. }
  6027. sstr[c] = '\0';
  6028. durationInt = atoi(sstr);
  6029. }
  6030. //****************startSchedule******************/
  6031. loc = strstr(payload, "startSchedule");
  6032. if(loc == NULL)
  6033. {
  6034. startScheduleIsNULL = TRUE;
  6035. }
  6036. else
  6037. {
  6038. c = 0;
  6039. memset(sstr ,0, sizeof(sstr) );
  6040. while (loc[3+strlen("startSchedule")+c] != '\"')
  6041. {
  6042. sstr[c] = loc[3+strlen("startSchedule")+c];
  6043. c++;
  6044. }
  6045. sstr[c] = '\0';
  6046. strcpy(startSchedulestr,sstr);
  6047. }
  6048. //****************chargingRateUnit*******************/
  6049. c = 0;
  6050. memset(sstr ,0, sizeof(sstr) );
  6051. loc = strstr(payload, "chargingRateUnit");
  6052. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6053. {
  6054. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6055. c++;
  6056. }
  6057. sstr[c] = '\0';
  6058. strcpy(chargingRateUnitstr,sstr);
  6059. //****************minChargingRate*******************/
  6060. loc = strstr(payload, "minChargingRate");
  6061. if(loc == NULL)
  6062. {
  6063. minChargingRateIsNULL = TRUE;
  6064. }
  6065. else
  6066. {
  6067. c=0;
  6068. memset(sstr ,0, sizeof(sstr) );
  6069. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6070. {
  6071. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6072. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6073. c++;
  6074. }
  6075. sstr[c] = '\0';
  6076. minChargingRateflaot = atof(sstr);
  6077. }
  6078. //****************chargingSchedulePeriod count*******************/
  6079. int what_len = strlen("startPeriod");
  6080. char *where = payload;
  6081. while ((where = strstr(where, "startPeriod"))) {
  6082. where += what_len;
  6083. chargingSchedulePeriodCount++;
  6084. }
  6085. where = payload;
  6086. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6087. {
  6088. //****************startPeriod*******************/
  6089. c=0;
  6090. loc = strstr(where, "startPeriod");
  6091. memset(sstr ,0, sizeof(sstr) );
  6092. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6093. {
  6094. sstr[c] = loc[strlen("startPeriod")+2+c];
  6095. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6096. c++;
  6097. }
  6098. sstr[c] = '\0';
  6099. startPeriodInt[periodNums] = atoi(sstr);
  6100. //****************limit*******************/
  6101. c=0;
  6102. loc = strstr(where, "limit");
  6103. memset(sstr ,0, sizeof(sstr) );
  6104. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6105. {
  6106. sstr[c] = loc[strlen("limit")+2+c];
  6107. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6108. c++;
  6109. }
  6110. sstr[c] = '\0';
  6111. limitflaot[periodNums] = atof(sstr);
  6112. //****************numberPhases*******************/
  6113. loc = strstr(where, "numberPhases");
  6114. if(loc == NULL)
  6115. {
  6116. numberPhasesIsNULL = TRUE;
  6117. }
  6118. else
  6119. {
  6120. c=0;
  6121. memset(sstr ,0, sizeof(sstr) );
  6122. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6123. {
  6124. sstr[c] = loc[strlen("numberPhases")+2+c];
  6125. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6126. c++;
  6127. }
  6128. sstr[c] = '\0';
  6129. numberPhasesInt[periodNums] = atoi(sstr);
  6130. }
  6131. where = loc;
  6132. }
  6133. }
  6134. }
  6135. /*
  6136. enum _SYSTEM_STATUS
  6137. {
  6138. S_BOOTING = 0,
  6139. S_IDLE, = 1
  6140. S_AUTHORIZING, =2
  6141. S_REASSIGN_CHECK, =3
  6142. S_REASSIGN, =4
  6143. S_PRECHARGE, =5
  6144. S_PREPARING_FOR_EV, =6
  6145. S_PREPARING_FOR_EVSE, =7
  6146. S_CHARGING, =8
  6147. S_TERMINATING, =9
  6148. S_COMPLETE, =10
  6149. S_ALARM, =11
  6150. S_FAULT =12
  6151. }
  6152. */
  6153. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6154. {
  6155. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6156. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6157. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6158. //check Transaction active
  6159. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6160. {
  6161. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6162. {
  6163. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6164. {
  6165. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6166. {
  6167. //Reserved
  6168. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6169. }
  6170. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6171. {
  6172. //Reserved
  6173. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6174. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6175. goto end;
  6176. }
  6177. else
  6178. {
  6179. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6180. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6181. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6182. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6183. {
  6184. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6185. goto end;
  6186. }
  6187. }//END FOR ELSE
  6188. }
  6189. }// END FOR CHAdeMO_QUANTITY
  6190. for (int index = 0; index < CCS_QUANTITY; index++)
  6191. {
  6192. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6193. {
  6194. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6195. {
  6196. //Reserved
  6197. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6198. }
  6199. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6200. {
  6201. //Reserved
  6202. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6203. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6204. goto end;
  6205. }
  6206. else
  6207. {
  6208. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6209. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6210. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6211. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6212. {
  6213. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6214. goto end;
  6215. }
  6216. }// END FOR ELSE
  6217. }
  6218. }// END FOR CCS_QUANTITY
  6219. for (int index = 0; index < GB_QUANTITY; index++)
  6220. {
  6221. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6222. {
  6223. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6224. {
  6225. //Reserved
  6226. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6227. }
  6228. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6229. {
  6230. //Reserved
  6231. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6232. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6233. goto end;
  6234. }
  6235. else
  6236. {
  6237. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6238. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6239. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6240. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6241. {
  6242. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6243. goto end;
  6244. }
  6245. }// END FOR ELSE
  6246. }
  6247. } // END FOR GB_QUANTITY
  6248. }
  6249. else
  6250. {
  6251. for (int index = 0; index < AC_QUANTITY; index++)
  6252. {
  6253. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6254. {
  6255. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6256. {
  6257. //Reserved
  6258. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6259. }
  6260. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6261. {
  6262. //Reserved
  6263. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6265. goto end;
  6266. }
  6267. else
  6268. {
  6269. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6270. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6271. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6272. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6273. {
  6274. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6275. goto end;
  6276. }
  6277. }//END FOR ELSE
  6278. }
  6279. }// END FOR AC_QUANTITY
  6280. }
  6281. if(chargingProfileIsNULL == FALSE)
  6282. {
  6283. //ChargingProfile
  6284. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6285. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6286. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6287. if(recurrencyKindIsNULL == FALSE) //OPTION
  6288. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6289. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6290. if(transactionIdIsNULL == FALSE) // OPTION
  6291. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6292. if(validFromIsNULL == FALSE) // OPTION
  6293. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6294. if(validToIsNULL == FALSE) //OPTION
  6295. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6296. //ChargingSchedule
  6297. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6298. if(durationIsNULL == FALSE) //OPTION
  6299. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6300. if(minChargingRateIsNULL == FALSE) //OPTION
  6301. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6302. if(startScheduleIsNULL == FALSE) //OPTION
  6303. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6304. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6305. {
  6306. //ChargingSchedulePeriod
  6307. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6308. if(numberPhasesIsNULL == FALSE)
  6309. {
  6310. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6311. }
  6312. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6313. }
  6314. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6315. {
  6316. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6317. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6318. //memset idTag
  6319. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6320. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6321. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6322. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6323. }
  6324. else
  6325. {
  6326. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6327. }
  6328. }
  6329. else
  6330. {
  6331. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6332. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6333. //memset idTag
  6334. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6335. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6336. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6337. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6338. }
  6339. }
  6340. else
  6341. {
  6342. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6343. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6344. }
  6345. end:
  6346. if(connectorIdIsNULL == FALSE)
  6347. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6348. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6349. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6350. //OCPP send RemoteStartConfirmation by first.
  6351. sendRemoteStartConfirmation(uuid, comfirmstr);
  6352. return result;
  6353. }
  6354. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6355. {
  6356. mtrace();
  6357. int result = FAIL;
  6358. int match = FALSE;
  6359. int GunNO = 0;
  6360. int transactionIdInt=0;
  6361. int transactionIdIsNULL= FALSE;
  6362. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6363. int c = 0;
  6364. char *loc;
  6365. char comfirmstr[20];
  6366. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6367. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6368. if(server_pending == TRUE)
  6369. {
  6370. return 0;
  6371. }
  6372. c=0;
  6373. loc = strstr(payload, "transactionId");
  6374. if(loc == NULL)
  6375. {
  6376. transactionIdIsNULL= TRUE;
  6377. }
  6378. else
  6379. {
  6380. memset(sstr ,0, sizeof(sstr) );
  6381. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6382. {
  6383. sstr[c] = loc[strlen("transactionId")+2+c];
  6384. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6385. c++;
  6386. }
  6387. sstr[c] = '\0';
  6388. transactionIdInt = atoi(sstr);
  6389. }
  6390. if(transactionIdIsNULL == FALSE)
  6391. {
  6392. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6393. {
  6394. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6395. {
  6396. //check Transaction active
  6397. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6398. {
  6399. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6400. {
  6401. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6402. {
  6403. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6404. {
  6405. match = TRUE;
  6406. GunNO = gun_index;
  6407. }
  6408. }
  6409. }// END FOR CHAdeMO_QUANTITY
  6410. for (int index = 0; index < CCS_QUANTITY; index++)
  6411. {
  6412. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6413. {
  6414. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6415. {
  6416. match = TRUE;
  6417. GunNO = gun_index;
  6418. }
  6419. }
  6420. }// END FOR CCS_QUANTITY
  6421. for (int index = 0; index < GB_QUANTITY; index++)
  6422. {
  6423. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6424. {
  6425. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6426. {
  6427. match = TRUE;
  6428. GunNO = gun_index;
  6429. }
  6430. }
  6431. }// END FOR GB_QUANTITY
  6432. }
  6433. else
  6434. {
  6435. for (int index = 0; index < AC_QUANTITY; index++)
  6436. {
  6437. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6438. {
  6439. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6440. {
  6441. match = TRUE;
  6442. GunNO = gun_index;
  6443. }
  6444. }
  6445. }// END FOR CHAdeMO_QUANTITY
  6446. }// END FOR AC ELSE
  6447. }// CHECK IF ResponseTransactionId == transactionIdInt
  6448. }//END FOR
  6449. if( match == TRUE)
  6450. {
  6451. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6452. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6453. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6454. }
  6455. else
  6456. {
  6457. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6458. }
  6459. }
  6460. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6461. return result;
  6462. }
  6463. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6464. {
  6465. mtrace();
  6466. int result = FAIL;
  6467. int connectorIdInt=0, reservationIdInt=0;
  6468. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6469. char comfirmstr[20]={0};
  6470. char sstr[180]={ 0 };
  6471. int c = 0;
  6472. char *loc;
  6473. //char *ptr;
  6474. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6475. //***(1)connectorId ****/
  6476. c=0;
  6477. loc = strstr(payload, "connectorId");
  6478. memset(sstr ,0, sizeof(sstr) );
  6479. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6480. {
  6481. sstr[c] = loc[strlen("connectorId")+2+c];
  6482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6483. c++;
  6484. }
  6485. sstr[c] = '\0';
  6486. connectorIdInt = atoi(sstr);
  6487. //***(2)expiryDate ****/
  6488. loc = strstr(payload, "expiryDate");
  6489. memset(sstr ,0, sizeof(sstr) );
  6490. c = 0;
  6491. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6492. {
  6493. sstr[c] = loc[3+strlen("expiryDate")+c];
  6494. c++;
  6495. }
  6496. sstr[c] = '\0';
  6497. strcpy(expiryDatestr, sstr);
  6498. //***(3)idTag ****/
  6499. loc = strstr(payload, "idTag");
  6500. memset(sstr ,0, sizeof(sstr) );
  6501. c = 0;
  6502. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6503. {
  6504. sstr[c] = loc[3+strlen("idTag")+c];
  6505. c++;
  6506. }
  6507. sstr[c] = '\0';
  6508. strcpy(idTagstr, sstr);
  6509. //***(4)parentIdTag ****/
  6510. loc = strstr(payload, "parentIdTag");
  6511. memset(sstr ,0, sizeof(sstr) );
  6512. c = 0;
  6513. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6514. {
  6515. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6516. c++;
  6517. }
  6518. sstr[c] = '\0';
  6519. strcpy(parentIdTagstr, sstr);
  6520. //***(5)reservationId ****/
  6521. c=0;
  6522. loc = strstr(payload, "reservationId");
  6523. memset(sstr ,0, sizeof(sstr) );
  6524. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6525. {
  6526. sstr[c] = loc[strlen("reservationId")+2+c];
  6527. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6528. c++;
  6529. }
  6530. sstr[c] = '\0';
  6531. reservationIdInt = atoi(sstr);
  6532. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6533. /*
  6534. enum _SYSTEM_STATUS
  6535. {
  6536. S_BOOTING = 0,
  6537. S_IDLE, = 1
  6538. S_AUTHORIZING, =2
  6539. S_REASSIGN_CHECK, =3
  6540. S_REASSIGN, =4
  6541. S_PRECHARGE, =5
  6542. S_PREPARING_FOR_EV, =6
  6543. S_PREPARING_FOR_EVSE, =7
  6544. S_CHARGING, =8
  6545. S_TERMINATING, =9
  6546. S_COMPLETE, =10
  6547. S_ALARM, =11
  6548. S_FAULT =12
  6549. }
  6550. */
  6551. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6552. {
  6553. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6554. goto end;
  6555. }
  6556. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6557. {
  6558. //check Transaction active
  6559. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6560. {
  6561. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6562. {
  6563. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6564. {
  6565. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6566. {
  6567. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6568. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6569. {
  6570. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6571. {
  6572. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6573. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6574. }
  6575. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6576. {
  6577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6578. }
  6579. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6580. {
  6581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6582. }
  6583. else
  6584. {
  6585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6586. }
  6587. }
  6588. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6589. {
  6590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6591. }
  6592. }
  6593. else
  6594. {
  6595. //replace reservation
  6596. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6597. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6598. }
  6599. }
  6600. } // END FOR CHAdeMO_QUANTITY
  6601. for (int index = 0; index < CCS_QUANTITY; index++)
  6602. {
  6603. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6604. {
  6605. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6606. {
  6607. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6608. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6609. {
  6610. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6611. {
  6612. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6614. }
  6615. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6616. {
  6617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6618. }
  6619. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6620. {
  6621. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6622. }
  6623. else
  6624. {
  6625. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6626. }
  6627. }
  6628. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6629. {
  6630. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6631. }
  6632. }
  6633. else
  6634. {
  6635. //replace reservation
  6636. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6638. }
  6639. }
  6640. } // END FOR CCS_QUANTITY
  6641. for (int index = 0; index < GB_QUANTITY; index++)
  6642. {
  6643. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6644. {
  6645. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6646. {
  6647. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6648. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6649. {
  6650. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6651. {
  6652. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6653. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6654. }
  6655. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6656. {
  6657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6658. }
  6659. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6660. {
  6661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6662. }
  6663. else
  6664. {
  6665. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6666. }
  6667. }
  6668. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6669. {
  6670. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6671. }
  6672. }
  6673. else
  6674. {
  6675. //replace reservation
  6676. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6677. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6678. }
  6679. }
  6680. }// END FOR GB_QUANTITY
  6681. }
  6682. else
  6683. {
  6684. for (int index = 0; index < AC_QUANTITY; index++)
  6685. {
  6686. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6687. {
  6688. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6689. {
  6690. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6691. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6692. {
  6693. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6694. {
  6695. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6697. }
  6698. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6699. {
  6700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6701. }
  6702. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6703. {
  6704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6705. }
  6706. else
  6707. {
  6708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6709. }
  6710. }
  6711. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6712. {
  6713. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6714. }
  6715. }
  6716. else
  6717. {
  6718. //replace reservation
  6719. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6721. }
  6722. }
  6723. } // END FOR AC_QUANTITY
  6724. }//END FOR AC ELSE
  6725. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6726. }
  6727. else if(connectorIdInt == 0)
  6728. {
  6729. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6730. {
  6731. //check Transaction active
  6732. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6733. {
  6734. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6735. {
  6736. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6737. {
  6738. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6739. goto end;
  6740. }
  6741. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6742. {
  6743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6744. goto end;
  6745. }
  6746. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6747. {
  6748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6749. goto end;
  6750. }
  6751. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6752. {
  6753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6754. goto end;
  6755. }
  6756. }
  6757. }// END FOR CHAdeMO_QUANTITY
  6758. for (int index = 0; index < CCS_QUANTITY; index++)
  6759. {
  6760. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6761. {
  6762. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6763. {
  6764. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6765. }
  6766. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6767. {
  6768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6769. }
  6770. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6771. {
  6772. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6773. }
  6774. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6775. {
  6776. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6777. }
  6778. }
  6779. } // END FOR CCS_QUANTITY
  6780. for (int index = 0; index < GB_QUANTITY; index++)
  6781. {
  6782. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6783. {
  6784. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6785. {
  6786. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6787. }
  6788. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6789. {
  6790. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6791. }
  6792. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6793. {
  6794. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6795. }
  6796. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6797. {
  6798. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6799. }
  6800. }
  6801. } // END FOR GB_QUANTITY
  6802. }
  6803. else
  6804. {
  6805. for (int index = 0; index < AC_QUANTITY; index++)
  6806. {
  6807. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6808. {
  6809. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6810. {
  6811. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6812. goto end;
  6813. }
  6814. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6815. {
  6816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6817. goto end;
  6818. }
  6819. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6820. {
  6821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6822. goto end;
  6823. }
  6824. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6825. {
  6826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6827. goto end;
  6828. }
  6829. }
  6830. }// END FOR AC_QUANTITY
  6831. }
  6832. //The connectorId is 0
  6833. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6835. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6836. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6837. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6838. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6839. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6840. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6841. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6842. result = TRUE;
  6843. return result;
  6844. }
  6845. else
  6846. {
  6847. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6848. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6849. }
  6850. if(strcmp(comfirmstr,"Accepted") == 0)
  6851. {
  6852. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6853. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6854. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6855. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6856. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6857. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6858. result = TRUE;
  6859. return result;
  6860. }
  6861. end:
  6862. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6863. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6864. return result;
  6865. }
  6866. int handleResetRequest(char *uuid, char *payload)
  6867. {
  6868. mtrace();
  6869. int result = FAIL;
  6870. char sstr[10]={0};
  6871. char typestr[10]={0};
  6872. char comfirmstr[20]={0};
  6873. int c = 0;
  6874. char *loc;
  6875. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6876. DEBUG_INFO("handleResetRequest ...\n");
  6877. loc = strstr(payload, "type");
  6878. memset(sstr ,0, sizeof(sstr) );
  6879. c = 0;
  6880. while (loc[3+strlen("type")+c] != '\"')
  6881. {
  6882. sstr[c] = loc[3+strlen("type")+c];
  6883. c++;
  6884. }
  6885. sstr[c] = '\0';
  6886. strcpy(typestr,sstr);
  6887. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6888. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6889. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6890. {
  6891. //check Transaction active
  6892. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6893. {
  6894. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6895. {
  6896. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6897. {
  6898. //0: unplug, 1: Plug-in
  6899. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6900. }
  6901. }
  6902. for (int index = 0; index < CCS_QUANTITY; index++)
  6903. {
  6904. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6905. {
  6906. //0: unplug, 1: Plug-in
  6907. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6908. }
  6909. }
  6910. for (int index = 0; index < GB_QUANTITY; index++)
  6911. {
  6912. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6913. {
  6914. //0: unplug, 1: Plug-in
  6915. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6916. }
  6917. }
  6918. }
  6919. else
  6920. {
  6921. for (int index = 0; index < AC_QUANTITY; index++)
  6922. {
  6923. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6924. {
  6925. //0: unplug, 1: Plug-in
  6926. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6927. }
  6928. }
  6929. }// END FOR AC ELSE
  6930. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6931. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6932. result = TRUE;
  6933. return result;
  6934. }
  6935. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6936. {
  6937. //check Transaction active
  6938. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6939. {
  6940. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6941. {
  6942. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6943. {
  6944. //0: unplug, 1: Plug-in
  6945. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6946. }
  6947. }
  6948. for (int index = 0; index < CCS_QUANTITY; index++)
  6949. {
  6950. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6951. {
  6952. //0: unplug, 1: Plug-in
  6953. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6954. }
  6955. }
  6956. for (int index = 0; index < GB_QUANTITY; index++)
  6957. {
  6958. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6959. {
  6960. //0: unplug, 1: Plug-in
  6961. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6962. }
  6963. }
  6964. }
  6965. else
  6966. {
  6967. for (int index = 0; index < AC_QUANTITY; index++)
  6968. {
  6969. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6970. {
  6971. //0: unplug, 1: Plug-in
  6972. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6973. }
  6974. }
  6975. }// END FOR AC ELSE
  6976. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6977. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6978. result = TRUE;
  6979. return result;
  6980. }
  6981. else
  6982. {
  6983. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6984. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6985. goto errorend;
  6986. }
  6987. errorend:
  6988. sendResetConfirmation(uuid, comfirmstr);
  6989. return result;
  6990. }
  6991. int handleSendLocalListRequest(char *uuid, char *payload)
  6992. {
  6993. mtrace();
  6994. int result = FAIL;
  6995. int listVersionInt;
  6996. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6997. char listsearch[]="listVersion";
  6998. char updateTypesearch[]="updateType";
  6999. char localAuthorizationListsearch[]="localAuthorizationList";
  7000. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  7001. char CardList[500][160]={0};
  7002. char updateTypestr[15]={0};
  7003. char idTagstr[20]={0};
  7004. char parentIdTag[20]={0};
  7005. char expiryDate[30]={0};
  7006. char idTagstatus[16]={0};
  7007. int c = 0;
  7008. int i = 0;
  7009. char *delim1 = "}";
  7010. char * pch;
  7011. char *loc;
  7012. //char *ptr;
  7013. char comfirmstr[20];
  7014. //int n_localAuthorizations = 0;
  7015. int checkState_Faulted = FALSE;
  7016. DEBUG_INFO("handleSendLocalListRequest\n");
  7017. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7018. {
  7019. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7020. goto end;
  7021. }
  7022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7023. {
  7024. //check Charge Point state
  7025. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7026. {
  7027. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7028. {
  7029. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7030. }
  7031. }
  7032. for (int index = 0; index < CCS_QUANTITY; index++)
  7033. {
  7034. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7035. {
  7036. checkState_Faulted = TRUE; //OCPP Status
  7037. }
  7038. }
  7039. for (int index = 0; index < GB_QUANTITY; index++)
  7040. {
  7041. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7042. {
  7043. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7044. }
  7045. }
  7046. }
  7047. else
  7048. {
  7049. //check Charge Point state
  7050. for (int index = 0; index < AC_QUANTITY; index++)
  7051. {
  7052. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7053. {
  7054. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7055. }
  7056. }
  7057. }// END FOR AC ELSE
  7058. if(checkState_Faulted == TRUE)
  7059. {
  7060. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7061. goto end;
  7062. }
  7063. //listVersion
  7064. c = 0;
  7065. loc = strstr(payload, listsearch);
  7066. while (loc[strlen("listVersion")+2+c] != ',')
  7067. {
  7068. sstr[c] = loc[strlen("listVersion")+2+c];
  7069. c++;
  7070. }
  7071. sstr[c] = '\0';
  7072. listVersionInt = atoi(sstr);
  7073. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7074. //updateType
  7075. loc = strstr(payload, updateTypesearch);
  7076. c = 0;
  7077. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7078. {
  7079. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7080. c++;
  7081. }
  7082. sstr[c] = '\0';
  7083. strcpy(updateTypestr, sstr);
  7084. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7085. //localAuthorizationList
  7086. memset(sstr ,0, sizeof(sstr) );
  7087. loc = strstr(payload, localAuthorizationListsearch);
  7088. if(loc != NULL) // localAuthorizationList is not NULL
  7089. {
  7090. //Check UpdateType
  7091. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7092. {
  7093. //Local list full update
  7094. printf("Local list full update.\n");
  7095. OCPP_cleanLocalList();
  7096. }
  7097. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7098. {
  7099. //Local list different update
  7100. printf("Local list different update.\n");
  7101. OCPP_getListVerion();
  7102. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7103. {
  7104. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7105. goto end;
  7106. }
  7107. }
  7108. else
  7109. {
  7110. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7111. goto end;
  7112. }
  7113. c = 0;
  7114. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7115. {
  7116. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7117. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7118. c++;
  7119. }
  7120. sstr[c] = '\0';
  7121. //parsing strings to words
  7122. i = 0;
  7123. pch = strtok(sstr,delim1);
  7124. while (pch != NULL)
  7125. {
  7126. strcpy(CardList[i], pch);
  7127. pch = strtok (NULL, delim1);
  7128. i = i + 1;
  7129. }
  7130. //local Authorizations List Numbers
  7131. //n_localAuthorizations = i;
  7132. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7133. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7134. c= 0;
  7135. while(c < i)
  7136. {
  7137. //Search "IdToken"
  7138. memset(sstr ,0, sizeof(sstr) );
  7139. loc = strstr(CardList[c], "idTag");
  7140. int j = 0;
  7141. while (loc[3+strlen("idTag")+j] != '\"')
  7142. {
  7143. sstr[j] = loc[3+strlen("idTag")+j];
  7144. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7145. j++;
  7146. }
  7147. sstr[j] = '\0';
  7148. strcpy(idTagstr, sstr);
  7149. //Search "expiryDate"
  7150. memset(sstr ,0, sizeof(sstr) );
  7151. loc = strstr(CardList[c], "expiryDate");
  7152. j = 0;
  7153. while (loc[3+strlen("expiryDate")+j] != '\"')
  7154. {
  7155. sstr[j] = loc[3+strlen("expiryDate")+j];
  7156. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7157. j++;
  7158. }
  7159. sstr[j] = '\0';
  7160. strcpy(expiryDate, sstr);
  7161. //Search "parentIdTag"
  7162. memset(sstr ,0, sizeof(sstr) );
  7163. loc = strstr(CardList[c], "parentIdTag");
  7164. j = 0;
  7165. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7166. {
  7167. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7168. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7169. j++;
  7170. }
  7171. sstr[j] = '\0';
  7172. strcpy(parentIdTag, sstr);
  7173. //Search "status"
  7174. memset(sstr ,0, sizeof(sstr) );
  7175. loc = strstr(CardList[c], "status");
  7176. j = 0;
  7177. while (loc[3+strlen("status")+j] != '\"')
  7178. {
  7179. sstr[j] = loc[3+strlen("status")+j];
  7180. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7181. j++;
  7182. }
  7183. sstr[j] = '\0';
  7184. strcpy(idTagstatus, sstr);
  7185. OCPP_getIdTag(idTagstr);
  7186. //OCPP_getIdTag("test"); For Test
  7187. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7188. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7189. {
  7190. //Local list full update
  7191. DEBUG_INFO("Local list full update.\n");
  7192. // update list
  7193. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7194. OCPP_get_TableAuthlocalAllData();
  7195. }
  7196. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7197. {
  7198. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7199. {
  7200. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7201. }
  7202. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7203. {
  7204. OCPP_deleteIdTag(idTagstr);
  7205. }
  7206. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7207. {
  7208. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7209. }
  7210. }
  7211. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7212. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7213. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7214. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7215. c++;
  7216. }
  7217. }
  7218. else
  7219. {
  7220. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7221. {
  7222. //Local list different update
  7223. DEBUG_INFO("Local list different update.\n");
  7224. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7225. goto end;
  7226. }
  7227. }
  7228. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7229. end:
  7230. sendSendLocalListConfirmation(uuid, comfirmstr);
  7231. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7232. #if 0
  7233. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7234. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7235. #endif
  7236. return result;
  7237. }
  7238. /*
  7239. enum _SYSTEM_STATUS
  7240. {
  7241. S_BOOTING = 0,
  7242. S_IDLE, =1
  7243. S_AUTHORIZING, =2
  7244. S_REASSIGN_CHECK, =3
  7245. S_REASSIGN, =4
  7246. S_PRECHARGE, =5
  7247. S_PREPARING_FOR_EV, =6
  7248. S_PREPARING_FOR_EVSE, =7
  7249. S_CHARGING, =8
  7250. S_TERMINATING, =9
  7251. S_COMPLETE, =10
  7252. S_ALARM, =11
  7253. S_FAULT =12
  7254. };
  7255. */
  7256. #define MAX 200
  7257. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7258. {
  7259. mtrace();
  7260. int result = FAIL;
  7261. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7262. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7263. char chargingProfilePurposeStr[30]={0};
  7264. char chargingProfileKindStr[16]={0};
  7265. char recurrencyKindStr[10]={0};
  7266. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7267. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7268. int chargingSchedulePeriodCount = 0;
  7269. //int updateflag = FALSE;
  7270. char comfirmstr[20]={0};
  7271. int meet= FALSE;
  7272. char sstr[10]={0};
  7273. int c = 0;
  7274. char *loc;
  7275. FILE *fptr1;//, *fptr2;
  7276. //int lno=0;//, linectr = 0;
  7277. //int modifyflag = FALSE;
  7278. char filename[MAX]={0};
  7279. char tempfile[] = "../Storage/OCPP/temp.json";
  7280. //int resultRename=0;
  7281. char rmFileCmd[50]={0};
  7282. char tempchargingProfilePurposeStr[30]={0};
  7283. //[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}}}]
  7284. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7285. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7286. //*********************connectorId***************************/
  7287. loc = strstr(payload, "connectorId");
  7288. c = 0;
  7289. memset(sstr ,0, sizeof(sstr) );
  7290. while (loc[strlen("connectorId")+2+c] != ',')
  7291. {
  7292. sstr[c] = loc[strlen("connectorId")+2+c];
  7293. c++;
  7294. }
  7295. sstr[c] = '\0';
  7296. connectorIdInt = atoi(sstr);
  7297. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7298. {
  7299. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7300. }
  7301. else
  7302. {
  7303. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7304. }
  7305. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7306. //*********************chargingProfileId***************************/
  7307. loc = strstr(payload, "chargingProfileId");
  7308. c = 0;
  7309. memset(sstr ,0, sizeof(sstr) );
  7310. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7311. {
  7312. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7313. c++;
  7314. }
  7315. sstr[c] = '\0';
  7316. chargingProfileIdInt = atoi(sstr);
  7317. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7318. {
  7319. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7320. }
  7321. else
  7322. {
  7323. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7324. }
  7325. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7326. //*********************transactionId***************************/
  7327. loc = strstr(payload, "transactionId");
  7328. if(loc != NULL)
  7329. {
  7330. c = 0;
  7331. memset(sstr ,0, sizeof(sstr) );
  7332. while (loc[strlen("transactionId")+2+c] != ',')
  7333. {
  7334. sstr[c] = loc[strlen("transactionId")+2+c];
  7335. c++;
  7336. }
  7337. sstr[c] = '\0';
  7338. transactionIdInt = atoi(sstr);
  7339. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7340. {
  7341. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7342. }
  7343. else
  7344. {
  7345. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7346. }
  7347. }
  7348. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7349. //*********************stackLevel***************************/
  7350. loc = strstr(payload, "stackLevel");
  7351. c = 0;
  7352. memset(sstr ,0, sizeof(sstr) );
  7353. while (loc[strlen("stackLevel")+2+c] != ',')
  7354. {
  7355. sstr[c] = loc[strlen("stackLevel")+2+c];
  7356. c++;
  7357. }
  7358. sstr[c] = '\0';
  7359. stackLevelInt = atoi(sstr);
  7360. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7361. {
  7362. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7363. }
  7364. else
  7365. {
  7366. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7367. }
  7368. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7369. //*********************chargingProfilePurpose***************************/
  7370. loc = strstr(payload, "chargingProfilePurpose");
  7371. c = 0;
  7372. memset(sstr ,0, sizeof(sstr) );
  7373. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7374. {
  7375. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7376. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7377. c++;
  7378. }
  7379. sstr[c] = '\0';
  7380. strcpy(chargingProfilePurposeStr,sstr);
  7381. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7382. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7383. {
  7384. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7385. }
  7386. else
  7387. {
  7388. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7389. }
  7390. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7391. //*********************chargingProfileKind***************************/
  7392. loc = strstr(payload, "chargingProfileKind");
  7393. c = 0;
  7394. memset(sstr ,0, sizeof(sstr) );
  7395. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7396. {
  7397. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7398. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7399. c++;
  7400. }
  7401. sstr[c] = '\0';
  7402. strcpy(chargingProfileKindStr,sstr);
  7403. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7404. {
  7405. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7406. }
  7407. else
  7408. {
  7409. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7410. }
  7411. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7412. //*********************recurrencyKind***************************/
  7413. loc = strstr(payload, "recurrencyKind");
  7414. if(loc != NULL)
  7415. {
  7416. c = 0;
  7417. memset(sstr ,0, sizeof(sstr) );
  7418. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7419. {
  7420. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7421. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7422. c++;
  7423. }
  7424. sstr[c] = '\0';
  7425. strcpy(recurrencyKindStr,sstr);
  7426. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7427. {
  7428. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7429. }
  7430. else
  7431. {
  7432. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7433. }
  7434. }
  7435. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7436. //*********************validFrom***************************/
  7437. loc = strstr(payload, "validFrom");
  7438. if(loc != NULL)
  7439. {
  7440. c = 0;
  7441. memset(sstr ,0, sizeof(sstr) );
  7442. while (loc[3+strlen("validFrom")+c] != '\"')
  7443. {
  7444. sstr[c] = loc[3+strlen("validFrom")+c];
  7445. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7446. c++;
  7447. }
  7448. sstr[c] = '\0';
  7449. strcpy(validFromStr,sstr);
  7450. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7451. {
  7452. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7453. }
  7454. else
  7455. {
  7456. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7457. }
  7458. }
  7459. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7460. //*********************validTo***************************/
  7461. loc = strstr(payload, "validTo");
  7462. if(loc != NULL)
  7463. {
  7464. c = 0;
  7465. memset(sstr ,0, sizeof(sstr) );
  7466. while (loc[3+strlen("validTo")+c] != '\"')
  7467. {
  7468. sstr[c] = loc[3+strlen("validTo")+c];
  7469. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7470. c++;
  7471. }
  7472. sstr[c] = '\0';
  7473. strcpy(validToStr,sstr);
  7474. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7475. {
  7476. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7477. }
  7478. else
  7479. {
  7480. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7481. }
  7482. }
  7483. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7484. //*********************duration***************************/
  7485. loc = strstr(payload, "duration");
  7486. if(loc != NULL)
  7487. {
  7488. c = 0;
  7489. memset(sstr ,0, sizeof(sstr) );
  7490. while (loc[strlen("duration")+2+c] != ',')
  7491. {
  7492. sstr[c] = loc[strlen("duration")+2+c];
  7493. c++;
  7494. }
  7495. sstr[c] = '\0';
  7496. durationInt = atoi(sstr);
  7497. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7498. {
  7499. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7500. }
  7501. else
  7502. {
  7503. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7504. }
  7505. }
  7506. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7507. //*********************startSchedule***************************/
  7508. loc = strstr(payload, "startSchedule");
  7509. if(loc != NULL)
  7510. {
  7511. c = 0;
  7512. memset(sstr ,0, sizeof(sstr) );
  7513. while (loc[3+strlen("startSchedule")+c] != '\"')
  7514. {
  7515. sstr[c] = loc[3+strlen("startSchedule")+c];
  7516. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7517. c++;
  7518. }
  7519. sstr[c] = '\0';
  7520. strcpy(startScheduleStr,sstr);
  7521. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7522. {
  7523. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7524. }
  7525. else
  7526. {
  7527. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7528. }
  7529. }
  7530. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7531. //*********************chargingRateUnit***************************/
  7532. loc = strstr(payload, "chargingRateUnit");
  7533. if(loc != NULL)
  7534. {
  7535. c = 0;
  7536. memset(sstr ,0, sizeof(sstr) );
  7537. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7538. {
  7539. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7540. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7541. c++;
  7542. }
  7543. sstr[c] = '\0';
  7544. strcpy(chargingRateUnitStr,sstr);
  7545. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7546. {
  7547. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7548. }
  7549. else
  7550. {
  7551. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7552. }
  7553. }
  7554. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7555. //****************chargingSchedulePeriod count start*******************/
  7556. int what_len = strlen("startPeriod");
  7557. char *where = payload;
  7558. if (what_len)
  7559. while ((where = strstr(where, "startPeriod"))) {
  7560. where += what_len;
  7561. chargingSchedulePeriodCount++;
  7562. }
  7563. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7564. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7565. where = payload;
  7566. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7567. {
  7568. //****************startPeriod*******************/
  7569. c=0;
  7570. loc = strstr(where, "startPeriod");
  7571. memset(sstr ,0, sizeof(sstr) );
  7572. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7573. {
  7574. sstr[c] = loc[strlen("startPeriod")+2+c];
  7575. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7576. c++;
  7577. }
  7578. sstr[c] = '\0';
  7579. startPeriodInt[periodNums] = atoi(sstr);
  7580. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7581. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7582. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7583. {
  7584. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7585. }
  7586. else
  7587. {
  7588. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7589. }
  7590. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7591. //****************limit*******************/
  7592. c=0;
  7593. loc = strstr(where, "limit");
  7594. memset(sstr ,0, sizeof(sstr) );
  7595. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7596. {
  7597. sstr[c] = loc[strlen("limit")+2+c];
  7598. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7599. c++;
  7600. }
  7601. sstr[c] = '\0';
  7602. limitflaot[periodNums] = atof(sstr);
  7603. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7604. {
  7605. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7606. }
  7607. else
  7608. {
  7609. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7610. }
  7611. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7612. //****************numberPhases*******************/
  7613. loc = strstr(where, "numberPhases");
  7614. if(loc != NULL)
  7615. {
  7616. c=0;
  7617. memset(sstr ,0, sizeof(sstr) );
  7618. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7619. {
  7620. sstr[c] = loc[strlen("numberPhases")+2+c];
  7621. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7622. c++;
  7623. }
  7624. sstr[c] = '\0';
  7625. numberPhasesInt[periodNums] = atoi(sstr);
  7626. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7627. {
  7628. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7629. }
  7630. else
  7631. {
  7632. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7633. }
  7634. }
  7635. where = loc;
  7636. }
  7637. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7638. //****************chargingSchedulePeriod count end*******************/
  7639. //*********************minChargingRate***************************/
  7640. loc = strstr(payload, "minChargingRate");
  7641. if(loc != NULL)
  7642. {
  7643. c = 0;
  7644. memset(sstr ,0, sizeof(sstr) );
  7645. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7646. {
  7647. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7648. c++;
  7649. }
  7650. sstr[c] = '\0';
  7651. minChargingRateFloat = atof(sstr);
  7652. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7653. {
  7654. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7655. }
  7656. else
  7657. {
  7658. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7659. }
  7660. }
  7661. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7662. {
  7663. //printf("set chargingProfile 1-2\n");
  7664. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7665. if(connectorIdInt != 0)
  7666. {
  7667. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7668. goto end;
  7669. }
  7670. strcpy(filename, ChargePointMaxProfile_JSON );
  7671. fptr1 = fopen(filename, "r");
  7672. if (!fptr1)
  7673. {
  7674. //file not exist
  7675. DEBUG_INFO("Unable to open the input file!!\n");
  7676. fptr1 = fopen(filename, "w+");
  7677. }
  7678. fclose(fptr1);
  7679. }
  7680. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7681. {
  7682. //printf("set chargingProfile 1-3\n");
  7683. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7684. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7685. {
  7686. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7687. goto end;
  7688. }
  7689. switch(connectorIdInt)
  7690. {
  7691. case 0:
  7692. strcpy(filename, TxDefaultProfile_0_JSON );
  7693. break;
  7694. case 1:
  7695. strcpy(filename, TxDefaultProfile_1_JSON );
  7696. break;
  7697. case 2:
  7698. strcpy(filename, TxDefaultProfile_2_JSON );
  7699. break;
  7700. default:
  7701. strcpy(filename, TxDefaultProfile_0_JSON );
  7702. break;
  7703. }
  7704. fptr1 = fopen(filename, "r");
  7705. if (!fptr1)
  7706. {
  7707. //file not exist
  7708. //DEBUG_INFO("Unable to open the input file!!\n");
  7709. fptr1 = fopen(filename, "w+");
  7710. }
  7711. fclose(fptr1);
  7712. }
  7713. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7714. {
  7715. //printf("set chargingProfile 1-4\n");
  7716. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7717. //check Transaction active
  7718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7719. {
  7720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7721. {
  7722. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7723. {
  7724. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7725. {
  7726. meet = TRUE;
  7727. break;
  7728. }
  7729. }
  7730. }
  7731. }
  7732. for (int index = 0; index < CCS_QUANTITY; index++)
  7733. {
  7734. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7735. {
  7736. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7737. {
  7738. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7739. {
  7740. meet = TRUE;
  7741. break;
  7742. }
  7743. }
  7744. }
  7745. }
  7746. for (int index = 0; index < GB_QUANTITY; index++)
  7747. {
  7748. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7749. {
  7750. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7751. {
  7752. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7753. {
  7754. meet = TRUE;
  7755. break;
  7756. }
  7757. }
  7758. }
  7759. }
  7760. if(meet == FALSE)
  7761. {
  7762. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7763. goto end;
  7764. }
  7765. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7766. {
  7767. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7768. goto end;
  7769. }
  7770. switch(connectorIdInt)
  7771. {
  7772. case 0:
  7773. break;
  7774. case 1:
  7775. strcpy(filename, TxProfile_1_JSON);
  7776. break;
  7777. case 2:
  7778. strcpy(filename, TxProfile_2_JSON);
  7779. break;
  7780. default:
  7781. strcpy(filename, TxProfile_1_JSON);
  7782. break;
  7783. }
  7784. fptr1 = fopen(filename, "r");
  7785. if (!fptr1)
  7786. {
  7787. //file not exist
  7788. DEBUG_INFO("Unable to open the input file!!\n");
  7789. fptr1 = fopen(filename, "w+");
  7790. }
  7791. fclose(fptr1);
  7792. }
  7793. //**********************************Write to File********************************************************/
  7794. FILE *infile;
  7795. FILE *outfile;
  7796. // open file for writing
  7797. infile = fopen (filename, "r");
  7798. outfile = fopen (tempfile, "w");
  7799. int d =0;
  7800. d = fgetc(infile);
  7801. //DEBUG_INFO("d:%d\n",d);
  7802. rewind(infile);
  7803. //*检测到文件结束标识返回1,否则返回0。*/
  7804. if(d == EOF)
  7805. {
  7806. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7807. fprintf(outfile,"%s\n",payload);
  7808. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7809. fclose(infile);
  7810. fclose(outfile);
  7811. sprintf(rmFileCmd,"rm -f %s",filename);
  7812. system(rmFileCmd);
  7813. rename(tempfile, filename);
  7814. #if 0
  7815. resultRename = rename(tempfile, filename);
  7816. if(resultRename == 0)
  7817. {
  7818. DEBUG_INFO("File chargingProfile renamed successfully");
  7819. }
  7820. else
  7821. {
  7822. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7823. }
  7824. #endif
  7825. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7826. //system(rmFileCmd);
  7827. }
  7828. else
  7829. {
  7830. char buf[1000]={0};
  7831. int ChargingProfileAdded = FALSE;
  7832. while (fgets(buf, sizeof(buf), infile) != NULL)
  7833. {
  7834. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7835. //*************************tempconnectorIdInt*********************************/
  7836. loc = strstr(buf, "connectorId");
  7837. c = 0;
  7838. memset(sstr ,0, sizeof(sstr) );
  7839. while (loc[strlen("connectorId")+2+c] != ',')
  7840. {
  7841. sstr[c] = loc[strlen("connectorId")+2+c];
  7842. c++;
  7843. }
  7844. sstr[c] = '\0';
  7845. tempconnectorIdInt = atoi(sstr);
  7846. //*************************tempchargingProfileIdInt*********************************/
  7847. loc = strstr(buf, "chargingProfileId");
  7848. c = 0;
  7849. memset(sstr ,0, sizeof(sstr) );
  7850. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7851. {
  7852. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7853. c++;
  7854. }
  7855. sstr[c] = '\0';
  7856. tempchargingProfileIdInt = atoi(sstr);
  7857. //*************************tempstackLevelInt*********************************/
  7858. loc = strstr(buf, "stackLevel");
  7859. c = 0;
  7860. memset(sstr ,0, sizeof(sstr) );
  7861. while (loc[strlen("stackLevel")+2+c] != ',')
  7862. {
  7863. sstr[c] = loc[strlen("stackLevel")+2+c];
  7864. c++;
  7865. }
  7866. sstr[c] = '\0';
  7867. tempstackLevelInt = atoi(sstr);
  7868. //*************************tempchargingProfilePurposeStr*********************************/
  7869. loc = strstr(payload, "chargingProfilePurpose");
  7870. c = 0;
  7871. memset(sstr ,0, sizeof(sstr) );
  7872. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7873. {
  7874. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7875. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7876. c++;
  7877. }
  7878. sstr[c] = '\0';
  7879. strcpy(tempchargingProfilePurposeStr,sstr);
  7880. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7881. {
  7882. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7883. {
  7884. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7885. if(ChargingProfileAdded == FALSE)
  7886. {
  7887. fprintf(outfile,"%s\n",payload);
  7888. ChargingProfileAdded = TRUE;
  7889. }
  7890. }
  7891. else
  7892. {
  7893. if(tempstackLevelInt < stackLevelInt)
  7894. {
  7895. if(ChargingProfileAdded == FALSE)
  7896. {
  7897. fprintf(outfile,"%s\n",payload);
  7898. ChargingProfileAdded = TRUE;
  7899. fprintf(outfile,"%s\n",buf);
  7900. }
  7901. else
  7902. {
  7903. fprintf(outfile,"%s\n",buf);
  7904. }
  7905. }
  7906. else
  7907. {
  7908. if(ChargingProfileAdded == FALSE)
  7909. {
  7910. fprintf(outfile,"%s\n",buf);
  7911. fprintf(outfile,"%s\n",payload);
  7912. ChargingProfileAdded = TRUE;
  7913. }
  7914. else
  7915. {
  7916. fprintf(outfile,"%s\n",buf);
  7917. }
  7918. }
  7919. }
  7920. }
  7921. else
  7922. {
  7923. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7924. {
  7925. if(ChargingProfileAdded == FALSE)
  7926. {
  7927. fprintf(outfile,"%s\n",payload);
  7928. ChargingProfileAdded = TRUE;
  7929. fprintf(outfile,"%s\n",buf);
  7930. }
  7931. else
  7932. {
  7933. fprintf(outfile,"%s\n",buf);
  7934. }
  7935. }
  7936. else if(tempstackLevelInt < stackLevelInt)
  7937. {
  7938. if(ChargingProfileAdded == FALSE)
  7939. {
  7940. fprintf(outfile,"%s\n",payload);
  7941. ChargingProfileAdded = TRUE;
  7942. fprintf(outfile,"%s\n",buf);
  7943. }
  7944. else
  7945. {
  7946. fprintf(outfile,"%s\n",buf);
  7947. }
  7948. }
  7949. else
  7950. {
  7951. if(ChargingProfileAdded == FALSE)
  7952. {
  7953. fprintf(outfile,"%s\n",buf);
  7954. fprintf(outfile,"%s\n",payload);
  7955. ChargingProfileAdded = TRUE;
  7956. }
  7957. else
  7958. {
  7959. fprintf(outfile,"%s\n",buf);
  7960. }
  7961. }
  7962. }
  7963. } // end of while loop
  7964. fclose(infile);
  7965. fclose(outfile);
  7966. sprintf(rmFileCmd,"rm -f %s",filename);
  7967. system(rmFileCmd);
  7968. rename(tempfile, filename);
  7969. #if 0
  7970. resultRename = rename(tempfile, filename);
  7971. if(resultRename == 0)
  7972. {
  7973. DEBUG_INFO("File chargingProfile renamed successfully");
  7974. }
  7975. else
  7976. {
  7977. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7978. }
  7979. #endif
  7980. result = TRUE;
  7981. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7982. }
  7983. end:
  7984. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7985. return result;
  7986. return result;
  7987. }
  7988. int handleTriggerMessageRequest(char *uuid, char *payload)
  7989. {
  7990. mtrace();
  7991. int result = FAIL;
  7992. int connectorIdIsNULL = FALSE;
  7993. int connectorIdInt =0;
  7994. char sstr[40]={0};
  7995. char requestedMessagestr[40]={0};
  7996. char comfirmstr[20]={0};
  7997. int c = 0;
  7998. char *loc;
  7999. DEBUG_INFO("handleTriggerMessageRequest\n");
  8000. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8001. c = 0;
  8002. loc = strstr(payload, "requestedMessage");
  8003. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8004. {
  8005. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8006. c++;
  8007. }
  8008. sstr[c] = '\0';
  8009. strcpy(requestedMessagestr, sstr);
  8010. c = 0;
  8011. loc = strstr(payload, "connectorId");
  8012. if(loc == NULL)
  8013. {
  8014. connectorIdIsNULL = TRUE;
  8015. }
  8016. else
  8017. {
  8018. memset(sstr ,0, sizeof(sstr) );
  8019. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8020. {
  8021. sstr[c] = loc[strlen("connectorId")+2+c];
  8022. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8023. c++;
  8024. }
  8025. sstr[c] = '\0';
  8026. connectorIdInt = atoi(sstr);
  8027. }
  8028. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8029. {
  8030. //connectorIdInt = json_object_get_int(connectorId);
  8031. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8032. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8033. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8034. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8035. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8036. }
  8037. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8038. {
  8039. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8040. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8041. return TRUE;
  8042. }
  8043. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8044. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8045. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8046. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8047. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8048. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8049. {
  8050. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8051. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8052. return TRUE;
  8053. }
  8054. else
  8055. {
  8056. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8057. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8058. }
  8059. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8060. {
  8061. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  8062. {
  8063. FirmwareStatusNotificationStatus = 3;
  8064. }
  8065. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8066. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8067. }
  8068. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8069. {
  8070. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8071. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8072. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8073. }
  8074. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8075. {
  8076. sendBootNotificationRequest();
  8077. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8078. }
  8079. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8080. {
  8081. sendHeartbeatRequest(connectorIdInt);
  8082. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8083. }
  8084. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8085. {
  8086. if(connectorIdIsNULL == FALSE)
  8087. {
  8088. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8089. {
  8090. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8091. sendMeterValuesRequest(connectorIdInt -1);
  8092. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8093. }
  8094. }
  8095. else
  8096. {
  8097. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8098. {
  8099. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8100. sendMeterValuesRequest(idx);
  8101. }
  8102. }
  8103. }
  8104. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8105. {
  8106. if(connectorIdIsNULL == FALSE)
  8107. {
  8108. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8109. {
  8110. sendStatusNotificationRequest(connectorIdInt -1);
  8111. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8112. }
  8113. }
  8114. else
  8115. {
  8116. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8117. sendStatusNotificationRequest(idx);
  8118. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8119. }
  8120. }
  8121. return result;
  8122. }
  8123. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8124. {
  8125. mtrace();
  8126. int result = FAIL;
  8127. char sstr[6]={0};
  8128. int connectorIdInt =0;
  8129. char comfirmstr[20]={0};
  8130. int c = 0;
  8131. char *loc;
  8132. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8133. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8134. c = 0;
  8135. loc = strstr(payload, "connectorId");
  8136. memset(sstr ,0, sizeof(sstr) );
  8137. while (loc[strlen("connectorId")+2+c] != '}')
  8138. {
  8139. sstr[c] = loc[strlen("connectorId")+2+c];
  8140. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8141. c++;
  8142. }
  8143. sstr[c] = '\0';
  8144. connectorIdInt = atoi(sstr);
  8145. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8146. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8147. {
  8148. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8149. goto end;
  8150. }
  8151. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8152. {
  8153. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8154. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8155. goto end;
  8156. }
  8157. else
  8158. {
  8159. //check Transaction active
  8160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8161. {
  8162. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8163. {
  8164. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8165. {
  8166. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8167. }
  8168. }
  8169. for (int index = 0; index < CCS_QUANTITY; index++)
  8170. {
  8171. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8172. {
  8173. //stop Transaction
  8174. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8175. }
  8176. }
  8177. for (int index = 0; index < GB_QUANTITY; index++)
  8178. {
  8179. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8180. {
  8181. //stop Transaction
  8182. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8183. }
  8184. }
  8185. }
  8186. else
  8187. {
  8188. for (int index = 0; index < AC_QUANTITY; index++)
  8189. {
  8190. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8191. {
  8192. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8193. }
  8194. }
  8195. }// END FOR AC ELSE
  8196. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8197. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8198. result = TRUE;
  8199. return result;
  8200. }
  8201. end:
  8202. //json_object_put(obj); --- remove temporally
  8203. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8204. return result;
  8205. }
  8206. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8207. {
  8208. mtrace();
  8209. int result = FAIL;
  8210. pthread_t t;
  8211. sendUpdateFirmwareConfirmation(uuid);
  8212. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8213. ////pthread_join(t, NULL); //
  8214. pthread_detach(t);
  8215. //sendUpdateFirmwareConfirmation(uuid);
  8216. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8217. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8218. return result;
  8219. }
  8220. void *UpdateFirmwareProcess(void *data)
  8221. {
  8222. mtrace();
  8223. int retriesInt =0, retryIntervalInt=0;
  8224. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8225. int port=0;
  8226. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8227. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8228. //char comfirmstr[20];
  8229. int isSuccess = 0;
  8230. char ftpbuf[200];
  8231. char temp[100];
  8232. char * pch;
  8233. int retriesISNULL=FALSE;
  8234. int retryInterval=FALSE;
  8235. int c = 0;
  8236. //int i = 0;
  8237. char *loc;
  8238. char sstr[300]={ 0 };
  8239. char *str = (char*) data; // ? ?輸入資 ?
  8240. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8241. //***************location **************/
  8242. loc = strstr(str, "location");
  8243. memset(sstr ,0, sizeof(sstr) );
  8244. c = 0;
  8245. while (loc[3+strlen("location")+c] != '\"')
  8246. {
  8247. sstr[c] = loc[3+strlen("location")+c];
  8248. c++;
  8249. }
  8250. sstr[c] = '\0';
  8251. strcpy(locationstr, sstr);
  8252. //***************retries**************/
  8253. c = 0;
  8254. loc = strstr(str, "retries");
  8255. if(loc == NULL)
  8256. {
  8257. retriesISNULL=TRUE;
  8258. }
  8259. else
  8260. {
  8261. memset(sstr ,0, sizeof(sstr) );
  8262. while (loc[strlen("retries")+2+c] != ',')
  8263. {
  8264. sstr[c] = loc[strlen("retries")+2+c];
  8265. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8266. c++;
  8267. }
  8268. sstr[c] = '\0';
  8269. }
  8270. if(retriesISNULL == FALSE)
  8271. {
  8272. retriesInt = atoi(sstr);
  8273. }
  8274. //***************retrieveDate **************/
  8275. loc = strstr(str, "retrieveDate");
  8276. memset(sstr ,0, sizeof(sstr) );
  8277. c = 0;
  8278. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8279. {
  8280. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8281. c++;
  8282. }
  8283. sstr[c] = '\0';
  8284. strcpy(retrieveDatestr, sstr);
  8285. //***************retryInterval **************/
  8286. c = 0;
  8287. loc = strstr(str, "retryInterval");
  8288. memset(sstr ,0, sizeof(sstr) );
  8289. if(loc == NULL)
  8290. {
  8291. retryInterval=TRUE;
  8292. }
  8293. else
  8294. {
  8295. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8296. {
  8297. sstr[c] = loc[strlen("retryInterval")+2+c];
  8298. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8299. c++;
  8300. }
  8301. sstr[c] = '\0';
  8302. }
  8303. if(retryInterval==FALSE)
  8304. {
  8305. retryIntervalInt = atoi(sstr);
  8306. }
  8307. memset(ftppath, 0, sizeof(ftppath));
  8308. memset(path, 0, sizeof(path));
  8309. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8310. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8311. if(strncmp(locationstr,"http", 4) == 0)
  8312. {
  8313. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8314. protocol, host, path);
  8315. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8316. // protocol, user, password, host, path);
  8317. sprintf(ftppath,"/%s", path);
  8318. DEBUG_INFO("protocol =%s\n",protocol);
  8319. DEBUG_INFO("host =%s\n",host);
  8320. DEBUG_INFO("path =%s\n",path);
  8321. DEBUG_INFO("ftppath=%s\n",ftppath);
  8322. int ftppathlen=strlen(ftppath);
  8323. int i=1;
  8324. char filenametemp[50];
  8325. while(i < ftppathlen)
  8326. {
  8327. int len=ftppathlen-i;
  8328. if(ftppath[len]== 47) // '/' ascll code: 47
  8329. {
  8330. DEBUG_INFO("compare '/' all right\n");
  8331. break;
  8332. }
  8333. i=i+1;
  8334. }
  8335. memset(filenametemp, 0, sizeof(filenametemp));
  8336. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8337. filenametemp[i+1] = 0;
  8338. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8339. do{
  8340. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8341. sleep(retryIntervalInt);
  8342. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8343. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8344. if(!isSuccess)
  8345. {
  8346. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8347. }
  8348. else
  8349. {
  8350. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8351. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8352. isUpdateRequest = TRUE;
  8353. }
  8354. }
  8355. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8356. {
  8357. memset(ftpbuf, 0, sizeof(ftpbuf));
  8358. memset(temp, 0, sizeof(temp));
  8359. DEBUG_INFO("locationstr=%s\n",locationstr);
  8360. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8361. int ftppathlen=strlen(ftpbuf);
  8362. int i=1;
  8363. char filenametemp[50];
  8364. while(i < ftppathlen)
  8365. {
  8366. int len=ftppathlen-i;
  8367. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8368. {
  8369. DEBUG_INFO(" compare '/' all right\n");
  8370. break;
  8371. }
  8372. i=i+1;
  8373. }
  8374. memset(filenametemp, 0, sizeof(filenametemp));
  8375. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8376. filenametemp[i+1] = 0;
  8377. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8378. pch=strchr(temp,'@');
  8379. if(pch==NULL)
  8380. {
  8381. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8382. protocol, host, &port, path);
  8383. strcpy(user,"anonymous");
  8384. strcpy(password,"");
  8385. }
  8386. else
  8387. {
  8388. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8389. protocol, user, password, host, &port, path);
  8390. }
  8391. sscanf(host,"%[^/]%s",host1, path1);
  8392. sprintf(ftppath,"%s", path1);
  8393. DEBUG_INFO("protocol =%s\n",protocol);
  8394. DEBUG_INFO("user =%s\n",user);
  8395. DEBUG_INFO("password =%s\n",password);
  8396. DEBUG_INFO("host1 =%s\n",host1);
  8397. DEBUG_INFO("port =%d\n",port);
  8398. DEBUG_INFO("path1 =%s\n",path1);
  8399. DEBUG_INFO("ftppath=%s\n",ftppath);
  8400. //ftpFile(host, user, password, port, ftppath, fname);
  8401. //download firmware pthred
  8402. if(port == 0)
  8403. {
  8404. port = 21;
  8405. }
  8406. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8407. do{
  8408. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8409. sleep(retryIntervalInt);
  8410. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8411. if(!isSuccess)
  8412. {
  8413. //BulldogUtil.sleepMs(interval*1000);
  8414. DEBUG_INFO("Update firmware request and download file fail.\n");
  8415. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8416. }
  8417. else
  8418. {
  8419. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8420. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8421. isUpdateRequest = TRUE;
  8422. }
  8423. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8424. }
  8425. else
  8426. {
  8427. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8428. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8429. }
  8430. pthread_exit(NULL);
  8431. }
  8432. //==========================================
  8433. // Handle server response routine
  8434. //==========================================
  8435. void handleAuthorizeResponse(char *payload, int gun_index)
  8436. {
  8437. mtrace();
  8438. char expiryDatestr[30]={0};
  8439. char parentIdTagstr[20]={0};
  8440. char statusstr[20]={0};
  8441. char expiryDatestrtemp[30]={0};
  8442. char parentIdTagstrtemp[20]={0};
  8443. char IdTagstrtemp[20]={0};
  8444. char statusstrtemp[20]={0};
  8445. int expiryDateISNULL=FALSE;
  8446. int parentIdTagISNULL=FALSE;
  8447. char sstr[160]={ 0 };
  8448. char* filename = AuthorizationCache_JSON;
  8449. char tempfile[] = "../Storage/OCPP/temp.json";
  8450. int c = 0;
  8451. char *loc;
  8452. int resultRename=0;
  8453. int responseIdTagInfoAsZero= 0;
  8454. char rmFileCmd[50]={0};
  8455. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8456. //***********expiryDate*************/
  8457. loc = strstr(payload, "expiryDate");
  8458. memset(sstr ,0, sizeof(sstr) );
  8459. c = 0;
  8460. if(loc == NULL)
  8461. {
  8462. expiryDateISNULL = TRUE;
  8463. }
  8464. else
  8465. {
  8466. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8467. {
  8468. sstr[c] = loc[3+strlen("expiryDate")+c];
  8469. c++;
  8470. }
  8471. sstr[c] = '\0';
  8472. strcpy(expiryDatestr, sstr);
  8473. }
  8474. //***********parentIdTag*************/
  8475. loc = strstr(payload, "parentIdTag");
  8476. memset(sstr ,0, sizeof(sstr) );
  8477. c = 0;
  8478. if(loc == NULL)
  8479. {
  8480. parentIdTagISNULL = TRUE;
  8481. }
  8482. else
  8483. {
  8484. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8485. {
  8486. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8487. c++;
  8488. }
  8489. sstr[c] = '\0';
  8490. strcpy(parentIdTagstr, sstr);
  8491. }
  8492. //***********status*************/
  8493. loc = strstr(payload, "status");
  8494. memset(sstr ,0, sizeof(sstr) );
  8495. c = 0;
  8496. while (loc[3+strlen("status")+c] != '\"')
  8497. {
  8498. sstr[c] = loc[3+strlen("status")+c];
  8499. c++;
  8500. }
  8501. sstr[c] = '\0';
  8502. strcpy(statusstr, sstr);
  8503. //#ifdef SystemLogMessage
  8504. // if(expiryDateISNULL == FALSE)
  8505. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8506. // if(parentIdTagISNULL == FALSE)
  8507. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8508. // DEBUG_INFO("status: %s\n", statusstr);
  8509. //#endif
  8510. if(expiryDateISNULL == FALSE)
  8511. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8512. if(parentIdTagISNULL == FALSE)
  8513. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8514. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8515. //Update idTag information to authorization cache if supproted
  8516. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8517. {
  8518. if((access(filename,F_OK))!=-1)
  8519. {
  8520. DEBUG_INFO("AuthorizationCache exist.\n");
  8521. }
  8522. else
  8523. {
  8524. DEBUG_INFO("AuthorizationCache not exist\n");
  8525. FILE *log = fopen(filename, "w+");
  8526. if(log == NULL)
  8527. {
  8528. DEBUG_INFO("log is NULL\n");
  8529. goto out;
  8530. }
  8531. else
  8532. {
  8533. fclose(log);
  8534. }
  8535. }
  8536. FILE *infile;
  8537. FILE *outfile;
  8538. // open file for writing
  8539. infile = fopen (filename, "r");
  8540. outfile = fopen (tempfile, "w");
  8541. //*检测到文件结束标识返回1,否则返回0。*/
  8542. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8543. int c;
  8544. c = fgetc(infile);
  8545. //DEBUG_INFO("c:%d\n",c);
  8546. rewind(infile);
  8547. if(c == EOF)
  8548. {
  8549. DEBUG_INFO("Orignal File is NULL\n");
  8550. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8551. {
  8552. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8553. }
  8554. else
  8555. {
  8556. strcpy(expiryDatestrtemp, "");
  8557. }
  8558. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8559. {
  8560. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8561. }
  8562. else
  8563. {
  8564. //write Authorize IdTag
  8565. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8566. }
  8567. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8568. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8569. fclose(infile);
  8570. fclose(outfile);
  8571. sprintf(rmFileCmd,"rm -f %s",filename);
  8572. system(rmFileCmd);
  8573. resultRename = rename(tempfile, filename);
  8574. if(resultRename == 0)
  8575. {
  8576. DEBUG_INFO("File renamed successfully");
  8577. }
  8578. else
  8579. {
  8580. DEBUG_INFO("Error: unable to rename the file");
  8581. }
  8582. }
  8583. else
  8584. {
  8585. char buf[160]={0};
  8586. //DEBUG_INFO("Orignal File is not NULL\n");
  8587. while (fgets(buf, sizeof(buf), infile) != NULL)
  8588. {
  8589. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8590. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8591. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8592. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8593. memset(statusstr, 0, sizeof(statusstrtemp));
  8594. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8595. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8596. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8597. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8598. //------------------IdTag-----------------------
  8599. loc = strstr(buf, "idTag");
  8600. memset(sstr ,0, sizeof(sstr) );
  8601. c = 0;
  8602. while (loc[3+strlen("idTag")+c] != '\"')
  8603. {
  8604. sstr[c] = loc[3+strlen("idTag")+c];
  8605. c++;
  8606. }
  8607. sstr[c] = '\0';
  8608. strcpy(IdTagstrtemp,sstr);
  8609. //*********************expiryDate***************/
  8610. loc = strstr(buf, "expiryDate");
  8611. memset(sstr ,0, sizeof(sstr) );
  8612. c = 0;
  8613. while (loc[3+strlen("expiryDate")+c] != '\"')
  8614. {
  8615. sstr[c] = loc[3+strlen("expiryDate")+c];
  8616. c++;
  8617. }
  8618. sstr[c] = '\0';
  8619. strcpy(expiryDatestr,sstr);
  8620. //*********************parentIdTag***************/
  8621. loc = strstr(buf, "parentIdTag");
  8622. memset(sstr ,0, sizeof(sstr) );
  8623. c = 0;
  8624. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8625. {
  8626. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8627. c++;
  8628. }
  8629. sstr[c] = '\0';
  8630. strcpy(parentIdTagstr,sstr);
  8631. //*********************status***************/
  8632. loc = strstr(buf, "status");
  8633. memset(sstr ,0, sizeof(sstr) );
  8634. c = 0;
  8635. while (loc[3+strlen("status")+c] != '\"')
  8636. {
  8637. sstr[c] = loc[3+strlen("status")+c];
  8638. c++;
  8639. }
  8640. sstr[c] = '\0';
  8641. strcpy(statusstr,sstr);
  8642. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8643. {
  8644. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8645. responseIdTagInfoAsZero = 1;
  8646. }
  8647. else
  8648. {
  8649. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8650. }
  8651. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8652. {
  8653. //modify item
  8654. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8655. {
  8656. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8657. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8658. }
  8659. else
  8660. {
  8661. strcpy(expiryDatestrtemp, "");
  8662. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8663. }
  8664. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8665. {
  8666. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8667. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8668. }
  8669. else
  8670. {
  8671. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8672. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8673. }
  8674. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8675. }
  8676. else
  8677. {
  8678. //wrie original item
  8679. strcpy(expiryDatestrtemp, expiryDatestr);
  8680. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8681. strcpy(statusstrtemp, statusstr);
  8682. }
  8683. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8684. }
  8685. fclose(infile);
  8686. fclose(outfile);
  8687. sprintf(rmFileCmd,"rm -f %s",filename);
  8688. system(rmFileCmd);
  8689. resultRename = rename(tempfile, filename);
  8690. if(resultRename == 0)
  8691. {
  8692. DEBUG_INFO("File renamed successfully");
  8693. }
  8694. else
  8695. {
  8696. DEBUG_INFO("Error: unable to rename the file");
  8697. }
  8698. }
  8699. }
  8700. out:
  8701. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8702. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8703. authorizeRetryTimes = 0;
  8704. }
  8705. void handleBootNotificationResponse(char *payload, int gun_index)
  8706. {
  8707. mtrace();
  8708. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8709. char statusStr[12]={0};
  8710. char currentTimeStr[30]={0};
  8711. char *loc;
  8712. int intervalInt = 0;
  8713. int c = 0;
  8714. //double diff_t;
  8715. struct tm tp;
  8716. char buf[28]={0};
  8717. char timebuf[50]={0};
  8718. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8719. //*** interval ****/
  8720. c = 0;
  8721. loc = strstr(payload, "interval");
  8722. //printf("loc=%s\n",loc);
  8723. memset(sstr ,0, sizeof(sstr) );
  8724. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8725. {
  8726. sstr[c] = loc[strlen("interval")+2+c];
  8727. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8728. c++;
  8729. }
  8730. sstr[c] = '\0';
  8731. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8732. intervalInt = atoi(sstr);
  8733. //***status ****/
  8734. loc = strstr(payload, "status");
  8735. memset(sstr ,0, sizeof(sstr) );
  8736. c = 0;
  8737. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8738. {
  8739. sstr[c] = loc[3+strlen("status")+c];
  8740. c++;
  8741. }
  8742. sstr[c] = '\0';
  8743. strcpy(statusStr, sstr);
  8744. //***currentTime ****/
  8745. loc = strstr(payload, "currentTime");
  8746. //printf("loc=%s\n",loc);
  8747. memset(sstr ,0, sizeof(sstr) );
  8748. c = 0;
  8749. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8750. {
  8751. sstr[c] = loc[3+strlen("currentTime")+c];
  8752. c++;
  8753. }
  8754. sstr[c] = '\0';
  8755. strcpy(currentTimeStr, sstr);
  8756. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8757. HeartBeatWaitTime = BootNotificationInterval;
  8758. //#ifdef SystemLogMessage
  8759. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8760. // DEBUG_INFO("interval: %d\n", intervalInt);
  8761. // DEBUG_INFO("status: %s\n", statusStr);
  8762. //#endif
  8763. //write back to ShmOCPP16Data->BootNotification
  8764. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8765. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8766. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8767. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8768. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8769. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8770. {
  8771. server_sign = TRUE;
  8772. server_pending =FALSE;
  8773. }
  8774. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8775. {
  8776. server_pending = TRUE;
  8777. }
  8778. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8779. tp.tm_isdst = -1;
  8780. //time_t utc = mktime(&tp);
  8781. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8782. memset(timebuf, 0, sizeof timebuf);
  8783. sprintf(timebuf,"date -s '%s'",buf);
  8784. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8785. system(timebuf);
  8786. //==============================================
  8787. // RTC sync
  8788. //==============================================
  8789. system("/sbin/hwclock -w --systohc");
  8790. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8791. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8792. }
  8793. void handleDataTransferResponse(char *payload, int gun_index)
  8794. {
  8795. char sstr[160]={0};//sstr[200]={ 0 };
  8796. int c = 0;
  8797. char *loc;
  8798. DEBUG_INFO("handleDataTransferResponse ...\n");
  8799. loc = strstr(payload, "status");
  8800. printf("loc=%s\n",loc);
  8801. c = 0;
  8802. while (loc[3+strlen("status")+c] != '\"')
  8803. {
  8804. sstr[c] = loc[3+strlen("status")+c];
  8805. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8806. c++;
  8807. }
  8808. sstr[c] = '\0';
  8809. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8810. //#ifdef SystemLogMessage
  8811. //DEBUG_INFO("data: %s\n", payload);
  8812. //#endif
  8813. }
  8814. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8815. {
  8816. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8817. //struct json_object *obj;
  8818. // obj = json_tokener_parse(payload);
  8819. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8820. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8821. //No fields are defined.
  8822. }
  8823. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8824. {
  8825. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8826. //struct json_object *obj;
  8827. // obj = json_tokener_parse(payload);
  8828. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8829. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8830. //No fields are defined.
  8831. }
  8832. void handleHeartbeatResponse(char *payload, int gun_index)
  8833. {
  8834. mtrace();
  8835. //double diff_t;
  8836. struct tm tp;
  8837. char buf[28]={0};
  8838. char timebuf[50]={0};
  8839. char sstr[30]={ 0 };
  8840. int c = 0;
  8841. char *loc;
  8842. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8843. if((HeartBeatCount%360) == 0)
  8844. {
  8845. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8846. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8847. }
  8848. HeartBeatCount = HeartBeatCount + 1;
  8849. c = 0;
  8850. loc = strstr(payload, "currentTime");
  8851. memset(sstr ,0, sizeof(sstr) );
  8852. while (loc[3+strlen("currentTime")+c] != '\"')
  8853. {
  8854. sstr[c] = loc[3+strlen("currentTime")+c];
  8855. c++;
  8856. }
  8857. sstr[c] = '\0';
  8858. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8859. // #ifdef SystemLogMessage
  8860. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8861. // #endif
  8862. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8863. tp.tm_isdst = -1;
  8864. //time_t utc = mktime(&tp);
  8865. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8866. memset(timebuf, 0, sizeof timebuf);
  8867. sprintf(timebuf,"date -s '%s'",buf);
  8868. system(timebuf);
  8869. //==============================================
  8870. // RTC sync
  8871. //==============================================
  8872. system("/sbin/hwclock -w --systohc");
  8873. if(FirstHeartBeat == 0)
  8874. {
  8875. FirstHeartBeat = 1;
  8876. }
  8877. HeartBeatWithNOResponse = 0;
  8878. }
  8879. void handleMeterValuesResponse(char *payload, int gun_index)
  8880. {
  8881. mtrace();
  8882. //struct json_object *obj;
  8883. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8884. //No fields are defined.
  8885. }
  8886. void handleStartTransactionResponse(char *payload, int gun_index)
  8887. {
  8888. mtrace();
  8889. char sstr[28]={ 0 };
  8890. int c = 0;
  8891. char *loc;
  8892. int transactionIdInt = 0;
  8893. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8894. DEBUG_INFO("handleStartTransactionResponse\n");
  8895. //****************expiryDate********************/
  8896. loc = strstr(payload, "expiryDate");
  8897. if(loc == NULL)
  8898. {
  8899. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8900. }
  8901. else
  8902. {
  8903. c = 0;
  8904. memset(sstr ,0, sizeof(sstr) );
  8905. while (loc[3+strlen("expiryDate")+c] != '\"')
  8906. {
  8907. sstr[c] = loc[3+strlen("expiryDate")+c];
  8908. c++;
  8909. }
  8910. sstr[c] = '\0';
  8911. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8912. }
  8913. //****************parentIdTag********************/
  8914. loc = strstr(payload, "parentIdTag");
  8915. if(loc == NULL)
  8916. {
  8917. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8918. }
  8919. else
  8920. {
  8921. c = 0;
  8922. memset(sstr ,0, sizeof(sstr) );
  8923. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8924. {
  8925. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8926. c++;
  8927. }
  8928. sstr[c] = '\0';
  8929. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8930. }
  8931. //****************status********************/
  8932. loc = strstr(payload, "status");
  8933. if(loc == NULL)
  8934. {
  8935. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8936. }
  8937. else
  8938. {
  8939. c = 0;
  8940. memset(sstr ,0, sizeof(sstr) );
  8941. while (loc[3+strlen("status")+c] != '\"')
  8942. {
  8943. sstr[c] = loc[3+strlen("status")+c];
  8944. c++;
  8945. }
  8946. sstr[c] = '\0';
  8947. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8948. }
  8949. //****************transactionId********************/
  8950. c=0;
  8951. loc = strstr(payload, "transactionId");
  8952. memset(sstr ,0, sizeof(sstr) );
  8953. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8954. {
  8955. sstr[c] = loc[strlen("transactionId")+2+c];
  8956. c++;
  8957. }
  8958. sstr[c] = '\0';
  8959. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8960. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8961. TransactionId[gun_index] = transactionIdInt;
  8962. DEBUG_INFO("gun_index: %d\n", gun_index);
  8963. DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  8964. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8965. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8966. #ifdef SystemLogMessage
  8967. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8968. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8969. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8970. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8971. #endif
  8972. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8973. {
  8974. //add Charging Record
  8975. SettingChargingRecord(gun_index, transactionIdInt);
  8976. }
  8977. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8978. }
  8979. void handleStatusNotificationResponse(char *payload, int gun_index)
  8980. {
  8981. mtrace();
  8982. printf("handleStatusNotificationResponse\n");
  8983. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8984. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8985. }
  8986. void handleStopTransactionnResponse(char *payload, int gun_index)
  8987. {
  8988. mtrace();
  8989. char sstr[30]={ 0 };
  8990. int c = 0;
  8991. char *loc;
  8992. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8993. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8994. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8995. loc = strstr(payload, "idTagInfo");
  8996. //***********************idTagInfo************************/
  8997. if(loc != NULL)
  8998. {
  8999. //***********************expiryDate************************/
  9000. loc = strstr(payload, "expiryDate");
  9001. if(loc != NULL)
  9002. {
  9003. memset(sstr ,0, sizeof(sstr) );
  9004. c = 0;
  9005. while (loc[3+strlen("expiryDate")+c] != '\"')
  9006. {
  9007. sstr[c] = loc[3+strlen("expiryDate")+c];
  9008. c++;
  9009. }
  9010. sstr[c] = '\0';
  9011. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  9012. }
  9013. //***********************parentIdTag************************/
  9014. loc = strstr(payload, "parentIdTag");
  9015. if(loc != NULL)
  9016. {
  9017. memset(sstr ,0, sizeof(sstr) );
  9018. c = 0;
  9019. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9020. {
  9021. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9022. c++;
  9023. }
  9024. sstr[c] = '\0';
  9025. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  9026. }
  9027. //***********************status************************/
  9028. loc = strstr(payload, "status");
  9029. memset(sstr ,0, sizeof(sstr) );
  9030. c = 0;
  9031. while (loc[3+strlen("status")+c] != '\"')
  9032. {
  9033. sstr[c] = loc[3+strlen("status")+c];
  9034. c++;
  9035. }
  9036. sstr[c] = '\0';
  9037. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  9038. }
  9039. #ifdef SystemLogMessage
  9040. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9041. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9042. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9043. #endif
  9044. }
  9045. //==========================================
  9046. // Handle Error routine
  9047. //==========================================
  9048. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9049. {
  9050. mtrace();
  9051. #ifdef SystemLogMessage
  9052. DEBUG_INFO("errorCode: %s\n", errorCode);
  9053. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9054. DEBUG_INFO("errorDetails: %s\n", payload);
  9055. #endif
  9056. }
  9057. //===============================================
  9058. // Common routine
  9059. //===============================================
  9060. int initialConfigurationTable(void)
  9061. {
  9062. printf("initialConfigurationTable \n");
  9063. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9064. /*Core Profile*/
  9065. //AllowOfflineTxForUnknownId
  9066. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9067. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9070. //AuthorizationCacheEnabled
  9071. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9074. //AuthorizeRemoteTxRequests
  9075. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9078. //BlinkRepeat
  9079. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9082. //ClockAlignedDataInterval
  9083. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9086. //ConnectionTimeOut
  9087. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  9090. //GetConfigurationMaxKeys
  9091. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9094. // HeartbeatInterval
  9095. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9098. // LightIntensity
  9099. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9102. // LocalAuthorizeOffline
  9103. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9106. // LocalPreAuthorize
  9107. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9110. // MaxEnergyOnInvalidId
  9111. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9114. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9115. // MeterValuesAlignedData
  9116. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9119. // MeterValuesAlignedDataMaxLength
  9120. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9123. // MeterValuesSampledData
  9124. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9127. // MeterValuesSampledDataMaxLength
  9128. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9131. // MeterValueSampleInterval
  9132. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9135. // MinimumStatusDuration
  9136. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9139. // NumberOfConnectors
  9140. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  9143. // ResetRetries
  9144. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9147. // ConnectorPhaseRotation
  9148. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9151. // ConnectorPhaseRotationMaxLength
  9152. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9155. // StopTransactionOnEVSideDisconnect
  9156. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9159. // StopTransactionOnInvalidId
  9160. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9163. // StopTxnAlignedData
  9164. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9167. // StopTxnAlignedDataMaxLength
  9168. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9171. // StopTxnSampledData
  9172. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9175. // StopTxnSampledDataMaxLength
  9176. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9179. // SupportedFeatureProfiles
  9180. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9183. // SupportedFeatureProfilesMaxLength
  9184. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9185. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9187. // TransactionMessageAttempts
  9188. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9191. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9192. // TransactionMessageRetryInterval
  9193. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9196. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9197. // UnlockConnectorOnEVSideDisconnect
  9198. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9201. // WebSocketPingInterval
  9202. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9205. //* Local Auth List Management Profile*/
  9206. #if 0
  9207. //For OCTT Test Case
  9208. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9211. #endif
  9212. #if 1
  9213. //LocalAuthListEnabled
  9214. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9217. #endif
  9218. //LocalAuthListMaxLength
  9219. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9222. //SendLocalListMaxLength
  9223. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9226. //ReserveConnectorZeroSupported
  9227. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9230. //* Smart Charging Profile */
  9231. //ChargeProfileMaxStackLevel
  9232. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9235. // ChargingScheduleAllowedChargingRateUnit
  9236. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9239. // ChargingScheduleMaxPeriods
  9240. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9241. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9243. // ConnectorSwitch3to1PhaseSupported
  9244. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9247. // MaxChargingProfilesInstalled
  9248. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9251. return 0;
  9252. }
  9253. void getKeyValue(char *keyReq)
  9254. {
  9255. int isEmpty = FALSE;
  9256. int isKnowKey = FALSE;
  9257. //int unKnowIndex = 0;
  9258. DEBUG_INFO("getKeyValue \n");
  9259. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9260. isEmpty = TRUE;
  9261. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9262. {
  9263. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9266. {
  9267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9268. }
  9269. else
  9270. {
  9271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9272. }
  9273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9274. isKnowKey = TRUE;
  9275. }
  9276. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9277. {
  9278. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9281. {
  9282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9283. }
  9284. else
  9285. {
  9286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9287. }
  9288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9289. isKnowKey = TRUE;
  9290. }
  9291. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9292. {
  9293. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9296. {
  9297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9298. }
  9299. else
  9300. {
  9301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9302. }
  9303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9304. isKnowKey = TRUE;
  9305. }
  9306. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9307. {
  9308. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9311. {
  9312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9313. }
  9314. else
  9315. {
  9316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9317. }
  9318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9319. isKnowKey = TRUE;
  9320. }
  9321. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9322. {
  9323. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9326. {
  9327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9328. }
  9329. else
  9330. {
  9331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9332. }
  9333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9334. isKnowKey = TRUE;
  9335. }
  9336. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9337. {
  9338. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9341. {
  9342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9343. }
  9344. else
  9345. {
  9346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9347. }
  9348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9349. isKnowKey = TRUE;
  9350. }
  9351. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9352. {
  9353. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9355. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9356. {
  9357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9358. }
  9359. else
  9360. {
  9361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9362. }
  9363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9364. isKnowKey = TRUE;
  9365. }
  9366. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9367. {
  9368. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9371. {
  9372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9373. }
  9374. else
  9375. {
  9376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9377. }
  9378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9379. isKnowKey = TRUE;
  9380. }
  9381. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9382. {
  9383. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9386. {
  9387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9388. }
  9389. else
  9390. {
  9391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9392. }
  9393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9394. isKnowKey = TRUE;
  9395. }
  9396. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9397. {
  9398. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9401. {
  9402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9403. }
  9404. else
  9405. {
  9406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9407. }
  9408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9409. isKnowKey = TRUE;
  9410. }
  9411. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9412. {
  9413. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9416. {
  9417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9418. }
  9419. else
  9420. {
  9421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9422. }
  9423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9424. isKnowKey = TRUE;
  9425. }
  9426. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9427. {
  9428. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9430. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9431. {
  9432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9433. }
  9434. else
  9435. {
  9436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9437. }
  9438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9439. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  9440. isKnowKey = TRUE;
  9441. }
  9442. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9443. {
  9444. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9446. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9447. {
  9448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9449. }
  9450. else
  9451. {
  9452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9453. }
  9454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9455. isKnowKey = TRUE;
  9456. }
  9457. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9458. {
  9459. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9461. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9462. {
  9463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9464. }
  9465. else
  9466. {
  9467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9468. }
  9469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9470. isKnowKey = TRUE;
  9471. }
  9472. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9473. {
  9474. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9477. {
  9478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9479. }
  9480. else
  9481. {
  9482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9483. }
  9484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9485. isKnowKey = TRUE;
  9486. }
  9487. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9488. {
  9489. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9491. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9492. {
  9493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9494. }
  9495. else
  9496. {
  9497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9498. }
  9499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9500. isKnowKey = TRUE;
  9501. }
  9502. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9503. {
  9504. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9507. {
  9508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9509. }
  9510. else
  9511. {
  9512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9513. }
  9514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9515. isKnowKey = TRUE;
  9516. }
  9517. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9518. {
  9519. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9521. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9522. {
  9523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9524. }
  9525. else
  9526. {
  9527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9528. }
  9529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9530. isKnowKey = TRUE;
  9531. }
  9532. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9533. {
  9534. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9537. {
  9538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9539. }
  9540. else
  9541. {
  9542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9543. }
  9544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9545. isKnowKey = TRUE;
  9546. }
  9547. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9548. {
  9549. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9552. {
  9553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9554. }
  9555. else
  9556. {
  9557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9558. }
  9559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9560. isKnowKey = TRUE;
  9561. }
  9562. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9563. {
  9564. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9565. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9566. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9567. {
  9568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9569. }
  9570. else
  9571. {
  9572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9573. }
  9574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9575. isKnowKey = TRUE;
  9576. }
  9577. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9578. {
  9579. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9581. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9582. {
  9583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9584. }
  9585. else
  9586. {
  9587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9588. }
  9589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9590. isKnowKey = TRUE;
  9591. }
  9592. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9593. {
  9594. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9597. {
  9598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9599. }
  9600. else
  9601. {
  9602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9603. }
  9604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9605. isKnowKey = TRUE;
  9606. }
  9607. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9608. {
  9609. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9612. {
  9613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9614. }
  9615. else
  9616. {
  9617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9618. }
  9619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9620. isKnowKey = TRUE;
  9621. }
  9622. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9623. {
  9624. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9626. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9627. {
  9628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9629. }
  9630. else
  9631. {
  9632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9633. }
  9634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9635. isKnowKey = TRUE;
  9636. }
  9637. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9638. {
  9639. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9642. {
  9643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9644. }
  9645. else
  9646. {
  9647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9648. }
  9649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9650. isKnowKey = TRUE;
  9651. }
  9652. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9653. {
  9654. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9657. {
  9658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9659. }
  9660. else
  9661. {
  9662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9663. }
  9664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9665. isKnowKey = TRUE;
  9666. }
  9667. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9668. {
  9669. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9672. {
  9673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9674. }
  9675. else
  9676. {
  9677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9678. }
  9679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9680. isKnowKey = TRUE;
  9681. }
  9682. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9683. {
  9684. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9686. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9687. {
  9688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9689. }
  9690. else
  9691. {
  9692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9693. }
  9694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9695. isKnowKey = TRUE;
  9696. }
  9697. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9698. {
  9699. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9702. {
  9703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9704. }
  9705. else
  9706. {
  9707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9708. }
  9709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9710. isKnowKey = TRUE;
  9711. }
  9712. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9713. {
  9714. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9716. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9717. {
  9718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9719. }
  9720. else
  9721. {
  9722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9723. }
  9724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9725. isKnowKey = TRUE;
  9726. }
  9727. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9728. {
  9729. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9731. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9732. {
  9733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9734. }
  9735. else
  9736. {
  9737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9738. }
  9739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9740. isKnowKey = TRUE;
  9741. }
  9742. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9743. {
  9744. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9746. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9747. {
  9748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9749. }
  9750. else
  9751. {
  9752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9753. }
  9754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9755. isKnowKey = TRUE;
  9756. }
  9757. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9758. {
  9759. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9762. {
  9763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9764. }
  9765. else
  9766. {
  9767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9768. }
  9769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9770. isKnowKey = TRUE;
  9771. }
  9772. #if 0
  9773. //For OCTT Test Case
  9774. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9775. {
  9776. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9778. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9779. {
  9780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9781. }
  9782. else
  9783. {
  9784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9785. }
  9786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9787. isKnowKey = TRUE;
  9788. }
  9789. #endif
  9790. #if 1
  9791. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9792. {
  9793. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9795. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9796. {
  9797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9798. }
  9799. else
  9800. {
  9801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9802. }
  9803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9804. isKnowKey = TRUE;
  9805. }
  9806. #endif
  9807. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9808. {
  9809. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9811. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9812. {
  9813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9814. }
  9815. else
  9816. {
  9817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9818. }
  9819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9820. isKnowKey = TRUE;
  9821. }
  9822. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9823. {
  9824. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9826. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9827. {
  9828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9829. }
  9830. else
  9831. {
  9832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9833. }
  9834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9835. isKnowKey = TRUE;
  9836. }
  9837. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9838. {
  9839. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9841. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9842. {
  9843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9844. }
  9845. else
  9846. {
  9847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9848. }
  9849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9850. isKnowKey = TRUE;
  9851. }
  9852. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9853. {
  9854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9856. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9857. {
  9858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9859. }
  9860. else
  9861. {
  9862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9863. }
  9864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9865. isKnowKey = TRUE;
  9866. }
  9867. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9868. {
  9869. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9871. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9872. {
  9873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9874. }
  9875. else
  9876. {
  9877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9878. }
  9879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9880. isKnowKey = TRUE;
  9881. }
  9882. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9883. {
  9884. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9886. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9887. {
  9888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9889. }
  9890. else
  9891. {
  9892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9893. }
  9894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9895. isKnowKey = TRUE;
  9896. }
  9897. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9898. {
  9899. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9901. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9902. {
  9903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9904. }
  9905. else
  9906. {
  9907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9908. }
  9909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9910. isKnowKey = TRUE;
  9911. }
  9912. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9913. {
  9914. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9916. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9917. {
  9918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9919. }
  9920. else
  9921. {
  9922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9923. }
  9924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9925. isKnowKey = TRUE;
  9926. }
  9927. //=========================================================
  9928. if(!isEmpty && !isKnowKey)
  9929. {
  9930. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9931. strcpy(unknownkey[UnknownKeynum], keyReq);
  9932. UnknownKeynum = UnknownKeynum + 1;
  9933. }
  9934. }
  9935. void processUnkownKey(void)
  9936. {
  9937. DEBUG_INFO("processUnkownKey\n");
  9938. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9939. for(int index=0; index < UnknownKeynum; index++)
  9940. {
  9941. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9942. {
  9943. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9944. }
  9945. }
  9946. }
  9947. int setKeyValue(char *key, char *value)
  9948. {
  9949. int isSuccess = NotSupported;
  9950. int check_ascii=0;
  9951. #ifdef Debug
  9952. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9953. #endif
  9954. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9955. {
  9956. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9958. {
  9959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9960. isSuccess = ConfigurationStatus_Accepted;
  9961. }
  9962. else
  9963. {
  9964. isSuccess = ConfigurationStatus_Rejected;
  9965. }
  9966. }
  9967. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9968. {
  9969. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9971. {
  9972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9973. isSuccess = ConfigurationStatus_Accepted;
  9974. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9975. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9976. }
  9977. else
  9978. {
  9979. isSuccess = ConfigurationStatus_Rejected;
  9980. }
  9981. }
  9982. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9983. {
  9984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9985. {
  9986. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9987. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9988. isSuccess = ConfigurationStatus_Accepted;
  9989. }
  9990. else
  9991. {
  9992. isSuccess = ConfigurationStatus_Rejected;
  9993. }
  9994. }
  9995. if(strcmp(key, "BlinkRepeat") == 0)
  9996. {
  9997. //Charger.BlinkRepeat = Integer.parseInt(value);
  9998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9999. {
  10000. check_ascii = value[0];
  10001. if( (check_ascii < 48) || (check_ascii > 57) )
  10002. {
  10003. isSuccess = ConfigurationStatus_Rejected;
  10004. }
  10005. else
  10006. {
  10007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  10008. isSuccess = ConfigurationStatus_Accepted;
  10009. }
  10010. }
  10011. else
  10012. {
  10013. isSuccess = ConfigurationStatus_Rejected;
  10014. }
  10015. }
  10016. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  10017. {
  10018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10019. {
  10020. check_ascii = value[0];
  10021. if( (check_ascii < 48) || (check_ascii > 57) )
  10022. {
  10023. isSuccess = ConfigurationStatus_Rejected;
  10024. }
  10025. else
  10026. {
  10027. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  10028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  10029. isSuccess = ConfigurationStatus_Accepted;
  10030. }
  10031. }
  10032. else
  10033. {
  10034. isSuccess = ConfigurationStatus_Rejected;
  10035. }
  10036. }
  10037. if(strcmp(key, "ConnectionTimeOut") == 0 )
  10038. {
  10039. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10040. {
  10041. check_ascii = value[0];
  10042. if( (check_ascii < 48) || (check_ascii > 57) )
  10043. {
  10044. isSuccess = ConfigurationStatus_Rejected;
  10045. }
  10046. else
  10047. {
  10048. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  10049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  10050. isSuccess = ConfigurationStatus_Accepted;
  10051. }
  10052. }
  10053. else
  10054. {
  10055. isSuccess = ConfigurationStatus_Rejected;
  10056. }
  10057. }
  10058. if(strcmp(key, "HeartbeatInterval") == 0)
  10059. {
  10060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10061. {
  10062. check_ascii = value[0];
  10063. if( (check_ascii < 48) || (check_ascii > 57) )
  10064. {
  10065. isSuccess = ConfigurationStatus_Rejected;
  10066. }
  10067. else
  10068. {
  10069. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  10071. HeartBeatWaitTime = atoi(value);
  10072. isSuccess = ConfigurationStatus_Accepted;
  10073. }
  10074. }
  10075. else
  10076. {
  10077. isSuccess = ConfigurationStatus_Rejected;
  10078. }
  10079. }
  10080. if(strcmp(key, "LightIntensity") == 0)
  10081. {
  10082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10083. {
  10084. check_ascii = value[0];
  10085. if( (check_ascii < 48) || (check_ascii > 57) )
  10086. {
  10087. isSuccess = ConfigurationStatus_Rejected;
  10088. }
  10089. else
  10090. {
  10091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10092. isSuccess = ConfigurationStatus_Accepted;
  10093. }
  10094. }
  10095. else
  10096. {
  10097. isSuccess = ConfigurationStatus_Rejected;
  10098. }
  10099. }
  10100. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10101. {
  10102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10103. {
  10104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10105. isSuccess = ConfigurationStatus_Accepted;
  10106. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10107. }
  10108. else
  10109. {
  10110. isSuccess = ConfigurationStatus_Rejected;
  10111. }
  10112. }
  10113. if(strcmp(key, "LocalPreAuthorize") == 0)
  10114. {
  10115. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10116. {
  10117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10118. isSuccess = ConfigurationStatus_Accepted;
  10119. }
  10120. else
  10121. {
  10122. isSuccess = ConfigurationStatus_Rejected;
  10123. }
  10124. }
  10125. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10126. {
  10127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10128. {
  10129. check_ascii = value[0];
  10130. if( (check_ascii < 48) || (check_ascii > 57) )
  10131. {
  10132. isSuccess = ConfigurationStatus_Rejected;
  10133. }
  10134. else
  10135. {
  10136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10137. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  10138. isSuccess = ConfigurationStatus_Accepted;
  10139. }
  10140. }
  10141. else
  10142. {
  10143. isSuccess = ConfigurationStatus_Rejected;
  10144. }
  10145. }
  10146. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10147. {
  10148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10149. {
  10150. //int valueLength = strlen(value);
  10151. for(int i = 0; value[i]; i++){
  10152. value[i] = tolower(value[i]);
  10153. }
  10154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10155. isSuccess = ConfigurationStatus_Accepted;
  10156. }
  10157. else
  10158. {
  10159. isSuccess = ConfigurationStatus_Rejected;
  10160. }
  10161. }
  10162. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10163. {
  10164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10165. {
  10166. //int valueLength = strlen(value);
  10167. for(int i = 0; value[i]; i++){
  10168. value[i] = tolower(value[i]);
  10169. }
  10170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10171. isSuccess = ConfigurationStatus_Accepted;
  10172. }
  10173. else
  10174. {
  10175. isSuccess = ConfigurationStatus_Rejected;
  10176. }
  10177. }
  10178. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10179. {
  10180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10181. {
  10182. check_ascii = value[0];
  10183. if( (check_ascii < 48) || (check_ascii > 57) )
  10184. {
  10185. isSuccess = ConfigurationStatus_Rejected;
  10186. }
  10187. else
  10188. {
  10189. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10191. isSuccess = ConfigurationStatus_Accepted;
  10192. }
  10193. #ifdef Debug
  10194. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10195. #endif
  10196. }
  10197. else
  10198. {
  10199. isSuccess = ConfigurationStatus_Rejected;
  10200. #ifdef Debug
  10201. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10202. #endif
  10203. }
  10204. }
  10205. if(strcmp(key, "MinimumStatusDuration") == 0)
  10206. {
  10207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].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.MinimumStatusDuration = Integer.parseInt(value);
  10217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10218. isSuccess = ConfigurationStatus_Accepted;
  10219. }
  10220. }
  10221. else
  10222. {
  10223. isSuccess = ConfigurationStatus_Rejected;
  10224. }
  10225. }
  10226. if(strcmp(key, "ResetRetries") == 0)
  10227. {
  10228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10229. {
  10230. check_ascii = value[0];
  10231. if( (check_ascii < 48) || (check_ascii > 57) )
  10232. {
  10233. isSuccess = ConfigurationStatus_Rejected;
  10234. }
  10235. else
  10236. {
  10237. //Charger.ResetRetries = Integer.parseInt(value);
  10238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10239. isSuccess = ConfigurationStatus_Accepted;
  10240. }
  10241. }
  10242. else
  10243. {
  10244. isSuccess = ConfigurationStatus_Rejected;
  10245. }
  10246. }
  10247. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10248. {
  10249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10250. {
  10251. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10252. //int valueLength = strlen(value);
  10253. for(int i = 0; value[i]; i++){
  10254. value[i] = tolower(value[i]);
  10255. }
  10256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10257. isSuccess = ConfigurationStatus_Accepted;
  10258. }
  10259. else
  10260. {
  10261. isSuccess = ConfigurationStatus_Rejected;
  10262. }
  10263. }
  10264. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10265. {
  10266. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10267. {
  10268. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10270. isSuccess = ConfigurationStatus_Accepted;
  10271. }
  10272. else
  10273. {
  10274. isSuccess = ConfigurationStatus_Rejected;
  10275. }
  10276. }
  10277. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10278. {
  10279. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10280. {
  10281. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10283. isSuccess = ConfigurationStatus_Accepted;
  10284. }
  10285. else
  10286. {
  10287. isSuccess = ConfigurationStatus_Rejected;
  10288. }
  10289. }
  10290. if(strcmp(key, "StopTxnAlignedData") == 0)
  10291. {
  10292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10293. {
  10294. //Charger.StopTxnAlignedData = value.toLowerCase();
  10295. //int valueLength = strlen(value);
  10296. for(int i = 0; value[i]; i++){
  10297. value[i] = tolower(value[i]);
  10298. }
  10299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10300. isSuccess = ConfigurationStatus_Accepted;
  10301. }
  10302. else
  10303. {
  10304. isSuccess = ConfigurationStatus_Rejected;
  10305. }
  10306. }
  10307. if(strcmp(key, "StopTxnSampledData") == 0)
  10308. {
  10309. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10310. {
  10311. //Charger.StopTxnSampledData = value.toLowerCase();
  10312. //int valueLength = strlen(value);
  10313. for(int i = 0; value[i]; i++){
  10314. value[i] = tolower(value[i]);
  10315. }
  10316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10317. isSuccess = ConfigurationStatus_Accepted;
  10318. }
  10319. else
  10320. {
  10321. isSuccess = ConfigurationStatus_Rejected;
  10322. }
  10323. }
  10324. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10325. {
  10326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10327. {
  10328. check_ascii = value[0];
  10329. if( (check_ascii < 48) || (check_ascii > 57) )
  10330. {
  10331. isSuccess = ConfigurationStatus_Rejected;
  10332. }
  10333. else
  10334. {
  10335. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10337. TransactionMessageAttemptsValue = atoi(value);
  10338. isSuccess = ConfigurationStatus_Accepted;
  10339. }
  10340. }
  10341. else
  10342. {
  10343. isSuccess = ConfigurationStatus_Rejected;
  10344. }
  10345. }
  10346. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10347. {
  10348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10349. {
  10350. check_ascii = value[0];
  10351. if( (check_ascii < 48) || (check_ascii > 57) )
  10352. {
  10353. isSuccess = ConfigurationStatus_Rejected;
  10354. }
  10355. else
  10356. {
  10357. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10359. TransactionMessageRetryIntervalValue = atoi(value);
  10360. isSuccess = ConfigurationStatus_Accepted;
  10361. }
  10362. }
  10363. else
  10364. {
  10365. isSuccess = ConfigurationStatus_Rejected;
  10366. }
  10367. }
  10368. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10369. {
  10370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10371. {
  10372. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10373. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10374. isSuccess = ConfigurationStatus_Accepted;
  10375. }
  10376. else
  10377. {
  10378. isSuccess = ConfigurationStatus_Rejected;
  10379. }
  10380. }
  10381. if(strcmp(key, "WebSocketPingInterval") == 0)
  10382. {
  10383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10384. {
  10385. check_ascii = value[0];
  10386. if( (check_ascii < 48) || (check_ascii > 57) )
  10387. {
  10388. isSuccess = ConfigurationStatus_Rejected;
  10389. }
  10390. else
  10391. {
  10392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10393. isSuccess = ConfigurationStatus_Accepted;
  10394. }
  10395. }
  10396. else
  10397. {
  10398. isSuccess = ConfigurationStatus_Rejected;
  10399. }
  10400. }
  10401. #if 0
  10402. //For OCPP Test Case
  10403. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10404. {
  10405. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10406. {
  10407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10408. isSuccess = ConfigurationStatus_Accepted;
  10409. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10410. }
  10411. else
  10412. {
  10413. isSuccess = ConfigurationStatus_Rejected;
  10414. }
  10415. }
  10416. #endif
  10417. #if 1
  10418. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10419. {
  10420. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10421. {
  10422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10423. isSuccess = ConfigurationStatus_Accepted;
  10424. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10425. }
  10426. else
  10427. {
  10428. isSuccess = ConfigurationStatus_Rejected;
  10429. }
  10430. }
  10431. #endif
  10432. return isSuccess;
  10433. }
  10434. int updateSetting(char *key, char *value)
  10435. {
  10436. mtrace();
  10437. int isSuccess = FALSE;
  10438. char string[1000]={0}, buffer[1000]={0};
  10439. char strtemp[50]={0};
  10440. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10441. int pos, c = 0;
  10442. char *loc;
  10443. int pos1=0;
  10444. FILE *f = fopen("/var/www/settings1", "r");
  10445. if(f == NULL)
  10446. {
  10447. #ifdef Debug
  10448. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10449. #endif
  10450. return isSuccess;
  10451. }
  10452. fseek(f, 0, SEEK_END);
  10453. long fsize = ftell(f);
  10454. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10455. fread(string, 1, fsize, f);
  10456. fclose(f);
  10457. string[fsize] = 0;
  10458. loc = strstr(string, key);
  10459. if(loc != NULL)
  10460. {
  10461. DEBUG_INFO("key exist!\n");
  10462. pos = loc - string-1;
  10463. f = fopen("/var/www/settings1", "w");
  10464. strncpy(buffer, string, pos);
  10465. fprintf(f, "%s", buffer);
  10466. memset(sstr ,0, sizeof(sstr) );
  10467. c = 0;
  10468. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10469. {
  10470. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10471. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10472. c++;
  10473. }
  10474. sstr[c] = '\0';
  10475. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10476. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10477. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10478. memset(buffer ,0, sizeof(buffer) );
  10479. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10480. //printf("buffer=%s",buffer);
  10481. fprintf(f, "%s", buffer);
  10482. fclose(f);
  10483. }
  10484. else
  10485. {
  10486. printf("key not exist!\n");
  10487. f = fopen("/var/www/settings1", "w+");
  10488. fputs(string, f);
  10489. fseek(f, -1, SEEK_CUR);
  10490. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10491. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10492. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10493. fclose(f);
  10494. }
  10495. isSuccess = TRUE;
  10496. return isSuccess;
  10497. }
  10498. int TransactionMessageAttemptsGet(void)
  10499. {
  10500. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10501. }
  10502. int FirstHeartBeatResponse(void)
  10503. {
  10504. return FirstHeartBeat;
  10505. }
  10506. int TransactionMessageRetryIntervalGet(void)
  10507. {
  10508. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10509. }
  10510. #define SA struct sockaddr
  10511. #define MAXBUF 1024
  10512. //static int m_socket_data;
  10513. //static int sockfd;
  10514. int ReadHttpStatus(int sock){
  10515. //char c;
  10516. char buff[1024]="",*ptr=buff+1;
  10517. int bytes_received, status;
  10518. DEBUG_INFO("Begin Response ..\n");
  10519. while((bytes_received = recv(sock, ptr, 1, 0))){
  10520. if(bytes_received==-1){
  10521. perror("ReadHttpStatus");
  10522. exit(1);
  10523. }
  10524. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10525. ptr++;
  10526. }
  10527. *ptr=0;
  10528. ptr=buff+1;
  10529. sscanf(ptr,"%*s %d ", &status);
  10530. DEBUG_INFO("%s\n",ptr);
  10531. DEBUG_INFO("status=%d\n",status);
  10532. DEBUG_INFO("End Response ..\n");
  10533. return (bytes_received>0)?status:0;
  10534. }
  10535. //the only filed that it parsed is 'Content-Length'
  10536. int ParseHeader(int sock){
  10537. //char c;
  10538. char buff[1024]="",*ptr=buff+4;
  10539. int bytes_received;
  10540. DEBUG_INFO("Begin HEADER ..\n");
  10541. while((bytes_received = recv(sock, ptr, 1, 0))){
  10542. if(bytes_received==-1){
  10543. perror("Parse Header");
  10544. exit(1);
  10545. }
  10546. if(
  10547. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10548. (ptr[-1]=='\r') && (*ptr=='\n' )
  10549. ) break;
  10550. ptr++;
  10551. }
  10552. *ptr=0;
  10553. ptr=buff+4;
  10554. //printf("%s",ptr);
  10555. if(bytes_received){
  10556. ptr=strstr(ptr,"Content-Length:");
  10557. if(ptr){
  10558. sscanf(ptr,"%*s %d",&bytes_received);
  10559. }else
  10560. bytes_received=-1; //unknown size
  10561. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10562. }
  10563. DEBUG_INFO("End HEADER ..\n");
  10564. return bytes_received ;
  10565. }
  10566. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10567. {
  10568. char rmFileCmd[100]={0};
  10569. char FilePath[100]={0};
  10570. char ftpbuf[200];
  10571. int systemresult;
  10572. DEBUG_INFO("filename=%s\n",filename);
  10573. DEBUG_INFO("url=%s\n",url);
  10574. sprintf(FilePath,"../mnt/%s",filename);
  10575. if((access(FilePath,F_OK))!=-1)
  10576. {
  10577. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10578. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10579. system(rmFileCmd);
  10580. }
  10581. memset(ftpbuf, 0, sizeof(ftpbuf));
  10582. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10583. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10584. systemresult = system(ftpbuf);
  10585. DEBUG_INFO("systemresult=%d\n",systemresult);
  10586. if(systemresult != 0)
  10587. {
  10588. DEBUG_INFO("http DownLoad error!\n");
  10589. return FALSE;
  10590. }
  10591. return TRUE;
  10592. }
  10593. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10594. {
  10595. char rmFileCmd[100]={0};
  10596. char FilePath[100]={0};
  10597. char ftpbuf[200];
  10598. int systemresult;
  10599. //char temp[100];
  10600. #if 0
  10601. struct hostent* server;
  10602. char *IPbuffer;
  10603. server = gethostbyname(location);
  10604. // To convert an Internet network
  10605. // address into ASCII string
  10606. IPbuffer = inet_ntoa(*((struct in_addr*)
  10607. server->h_addr_list[0]));
  10608. #endif
  10609. sprintf(FilePath,"../mnt/%s",filename);
  10610. if((access(FilePath,F_OK))!=-1)
  10611. {
  10612. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10613. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10614. system(rmFileCmd);
  10615. }
  10616. memset(ftpbuf, 0, sizeof(ftpbuf));
  10617. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10618. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10619. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10620. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10621. systemresult = system(ftpbuf);
  10622. DEBUG_INFO("systemresult=%d\n",systemresult);
  10623. if(systemresult != 0)
  10624. {
  10625. printf("ftpget error!\n");
  10626. return FALSE;
  10627. }
  10628. return TRUE;
  10629. }
  10630. int httpUploadFile(char *location, char *path, char *filename,char *url)
  10631. {
  10632. char rmFileCmd[100]={0};
  10633. char FilePath[100]={0};
  10634. char ftpbuf[200];
  10635. int systemresult;
  10636. DEBUG_INFO("filename=%s\n",filename);
  10637. DEBUG_INFO("url=%s\n",url);
  10638. sprintf(FilePath,"%s","../mnt/upload_file.txt");
  10639. if((access(FilePath,F_OK))!=-1)
  10640. {
  10641. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10642. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10643. system(rmFileCmd);
  10644. }
  10645. FILE *fp = fopen("../mnt/upload_file.txt", "w+");
  10646. if(fp == NULL)
  10647. {
  10648. DEBUG_INFO("log is NULL\n");
  10649. return 0;
  10650. }
  10651. else
  10652. {
  10653. fprintf(fp, "%s\n", url);
  10654. fprintf(fp, "%s\n", filename);
  10655. fclose(fp);
  10656. }
  10657. memset(ftpbuf, 0, sizeof(ftpbuf));
  10658. sprintf(ftpbuf, "%s","../bin/php-cgi /var/www/ocpp_upload.php");
  10659. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10660. systemresult = system(ftpbuf);
  10661. DEBUG_INFO("systemresult=%d\n",systemresult);
  10662. if(systemresult != 0)
  10663. {
  10664. DEBUG_INFO("http DownLoad error!\n");
  10665. return FALSE;
  10666. }
  10667. return TRUE;
  10668. }
  10669. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10670. {
  10671. struct hostent* server;
  10672. char *IPbuffer;
  10673. char ftpbuf[200];
  10674. int systemresult;
  10675. // To retrieve host information
  10676. server = gethostbyname(location);
  10677. // To convert an Internet network
  10678. // address into ASCII string
  10679. IPbuffer = inet_ntoa(*((struct in_addr*)
  10680. server->h_addr_list[0]));
  10681. memset(ftpbuf, 0, sizeof(ftpbuf));
  10682. /* format : ftpput -u username -p passwd IP target source*/
  10683. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10684. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10685. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10686. systemresult = system(ftpbuf);
  10687. DEBUG_INFO("systemresult=%d\n",systemresult);
  10688. if(systemresult != 0)
  10689. {
  10690. DEBUG_INFO("ftpput error!\n");
  10691. return FALSE;
  10692. }
  10693. return TRUE;
  10694. }
  10695. int SettingChargingRecord(int target, int transactionId)
  10696. {
  10697. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10698. {
  10699. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10700. {
  10701. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10702. {
  10703. addBuff(target, transactionId, 0);
  10704. return TRUE;
  10705. }
  10706. }
  10707. for (int index = 0; index < CCS_QUANTITY; index++)
  10708. {
  10709. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10710. {
  10711. addBuff(target, transactionId, 0);
  10712. return TRUE;
  10713. }
  10714. }
  10715. for (int index = 0; index < GB_QUANTITY; index++)
  10716. {
  10717. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10718. {
  10719. addBuff(target, transactionId, 0);
  10720. return TRUE;
  10721. }
  10722. }
  10723. }
  10724. else
  10725. {
  10726. for (int index = 0; index < AC_QUANTITY; index++)
  10727. {
  10728. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10729. {
  10730. addBuff(target, transactionId, 0);
  10731. return TRUE;
  10732. }
  10733. }
  10734. }
  10735. return FALSE;
  10736. }
  10737. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10738. {
  10739. int isSuccess = FALSE;
  10740. //char *query = NULL;
  10741. sqlite3_stmt *stmt;
  10742. int rc; // return code
  10743. char str[20];
  10744. sprintf(str,"%d",user_id);
  10745. 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 */
  10746. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10747. rc = sqlite3_step(stmt); /* 3 */
  10748. if (rc != SQLITE_DONE) {
  10749. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10750. goto out;
  10751. }
  10752. sqlite3_finalize(stmt);
  10753. // free(query);
  10754. out:
  10755. //----------------------
  10756. // close SQLite database
  10757. //----------------------
  10758. sqlite3_close(db);
  10759. printf("database closed.\n");
  10760. return isSuccess;
  10761. }
  10762. /**
  10763. * Place the contents of the specified file into a memory buffer
  10764. *
  10765. * @param[in] filename The path and name of the file to read
  10766. * @param[out] filebuffer A pointer to the contents in memory
  10767. * @return status 0 success, 1 on failure
  10768. */
  10769. int get_file_contents(const char* filename, char** outbuffer) {
  10770. FILE* file = NULL;
  10771. long filesize;
  10772. const int blocksize = 1;
  10773. size_t readsize;
  10774. char* filebuffer;
  10775. // Open the file
  10776. file = fopen(filename, "r");
  10777. if (NULL == file)
  10778. {
  10779. printf("'%s' not opened\n", filename);
  10780. exit(EXIT_FAILURE);
  10781. }
  10782. // Determine the file size
  10783. fseek(file, 0, SEEK_END);
  10784. filesize = ftell(file);
  10785. rewind (file);
  10786. // Allocate memory for the file contents
  10787. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10788. *outbuffer = filebuffer;
  10789. if (filebuffer == NULL)
  10790. {
  10791. fputs ("malloc out-of-memory", stderr);
  10792. exit(EXIT_FAILURE);
  10793. }
  10794. // Read in the file
  10795. readsize = fread(filebuffer, blocksize, filesize, file);
  10796. if (readsize != filesize)
  10797. {
  10798. fputs ("didn't read file completely",stderr);
  10799. exit(EXIT_FAILURE);
  10800. }
  10801. // Clean exit
  10802. fclose(file);
  10803. return EXIT_SUCCESS;
  10804. }
  10805. static int selectSqlCount = 0;
  10806. static int callback(void *data, int argc, char **argv, char **azColName){
  10807. int i;
  10808. printf("%s: ", (const char*)data);
  10809. selectSqlCount = argc;
  10810. for(i = 0; i<argc; i++){
  10811. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10812. }
  10813. printf("\n");
  10814. return 0;
  10815. }
  10816. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10817. //int i;
  10818. //printf("%s:\n", (const char*)data);
  10819. localversion = argv[5] ? atoi(argv[5]) : 0;
  10820. printf("localversion=%d\n", localversion);
  10821. return 0;
  10822. }
  10823. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10824. //int i;
  10825. //printf("%s:\n", (const char*)data);
  10826. //idTag
  10827. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10828. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10829. //parentIdTag
  10830. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10831. //expir_date
  10832. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10833. //status
  10834. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10835. //version
  10836. idTagQuery.listVersionInt = atoi(argv[5]);
  10837. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10838. return 0;
  10839. }
  10840. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10841. int i;
  10842. //printf("%s:\n", (const char*)data);
  10843. #if 1
  10844. for(i=0; i<argc; i++){
  10845. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10846. }
  10847. //printf("");
  10848. #endif
  10849. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10850. // printf("localversion=%d\n", localversion);
  10851. return 0;
  10852. }
  10853. /** sqlite3_exec的回调。
  10854. *
  10855. * 向控制台打印查询的结果。
  10856. *
  10857. * @param in data 传递给回调函数的数据。
  10858. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10859. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10860. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10861. * @return 状态码。
  10862. */
  10863. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10864. {
  10865. for (int i = 0; i < n_columns; i++)
  10866. {
  10867. DEBUG_INFO("%s/t", col_values[i]);
  10868. }
  10869. DEBUG_INFO("/n");
  10870. return 0;
  10871. }
  10872. void OCPP_getListVerion()
  10873. {
  10874. int rc = 0;
  10875. // const char* data = "Callback function called";
  10876. char sql[100];
  10877. char zErrMsg[100];
  10878. memset(sql, 0, 100);
  10879. memset(zErrMsg, 0, 100);
  10880. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10881. /* Execute SQL statement */
  10882. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10883. DEBUG_INFO("rc=%d\n",rc);
  10884. if( rc != SQLITE_OK ){
  10885. DEBUG_INFO("SQL error: %s", zErrMsg);
  10886. //sqlite3_free(zErrMsg);
  10887. }else{
  10888. DEBUG_INFO("Operation done successfully");
  10889. }
  10890. }
  10891. void OCPP_getIdTag(char *idTag)
  10892. {
  10893. int rc = 0;
  10894. // const char* data = "Callback function called";
  10895. char sql[100];
  10896. char zErrMsg[100];
  10897. memset(sql, 0, 100);
  10898. memset(zErrMsg, 0, 100);
  10899. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10900. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10901. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10902. /* Execute SQL statement */
  10903. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10904. if( rc != SQLITE_OK ){
  10905. DEBUG_INFO("SQL error: %s", zErrMsg);
  10906. //sqlite3_free(zErrMsg);
  10907. }else{
  10908. printf("Operation done successfully");
  10909. }
  10910. //return ver;
  10911. }
  10912. void OCPP_get_TableAuthlocalAllData(void)
  10913. {
  10914. int rc = 0;
  10915. // const char* data = "Callback function called";
  10916. char sql[100];
  10917. char zErrMsg[100];
  10918. memset(sql, 0, 100);
  10919. memset(zErrMsg, 0, 100);
  10920. sprintf(sql,"select * from ocpp_auth_local ");
  10921. /* Execute SQL statement */
  10922. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10923. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10924. if( rc != SQLITE_OK ){
  10925. DEBUG_INFO("SQL error: %s", zErrMsg);
  10926. //sqlite3_free(zErrMsg);
  10927. }else{
  10928. DEBUG_INFO("Operation done successfully");
  10929. }
  10930. //return ver;
  10931. }
  10932. int OCPP_cleanLocalList()
  10933. {
  10934. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10935. char *errMsg = 0;
  10936. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10937. if (SQLITE_OK != rc)
  10938. {
  10939. DEBUG_INFO("%s\n",errMsg);
  10940. return FALSE;
  10941. }
  10942. else
  10943. {
  10944. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10945. }
  10946. return TRUE;
  10947. }
  10948. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10949. {
  10950. int isSuccess = FALSE;
  10951. int ret = 0;
  10952. //const char* data = "Callback function called";
  10953. char sql[200];
  10954. char zErrMsg[100];
  10955. memset(sql, 0, 200);
  10956. memset(zErrMsg, 0, 100);
  10957. 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);
  10958. //* Execute SQL statement */
  10959. //zErrMsg = 0;
  10960. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10961. if( ret != SQLITE_OK ){
  10962. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10963. // free(zErrMsg);
  10964. // free(sql);
  10965. return isSuccess;
  10966. }
  10967. DEBUG_INFO("successfully Insert records created\n");
  10968. isSuccess = TRUE;
  10969. return isSuccess;
  10970. }
  10971. void OCPP_deleteIdTag(char *idTag)
  10972. {
  10973. //int ver = 0;
  10974. //int isSuccess = FALSE;
  10975. int rc = 0;
  10976. char sql[100];
  10977. char zErrMsg[100];
  10978. memset(sql, 0, 100);
  10979. memset(zErrMsg, 0, 100);
  10980. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10981. //* Execute SQL statement */
  10982. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10983. if( rc != SQLITE_OK ){
  10984. DEBUG_INFO("SQL error: %s", zErrMsg);
  10985. //sqlite3_free(zErrMsg);
  10986. }else{
  10987. DEBUG_INFO("Operation done successfully");
  10988. }
  10989. }
  10990. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10991. {
  10992. int isSuccess = FALSE;
  10993. int ret = 0;
  10994. const char* data = "Callback function called";
  10995. char sql[200];
  10996. char zErrMsg[100];
  10997. memset(sql, 0, 200);
  10998. memset(zErrMsg, 0, 100);
  10999. //* selectFromTable */
  11000. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  11001. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11002. //* Execute SQL statement */
  11003. selectSqlCount = 0;
  11004. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11005. if( ret != SQLITE_OK ){
  11006. printf("Error SQL: %s\n", zErrMsg);
  11007. }
  11008. printf("successfully select operation done\n");
  11009. memset(sql, 0, 200);
  11010. memset(zErrMsg, 0, 100);
  11011. if(selectSqlCount == 0)
  11012. {
  11013. //Insert
  11014. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  11015. 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);
  11016. DEBUG_INFO("sql:%s\n", sql);
  11017. //* Execute SQL statement */
  11018. //zErrMsg = 0;
  11019. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  11020. if( ret != SQLITE_OK ){
  11021. printf("SQL error: %s\n", zErrMsg);
  11022. return isSuccess;
  11023. }
  11024. DEBUG_INFO("successfully Insert records created\n");
  11025. isSuccess = TRUE;
  11026. }
  11027. else
  11028. {
  11029. //Update
  11030. //* Create merged SQL statement */
  11031. 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);
  11032. /* Execute SQL statement */
  11033. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11034. if( ret != SQLITE_OK ){
  11035. printf("SQL error: %s\n", zErrMsg);
  11036. //sqlite3_free(zErrMsg);
  11037. //sqlite3_free(sql);
  11038. return isSuccess;
  11039. }
  11040. DEBUG_INFO("Successfully operation done \n");
  11041. isSuccess = TRUE;
  11042. }
  11043. return isSuccess;
  11044. }
  11045. char *GetOcppServerURL()
  11046. {
  11047. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  11048. memset(OcppHost, 0, sizeof(OcppHost));
  11049. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  11050. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  11051. {
  11052. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  11053. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  11054. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11055. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  11056. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  11057. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  11058. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  11059. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  11060. goto End;
  11061. }
  11062. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  11063. {
  11064. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  11065. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  11066. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11067. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  11068. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  11069. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  11070. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  11071. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  11072. goto End;
  11073. }
  11074. else
  11075. {
  11076. strcpy(OcppHost,"");
  11077. }
  11078. End:
  11079. return OcppHost;
  11080. }
  11081. char *GetOcppPath()
  11082. {
  11083. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  11084. {
  11085. if(OcppTempPath == NULL)
  11086. {
  11087. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  11088. }
  11089. else
  11090. {
  11091. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  11092. }
  11093. goto End;
  11094. }
  11095. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  11096. {
  11097. if(OcppTempPath == NULL)
  11098. {
  11099. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  11100. }
  11101. else
  11102. {
  11103. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  11104. }
  11105. goto End;
  11106. }
  11107. else
  11108. {
  11109. strcpy(OcppHost,"");
  11110. }
  11111. End:
  11112. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  11113. return OcppPath;
  11114. }
  11115. int GetOcppPort()
  11116. {
  11117. return OcppPort;
  11118. }
  11119. int GetOcppConnStatus(void)
  11120. {
  11121. return ShmOCPP16Data->OcppConnStatus;
  11122. }
  11123. void SetOcppConnStatus(uint8_t status)
  11124. {
  11125. ShmOCPP16Data->OcppConnStatus = status;
  11126. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  11127. if(status == FALSE)
  11128. {
  11129. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11130. {
  11131. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  11132. }
  11133. else
  11134. {
  11135. SystemInitial = AC_QUANTITY;
  11136. }
  11137. }
  11138. }
  11139. int GetHeartBeatWithNOResponse(void)
  11140. {
  11141. return HeartBeatWithNOResponse;
  11142. }
  11143. void SetHeartBeatWithNOResponse(void)
  11144. {
  11145. HeartBeatWithNOResponse = 0;
  11146. }
  11147. int GetTransactionId(int gunindex)
  11148. {
  11149. return TransactionId[gunindex];
  11150. }
  11151. void SetTransactionIdZero(int gunindex)
  11152. {
  11153. TransactionId[gunindex] = 0;
  11154. }
  11155. int InternetDisconnect(void)
  11156. {
  11157. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  11158. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  11159. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  11160. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  11161. }
  11162. void GetChargingProfileRequest(int gunindex)
  11163. {
  11164. mtrace();
  11165. //int connectorIdInt, durationInt;
  11166. //char chargingRateUnitStr[4]={0};
  11167. int tempdurationInt = 0;
  11168. int tempchargingProfileId = 0;
  11169. int tempstackLevel = 0;
  11170. int temptransactionId = 0;
  11171. float tempminChargingRateFloat = 0.0;
  11172. char tempchargingProfilePurposeStr[24]={0};
  11173. char tempchargingProfileKindStr[12]={0};
  11174. char temprecurrencyKindStr[8]={0};
  11175. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  11176. char tempvalidToStr[28]={0};
  11177. int tempStartPeriodInt = 0;
  11178. float tempLimitInt = 0.0;//0.1;
  11179. int tempNumberPhasesInt=0;
  11180. char fname[200];
  11181. //char comfirmstr[20];
  11182. float MinChargingRate =0.0;
  11183. double diff_t;
  11184. struct tm tp;
  11185. FILE *fptr1;//, *fptr2;
  11186. int c = 0;
  11187. char * pch;
  11188. char *loc;
  11189. char sstr[200]={ 0 };
  11190. int n_chargingProfile = 0;
  11191. int n_SchedulePeriods = 0;
  11192. char SchedulePeriodList[10][200]={0};
  11193. char sLineWord[800]={0};
  11194. char word[1000]={0};
  11195. int confirmPeriods = 0;
  11196. struct StructProfile ChargePointMaxProfile;
  11197. struct StructProfile TxDefaultProfile;
  11198. struct StructProfile TxProfile;
  11199. struct StructProfile TxDefaultProfiletemp[2]={0};
  11200. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  11201. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  11202. struct StructChargingProfile TxProfile_TEMP={0};
  11203. int TxDefaultProfileFileIsNull=FALSE;
  11204. int ChargePointMaxProfileIsNull=FALSE;
  11205. int TxProfileIsNull=FALSE;
  11206. // int CompositeSceduleIndex = 0;
  11207. char ChargePointMaxProfileScheduleStr[30]={0};
  11208. char TxDefaultProfileScheduleStr[30]={0};
  11209. char TxProfileScheduleStr[30]={0};
  11210. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  11211. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  11212. memset(&TxProfile,0,sizeof(struct StructProfile));
  11213. DEBUG_INFO("GetChargingProfileRequest\n");
  11214. //*****************************ChargePointMaxProfile******************************************/
  11215. strcpy(fname, ChargePointMaxProfile_JSON);
  11216. ChargePointMaxProfileIsNull=TRUE;
  11217. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  11218. {
  11219. fptr1 = fopen(fname, "r");
  11220. int c;
  11221. c = fgetc(fptr1);
  11222. //DEBUG_INFO("c:%d\n",c);
  11223. rewind(fptr1);
  11224. if(c == EOF)
  11225. {
  11226. DEBUG_INFO("\n End of file reached.");
  11227. ChargePointMaxProfileIsNull=TRUE;
  11228. fclose(fptr1);
  11229. }
  11230. else
  11231. {
  11232. ChargePointMaxProfileIsNull=FALSE;
  11233. while(fscanf(fptr1, "%s", word) != EOF)
  11234. {
  11235. if(strcmp(word, "chargingProfileId") == 0)
  11236. {
  11237. n_chargingProfile = n_chargingProfile + 1;
  11238. }
  11239. }
  11240. rewind(fptr1);
  11241. //search Charging Profile Element
  11242. int i = 0;
  11243. int j = 0;
  11244. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11245. //***********chargingProfileId**************/
  11246. c = 0;
  11247. loc = strstr(sLineWord, "chargingProfileId");
  11248. //DEBUG_INFO("loc=%s\n",loc);
  11249. memset(sstr ,0, sizeof(sstr) );
  11250. if(loc != NULL)
  11251. {
  11252. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11253. {
  11254. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11255. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11256. c++;
  11257. }
  11258. sstr[c] = '\0';
  11259. tempchargingProfileId = atoi(sstr);
  11260. }
  11261. else
  11262. {
  11263. tempchargingProfileId = 0;
  11264. }
  11265. //***********stackLevel**************/
  11266. c = 0;
  11267. loc = strstr(sLineWord, "stackLevel");
  11268. //DEBUG_INFO("loc=%s\n",loc);
  11269. memset(sstr ,0, sizeof(sstr) );
  11270. if(loc != NULL)
  11271. {
  11272. while (loc[2+strlen("stackLevel")+c] != '\"')
  11273. {
  11274. sstr[c] = loc[2+strlen("stackLevel")+c];
  11275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11276. c++;
  11277. }
  11278. sstr[c] = '\0';
  11279. tempstackLevel = atoi(sstr);
  11280. }
  11281. else
  11282. {
  11283. tempstackLevel = 0;
  11284. }
  11285. //***********chargingProfilePurpose **************/
  11286. c = 0;
  11287. loc = strstr(sLineWord, "chargingProfilePurpose");
  11288. //DEBUG_INFO("loc=%s\n",loc);
  11289. memset(sstr ,0, sizeof(sstr) );
  11290. if(loc != NULL)
  11291. {
  11292. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11293. {
  11294. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11295. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11296. c++;
  11297. }
  11298. sstr[c] = '\0';
  11299. strcpy(tempchargingProfilePurposeStr,sstr);
  11300. }
  11301. else
  11302. {
  11303. strcpy(tempchargingProfilePurposeStr,"");
  11304. }
  11305. //***********chargingProfileKind **************/
  11306. c = 0;
  11307. loc = strstr(sLineWord, "chargingProfileKind");
  11308. //DEBUG_INFO("loc=%s\n",loc);
  11309. memset(sstr ,0, sizeof(sstr) );
  11310. if(loc != NULL)
  11311. {
  11312. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11313. {
  11314. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11315. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11316. c++;
  11317. }
  11318. sstr[c] = '\0';
  11319. strcpy(tempchargingProfileKindStr,sstr);
  11320. }
  11321. else
  11322. {
  11323. strcpy(tempchargingProfileKindStr,"");
  11324. }
  11325. //***********recurrencyKind **************/
  11326. c = 0;
  11327. loc = strstr(sLineWord, "recurrencyKind");
  11328. //DEBUG_INFO("loc=%s\n",loc);
  11329. memset(sstr ,0, sizeof(sstr) );
  11330. if(loc != NULL)
  11331. {
  11332. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11333. {
  11334. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11335. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11336. c++;
  11337. }
  11338. sstr[c] = '\0';
  11339. strcpy(temprecurrencyKindStr,sstr);
  11340. }
  11341. else
  11342. {
  11343. strcpy(temprecurrencyKindStr,"");
  11344. }
  11345. //***********validFrom**************/
  11346. c = 0;
  11347. loc = strstr(sLineWord, "validFrom");
  11348. //DEBUG_INFO("loc=%s\n",loc);
  11349. memset(sstr ,0, sizeof(sstr) );
  11350. if(loc != NULL)
  11351. {
  11352. while (loc[3+strlen("validFrom")+c] != '\"')
  11353. {
  11354. sstr[c] = loc[3+strlen("validFrom")+c];
  11355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11356. c++;
  11357. }
  11358. sstr[c] = '\0';
  11359. strcpy(tempvalidFromStr,sstr);
  11360. }
  11361. else
  11362. {
  11363. strcpy(tempvalidFromStr,"");
  11364. }
  11365. //***********validTo **************/
  11366. c = 0;
  11367. loc = strstr(sLineWord, "validTo");
  11368. //DEBUG_INFO("loc=%s\n",loc);
  11369. memset(sstr ,0, sizeof(sstr) );
  11370. if(loc != NULL)
  11371. {
  11372. while (loc[3+strlen("validTo")+c] != '\"')
  11373. {
  11374. sstr[c] = loc[3+strlen("validTo")+c];
  11375. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11376. c++;
  11377. }
  11378. sstr[c] = '\0';
  11379. strcpy(tempvalidToStr,sstr);
  11380. }
  11381. else
  11382. {
  11383. strcpy(tempvalidToStr,"");
  11384. }
  11385. //***********validFrom**************/
  11386. c = 0;
  11387. loc = strstr(sLineWord, "validFrom");
  11388. if(loc != NULL)
  11389. {
  11390. memset(sstr ,0, sizeof(sstr) );
  11391. while (loc[3+strlen("validFrom")+c] != '\"')
  11392. {
  11393. sstr[c] = loc[3+strlen("validFrom")+c];
  11394. c++;
  11395. }
  11396. sstr[c] = '\0';
  11397. strcpy(tempvalidFromStr,sstr);
  11398. }
  11399. else
  11400. {
  11401. strcpy(tempvalidFromStr,"");
  11402. }
  11403. //***********duration**************/
  11404. c = 0;
  11405. loc = strstr(sLineWord, "duration");
  11406. if(loc != NULL)
  11407. {
  11408. memset(sstr ,0, sizeof(sstr) );
  11409. while (loc[2+strlen("duration")+c] != ',')
  11410. {
  11411. sstr[c] = loc[2+strlen("duration")+c];
  11412. c++;
  11413. }
  11414. sstr[c] = '\0';
  11415. tempdurationInt = atoi(sstr);
  11416. }
  11417. else
  11418. {
  11419. tempdurationInt = 0;
  11420. }
  11421. //**********startSchedule**********/
  11422. c = 0;
  11423. loc = strstr(sLineWord, "startSchedule");
  11424. memset(sstr ,0, sizeof(sstr) );
  11425. while (loc[3+strlen("startSchedule")+c] != '\"')
  11426. {
  11427. sstr[c] = loc[3+strlen("startSchedule")+c];
  11428. c++;
  11429. }
  11430. sstr[c] = '\0';
  11431. strcpy(tempstartScheduleStr, sstr);
  11432. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  11433. //**********chargingRateUnit**********/
  11434. c = 0;
  11435. loc = strstr(sLineWord, "chargingRateUnit");
  11436. memset(sstr ,0, sizeof(sstr) );
  11437. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  11438. {
  11439. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  11440. c++;
  11441. }
  11442. sstr[c] = '\0';
  11443. strcpy(tempchargingRateUnitStr, sstr);
  11444. //**********minChargingRate*******/
  11445. c = 0;
  11446. loc = strstr(sLineWord, "minChargingRate");
  11447. if(loc != NULL)
  11448. {
  11449. memset(sstr ,0, sizeof(sstr) );
  11450. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  11451. {
  11452. sstr[c] = loc[2+strlen("minChargingRate")+c];
  11453. c++;
  11454. }
  11455. sstr[c] = '\0';
  11456. tempminChargingRateFloat = atof(sstr);
  11457. }
  11458. else
  11459. {
  11460. tempminChargingRateFloat = 0.0;
  11461. }
  11462. //
  11463. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  11464. tp.tm_isdst = -1;
  11465. time_t utc = mktime(&tp);
  11466. time_t t = time(NULL);
  11467. diff_t = difftime(t, utc);
  11468. //DEBUG_INFO("diff_t=%f\n",diff_t);
  11469. //parsing strings to words
  11470. i = 0;
  11471. loc = strstr(sLineWord, "chargingSchedulePeriod");
  11472. loc = loc+3+strlen("chargingSchedulePeriod");
  11473. pch = strtok(loc ,"{");
  11474. while (pch != NULL)
  11475. {
  11476. strcpy(SchedulePeriodList[i], pch);
  11477. pch = strtok (NULL, "{");
  11478. i = i + 1;
  11479. }
  11480. n_SchedulePeriods = i;
  11481. for(int i=0;i<n_SchedulePeriods;i++)
  11482. {
  11483. //*************startPeriod****************/
  11484. c = 0;
  11485. loc = strstr(SchedulePeriodList[i], "startPeriod");
  11486. memset(sstr ,0, sizeof(sstr) );
  11487. while (loc[strlen("startPeriod")+2+c] != ',')
  11488. {
  11489. sstr[c] = loc[strlen("startPeriod")+2+c];
  11490. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11491. c++;
  11492. }
  11493. sstr[c] = '\0';
  11494. tempStartPeriodInt = atoi(sstr);
  11495. //*************limit****************/
  11496. c = 0;
  11497. loc = strstr(SchedulePeriodList[i], "limit");
  11498. memset(sstr ,0, sizeof(sstr) );
  11499. while (loc[strlen("limit")+2+c] != ',')
  11500. {
  11501. sstr[c] = loc[strlen("limit")+2+c];
  11502. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11503. c++;
  11504. }
  11505. sstr[c] = '\0';
  11506. tempLimitInt = atof(sstr);
  11507. //*************numberPhases****************/
  11508. c = 0;
  11509. loc = strstr(SchedulePeriodList[i], "numberPhases");
  11510. memset(sstr ,0, sizeof(sstr) );
  11511. while (loc[strlen("numberPhases")+2+c] != '}')
  11512. {
  11513. sstr[c] = loc[strlen("numberPhases")+2+c];
  11514. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11515. c++;
  11516. }
  11517. sstr[c] = '\0';
  11518. tempNumberPhasesInt = atoi(sstr);
  11519. if(j == 0)
  11520. {
  11521. ChargePointMaxProfile.Duration = tempdurationInt;
  11522. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  11523. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  11524. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  11525. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  11526. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  11527. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  11528. ChargePointMaxProfile_TEMP.TransactionId = 0;
  11529. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  11530. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  11531. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  11532. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  11533. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  11534. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  11535. }
  11536. }
  11537. if(MinChargingRate < tempminChargingRateFloat)
  11538. {
  11539. MinChargingRate = tempminChargingRateFloat;
  11540. }
  11541. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  11542. if(confirmPeriods < n_SchedulePeriods)
  11543. {
  11544. confirmPeriods = n_SchedulePeriods;
  11545. }
  11546. j = j + 1;
  11547. }
  11548. fclose(fptr1);
  11549. }
  11550. }// the end of access file ChargePointMaxProfile
  11551. //****************************TxDefaultProfile************************************************/
  11552. switch(gunindex + 1)
  11553. {
  11554. case 0:
  11555. break;
  11556. case 1:
  11557. strcpy(fname, TxDefaultProfile_1_JSON );
  11558. break;
  11559. case 2:
  11560. strcpy(fname, TxDefaultProfile_2_JSON );
  11561. break;
  11562. default:
  11563. strcpy(fname, TxDefaultProfile_1_JSON );
  11564. break;
  11565. }
  11566. TxDefaultProfileFileIsNull=TRUE;
  11567. if((access(fname,F_OK))!=-1)
  11568. {
  11569. fptr1 = fopen(fname, "r");
  11570. c = 0;
  11571. c = fgetc(fptr1);
  11572. //DEBUG_INFO("c:%d\n",c);
  11573. rewind(fptr1);
  11574. if(c == EOF)
  11575. {
  11576. DEBUG_INFO("\n End of file reached.");
  11577. TxDefaultProfileFileIsNull=TRUE;
  11578. fclose(fptr1);
  11579. }
  11580. else
  11581. {
  11582. TxDefaultProfileFileIsNull=FALSE;
  11583. while(fscanf(fptr1, "%s", word) != EOF)
  11584. {
  11585. if(strcmp(word, "chargingProfileId") == 0)
  11586. {
  11587. n_chargingProfile = n_chargingProfile + 1;
  11588. }
  11589. }
  11590. rewind(fptr1);
  11591. //search Charging Profile Element
  11592. int i = 0;
  11593. int j = 0;
  11594. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11595. #if 0
  11596. /***********connectorId****************/
  11597. c = 0;
  11598. loc = strstr(sLineWord, "connectorId");
  11599. memset(sstr ,0, sizeof(sstr) );
  11600. while (loc[strlen("connectorId")+2+c] != ',')
  11601. {
  11602. sstr[c] = loc[strlen("connectorId")+2+c];
  11603. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11604. c++;
  11605. }
  11606. sstr[c] = '\0';
  11607. tempconnectorIdInt = atoi(sstr);
  11608. #endif
  11609. //***********chargingProfileId**************/
  11610. c = 0;
  11611. loc = strstr(sLineWord, "chargingProfileId");
  11612. //DEBUG_INFO("loc=%s\n",loc);
  11613. memset(sstr ,0, sizeof(sstr) );
  11614. if(loc != NULL)
  11615. {
  11616. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11617. {
  11618. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11619. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11620. c++;
  11621. }
  11622. sstr[c] = '\0';
  11623. tempchargingProfileId = atoi(sstr);
  11624. }
  11625. else
  11626. {
  11627. tempchargingProfileId = 0;
  11628. }
  11629. //***********stackLevel**************/
  11630. c = 0;
  11631. loc = strstr(sLineWord, "stackLevel");
  11632. //DEBUG_INFO("loc=%s\n",loc);
  11633. memset(sstr ,0, sizeof(sstr) );
  11634. if(loc != NULL)
  11635. {
  11636. while (loc[2+strlen("stackLevel")+c] != '\"')
  11637. {
  11638. sstr[c] = loc[2+strlen("stackLevel")+c];
  11639. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11640. c++;
  11641. }
  11642. sstr[c] = '\0';
  11643. tempstackLevel = atoi(sstr);
  11644. }
  11645. else
  11646. {
  11647. tempstackLevel = 0;
  11648. }
  11649. //***********chargingProfilePurpose **************/
  11650. c = 0;
  11651. loc = strstr(sLineWord, "chargingProfilePurpose");
  11652. //DEBUG_INFO("loc=%s\n",loc);
  11653. memset(sstr ,0, sizeof(sstr) );
  11654. if(loc != NULL)
  11655. {
  11656. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11657. {
  11658. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11659. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11660. c++;
  11661. }
  11662. sstr[c] = '\0';
  11663. strcpy(tempchargingProfilePurposeStr,sstr);
  11664. }
  11665. else
  11666. {
  11667. strcpy(tempchargingProfilePurposeStr,"");
  11668. }
  11669. //***********chargingProfileKind **************/
  11670. c = 0;
  11671. loc = strstr(sLineWord, "chargingProfileKind");
  11672. //DEBUG_INFO("loc=%s\n",loc);
  11673. memset(sstr ,0, sizeof(sstr) );
  11674. if(loc != NULL)
  11675. {
  11676. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11677. {
  11678. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11679. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11680. c++;
  11681. }
  11682. sstr[c] = '\0';
  11683. strcpy(tempchargingProfileKindStr,sstr);
  11684. }
  11685. else
  11686. {
  11687. strcpy(tempchargingProfileKindStr,"");
  11688. }
  11689. //***********recurrencyKind **************/
  11690. c = 0;
  11691. loc = strstr(sLineWord, "recurrencyKind");
  11692. //DEBUG_INFO("loc=%s\n",loc);
  11693. memset(sstr ,0, sizeof(sstr) );
  11694. if(loc != NULL)
  11695. {
  11696. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11697. {
  11698. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11699. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11700. c++;
  11701. }
  11702. sstr[c] = '\0';
  11703. strcpy(temprecurrencyKindStr,sstr);
  11704. }
  11705. else
  11706. {
  11707. strcpy(temprecurrencyKindStr,"");
  11708. }
  11709. //***********validFrom**************/
  11710. c = 0;
  11711. loc = strstr(sLineWord, "validFrom");
  11712. if(loc != NULL)
  11713. {
  11714. memset(sstr ,0, sizeof(sstr) );
  11715. while (loc[3+strlen("validFrom")+c] != '\"')
  11716. {
  11717. sstr[c] = loc[3+strlen("validFrom")+c];
  11718. c++;
  11719. }
  11720. sstr[c] = '\0';
  11721. strcpy(tempvalidFromStr,sstr);
  11722. }
  11723. else
  11724. {
  11725. strcpy(tempvalidFromStr,"");
  11726. }
  11727. //***********validFrom**************/
  11728. c = 0;
  11729. loc = strstr(sLineWord, "duration");
  11730. if(loc != NULL)
  11731. {
  11732. memset(sstr ,0, sizeof(sstr) );
  11733. while (loc[2+strlen("duration")+c] != ',')
  11734. {
  11735. sstr[c] = loc[2+strlen("duration")+c];
  11736. c++;
  11737. }
  11738. sstr[c] = '\0';
  11739. tempdurationInt = atoi(sstr);
  11740. }
  11741. else
  11742. {
  11743. tempdurationInt = 0;
  11744. }
  11745. //**********startSchedule**********/
  11746. c = 0;
  11747. loc = strstr(sLineWord, "startSchedule");
  11748. memset(sstr ,0, sizeof(sstr) );
  11749. while (loc[3+strlen("startSchedule")+c] != '\"')
  11750. {
  11751. sstr[c] = loc[3+strlen("startSchedule")+c];
  11752. c++;
  11753. }
  11754. sstr[c] = '\0';
  11755. strcpy(tempstartScheduleStr, sstr);
  11756. strcpy(TxDefaultProfileScheduleStr, sstr);
  11757. //**********chargingRateUnit**********/
  11758. c = 0;
  11759. loc = strstr(sLineWord, "chargingRateUnit");
  11760. memset(sstr ,0, sizeof(sstr) );
  11761. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  11762. {
  11763. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  11764. c++;
  11765. }
  11766. sstr[c] = '\0';
  11767. strcpy(tempchargingRateUnitStr, sstr);
  11768. //**********minChargingRate*******/
  11769. c = 0;
  11770. loc = strstr(sLineWord, "minChargingRate");
  11771. if(loc != NULL)
  11772. {
  11773. memset(sstr ,0, sizeof(sstr) );
  11774. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  11775. {
  11776. sstr[c] = loc[2+strlen("minChargingRate")+c];
  11777. c++;
  11778. }
  11779. sstr[c] = '\0';
  11780. tempminChargingRateFloat = atof(sstr);
  11781. }
  11782. else
  11783. {
  11784. tempminChargingRateFloat = 0.0;
  11785. }
  11786. //
  11787. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  11788. tp.tm_isdst = -1;
  11789. time_t utc = mktime(&tp);
  11790. time_t t = time(NULL);
  11791. diff_t = difftime(t, utc);
  11792. printf("diff between startScheduleStr and now =%f\n",diff_t);
  11793. //parsing strings to words
  11794. i = 0;
  11795. loc = strstr(sLineWord, "chargingSchedulePeriod");
  11796. loc = loc+3+strlen("chargingSchedulePeriod");
  11797. pch = strtok(loc ,"{");
  11798. while (pch != NULL)
  11799. {
  11800. strcpy(SchedulePeriodList[i], pch);
  11801. pch = strtok (NULL, "{");
  11802. i = i + 1;
  11803. }
  11804. n_SchedulePeriods = i;
  11805. for(int i=0;i<n_SchedulePeriods;i++)
  11806. {
  11807. //*************startPeriod****************/
  11808. c = 0;
  11809. loc = strstr(SchedulePeriodList[i], "startPeriod");
  11810. memset(sstr ,0, sizeof(sstr) );
  11811. while (loc[strlen("startPeriod")+2+c] != ',')
  11812. {
  11813. sstr[c] = loc[strlen("startPeriod")+2+c];
  11814. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11815. c++;
  11816. }
  11817. sstr[c] = '\0';
  11818. tempStartPeriodInt = atoi(sstr);
  11819. //*************limit****************/
  11820. c = 0;
  11821. loc = strstr(SchedulePeriodList[i], "limit");
  11822. memset(sstr ,0, sizeof(sstr) );
  11823. while (loc[strlen("limit")+2+c] != ',')
  11824. {
  11825. sstr[c] = loc[strlen("limit")+2+c];
  11826. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11827. c++;
  11828. }
  11829. sstr[c] = '\0';
  11830. tempLimitInt = atof(sstr);
  11831. //*************numberPhases****************/
  11832. c = 0;
  11833. loc = strstr(SchedulePeriodList[i], "numberPhases");
  11834. memset(sstr ,0, sizeof(sstr) );
  11835. while (loc[strlen("numberPhases")+2+c] != '}')
  11836. {
  11837. sstr[c] = loc[strlen("numberPhases")+2+c];
  11838. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11839. c++;
  11840. }
  11841. sstr[c] = '\0';
  11842. tempNumberPhasesInt = atoi(sstr);
  11843. if(j == 0)
  11844. {
  11845. TxDefaultProfile.Duration = tempdurationInt;
  11846. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  11847. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  11848. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  11849. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  11850. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  11851. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  11852. TxDefaultProfile_TEMP.TransactionId = 0;
  11853. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  11854. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  11855. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  11856. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  11857. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  11858. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  11859. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  11860. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  11861. }
  11862. else
  11863. {
  11864. //other stack level charging Profile
  11865. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  11866. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  11867. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  11868. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  11869. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  11870. }
  11871. }
  11872. if(MinChargingRate < tempminChargingRateFloat)
  11873. {
  11874. MinChargingRate = tempminChargingRateFloat;
  11875. }
  11876. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  11877. if(confirmPeriods < n_SchedulePeriods)
  11878. confirmPeriods = n_SchedulePeriods;
  11879. j = j + 1;
  11880. }
  11881. fclose(fptr1);
  11882. //Stacking Charging Profiles
  11883. for(int l=0; l <(j-1) ;l++)
  11884. {
  11885. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  11886. {
  11887. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  11888. {
  11889. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  11890. {
  11891. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  11892. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  11893. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  11894. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11895. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11896. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  11897. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  11898. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  11899. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11900. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11901. }
  11902. else
  11903. {
  11904. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  11905. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  11906. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  11907. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11908. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11909. }
  11910. }
  11911. }
  11912. }
  11913. //end of Stacking Charging Profiles
  11914. }
  11915. }// the end of ACCESS TxDefaultProfile
  11916. //****************************TxProfile************************************************/
  11917. switch(gunindex + 1)
  11918. {
  11919. case 0:
  11920. break;
  11921. case 1:
  11922. strcpy(fname, TxProfile_1_JSON );
  11923. break;
  11924. case 2:
  11925. strcpy(fname, TxProfile_2_JSON );
  11926. break;
  11927. default:
  11928. strcpy(fname, TxProfile_1_JSON );
  11929. break;
  11930. }
  11931. TxProfileIsNull=TRUE;
  11932. if((access(fname,F_OK))!=-1)
  11933. {
  11934. fptr1 = fopen(fname, "r");
  11935. c = 0;
  11936. c = fgetc(fptr1);
  11937. //DEBUG_INFO("c:%d\n",c);
  11938. rewind(fptr1);
  11939. if(c == EOF)
  11940. {
  11941. DEBUG_INFO("\n End of file reached.");
  11942. TxProfileIsNull=TRUE;
  11943. fclose(fptr1);
  11944. }
  11945. else
  11946. {
  11947. TxProfileIsNull=FALSE;
  11948. while(fscanf(fptr1, "%s", word) != EOF)
  11949. {
  11950. if(strcmp(word, "chargingProfileId") == 0)
  11951. {
  11952. n_chargingProfile = n_chargingProfile + 1;
  11953. }
  11954. }
  11955. rewind(fptr1);
  11956. //search Charging Profile Element
  11957. int i= 0;
  11958. int j= 0;
  11959. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11960. #if 0
  11961. /***********connectorId****************/
  11962. c = 0;
  11963. loc = strstr(sLineWord, "connectorId");
  11964. memset(sstr ,0, sizeof(sstr) );
  11965. while (loc[strlen("connectorId")+2+c] != ',')
  11966. {
  11967. sstr[c] = loc[strlen("connectorId")+2+c];
  11968. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11969. c++;
  11970. }
  11971. sstr[c] = '\0';
  11972. tempconnectorIdInt = atoi(sstr);
  11973. #endif
  11974. //***********chargingProfileId**************/
  11975. c = 0;
  11976. loc = strstr(sLineWord, "chargingProfileId");
  11977. memset(sstr ,0, sizeof(sstr) );
  11978. if(loc != NULL)
  11979. {
  11980. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11981. {
  11982. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11983. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11984. c++;
  11985. }
  11986. sstr[c] = '\0';
  11987. tempchargingProfileId = atoi(sstr);
  11988. }
  11989. else
  11990. {
  11991. tempchargingProfileId = 0;
  11992. }
  11993. //***********transactionId **************/
  11994. c = 0;
  11995. loc = strstr(sLineWord, "transactionId");
  11996. //DEBUG_INFO("loc=%s\n",loc);
  11997. memset(sstr ,0, sizeof(sstr) );
  11998. if(loc != NULL)
  11999. {
  12000. while (loc[2+strlen("transactionId")+c] != '\"')
  12001. {
  12002. sstr[c] = loc[2+strlen("transactionId")+c];
  12003. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12004. c++;
  12005. }
  12006. sstr[c] = '\0';
  12007. temptransactionId = atoi(sstr);
  12008. }
  12009. else
  12010. {
  12011. temptransactionId = 0;
  12012. }
  12013. //***********stackLevel**************/
  12014. c = 0;
  12015. loc = strstr(sLineWord, "stackLevel");
  12016. //DEBUG_INFO("loc=%s\n",loc);
  12017. memset(sstr ,0, sizeof(sstr) );
  12018. if(loc != NULL)
  12019. {
  12020. while (loc[2+strlen("stackLevel")+c] != '\"')
  12021. {
  12022. sstr[c] = loc[2+strlen("stackLevel")+c];
  12023. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12024. c++;
  12025. }
  12026. sstr[c] = '\0';
  12027. tempstackLevel = atoi(sstr);
  12028. }
  12029. else
  12030. {
  12031. tempstackLevel = 0;
  12032. }
  12033. //***********chargingProfilePurpose **************/
  12034. c = 0;
  12035. loc = strstr(sLineWord, "chargingProfilePurpose");
  12036. //DEBUG_INFO("loc=%s\n",loc);
  12037. memset(sstr ,0, sizeof(sstr) );
  12038. if(loc != NULL)
  12039. {
  12040. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12041. {
  12042. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12043. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12044. c++;
  12045. }
  12046. sstr[c] = '\0';
  12047. strcpy(tempchargingProfilePurposeStr,sstr);
  12048. }
  12049. else
  12050. {
  12051. strcpy(tempchargingProfilePurposeStr,"");
  12052. }
  12053. //***********chargingProfileKind **************/
  12054. c = 0;
  12055. loc = strstr(sLineWord, "chargingProfileKind");
  12056. //DEBUG_INFO("loc=%s\n",loc);
  12057. memset(sstr ,0, sizeof(sstr) );
  12058. if(loc != NULL)
  12059. {
  12060. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12061. {
  12062. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12063. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12064. c++;
  12065. }
  12066. sstr[c] = '\0';
  12067. strcpy(tempchargingProfileKindStr,sstr);
  12068. }
  12069. else
  12070. {
  12071. strcpy(tempchargingProfileKindStr,"");
  12072. }
  12073. //***********recurrencyKind **************/
  12074. c = 0;
  12075. loc = strstr(sLineWord, "recurrencyKind");
  12076. //DEBUG_INFO("loc=%s\n",loc);
  12077. memset(sstr ,0, sizeof(sstr) );
  12078. if(loc != NULL)
  12079. {
  12080. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12081. {
  12082. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12083. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12084. c++;
  12085. }
  12086. sstr[c] = '\0';
  12087. strcpy(temprecurrencyKindStr,sstr);
  12088. }
  12089. else
  12090. {
  12091. strcpy(temprecurrencyKindStr,"");
  12092. }
  12093. //***********validFrom**************/
  12094. c = 0;
  12095. loc = strstr(sLineWord, "validFrom");
  12096. if(loc != NULL)
  12097. {
  12098. memset(sstr ,0, sizeof(sstr) );
  12099. while (loc[3+strlen("validFrom")+c] != '\"')
  12100. {
  12101. sstr[c] = loc[3+strlen("validFrom")+c];
  12102. c++;
  12103. }
  12104. sstr[c] = '\0';
  12105. strcpy(tempvalidFromStr,sstr);
  12106. }
  12107. else
  12108. {
  12109. strcpy(tempvalidFromStr,"");
  12110. }
  12111. //***********duration**************/
  12112. c = 0;
  12113. loc = strstr(sLineWord, "duration");
  12114. //DEBUG_INFO("loc=%s\n",loc);
  12115. memset(sstr ,0, sizeof(sstr) );
  12116. if(loc != NULL)
  12117. {
  12118. while (loc[2+strlen("duration")+c] != '\"')
  12119. {
  12120. sstr[c] = loc[2+strlen("duration")+c];
  12121. c++;
  12122. }
  12123. sstr[c] = '\0';
  12124. tempdurationInt = atoi(sstr);
  12125. }
  12126. else
  12127. {
  12128. tempdurationInt = 0;
  12129. }
  12130. //**********startSchedule**********/
  12131. c = 0;
  12132. loc = strstr(sLineWord, "startSchedule");
  12133. memset(sstr ,0, sizeof(sstr) );
  12134. while (loc[3+strlen("startSchedule")+c] != '\"')
  12135. {
  12136. sstr[c] = loc[3+strlen("startSchedule")+c];
  12137. c++;
  12138. }
  12139. sstr[c] = '\0';
  12140. strcpy(tempstartScheduleStr, sstr);
  12141. strcpy(TxProfileScheduleStr, sstr);
  12142. //**********chargingRateUnit**********/
  12143. c = 0;
  12144. loc = strstr(sLineWord, "chargingRateUnit");
  12145. memset(sstr ,0, sizeof(sstr) );
  12146. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12147. {
  12148. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12149. c++;
  12150. }
  12151. sstr[c] = '\0';
  12152. strcpy(tempchargingRateUnitStr, sstr);
  12153. //**********minChargingRate*******/
  12154. c = 0;
  12155. loc = strstr(sLineWord, "minChargingRate");
  12156. if(loc != NULL)
  12157. {
  12158. memset(sstr ,0, sizeof(sstr) );
  12159. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12160. {
  12161. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12162. c++;
  12163. }
  12164. sstr[c] = '\0';
  12165. tempminChargingRateFloat = atof(sstr);
  12166. }
  12167. else
  12168. {
  12169. tempminChargingRateFloat = 0.0;
  12170. }
  12171. //
  12172. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12173. tp.tm_isdst = -1;
  12174. time_t utc = mktime(&tp);
  12175. time_t t = time(NULL);
  12176. diff_t = difftime(t, utc);
  12177. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12178. //parsing strings to words
  12179. i = 0;
  12180. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12181. loc = loc+3+strlen("chargingSchedulePeriod");
  12182. pch = strtok(loc ,"{");
  12183. while (pch != NULL)
  12184. {
  12185. strcpy(SchedulePeriodList[i], pch);
  12186. pch = strtok (NULL, "{");
  12187. i = i + 1;
  12188. }
  12189. n_SchedulePeriods = i;
  12190. for(int i=0;i<n_SchedulePeriods;i++)
  12191. {
  12192. //*************startPeriod****************/
  12193. c = 0;
  12194. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12195. memset(sstr ,0, sizeof(sstr) );
  12196. while (loc[strlen("startPeriod")+2+c] != ',')
  12197. {
  12198. sstr[c] = loc[strlen("startPeriod")+2+c];
  12199. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12200. c++;
  12201. }
  12202. sstr[c] = '\0';
  12203. tempStartPeriodInt = atoi(sstr);
  12204. //*************limit****************/
  12205. c = 0;
  12206. loc = strstr(SchedulePeriodList[i], "limit");
  12207. memset(sstr ,0, sizeof(sstr) );
  12208. while (loc[strlen("limit")+2+c] != ',')
  12209. {
  12210. sstr[c] = loc[strlen("limit")+2+c];
  12211. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12212. c++;
  12213. }
  12214. sstr[c] = '\0';
  12215. tempLimitInt = atof(sstr);
  12216. //*************numberPhases****************/
  12217. c = 0;
  12218. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12219. memset(sstr ,0, sizeof(sstr) );
  12220. while (loc[strlen("numberPhases")+2+c] != '}')
  12221. {
  12222. sstr[c] = loc[strlen("numberPhases")+2+c];
  12223. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12224. c++;
  12225. }
  12226. sstr[c] = '\0';
  12227. tempNumberPhasesInt = atoi(sstr);
  12228. //TxProfile.Duration = durationInt;
  12229. TxProfile.TotalPeriod = n_SchedulePeriods;
  12230. TxProfile.Period[i].Limit = tempLimitInt;
  12231. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12232. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12233. }
  12234. if(MinChargingRate < tempminChargingRateFloat)
  12235. {
  12236. MinChargingRate = tempminChargingRateFloat;
  12237. }
  12238. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12239. if(confirmPeriods < n_SchedulePeriods)
  12240. confirmPeriods = n_SchedulePeriods;
  12241. if(j == 0)
  12242. {
  12243. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12244. TxProfile_TEMP.StackLevel = tempstackLevel;
  12245. TxProfile_TEMP.TransactionId = 0;
  12246. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  12247. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12248. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12249. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12250. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12251. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12252. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12253. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12254. }
  12255. }
  12256. fclose(fptr1);
  12257. }
  12258. }// the end of ACCESS TxProfile
  12259. //CompositeSchedule
  12260. int period=0;
  12261. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  12262. {
  12263. //TxProfile
  12264. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  12265. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  12266. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  12267. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  12268. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  12269. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  12270. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  12271. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  12272. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  12273. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  12274. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  12275. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  12276. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  12277. for(int k=0; k < TxProfile.TotalPeriod;k++)
  12278. {
  12279. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  12280. {
  12281. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  12282. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12283. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12284. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  12285. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12286. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12287. period = period + 1;
  12288. }
  12289. else
  12290. {
  12291. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  12292. {
  12293. }
  12294. else
  12295. {
  12296. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12297. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12298. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12299. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12300. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12301. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12302. period = period + 1;
  12303. }
  12304. }
  12305. }
  12306. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12307. {
  12308. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  12309. {
  12310. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  12311. {
  12312. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  12313. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  12314. }
  12315. else
  12316. {
  12317. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12318. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12319. }
  12320. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12321. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12322. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12323. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12324. period = period + 1;
  12325. }
  12326. }
  12327. }
  12328. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  12329. {
  12330. //TxDefaultProfile
  12331. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  12332. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  12333. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12334. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  12335. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  12336. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  12337. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  12338. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  12339. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  12340. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  12341. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  12342. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  12343. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  12344. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12345. {
  12346. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  12347. {
  12348. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12349. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12350. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12351. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12352. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12353. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12354. period = period + 1;
  12355. }
  12356. else
  12357. {
  12358. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  12359. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12360. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12361. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  12362. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12363. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12364. period = period + 1;
  12365. }
  12366. }
  12367. }
  12368. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  12369. {
  12370. //TxDefaultProfile
  12371. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  12372. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  12373. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12374. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  12375. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  12376. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  12377. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  12378. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  12379. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  12380. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  12381. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  12382. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  12383. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12384. {
  12385. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12386. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12387. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12388. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12389. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12390. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12391. period = period + 1;
  12392. }
  12393. }
  12394. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  12395. {
  12396. //ChargePointMaxProfile
  12397. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  12398. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  12399. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12400. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  12401. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  12402. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  12403. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  12404. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  12405. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  12406. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  12407. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  12408. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  12409. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  12410. {
  12411. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  12412. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  12413. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  12414. period = period + 1;
  12415. }
  12416. }
  12417. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  12418. {
  12419. //TxProfile
  12420. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  12421. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  12422. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  12423. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  12424. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  12425. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  12426. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  12427. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  12428. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  12429. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  12430. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  12431. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  12432. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  12433. for(int k=0; k < TxProfile.TotalPeriod;k++)
  12434. {
  12435. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  12436. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  12437. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  12438. }
  12439. }
  12440. confirmPeriods = period;
  12441. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  12442. DEBUG_INFO("\nchargingProfileId =%d, transactionId =%d\n, stackLevel =%d, chargingProfilePurpose=%s, chargingProfileKind=%s, recurrencyKind =%s, validFrom =%s, validTo =%s, duration=%d , startSchedule =%s, chargingRateUnit=%s, minChargingRate=%f,"
  12443. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  12444. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  12445. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  12446. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  12447. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  12448. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  12449. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  12450. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  12451. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  12452. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  12453. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  12454. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  12455. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  12456. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  12457. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  12458. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  12459. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  12460. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  12461. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  12462. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  12463. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  12464. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  12465. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  12466. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  12467. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  12468. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  12469. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  12470. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  12471. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  12472. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  12473. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  12474. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  12475. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  12476. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  12477. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  12478. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  12479. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  12480. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  12481. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  12482. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  12483. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  12484. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  12485. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  12486. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  12487. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  12488. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  12489. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  12490. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  12491. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  12492. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  12493. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  12494. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  12495. }
  12496. void LWS_Send(char * str)
  12497. {
  12498. //=====================================================
  12499. // Check InternetConn 0: disconnected, 1: connected
  12500. //====================================================
  12501. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  12502. {
  12503. DEBUG_INFO("\n offline now !!!\n");
  12504. return;
  12505. }
  12506. pthread_mutex_lock(&lock);
  12507. memset(SendBuffer,0,SendBufLen);
  12508. sprintf((char *)SendBuffer, "%s", str);
  12509. pthread_mutex_unlock(&lock);
  12510. lws_callback_on_writable(wsi_client);
  12511. lws_service(context, 10000);//timeout_ms
  12512. }