MessageHandler.c 515 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513
  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 other variables
  115. //===============================
  116. int isUpdateRequest = FALSE;
  117. static int HeartBeatWaitTime = 10;
  118. static int FirstHeartBeat = 0;
  119. static int FirmwareStatusNotificationStatus = 3; // Idle
  120. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  121. static char CurrentChargingProfileScheduleStr[30]={0};
  122. //========================================
  123. // OCPP status/previous related variables
  124. //========================================
  125. static int GunStatusInterval = 10;
  126. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  127. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  128. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  129. static int GbPreviousSystemStatus[GB_QUANTITY];
  130. static int AcPreviousSystemStatus[AC_QUANTITY];
  131. int TransactionMessageAttemptsValue = 0;
  132. int TransactionMessageRetryIntervalValue = 0;
  133. static struct OCPPAuthLocalElemet
  134. {
  135. int listVersionInt;
  136. char idTagstr[20];
  137. char parentIdTag[20];
  138. char expiryDate[30];
  139. char idTagstatus[16];
  140. }idTagQuery;
  141. //=============================================
  142. // OCPP HeartBeat Response Not Receive Counts
  143. //============================================
  144. static int HeartBeatWithNOResponse = 0;
  145. static int HeartBeatCount = 0;
  146. extern struct lws *wsi_client;
  147. extern struct lws_context *context;
  148. #if 0
  149. extern unsigned char *SendBuffer;
  150. #endif
  151. extern unsigned char SendBuffer[4096];
  152. extern int SendBufLen;
  153. //extern map_t hashMap;
  154. //extern data_struct_t* mapItem; --- remove for temporally
  155. //extern data_struct_t mapItem[0];
  156. extern char *random_uuid( char buf[37] );
  157. extern void split(char **arr, char *str, const char *del);
  158. extern pthread_mutex_t mutex1;
  159. extern struct Charger_Info Charger;
  160. extern sqlite3 *db;
  161. int TransactionMessageAttemptsGet(void);
  162. int TransactionMessageRetryIntervalGet(void);
  163. int GetOcppConnStatus(void);
  164. void SetOcppConnStatus(uint8_t status);
  165. int updateSetting(char *key, char *value);
  166. int setKeyValue(char *key, char *value);
  167. void OCPP_get_TableAuthlocalAllData(void);
  168. void processUnkownKey(void);
  169. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  170. struct StructOCPPMeterValue
  171. {
  172. unsigned char TimeStamp[28];
  173. struct StructSampledValue SampledValue[10];
  174. };
  175. struct ClientTime
  176. {
  177. unsigned int Heartbeat;
  178. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  179. unsigned int StartTransaction;
  180. unsigned int StopTransaction;
  181. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  182. }clientTime;
  183. typedef union
  184. {
  185. //Operations Initiated by Central System
  186. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  187. struct
  188. {
  189. //CsMsgValue[0]
  190. unsigned char StatusNotificationReq :1; //bit 0,
  191. unsigned char StatusNotificationConf :1; //bit 0,
  192. unsigned char :6; //bit 2~7
  193. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  194. }CpinitiateMsg;
  195. CpinitiateMsg cpinitateMsg;
  196. //==========================================
  197. // Init all Enumeration & Mapping String
  198. //==========================================
  199. /*ChargePointErrorCode*/
  200. typedef enum {
  201. ConnectorLockFailure,
  202. EVCommunicationError,
  203. GroundFailure,
  204. HighTemperature,
  205. InternalError,
  206. LocalListConflict,
  207. NoError,
  208. OtherError,
  209. OverCurrentFailure,
  210. OverVoltage,
  211. PowerMeterFailure,
  212. PowerSwitchFailure,
  213. ReaderFailure,
  214. ResetFailure,
  215. UnderVoltage,
  216. WeakSignal
  217. } ChargePointErrorCode;
  218. #if 0
  219. static char *ChargePointErrorCodeStr[] = {
  220. MACROSTR(ConnectorLockFailure),
  221. MACROSTR(EVCommunicationError),
  222. MACROSTR(GroundFailure),
  223. MACROSTR(HighTemperature),
  224. MACROSTR(InternalError),
  225. MACROSTR(LocalListConflict),
  226. MACROSTR(NoError),
  227. MACROSTR(OtherError),
  228. MACROSTR(OverCurrentFailure),
  229. MACROSTR(OverVoltage),
  230. MACROSTR(PowerMeterFailure),
  231. MACROSTR(PowerSwitchFailure),
  232. MACROSTR(ReaderFailure),
  233. MACROSTR(ResetFailure),
  234. MACROSTR(UnderVoltage),
  235. MACROSTR(WeakSignal)
  236. };
  237. #endif
  238. /*ChargePointStatus*/
  239. typedef enum {
  240. Available =0,
  241. Preparing,
  242. Charging,
  243. SuspendedEVSE,
  244. SuspendedEV,
  245. Finishing,
  246. Reserved,
  247. Unavailable,
  248. Faulted
  249. } ChargePointStatus;
  250. static char * ChargePointStatusStr[] = {
  251. MACROSTR(Available),
  252. MACROSTR(Preparing),
  253. MACROSTR(Charging),
  254. MACROSTR(SuspendedEVSE),
  255. MACROSTR(SuspendedEV),
  256. MACROSTR(Finishing),
  257. MACROSTR(Reserved),
  258. MACROSTR(Unavailable),
  259. MACROSTR(Faulted)
  260. };
  261. /*AvailabilityType*/
  262. typedef enum {
  263. RegistrationStatus_Accepted,
  264. RegistrationStatus_Pending,
  265. RegistrationStatus_Rejected
  266. } RegistrationStatus;
  267. static char *RegistrationStatusStr[] = {
  268. MACROSTR(Accepted),
  269. MACROSTR(Pending),
  270. MACROSTR(Rejected)
  271. };
  272. /*AvailabilityType*/
  273. typedef enum {
  274. Inoperative,
  275. Operative
  276. } AvailabilityType;
  277. static char *AvailabilityTypeStr[] = {
  278. MACROSTR(Inoperative),
  279. MACROSTR(Operative)
  280. };
  281. /*AvailabilityStatus*/
  282. typedef enum {
  283. Accepted,
  284. Rejected,
  285. Scheduled
  286. } AvailabilityStatus;
  287. static char *AvailabilityStatusStr[] = {
  288. MACROSTR(Accepted),
  289. MACROSTR(Rejected),
  290. MACROSTR(Scheduled)
  291. };
  292. /*ConfigurationStatus*/
  293. typedef enum {
  294. ConfigurationStatus_Accepted,
  295. ConfigurationStatus_Rejected,
  296. RebootRequired,
  297. NotSupported
  298. } ConfigurationStatus;
  299. static char *ConfigurationStatusStr[] = {
  300. MACROSTR(Accepted),
  301. MACROSTR(Rejected),
  302. MACROSTR(RebootRequired),
  303. MACROSTR(NotSupported)
  304. };
  305. /*ClearCacheStatus*/
  306. typedef enum {
  307. ClearCacheStatus_Accepted,
  308. ClearCacheStatus_Rejected
  309. } ClearCacheStatus;
  310. static char *ClearCacheStatusStr[] = {
  311. MACROSTR(Accepted),
  312. MACROSTR(Rejected)
  313. };
  314. /*ChargingProfilePurposeType*/
  315. typedef enum {
  316. ChargePointMaxProfile,
  317. TxDefaultProfile,
  318. TxProfile
  319. } ChargingProfilePurposeType;
  320. static char *ChargingProfilePurposeTypeStr[] = {
  321. MACROSTR(ChargePointMaxProfile),
  322. MACROSTR(TxDefaultProfile),
  323. MACROSTR(TxProfile)
  324. };
  325. /*ChargingProfileStatus*/
  326. typedef enum {
  327. ChargingProfileStatus_Accepted,
  328. ChargingProfileStatus_Rejected,
  329. ChargingProfileStatus_NotSupported
  330. } ChargingProfileStatus;
  331. static char *ChargingProfileStatusStr[] = {
  332. MACROSTR(Accepted),
  333. MACROSTR(Rejected),
  334. MACROSTR(NotSupported)
  335. };
  336. /*ClearChargingProfileStatus*/
  337. typedef enum {
  338. ClearChargingProfileStatus_Accepted,
  339. ClearChargingProfileStatus_Unknown
  340. } ClearChargingProfileStatus;
  341. static char *ClearChargingProfileStatusStr[] = {
  342. MACROSTR(Accepted),
  343. MACROSTR(Unknown)
  344. };
  345. /*GetCompositeScheduleStatus*/
  346. typedef enum {
  347. GetCompositeScheduleStatus_Accepted,
  348. GetCompositeScheduleStatus_Rejected
  349. } GetCompositeScheduleStatus;
  350. static char *GetCompositeScheduleStatusStr[] = {
  351. MACROSTR(Accepted),
  352. MACROSTR(Rejected)
  353. };
  354. /*ChargingRateUnitType*/
  355. typedef enum {
  356. ChargingRateUnitType_W,
  357. ChargingRateUnitType_A
  358. } ChargingRateUnitType;
  359. /*AuthorizationStatus*/
  360. typedef enum {
  361. AuthorizationStatus_Accepted ,
  362. AuthorizationStatus_Blocked ,
  363. AuthorizationStatus_Expired ,
  364. AuthorizationStatus_Invalid ,
  365. AuthorizationStatus_ConcurrentTx
  366. } AuthorizationStatus;
  367. /*UpdateType*/
  368. typedef enum {
  369. Differential ,
  370. Full
  371. } UpdateType;
  372. static char *UpdateTypeStr[] = {
  373. MACROSTR(Differential),
  374. MACROSTR(Full)
  375. };
  376. /*UpdateStatus*/
  377. typedef enum {
  378. UpdateStatus_Accepted ,
  379. UpdateStatus_Failed ,
  380. UpdateStatus_NotSupported ,
  381. UpdateStatus_VersionMismatch
  382. } UpdateStatus;
  383. static char *UpdateStatusStr[] = {
  384. MACROSTR(Accepted),
  385. MACROSTR(Failed),
  386. MACROSTR(NotSupported),
  387. MACROSTR(VersionMismatch)
  388. };
  389. /*RemoteStartStopStatus*/
  390. typedef enum {
  391. RemoteStartStopStatus_Accepted,
  392. RemoteStartStopStatus_Rejected
  393. } RemoteStartStopStatus;
  394. static char *RemoteStartStopStatusStr[] = {
  395. MACROSTR(Accepted),
  396. MACROSTR(Rejected)
  397. };
  398. /*ReservationStatus*/
  399. typedef enum {
  400. ReservationStatus_Accepted,
  401. ReservationStatus_Faulted,
  402. ReservationStatus_Occupied,
  403. ReservationStatus_Rejected,
  404. ReservationStatus_Unavailable
  405. } ReservationStatus;
  406. static char *ReservationStatusStr[] = {
  407. MACROSTR(Accepted),
  408. MACROSTR(Faulted),
  409. MACROSTR(Occupied),
  410. MACROSTR(Rejected),
  411. MACROSTR(Unavailable)
  412. };
  413. /*ResetType*/
  414. typedef enum {
  415. Hard,
  416. Soft
  417. } ResetType;
  418. static char *ResetTypeStr[] = {
  419. MACROSTR(Hard),
  420. MACROSTR(Soft)
  421. };
  422. /*ResetStatus*/
  423. typedef enum {
  424. ResetStatus_Accepted,
  425. ResetStatus_Rejected
  426. } ResetStatus;
  427. static char *ResetStatusStr[] = {
  428. MACROSTR(Accepted),
  429. MACROSTR(Rejected)
  430. };
  431. /*DiagnosticsStatus*/
  432. typedef enum {
  433. DiagnosticsStatus_Idle,
  434. DiagnosticsStatus_Uploaded,
  435. DiagnosticsStatus_UploadFailed,
  436. DiagnosticsStatus_Uploading
  437. } DiagnosticsStatus;
  438. static char * DiagnosticsStatusStr[] = {
  439. MACROSTR(Idle),
  440. MACROSTR(Uploaded),
  441. MACROSTR(UploadFailed),
  442. MACROSTR(Uploading)
  443. };
  444. /*FirmwareStatus*/
  445. typedef enum {
  446. FirmwareStatus_Downloaded,
  447. FirmwareStatus_DownloadFailed,
  448. FirmwareStatus_Downloading,
  449. FirmwareStatus_Idle,
  450. FirmwareStatus_InstallationFailed,
  451. FirmwareStatus_Installing,
  452. FirmwareStatus_Installed
  453. } FirmwareStatus;
  454. static char * FirmwareStatusStr[] = {
  455. MACROSTR(Downloaded),
  456. MACROSTR(DownloadFailed),
  457. MACROSTR(Downloading),
  458. MACROSTR(Idle),
  459. MACROSTR(InstallationFailed),
  460. MACROSTR(Installing),
  461. MACROSTR(Installed)
  462. };
  463. /*MessageTrigger*/
  464. typedef enum {
  465. BootNotification,
  466. DiagnosticsStatusNotification,
  467. FirmwareStatusNotification,
  468. Heartbeat,
  469. MeterValues,
  470. StatusNotification
  471. } MessageTrigger;
  472. static char * MessageTriggerStr[] = {
  473. MACROSTR(BootNotification),
  474. MACROSTR(DiagnosticsStatusNotification),
  475. MACROSTR(FirmwareStatusNotification),
  476. MACROSTR(Heartbeat),
  477. MACROSTR(MeterValues),
  478. MACROSTR(StatusNotification)
  479. };
  480. /*TriggerMessageStatus*/
  481. typedef enum {
  482. TriggerMessageStatus_Accepted ,
  483. TriggerMessageStatus_Rejected ,
  484. TriggerMessageStatus_NotImplemented
  485. } TriggerMessageStatus;
  486. static char * TriggerMessageStatusStr[] = {
  487. MACROSTR(Accepted),
  488. MACROSTR(Rejected),
  489. MACROSTR(NotImplemented)
  490. };
  491. /*UnlockStatus*/
  492. typedef enum {
  493. Unlocked,
  494. UnlockFailed,
  495. UnlockStatus_NotSupported
  496. } UnlockStatus;
  497. static char * UnlockStatusStr[] = {
  498. MACROSTR(Unlocked),
  499. MACROSTR(UnlockFailed),
  500. MACROSTR(NotSupported)
  501. };
  502. /*StopTransactionReason*/
  503. typedef enum {
  504. EmergencyStop,
  505. EVDisconnected,
  506. HardReset,
  507. Local,
  508. Other,
  509. PowerLoss,
  510. Reboot,
  511. Remote,
  512. SoftReset,
  513. UnlockCommand,
  514. DeAuthorized
  515. } StopTransactionReason;
  516. static char * StopTransactionReasonStr[] = {
  517. MACROSTR(EmergencyStop),
  518. MACROSTR(EVDisconnected),
  519. MACROSTR(HardReset),
  520. MACROSTR(Local),
  521. MACROSTR(Other),
  522. MACROSTR(PowerLoss),
  523. MACROSTR(Reboot),
  524. MACROSTR(Remote),
  525. MACROSTR(SoftReset),
  526. MACROSTR(UnlockCommand),
  527. MACROSTR(DeAuthorized)
  528. };
  529. /*CancelReservationStatus*/
  530. typedef enum {
  531. CancelReservationStatus_Accepted,
  532. CancelReservationStatus_Rejected
  533. } CancelReservationStatus;
  534. static char * CancelReservationStatusStr[] = {
  535. MACROSTR(Accepted),
  536. MACROSTR(Rejected)
  537. };
  538. /*ReadingContext*/
  539. typedef enum {
  540. ReadingContext_Interruption_Begin,
  541. ReadingContext_Interruption_End,
  542. ReadingContext_Other,
  543. ReadingContext_Sample_Clock,
  544. ReadingContext_Sample_Periodic ,
  545. ReadingContext_Transaction_Begin ,
  546. ReadingContext_Transaction_End,
  547. ReadingContext_Trigger
  548. } ReadingContext;
  549. static char * ReadingContextStr[] = {
  550. MACROSTR(Interruption.Begin),
  551. MACROSTR(Interruption.End),
  552. MACROSTR(Other),
  553. MACROSTR(Sample.Clock),
  554. MACROSTR(Sample.Periodic),
  555. MACROSTR(Transaction.Begin),
  556. MACROSTR(Transaction.End),
  557. MACROSTR(Trigger)
  558. };
  559. /*ValueFormat*/
  560. typedef enum {
  561. Raw,
  562. SignedData
  563. } ValueFormat;
  564. static char * ValueFormatStr[] = {
  565. MACROSTR(Raw),
  566. MACROSTR(SignedData)
  567. };
  568. /*Measurand*/
  569. typedef enum {
  570. Current_Export ,
  571. Current_Import,
  572. Current_Offered,
  573. Energy_Active_Export_Register,
  574. Energy_Active_Import_Register,
  575. Energy_Reactive_Export_Register,
  576. Energy_Reactive_Import_Register,
  577. Energy_Active_Export_Interval,
  578. Energy_Active_Import_Interval,
  579. Energy_Reactive_Export_Interval,
  580. Energy_Reactive_Import_Interval,
  581. Frequency,
  582. Power_Active_Export ,
  583. Power_Active_Import,
  584. Power_Factor,
  585. Power_Offered,
  586. Power_Reactive_Export,
  587. Power_Reactive_Import,
  588. RPM,
  589. SoC,
  590. Temperature ,
  591. Voltage
  592. } Measurand;
  593. static char * MeasurandStr[] = {
  594. MACROSTR(Current.Export),
  595. MACROSTR(Current.Import),
  596. MACROSTR(Current.Offered),
  597. MACROSTR(Energy.Active.Export.Register),
  598. MACROSTR(Energy.Active.Import.Register),
  599. MACROSTR(Energy.Reactive.Export.Register),
  600. MACROSTR(Energy.Reactive.Import.Register),
  601. MACROSTR(Energy.Active.Export.Interval),
  602. MACROSTR(Energy.Active.Import.Interval),
  603. MACROSTR(Energy.Reactive.Export.Interval),
  604. MACROSTR(Energy.Reactive.Import.Interval),
  605. MACROSTR(Frequency),
  606. MACROSTR(Power.Active.Export),
  607. MACROSTR(Power.Active.Import),
  608. MACROSTR(Power.Factor),
  609. MACROSTR(Power.Offered),
  610. MACROSTR(Power.Reactive.ExportMACROSTR),
  611. MACROSTR(Power.Reactive.Import),
  612. MACROSTR(RPM),
  613. MACROSTR(SoC),
  614. MACROSTR(Temperature),
  615. MACROSTR(Voltage)
  616. };
  617. /*Location*/
  618. typedef enum {
  619. Location_Body,
  620. Location_Cable,
  621. Location_EV,
  622. Location_Inlet ,
  623. Location_Outlet
  624. } Location;
  625. static char * LocationStr[] = {
  626. MACROSTR(Body),
  627. MACROSTR(Cable),
  628. MACROSTR(EV),
  629. MACROSTR(Inlet),
  630. MACROSTR(Outlet)
  631. };
  632. /*Phase*/
  633. typedef enum {
  634. L1,
  635. L2,
  636. L3,
  637. N,
  638. L1_N,
  639. L2_N,
  640. L3_N,
  641. L1_L2,
  642. L2_L3,
  643. L3_L1
  644. } Phase;
  645. static char * PhaseStr[] = {
  646. MACROSTR(L1),
  647. MACROSTR(L2),
  648. MACROSTR(L3),
  649. MACROSTR(N),
  650. MACROSTR(L1-N),
  651. MACROSTR(L2-N),
  652. MACROSTR(L3-N),
  653. MACROSTR(L1-L2),
  654. MACROSTR(L2-L3),
  655. MACROSTR(L3-L1)
  656. };
  657. /*UnitOfMeasure*/
  658. typedef enum {
  659. UnitOfMeasure_Wh,
  660. UnitOfMeasure_kWh ,
  661. UnitOfMeasure_varh ,
  662. UnitOfMeasure_kvarh ,
  663. UnitOfMeasure_W ,
  664. UnitOfMeasure_kW ,
  665. UnitOfMeasure_VA ,
  666. UnitOfMeasure_kVA ,
  667. UnitOfMeasure_var ,
  668. UnitOfMeasure_kvar ,
  669. UnitOfMeasure_A ,
  670. UnitOfMeasure_V ,
  671. UnitOfMeasure_Celsius ,
  672. UnitOfMeasure_Fahrenheit ,
  673. UnitOfMeasure_K ,
  674. UnitOfMeasure_Percent
  675. } UnitOfMeasure;
  676. static char * UnitOfMeasureStr[] = {
  677. MACROSTR(Wh),
  678. MACROSTR(kWh),
  679. MACROSTR(varh),
  680. MACROSTR(kvarh),
  681. MACROSTR(W),
  682. MACROSTR(kW),
  683. MACROSTR(VA),
  684. MACROSTR(kVA),
  685. MACROSTR(var),
  686. MACROSTR(kvar),
  687. MACROSTR(A),
  688. MACROSTR(V),
  689. MACROSTR(Celsius),
  690. MACROSTR(Fahrenheit),
  691. MACROSTR(K),
  692. MACROSTR(Percent)
  693. };
  694. /*Configuration enum*/
  695. enum CoreProfile {
  696. AllowOfflineTxForUnknownId=0,
  697. AuthorizationCacheEnabled,
  698. AuthorizeRemoteTxRequests,
  699. BlinkRepeat,
  700. ClockAlignedDataInterval,
  701. ConnectionTimeOut,
  702. GetConfigurationMaxKeys,
  703. HeartbeatInterval,
  704. LightIntensity,
  705. LocalAuthorizeOffline,
  706. LocalPreAuthorize,
  707. MaxEnergyOnInvalidId,
  708. MeterValuesAlignedData,
  709. MeterValuesAlignedDataMaxLength,
  710. MeterValuesSampledData,
  711. MeterValuesSampledDataMaxLength,
  712. MeterValueSampleInterval,
  713. MinimumStatusDuration,
  714. NumberOfConnectors,
  715. ResetRetries,
  716. ConnectorPhaseRotation,
  717. ConnectorPhaseRotationMaxLength,
  718. StopTransactionOnEVSideDisconnect,
  719. StopTransactionOnInvalidId,
  720. StopTxnAlignedData,
  721. StopTxnAlignedDataMaxLength,
  722. StopTxnSampledData,
  723. StopTxnSampledDataMaxLength,
  724. SupportedFeatureProfiles,
  725. SupportedFeatureProfilesMaxLength,
  726. TransactionMessageAttempts,
  727. TransactionMessageRetryInterval,
  728. UnlockConnectorOnEVSideDisconnect,
  729. WebSocketPingInterval,
  730. _CoreProfile_CNT
  731. };
  732. enum LocalAuthListManagementProfile{
  733. LocalAuthListEnabled=0,
  734. LocalAuthListMaxLength,
  735. SendLocalListMaxLength,
  736. _LocalAuthListManagementProfile_CNT
  737. };
  738. enum ReservationProfile{
  739. ReserveConnectorZeroSupported
  740. };
  741. enum SmartChargingProfile{
  742. ChargeProfileMaxStackLevel,
  743. ChargingScheduleAllowedChargingRateUnit,
  744. ChargingScheduleMaxPeriods,
  745. ConnectorSwitch3to1PhaseSupported,
  746. MaxChargingProfilesInstalled
  747. };
  748. enum ChargerSystemStatus{
  749. ChargerSystemStatus_Booting,
  750. ChargerSystemStatus_Idle,
  751. ChargerSystemStatus_Authorizing,
  752. ChargerSystemStatus_Preparing,
  753. ChargerSystemStatus_Charging,
  754. ChargerSystemStatus_Terminating,
  755. ChargerSystemStatus_Alarm,
  756. ChargerSystemStatus_Fault
  757. };
  758. enum GetConfigurationKey {
  759. GetConfiguration_AllowOfflineTxForUnknownId=0,
  760. GetConfiguration_AuthorizationCacheEnabled,
  761. GetConfiguration_AuthorizeRemoteTxRequests,
  762. GetConfiguration_BlinkRepeat,
  763. GetConfiguration_ClockAlignedDataInterval,
  764. GetConfiguration_ConnectionTimeOut,
  765. GetConfiguration_GetConfigurationMaxKeys,
  766. GetConfiguration_HeartbeatInterval,
  767. GetConfiguration_LightIntensity,
  768. GetConfiguration_LocalAuthorizeOffline,
  769. GetConfiguration_LocalPreAuthorize,
  770. GetConfiguration_MaxEnergyOnInvalidId,
  771. GetConfiguration_MeterValuesAlignedData,
  772. GetConfiguration_MeterValuesAlignedDataMaxLength,
  773. GetConfiguration_MeterValuesSampledData,
  774. GetConfiguration_MeterValuesSampledDataMaxLength,
  775. GetConfiguration_MeterValueSampleInterval,
  776. GetConfiguration_MinimumStatusDuration,
  777. GetConfiguration_NumberOfConnectors,
  778. GetConfiguration_ResetRetries,
  779. GetConfiguration_ConnectorPhaseRotation,
  780. GetConfiguration_ConnectorPhaseRotationMaxLength,
  781. GetConfiguration_StopTransactionOnEVSideDisconnect,
  782. GetConfiguration_StopTransactionOnInvalidId,
  783. GetConfiguration_StopTxnAlignedData,
  784. GetConfiguration_StopTxnAlignedDataMaxLength,
  785. GetConfiguration_StopTxnSampledData,
  786. GetConfiguration_StopTxnSampledDataMaxLength,
  787. GetConfiguration_SupportedFeatureProfiles,
  788. GetConfiguration_SupportedFeatureProfilesMaxLength,
  789. GetConfiguration_TransactionMessageAttempts,
  790. GetConfiguration_TransactionMessageRetryInterval,
  791. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  792. GetConfiguration_WebSocketPingInterval,
  793. GetConfiguration_LocalAuthListEnabled,
  794. GetConfiguration_LocalAuthListMaxLength,
  795. GetConfiguration_SendLocalListMaxLength,
  796. GetConfiguration_ReserveConnectorZeroSupported,
  797. GetConfiguration_ChargeProfileMaxStackLevel,
  798. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  799. GetConfiguration_ChargingScheduleMaxPeriods,
  800. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  801. GetConfiguration_MaxChargingProfilesInstalled,
  802. };
  803. //GetConfiguration Array
  804. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  805. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  806. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  807. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  808. //==========================================
  809. // Init all share memory
  810. //==========================================
  811. int InitShareMemory()
  812. {
  813. int result = PASS;
  814. int MeterSMId;
  815. //printf("1\n");
  816. //creat ShmSysConfigAndInfo
  817. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  818. {
  819. #ifdef SystemLogMessage
  820. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  821. #endif
  822. result = FAIL;
  823. }
  824. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  825. {
  826. #ifdef SystemLogMessage
  827. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  828. #endif
  829. result = FAIL;
  830. }
  831. else
  832. {}
  833. //printf("2\n");
  834. //creat ShmStatusCodeData
  835. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  836. {
  837. #ifdef SystemLogMessage
  838. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  839. #endif
  840. result = FAIL;
  841. }
  842. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  843. {
  844. #ifdef SystemLogMessage
  845. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  846. #endif
  847. result = FAIL;
  848. }
  849. else
  850. {}
  851. //printf("3\n");
  852. //creat ShmPsuData
  853. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  854. {
  855. #ifdef SystemLogMessage
  856. DEBUG_ERROR("shmget ShmPsuData NG\n");
  857. #endif
  858. result = FAIL;
  859. }
  860. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  861. {
  862. #ifdef SystemLogMessage
  863. DEBUG_ERROR("shmat ShmPsuData NG\n");
  864. #endif
  865. result = FAIL;
  866. }
  867. else
  868. {}
  869. //creat ShmOCPP16Data
  870. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  871. {
  872. #ifdef SystemLogMessage
  873. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  874. #endif
  875. result = FAIL;
  876. }
  877. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  878. {
  879. #ifdef SystemLogMessage
  880. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  881. #endif
  882. result = FAIL;
  883. }
  884. else
  885. {}
  886. /****************************** For Initial Settings************************************************/
  887. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  888. //memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY));
  889. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  890. {
  891. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  892. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  893. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  894. }
  895. // Charger PRE_SYS_MODE
  896. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  897. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  898. clientTime.Heartbeat=time((time_t*)NULL);
  899. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  900. {
  901. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  902. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  903. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  904. }
  905. //HeartBeatWaitTime = 10;
  906. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  907. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  908. // allocate Configuration memory address
  909. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  910. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  911. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  912. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  913. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  914. {
  915. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  916. DEBUG_INFO("DC ...\n");
  917. }
  918. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  919. {
  920. SystemInitial = AC_QUANTITY;
  921. DEBUG_INFO("AC ...\n");
  922. }
  923. //Status Setting
  924. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  925. {
  926. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  927. }
  928. for (int index = 0; index < CCS_QUANTITY; index++)
  929. {
  930. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  931. }
  932. for (int index = 0; index < GB_QUANTITY; index++)
  933. {
  934. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  935. }
  936. for (int index = 0; index < AC_QUANTITY; index++)
  937. {
  938. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  939. }
  940. //memset(unknownkey, 0, 10);
  941. return result;
  942. }
  943. int ProcessShareMemory()
  944. {
  945. if(InitShareMemory() == FAIL)
  946. {
  947. #ifdef SystemLogMessage
  948. DEBUG_ERROR("InitShareMemory NG\n");
  949. #endif
  950. if(ShmStatusCodeData!=NULL)
  951. {
  952. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  953. }
  954. sleep(5);
  955. return FAIL;
  956. }
  957. return PASS;
  958. }
  959. //---------------------------------------------
  960. // new:
  961. // enum SYSTEM_STATUS
  962. // {
  963. // SYS_MODE_BOOTING = 0,
  964. // SYS_MODE_IDLE = 1,
  965. // SYS_MODE_AUTHORIZING = 2,
  966. // SYS_MODE_PREPARING = 3,
  967. // SYS_MODE_CHARGING = 4,
  968. // SYS_MODE_TERMINATING = 5,
  969. // SYS_MODE_ALARM = 6,
  970. // SYS_MODE_FAULT = 7,
  971. // SYS_MODE_RESERVATION = 8,
  972. // SYS_MODE_BOOKING = 9,
  973. // SYS_MODE_MAINTAIN = 10,
  974. // SYS_MODE_DEBUG = 11,
  975. // SYS_MODE_REASSIGN_CHECK = 12,
  976. // SYS_MODE_REASSIGN = 13,
  977. // SYS_MODE_PRECHARGE = 14,
  978. // SYS_MODE_PREPARING_EV = 15,
  979. // SYS_MODE_PREPARING_EVSE = 16,
  980. // SYS_MODE_COMPLETE = 17
  981. // };
  982. //
  983. // old:
  984. // enum _SYSTEM_STATUS
  985. // {
  986. // S_BOOTING = 0,
  987. // S_IDLE, =1
  988. // S_AUTHORIZING, =2
  989. // S_REASSIGN_CHECK, =3
  990. // S_REASSIGN, =4
  991. // S_PRECHARGE, =5
  992. // S_PREPARING_FOR_EV, =6
  993. // S_PREPARING_FOR_EVSE, =7
  994. // S_CHARGING, =8
  995. // S_TERMINATING, =9
  996. // S_COMPLETE, =10
  997. // S_ALARM, =11
  998. // S_FAULT =12
  999. // };
  1000. //
  1001. //-----------------------------------------
  1002. void CheckSystemValue(void)
  1003. {
  1004. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1005. int IdleModeCnt = 0;
  1006. char filenmae[100]={0};
  1007. char str[100]={0};
  1008. //===============================
  1009. // send Heartbeat
  1010. //===============================
  1011. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1012. {
  1013. //parameter for test
  1014. sendHeartbeatRequest(0);
  1015. //==============================================
  1016. // Reset Waiting Time
  1017. //==============================================
  1018. clientTime.Heartbeat=time((time_t*)NULL);
  1019. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1020. }
  1021. //==============================================
  1022. // Update firmware request
  1023. //==============================================
  1024. if(isUpdateRequest == TRUE )
  1025. {
  1026. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1027. {
  1028. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1029. {
  1030. //check SystemStatus
  1031. /*************************DC*******************************/
  1032. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1033. {
  1034. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1035. {
  1036. IdleModeCnt = IdleModeCnt + 1;
  1037. }
  1038. }
  1039. for (int index = 0; index < CCS_QUANTITY; index++)
  1040. {
  1041. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1042. {
  1043. IdleModeCnt = IdleModeCnt + 1;
  1044. }
  1045. }
  1046. for (int index = 0; index < GB_QUANTITY; index++)
  1047. {
  1048. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1049. {
  1050. IdleModeCnt = IdleModeCnt + 1;
  1051. }
  1052. }
  1053. }
  1054. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1055. {
  1056. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1057. isUpdateRequest = FALSE;
  1058. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1059. }
  1060. }
  1061. else
  1062. {
  1063. /*************************AC*******************************/
  1064. for (int index = 0; index < AC_QUANTITY; index++)
  1065. {
  1066. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1067. {
  1068. IdleModeCnt = IdleModeCnt + 1;
  1069. }
  1070. }
  1071. if(IdleModeCnt == AC_QUANTITY)
  1072. {
  1073. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1074. isUpdateRequest = FALSE;
  1075. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1076. }
  1077. }
  1078. }
  1079. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1080. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1081. {
  1082. //===============================
  1083. // CSU Trigger Reset Conf
  1084. //===============================
  1085. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1086. {
  1087. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1088. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1089. {
  1090. server_sign = FALSE;
  1091. }
  1092. }
  1093. //===============================
  1094. // CSU Trigger Authorize Request
  1095. //===============================
  1096. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1097. {
  1098. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1099. {
  1100. sendAuthorizeRequest(0);
  1101. authorizeRetryTimes = authorizeRetryTimes + 1;
  1102. // authenrequest = TRUE
  1103. if(authorizeRetryTimes < 3)
  1104. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1105. }
  1106. }
  1107. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1108. {
  1109. authorizeRetryTimes = 0;
  1110. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1111. server_sign = FALSE;
  1112. }
  1113. //===============================
  1114. // CSU Trigger Smart Charging Profilw
  1115. //===============================
  1116. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1117. {
  1118. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1119. GetChargingProfileRequest(gun_index);
  1120. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1121. }
  1122. //==============================================
  1123. // Charger start transaction
  1124. //==============================================
  1125. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1126. {
  1127. sendStartTransactionRequest(gun_index);
  1128. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1129. clientTime.StartTransaction = time((time_t*)NULL);
  1130. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1131. }
  1132. //==============================================
  1133. // Charger stop transaction
  1134. //==============================================
  1135. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1136. {
  1137. sendStopTransactionRequest(gun_index);
  1138. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1139. clientTime.StopTransaction = time((time_t*)NULL);
  1140. }
  1141. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1142. //==============================================
  1143. // Charger status report
  1144. //==============================================
  1145. /* Check Mode Change */
  1146. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1147. {
  1148. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1149. {
  1150. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1151. {
  1152. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1153. {
  1154. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1155. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1156. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1157. statusModeChage[gun_index] = TRUE;
  1158. }
  1159. }
  1160. }
  1161. for (int index = 0; index < CCS_QUANTITY; index++)
  1162. {
  1163. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1164. {
  1165. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1166. {
  1167. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1168. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1169. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1170. statusModeChage[gun_index] = TRUE;
  1171. }
  1172. }
  1173. }
  1174. for (int index = 0; index < GB_QUANTITY; index++)
  1175. {
  1176. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1177. {
  1178. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1179. {
  1180. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1181. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1182. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1183. statusModeChage[gun_index] = TRUE;
  1184. }
  1185. }
  1186. }
  1187. }
  1188. else //AC
  1189. {
  1190. for (int index = 0; index < AC_QUANTITY; index++)
  1191. {
  1192. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1193. {
  1194. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1195. {
  1196. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1197. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1198. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1199. statusModeChage[gun_index] = TRUE;
  1200. }
  1201. }
  1202. }// END OF FOR
  1203. }// END OF ELSE
  1204. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1205. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1206. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1207. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1208. {
  1209. if(SystemInitial != 0)
  1210. SystemInitial = SystemInitial -1;
  1211. //GunStatusInterval= GunStatusInterval* gun_index;
  1212. sendStatusNotificationRequest(gun_index);
  1213. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1214. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1215. statusModeChage[gun_index] = FALSE;
  1216. //sleep(30); // sleep for 30 seconds
  1217. }
  1218. //==============================================
  1219. // Meter report
  1220. //==============================================
  1221. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1222. {
  1223. //check Transaction active
  1224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1225. {
  1226. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1227. {
  1228. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1229. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1230. {
  1231. meterValueSend[gun_index] =1;
  1232. }
  1233. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1234. {
  1235. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1236. if((access(filenmae,F_OK))!=-1)
  1237. {
  1238. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1239. sprintf(str,"rm -f %s",filenmae);
  1240. system(str);
  1241. }
  1242. }
  1243. }// End for CHAdeMO
  1244. for (int index = 0; index < CCS_QUANTITY; index++)
  1245. {
  1246. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1247. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1248. {
  1249. meterValueSend[gun_index] =1;
  1250. }
  1251. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1252. {
  1253. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1254. if((access(filenmae,F_OK))!=-1)
  1255. {
  1256. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1257. sprintf(str,"rm -f %s",filenmae);
  1258. system(str);
  1259. }
  1260. }
  1261. } // End for CCS
  1262. for (int index = 0; index < GB_QUANTITY; index++)
  1263. {
  1264. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1265. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1266. {
  1267. meterValueSend[gun_index] =1;
  1268. }
  1269. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1270. {
  1271. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1272. if((access(filenmae,F_OK))!=-1)
  1273. {
  1274. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1275. sprintf(str,"rm -f %s",filenmae);
  1276. system(str);
  1277. }
  1278. }
  1279. }// End for GB
  1280. }
  1281. else
  1282. {
  1283. for (int index = 0; index < AC_QUANTITY; index++)
  1284. {
  1285. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1286. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1287. {
  1288. meterValueSend[gun_index] =1;
  1289. }
  1290. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1291. {
  1292. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1293. if((access(filenmae,F_OK))!=-1)
  1294. {
  1295. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1296. sprintf(str,"rm -f %s",filenmae);
  1297. system(str);
  1298. }
  1299. }
  1300. }//End for AC
  1301. }//END OF ELSE
  1302. // sleep(1);
  1303. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1304. if(meterValueSend[gun_index] == 1)
  1305. sendMeterValuesRequest(gun_index);
  1306. }
  1307. //==============================================
  1308. // Check Connector reserved
  1309. //==============================================
  1310. //===============================
  1311. // Check if Reserve is expired
  1312. //===============================
  1313. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1314. {
  1315. double diff_t;
  1316. struct tm tp;
  1317. // current time
  1318. time_t t = time(NULL);
  1319. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1320. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1321. tp.tm_isdst = -1;
  1322. time_t utc = mktime(&tp);
  1323. diff_t = difftime(utc, t);
  1324. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1325. if(diff_t <= 0)
  1326. {
  1327. DEBUG_INFO("reserve expired !!! \n");
  1328. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1329. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1330. }
  1331. #if 0
  1332. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1333. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1334. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1335. {
  1336. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1337. }
  1338. else
  1339. {
  1340. //check Transaction active
  1341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1342. {
  1343. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1344. {
  1345. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1346. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1347. {
  1348. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1349. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1350. {
  1351. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1352. }
  1353. }
  1354. }
  1355. for (int index = 0; index < CCS_QUANTITY; index++)
  1356. {
  1357. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1358. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1359. {
  1360. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1361. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1362. {
  1363. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1364. }
  1365. }
  1366. }
  1367. for (int index = 0; index < GB_QUANTITY; index++)
  1368. {
  1369. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1370. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1371. {
  1372. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1373. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1374. {
  1375. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1376. }
  1377. }
  1378. }
  1379. }
  1380. else //AC
  1381. {
  1382. for (int index = 0; index < AC_QUANTITY; index++)
  1383. {
  1384. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1385. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1386. {
  1387. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1388. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1389. {
  1390. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1391. }
  1392. }
  1393. }
  1394. }// END OF ELSE
  1395. }// END OF check Transaction active
  1396. #endif
  1397. }//END OF Check if Reserve is expired
  1398. //==========================================
  1399. // csu trigger FirmwareStatusNotificationReq
  1400. //==========================================
  1401. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1402. {
  1403. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1404. }
  1405. //==========================================
  1406. // csu trigger CancelReservationConf
  1407. //==========================================
  1408. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1409. {
  1410. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1411. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1412. }
  1413. //==========================================
  1414. // csu trigger ChangeAvailabilityConf
  1415. //==========================================
  1416. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1417. {
  1418. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1419. }
  1420. //==========================================
  1421. // csu trigger UnlockConnectorConf
  1422. //==========================================
  1423. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1424. {
  1425. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1426. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1427. }
  1428. //==========================================
  1429. // csu trigger ReserveNowConf
  1430. //==========================================
  1431. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1432. {
  1433. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1434. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1435. }
  1436. //==========================================
  1437. // csu trigger DataTransferReq
  1438. //==========================================
  1439. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1440. {
  1441. sendDataTransferRequest(gun_index);
  1442. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1443. }
  1444. }
  1445. }
  1446. //==========================================
  1447. // send request routine
  1448. //==========================================
  1449. int sendAuthorizeRequest(int gun_index)
  1450. {
  1451. mtrace();
  1452. int result = FAIL;
  1453. char message[100]={0};
  1454. char guid[37];
  1455. char tempdata[65]={0};
  1456. DEBUG_INFO("sendAuthorizeRequest \n");
  1457. //Local Authorize
  1458. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1459. {
  1460. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1461. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1462. {
  1463. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1464. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1465. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1466. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1467. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1468. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1469. authorizeRetryTimes = 0;
  1470. return result;
  1471. }
  1472. else
  1473. {
  1474. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1475. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1476. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1477. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1478. result = PASS;
  1479. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1480. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1481. authorizeRetryTimes = 0;
  1482. return result;
  1483. }
  1484. }
  1485. //initailize struct Authorize
  1486. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1487. //get data from shared memory
  1488. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1489. random_uuid(guid);
  1490. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1491. LWS_Send(message);
  1492. sprintf(tempdata, "Authorize,%d", gun_index);
  1493. if(hashmap_operation(0, guid, tempdata) == 1)
  1494. {
  1495. result = PASS;
  1496. DEBUG_ERROR("Authorize mapItem pass\n");
  1497. }
  1498. //#ifdef SystemLogMessage
  1499. //DEBUG_INFO(">>>>>Authorize request\n");
  1500. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1501. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1502. //#endif
  1503. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1504. return result;
  1505. }
  1506. int sendBootNotificationRequest(void)
  1507. {
  1508. mtrace();
  1509. int result = FAIL;
  1510. char message[500]={0}, payload[700]={0};
  1511. char guid[37]={0};
  1512. char tempdata[65]={0};
  1513. int IsGunCharging = FALSE;
  1514. //check Transaction active
  1515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1516. {
  1517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1518. {
  1519. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1520. {
  1521. IsGunCharging = TRUE;
  1522. }
  1523. }
  1524. for (int index = 0; index < CCS_QUANTITY; index++)
  1525. {
  1526. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1527. {
  1528. IsGunCharging = TRUE;
  1529. }
  1530. }
  1531. for (int index = 0; index < GB_QUANTITY; index++)
  1532. {
  1533. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1534. {
  1535. IsGunCharging = TRUE;
  1536. }
  1537. }
  1538. }
  1539. else
  1540. {
  1541. for (int index = 0; index < AC_QUANTITY; index++)
  1542. {
  1543. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1544. {
  1545. IsGunCharging = TRUE;
  1546. }
  1547. }
  1548. }
  1549. if(IsGunCharging == TRUE)
  1550. {
  1551. server_sign = TRUE;
  1552. return result;
  1553. }
  1554. // Fill BootNotification fields
  1555. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1556. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1557. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1558. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1559. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1560. ShmOCPP16Data->ChargeBoxId
  1561. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1562. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1563. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1564. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1565. ,ShmOCPP16Data->BootNotification.CpIccid
  1566. ,ShmOCPP16Data->BootNotification.CpImsi
  1567. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1568. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1569. random_uuid(guid);
  1570. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1571. LWS_Send(message);
  1572. sprintf(tempdata, "BootNotification,0");
  1573. 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*/)
  1574. {
  1575. result = PASS;
  1576. }
  1577. memset(queuedata, 0, sizeof(queuedata));
  1578. strcpy(queuedata,message);
  1579. HeartBeatCount = 0;
  1580. //#ifdef SystemLogMessage
  1581. //DEBUG_INFO(">>>>>BootNotification request\n");
  1582. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1583. //#endif
  1584. return result;
  1585. }
  1586. int sendDataTransferRequest(int gun_index)
  1587. {
  1588. mtrace();
  1589. char message[1000]={0};
  1590. char guid[37]={0};
  1591. char tempdata[65]={0};
  1592. int result = FAIL;
  1593. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1594. random_uuid(guid);
  1595. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1596. MESSAGE_TYPE_CALL,
  1597. guid,
  1598. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1599. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1600. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1601. LWS_Send(message);
  1602. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1603. 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*/)
  1604. {
  1605. result = PASS;
  1606. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1607. }
  1608. //#ifdef SystemLogMessage
  1609. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1610. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1611. //#endif
  1612. return result;
  1613. }
  1614. int sendDiagnosticsStatusNotificationRequest(char *status)
  1615. {
  1616. mtrace();
  1617. int result = FAIL;
  1618. char message[110]={0};
  1619. char guid[37]={0};
  1620. char tempdata[65]={0};
  1621. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1622. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1623. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1624. random_uuid(guid);
  1625. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1626. LWS_Send(message);
  1627. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1628. if(hashmap_operation(0, guid, tempdata) == 1)
  1629. {
  1630. result = PASS;
  1631. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1632. }
  1633. //#ifdef SystemLogMessage
  1634. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1635. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1636. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1637. //#endif
  1638. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1639. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1640. //record status
  1641. if(strcmp(status,"Idle")==0)
  1642. {
  1643. DiagnosticsStatusNotificationStatus = 0;
  1644. }
  1645. else if(strcmp(status,"Uploaded")==0)
  1646. {
  1647. DiagnosticsStatusNotificationStatus = 1;
  1648. }
  1649. else if(strcmp(status,"UploadFailed")==0)
  1650. {
  1651. DiagnosticsStatusNotificationStatus = 2;
  1652. }
  1653. else if(strcmp(status,"Uploading")==0)
  1654. {
  1655. DiagnosticsStatusNotificationStatus = 3;
  1656. }
  1657. return result;
  1658. }
  1659. int sendFirmwareStatusNotificationRequest(char *status)
  1660. {
  1661. mtrace();
  1662. int result = FAIL;
  1663. char message[110]={0};
  1664. char guid[37]={0};
  1665. char tempdata[65]={0};
  1666. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1667. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1668. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1669. random_uuid(guid);
  1670. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1671. LWS_Send(message);
  1672. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1673. 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*/)
  1674. {
  1675. result = PASS;
  1676. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1677. }
  1678. //#ifdef SystemLogMessage
  1679. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1680. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1681. //#endif
  1682. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1683. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1684. //record status
  1685. if(strcmp(status,"Downloaded")==0)
  1686. {
  1687. FirmwareStatusNotificationStatus = 0;
  1688. }
  1689. else if(strcmp(status,"DownloadFailed")==0)
  1690. {
  1691. FirmwareStatusNotificationStatus = 1;
  1692. }
  1693. else if(strcmp(status,"Downloading")==0)
  1694. {
  1695. FirmwareStatusNotificationStatus = 2;
  1696. }
  1697. else if(strcmp(status,"Idle")==0)
  1698. {
  1699. FirmwareStatusNotificationStatus = 3;
  1700. }
  1701. else if(strcmp(status,"InstallationFailed")==0)
  1702. {
  1703. FirmwareStatusNotificationStatus = 4;
  1704. }
  1705. else if(strcmp(status,"Installing")==0)
  1706. {
  1707. FirmwareStatusNotificationStatus = 5;
  1708. }
  1709. else if(strcmp(status,"Installed")==0)
  1710. {
  1711. FirmwareStatusNotificationStatus = 6;
  1712. }
  1713. return result;
  1714. }
  1715. int sendHeartbeatRequest(int gun_index)
  1716. {
  1717. mtrace();
  1718. int result = FAIL;
  1719. char message[80]={0};
  1720. char guid[37]={0};
  1721. char tempdata[65]={0};
  1722. random_uuid(guid);
  1723. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1724. , MESSAGE_TYPE_CALL
  1725. , guid );
  1726. LWS_Send(message);
  1727. sprintf(tempdata, "Heartbeat,%d", 0);
  1728. 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*/)
  1729. {
  1730. result = PASS;
  1731. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1732. }
  1733. return result;
  1734. }
  1735. int sendStartTransactionRequest(int gun_index)
  1736. {
  1737. mtrace();
  1738. int result = FAIL;
  1739. char message[250]={0};
  1740. char guid[37]={0};
  1741. struct timeval tmnow;
  1742. struct tm *tm;
  1743. char buf[28];//, usec_buf[6];
  1744. char tempdata[65]={0};
  1745. DEBUG_INFO("sendStartTransactionRequest...");
  1746. gettimeofday(&tmnow, NULL);
  1747. time_t t;
  1748. t = time(NULL);
  1749. /*UTC time and date*/
  1750. tm = gmtime(&t);
  1751. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1752. #if 0 // remove temporally
  1753. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1754. strcat(buf,".");
  1755. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1756. strcat(buf,usec_buf);
  1757. #endif
  1758. //printf("Start Charging Time :%s",buf);
  1759. // set value
  1760. //if(ShmOCPP16Data->OcppConnStatus == 1 )
  1761. //{
  1762. //memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1763. //}
  1764. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1765. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1766. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1767. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1768. {
  1769. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1770. {
  1771. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1772. {
  1773. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1774. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1775. }
  1776. }
  1777. for (int index = 0; index < CCS_QUANTITY; index++)
  1778. {
  1779. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1780. {
  1781. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1782. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1783. }
  1784. }
  1785. for (int index = 0; index < GB_QUANTITY; index++)
  1786. {
  1787. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1788. {
  1789. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1790. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1791. }
  1792. }
  1793. }
  1794. else
  1795. {
  1796. for (int index = 0; index < AC_QUANTITY; index++)
  1797. {
  1798. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1799. {
  1800. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1801. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1802. }
  1803. }
  1804. }//END OF ELSE
  1805. random_uuid(guid);
  1806. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1807. , MESSAGE_TYPE_CALL
  1808. , guid
  1809. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1810. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1811. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1812. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1813. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1814. LWS_Send(message);
  1815. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1816. 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*/)
  1817. {
  1818. result = PASS;
  1819. }
  1820. strcpy(queuedata, message);
  1821. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1822. //#ifdef SystemLogMessage
  1823. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1824. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1825. //#endif
  1826. return result;
  1827. }
  1828. int sendStatusNotificationRequest(int gun_index)
  1829. {
  1830. mtrace();
  1831. int result = FAIL;
  1832. char message[600]={0};
  1833. char guid[37];
  1834. int currentStatus = 0;
  1835. struct timeval tmnow;
  1836. struct tm *tm;
  1837. char buf[28];//, usec_buf[6];
  1838. char tempdata[65]={0};
  1839. gettimeofday(&tmnow, NULL);
  1840. time_t t;
  1841. t = time(NULL);
  1842. /*UTC time and date*/
  1843. tm = gmtime(&t);
  1844. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1845. #if 0 // remove temporally
  1846. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1847. strcat(buf,".");
  1848. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1849. strcat(buf,usec_buf);
  1850. #endif
  1851. printf("%s",buf);
  1852. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1853. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1854. // it's option
  1855. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1856. /*
  1857. enum _SYSTEM_STATUS
  1858. {
  1859. S_BOOTING = 0,
  1860. S_IDLE, = 1
  1861. S_AUTHORIZING, =2
  1862. S_REASSIGN_CHECK, =3
  1863. S_REASSIGN, =4
  1864. S_PRECHARGE, =5
  1865. S_PREPARING_FOR_EV, =6
  1866. S_PREPARING_FOR_EVSE, =7
  1867. S_CHARGING, =8
  1868. S_TERMINATING, =9
  1869. S_COMPLETE, =10
  1870. S_ALARM, =11
  1871. S_FAULT =12
  1872. }
  1873. */
  1874. //check Transaction active
  1875. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1876. {
  1877. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1878. {
  1879. //printf("gun_index=%d\n",gun_index);
  1880. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1881. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1882. {
  1883. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1884. currentStatus = 0; //OCPP Status
  1885. }
  1886. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1887. {
  1888. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1889. currentStatus = 1; //OCPP Status
  1890. }
  1891. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1892. {
  1893. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1894. currentStatus = 2; //OCPP Status
  1895. }
  1896. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1897. {
  1898. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1899. currentStatus = 5; //OCPP Status
  1900. }
  1901. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1902. {
  1903. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1904. currentStatus = 4; //OCPP Status
  1905. }
  1906. 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
  1907. {
  1908. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1909. currentStatus = 7; //OCPP Status: Unavailable
  1910. }
  1911. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1912. {
  1913. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1914. currentStatus = 8; //OCPP Status: Faulted
  1915. }
  1916. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1917. {
  1918. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1919. currentStatus = 6; //OCPP Status: Reserved
  1920. }
  1921. }//end of for CHAdeMO_QUANTITY
  1922. for (int index = 0; index < CCS_QUANTITY; index++)
  1923. {
  1924. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1925. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1926. {
  1927. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1928. currentStatus = 0; //OCPP Status
  1929. }
  1930. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1931. {
  1932. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1933. currentStatus = 1; //OCPP Status
  1934. }
  1935. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1936. {
  1937. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1938. currentStatus = 2; //OCPP Status
  1939. }
  1940. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1941. {
  1942. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1943. currentStatus = 5; //OCPP Status
  1944. }
  1945. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1946. {
  1947. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1948. currentStatus = 4; //OCPP Status
  1949. }
  1950. 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
  1951. {
  1952. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1953. currentStatus = 7; //OCPP Status
  1954. }
  1955. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1956. {
  1957. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1958. currentStatus = 8; //OCPP Status
  1959. }
  1960. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1961. {
  1962. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1963. currentStatus = 6; //OCPP Status
  1964. }
  1965. }
  1966. for (int index = 0; index < GB_QUANTITY; index++)
  1967. {
  1968. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1969. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1970. {
  1971. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1972. currentStatus = 0; //OCPP Status
  1973. }
  1974. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1975. {
  1976. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1977. currentStatus = 1; //OCPP Status
  1978. }
  1979. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1980. {
  1981. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1982. currentStatus = 2; //OCPP Status
  1983. }
  1984. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1985. {
  1986. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1987. currentStatus = 5; //OCPP Status
  1988. }
  1989. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1990. {
  1991. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1992. currentStatus = 4; //OCPP Status
  1993. }
  1994. 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
  1995. {
  1996. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1997. currentStatus = 7; //OCPP Status: Unavailable
  1998. }
  1999. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2000. {
  2001. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2002. currentStatus = 8; //OCPP Status: Faulted
  2003. }
  2004. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2005. {
  2006. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2007. currentStatus = 6; //OCPP Status: Faulted
  2008. }
  2009. }
  2010. }
  2011. else
  2012. {
  2013. for (int index = 0; index < AC_QUANTITY; index++)
  2014. {
  2015. //printf("gun_index=%d\n",gun_index);
  2016. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2017. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2018. {
  2019. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2020. currentStatus = 0; //OCPP Status
  2021. }
  2022. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2023. {
  2024. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2025. currentStatus = 1; //OCPP Status
  2026. }
  2027. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2028. {
  2029. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2030. currentStatus = 2; //OCPP Status
  2031. }
  2032. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2033. {
  2034. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2035. currentStatus = 5; //OCPP Status
  2036. }
  2037. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2038. {
  2039. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2040. currentStatus = 4; //OCPP Status
  2041. }
  2042. 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
  2043. {
  2044. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2045. currentStatus = 7; //OCPP Status: Unavailable
  2046. }
  2047. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2048. {
  2049. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2050. currentStatus = 8; //OCPP Status: Faulted
  2051. }
  2052. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2053. {
  2054. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2055. currentStatus = 6; //OCPP Status: Reserved
  2056. }
  2057. }//end of for AC_QUANTITY
  2058. }//END OF ELSE
  2059. //it's option
  2060. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2061. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2062. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2063. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2064. random_uuid(guid);
  2065. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2066. , MESSAGE_TYPE_CALL
  2067. , guid
  2068. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2069. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2070. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2071. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2072. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2073. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2074. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2075. LWS_Send(message);
  2076. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2077. 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*/)
  2078. {
  2079. //DEBUG_ERROR("statusNotification mapitem pass");
  2080. result = PASS;
  2081. }
  2082. //#ifdef SystemLogMessage
  2083. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2084. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2085. //#endif
  2086. return result;
  2087. }
  2088. int sendStopTransactionRequest(int gun_index)
  2089. {
  2090. mtrace();
  2091. int result = FAIL;
  2092. //char message[1500]={0};
  2093. char guid[37]={0};
  2094. char tempdata[65]={0};
  2095. //int idx_sample=0;
  2096. DEBUG_ERROR("sendStopTransactionRequest \n");
  2097. memset(queuedata, 0, sizeof(queuedata));
  2098. //ENERGY_ACTIVE_IMPORT_REGISTER
  2099. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2100. {
  2101. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2102. {
  2103. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2104. {
  2105. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2106. //Check Status
  2107. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2108. {
  2109. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2110. }
  2111. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2112. }
  2113. }// END OF CHAdeMO_QUANTITY
  2114. for (int index = 0; index < CCS_QUANTITY; index++)
  2115. {
  2116. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2117. {
  2118. //for test
  2119. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2120. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2121. //Check Status
  2122. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2123. {
  2124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2125. }
  2126. else
  2127. {
  2128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2129. }
  2130. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2131. }
  2132. }// END OF CCS_QUANTITY
  2133. for (int index = 0; index < GB_QUANTITY; index++)
  2134. {
  2135. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2136. {
  2137. // for test
  2138. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2139. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2140. //Check Status
  2141. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2142. {
  2143. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2144. }
  2145. else
  2146. {
  2147. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2148. }
  2149. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2150. }
  2151. }// END OF GB_QUANTITY
  2152. }
  2153. else
  2154. {
  2155. for (int index = 0; index < AC_QUANTITY; index++)
  2156. {
  2157. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2158. {
  2159. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2160. //Check Status
  2161. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2162. {
  2163. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2164. }
  2165. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2166. }
  2167. }// END OF AC_QUANTITY
  2168. }//END OF ELSE
  2169. //Stop Transaction Time
  2170. struct timeval tmnow;
  2171. struct tm *tm;
  2172. char buf[28];//, usec_buf[6];
  2173. gettimeofday(&tmnow, NULL);
  2174. time_t t;
  2175. t = time(NULL);
  2176. /*UTC time and date*/
  2177. tm = gmtime(&t);
  2178. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2179. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2181. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2182. random_uuid(guid);
  2183. /***********************************transactionData******************************************************/
  2184. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2185. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2186. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2188. //=================================
  2189. // Transaction_Begin
  2190. //=================================
  2191. // Energy.Active.Export.Interval
  2192. //idx_sample=0;
  2193. 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
  2194. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2196. 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*/]);
  2197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2200. //=================================
  2201. // Transaction_End
  2202. //=================================
  2203. //Current.Export
  2204. //idx_sample=1;
  2205. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2206. {
  2207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2208. {
  2209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2210. {
  2211. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2212. }
  2213. }
  2214. for (int index = 0; index < CCS_QUANTITY; index++)
  2215. {
  2216. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2217. {
  2218. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2219. }
  2220. }
  2221. for (int index = 0; index < GB_QUANTITY; index++)
  2222. {
  2223. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2224. {
  2225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2226. }
  2227. }
  2228. }
  2229. else
  2230. {
  2231. for (int index = 0; index < AC_QUANTITY; index++)
  2232. {
  2233. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2234. {
  2235. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2236. }
  2237. }
  2238. }// END FOR AC ELSE
  2239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2245. //Energy.Active.Export.Interval
  2246. //idx_sample=2;
  2247. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2248. {
  2249. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2250. {
  2251. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2252. {
  2253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2254. }
  2255. }
  2256. for (int index = 0; index < CCS_QUANTITY; index++)
  2257. {
  2258. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2259. {
  2260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2261. }
  2262. }
  2263. for (int index = 0; index < GB_QUANTITY; index++)
  2264. {
  2265. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2266. {
  2267. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2268. }
  2269. }
  2270. }
  2271. else
  2272. {
  2273. for (int index = 0; index < AC_QUANTITY; index++)
  2274. {
  2275. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2276. {
  2277. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2278. }
  2279. }
  2280. }// END FOR AC ELSE
  2281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2287. //Power.Active.Export
  2288. //idx_sample=3;
  2289. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2290. {
  2291. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2292. {
  2293. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2294. {
  2295. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2296. }
  2297. }
  2298. for (int index = 0; index < CCS_QUANTITY; index++)
  2299. {
  2300. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2301. {
  2302. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2303. }
  2304. }
  2305. for (int index = 0; index < GB_QUANTITY; index++)
  2306. {
  2307. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2308. {
  2309. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2310. }
  2311. }
  2312. }
  2313. else
  2314. {
  2315. for (int index = 0; index < AC_QUANTITY; index++)
  2316. {
  2317. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2318. {
  2319. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2320. }
  2321. }
  2322. }// END FOR AC ELSE
  2323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2325. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2329. //Voltage
  2330. //idx_sample=4;
  2331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2332. {
  2333. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2334. {
  2335. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2336. {
  2337. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2338. }
  2339. }
  2340. for (int index = 0; index < CCS_QUANTITY; index++)
  2341. {
  2342. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2343. {
  2344. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2345. }
  2346. }
  2347. for (int index = 0; index < GB_QUANTITY; index++)
  2348. {
  2349. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2350. {
  2351. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2352. }
  2353. }
  2354. }
  2355. else
  2356. {
  2357. for (int index = 0; index < AC_QUANTITY; index++)
  2358. {
  2359. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2360. {
  2361. 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
  2362. }
  2363. }
  2364. }// END FOR AC ELSE
  2365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2371. //SoC
  2372. //idx_sample=5;
  2373. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2374. {
  2375. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2376. {
  2377. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2378. {
  2379. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2380. }
  2381. }
  2382. for (int index = 0; index < CCS_QUANTITY; index++)
  2383. {
  2384. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2385. {
  2386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2387. }
  2388. }
  2389. for (int index = 0; index < GB_QUANTITY; index++)
  2390. {
  2391. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2392. {
  2393. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2394. }
  2395. }
  2396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L1_N]);
  2400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2402. } // END FOR DC CASE
  2403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2404. {
  2405. 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\" } ] } ] } ]"
  2406. ,MESSAGE_TYPE_CALL
  2407. ,guid
  2408. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2409. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2410. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2411. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2412. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2413. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2414. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2415. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2416. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2417. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2418. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2419. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2420. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2421. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2422. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2423. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2424. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2425. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2426. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2427. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2428. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2429. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2430. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2431. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2432. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2433. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2434. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2435. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2436. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2437. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2438. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2439. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2440. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2441. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2442. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2443. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2444. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2445. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2446. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2447. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2448. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2449. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2450. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2451. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2452. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2453. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2454. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2455. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2456. );
  2457. }
  2458. else
  2459. {
  2460. 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\" } ] } ] } ]"
  2461. ,MESSAGE_TYPE_CALL
  2462. ,guid
  2463. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2464. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2465. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2466. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2467. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2468. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2469. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2470. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2471. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2472. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2473. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2474. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2475. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2476. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2477. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2478. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2479. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2480. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2481. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2482. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2483. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2484. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2485. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2486. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2487. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2488. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2489. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2490. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2491. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2492. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2493. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2494. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2495. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2496. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2497. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2498. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2499. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2500. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2501. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2502. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2503. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2504. );
  2505. }
  2506. LWS_Send(queuedata);
  2507. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2508. if(hashmap_operation(0, guid, tempdata) == 1)
  2509. {
  2510. result = PASS;
  2511. DEBUG_INFO("StopTransaction mapitem pass\n");
  2512. }
  2513. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2514. //for test
  2515. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2516. return result;
  2517. }
  2518. int sendMeterValuesRequest(int gun_index)
  2519. {
  2520. mtrace();
  2521. int result = FAIL;
  2522. // char message[1500]={0};
  2523. char guid[37]={0};
  2524. //int idx_sample=0;
  2525. //int length = 0;
  2526. char tempdata[65]={0};
  2527. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2528. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2529. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2530. {
  2531. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2532. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2533. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2534. return result;
  2535. }
  2536. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2537. {
  2538. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2539. }
  2540. memset(queuedata, 0, sizeof(queuedata));
  2541. //set value
  2542. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2543. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2544. random_uuid(guid);
  2545. //UTC Date time
  2546. struct timeval tmnow;
  2547. struct tm *tm;
  2548. char buf[28];//, usec_buf[6];
  2549. gettimeofday(&tmnow, NULL);
  2550. time_t t;
  2551. t = time(NULL);
  2552. /*UTC time and date*/
  2553. tm = gmtime(&t);
  2554. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2555. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2556. //idx_sample=0;
  2557. //********************************(1)Current.Export************************************************/
  2558. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2559. {
  2560. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2561. {
  2562. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2563. {
  2564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2565. }
  2566. }
  2567. for (int index = 0; index < CCS_QUANTITY; index++)
  2568. {
  2569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2570. {
  2571. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2572. }
  2573. }
  2574. for (int index = 0; index < GB_QUANTITY; index++)
  2575. {
  2576. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2577. {
  2578. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2579. }
  2580. }
  2581. }
  2582. else
  2583. {
  2584. for (int index = 0; index < AC_QUANTITY; index++)
  2585. {
  2586. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2587. {
  2588. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2589. }
  2590. }
  2591. }// END FOR AC ELSE
  2592. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2593. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2594. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2595. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2596. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2598. //idx_sample=1;
  2599. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2600. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2601. {
  2602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2603. {
  2604. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2605. {
  2606. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2607. }
  2608. }
  2609. for (int index = 0; index < CCS_QUANTITY; index++)
  2610. {
  2611. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2612. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2613. {
  2614. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2615. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2616. }
  2617. }
  2618. for (int index = 0; index < GB_QUANTITY; index++)
  2619. {
  2620. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2621. {
  2622. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2623. }
  2624. }
  2625. }
  2626. else
  2627. {
  2628. for (int index = 0; index < AC_QUANTITY; index++)
  2629. {
  2630. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2631. {
  2632. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2633. }
  2634. }
  2635. }//END FOR AC ELSE
  2636. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1]);
  2640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2641. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2642. //idx_sample=2;
  2643. //********************************(4)Power.Active.Export************************************************/
  2644. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2645. {
  2646. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2647. {
  2648. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2649. {
  2650. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2651. }
  2652. }
  2653. for (int index = 0; index < CCS_QUANTITY; index++)
  2654. {
  2655. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2656. {
  2657. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2658. }
  2659. }
  2660. for (int index = 0; index < GB_QUANTITY; index++)
  2661. {
  2662. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2663. {
  2664. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2665. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2666. }
  2667. }
  2668. }
  2669. else
  2670. {
  2671. for (int index = 0; index < AC_QUANTITY; index++)
  2672. {
  2673. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2674. {
  2675. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2676. }
  2677. }
  2678. }// END FOR AC ELSE
  2679. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2684. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2685. //idx_sample=3;
  2686. //***********************************************(5)VOLTAGE******************************************************/
  2687. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2688. {
  2689. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2690. {
  2691. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2692. {
  2693. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2694. }
  2695. }
  2696. for (int index = 0; index < CCS_QUANTITY; index++)
  2697. {
  2698. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2699. {
  2700. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2701. }
  2702. }
  2703. for (int index = 0; index < GB_QUANTITY; index++)
  2704. {
  2705. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2706. {
  2707. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2708. }
  2709. }
  2710. }
  2711. else
  2712. {
  2713. for (int index = 0; index < AC_QUANTITY; index++)
  2714. {
  2715. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2716. {
  2717. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2718. }
  2719. }
  2720. }//END FOR AC ELSE
  2721. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2722. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2723. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2724. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2725. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2726. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2727. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2728. {
  2729. //idx_sample=4;
  2730. //sampledValue = NULL;
  2731. //***********************************************(6)SOC******************************************************/
  2732. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2733. {
  2734. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2735. {
  2736. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2737. }
  2738. }
  2739. for (int index = 0; index < CCS_QUANTITY; index++)
  2740. {
  2741. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2742. {
  2743. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2744. }
  2745. }
  2746. for (int index = 0; index < GB_QUANTITY; index++)
  2747. {
  2748. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2749. {
  2750. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2751. }
  2752. }
  2753. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2754. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2755. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2756. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  2757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2758. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2759. }
  2760. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2761. {
  2762. 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\"}]}]}]"
  2763. ,MESSAGE_TYPE_CALL
  2764. ,guid
  2765. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2766. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2767. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2803. );
  2804. }
  2805. else
  2806. {
  2807. 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\"}]}]}]"
  2808. ,MESSAGE_TYPE_CALL
  2809. ,guid
  2810. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2811. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2812. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2832. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2833. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2834. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2835. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2836. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2837. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2838. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2839. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2840. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2841. );
  2842. }
  2843. LWS_Send(queuedata);
  2844. // Put request guid to hash map
  2845. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2846. 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*/)
  2847. {
  2848. result = PASS;
  2849. DEBUG_INFO("MeterValues mapitem pass\n");
  2850. }
  2851. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2852. return result;
  2853. }
  2854. //==========================================
  2855. // send confirm routine
  2856. //==========================================
  2857. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2858. {
  2859. mtrace();
  2860. int result = FAIL;
  2861. char message[100]={0};
  2862. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2863. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2864. LWS_Send(message);
  2865. result = TRUE;
  2866. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2867. return result;
  2868. }
  2869. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2870. {
  2871. mtrace();
  2872. int result = FAIL;
  2873. char message[100]={0};
  2874. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2875. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2876. LWS_Send(message);
  2877. result = TRUE;
  2878. return result;
  2879. }
  2880. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2881. {
  2882. mtrace();
  2883. int result = FAIL;
  2884. char message[100]={0};
  2885. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2886. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2887. LWS_Send(message);
  2888. result = TRUE;
  2889. return result;
  2890. }
  2891. int sendClearCacheConfirmation(char *uuid,char *payload)
  2892. {
  2893. mtrace();
  2894. int result = FAIL;
  2895. char message[500]={0};
  2896. // int count = 0;
  2897. // int gun_index = 0;
  2898. // char guid[37];
  2899. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2900. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2901. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2902. LWS_Send(message);
  2903. return result;
  2904. }
  2905. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2906. {
  2907. mtrace();
  2908. int result = FAIL;
  2909. char message[500]={0};
  2910. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2911. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2912. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2913. LWS_Send(message);
  2914. return result;
  2915. }
  2916. int sendDataTransferConfirmation(char *uuid,char *payload)
  2917. {
  2918. mtrace();
  2919. char statusStr[20]={0};
  2920. char dataStr[10]={0};
  2921. char sstr[20]={0};
  2922. int c = 0;
  2923. char *loc;
  2924. int result = FAIL;
  2925. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2926. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2927. /**********************status**************************/
  2928. loc = strstr(payload, "status");
  2929. memset(sstr ,0, sizeof(sstr) );
  2930. c = 0;
  2931. while (loc[3+strlen("status")+c] != '\"')
  2932. {
  2933. sstr[c] = loc[3+strlen("status")+c];
  2934. c++;
  2935. }
  2936. sstr[c] = '\0';
  2937. strcpy(statusStr, sstr);
  2938. /**********************data**************************/
  2939. loc = strstr(payload, "data");
  2940. memset(sstr ,0, sizeof(sstr) );
  2941. c = 0;
  2942. while (loc[3+strlen("data")+c] != '\"')
  2943. {
  2944. sstr[c] = loc[3+strlen("data")+c];
  2945. c++;
  2946. }
  2947. sstr[c] = '\0';
  2948. strcpy(dataStr, sstr);
  2949. return result;
  2950. }
  2951. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2952. {
  2953. mtrace();
  2954. int result = FAIL;
  2955. char message[1000]={0};
  2956. double diff_f = 0.0;
  2957. int diff_i = 0;
  2958. int diffSeconds = 0;
  2959. struct tm tp;
  2960. int TimeZero = FALSE;
  2961. int CompositeScheduleIndex = 0;
  2962. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2963. #if 0
  2964. if(connectorIdInt > 0)
  2965. {
  2966. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2967. {
  2968. TimeZero = TRUE;
  2969. }
  2970. else
  2971. {
  2972. strptime((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2973. }
  2974. }
  2975. else
  2976. {
  2977. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2978. {
  2979. TimeZero = TRUE;
  2980. }
  2981. else
  2982. {
  2983. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2984. }
  2985. }
  2986. DEBUG_INFO("ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule=%s\n",ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule);
  2987. #endif
  2988. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2989. {
  2990. TimeZero = TRUE;
  2991. }
  2992. else
  2993. {
  2994. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2995. }
  2996. if(TimeZero == FALSE)
  2997. {
  2998. tp.tm_isdst = -1;
  2999. time_t utc = mktime(&tp);
  3000. time_t t = time(NULL);
  3001. diff_f = difftime(t, utc);
  3002. diff_i = (int)diff_f;
  3003. diffSeconds = diff_i % 86400;//86400 seconds/day
  3004. }
  3005. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3006. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3007. #if 0 //remove temporally
  3008. 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}"
  3009. ,MESSAGE_TYPE_CALLRESULT
  3010. ,uuid
  3011. ,payload
  3012. ,connectorIdInt
  3013. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3014. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3015. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3016. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3017. #endif
  3018. if(nPeriod == 0)
  3019. {
  3020. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3021. ,MESSAGE_TYPE_CALLRESULT
  3022. ,uuid
  3023. ,payload
  3024. ,connectorIdInt
  3025. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3026. }
  3027. else
  3028. {
  3029. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3030. ,MESSAGE_TYPE_CALLRESULT
  3031. ,uuid
  3032. ,payload
  3033. ,connectorIdInt
  3034. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3035. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3036. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3037. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3038. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3039. #if 1 // remove temporally
  3040. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3041. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  3042. {
  3043. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3044. , 0
  3045. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3046. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3047. }
  3048. else
  3049. {
  3050. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3051. {
  3052. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  3053. {
  3054. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3055. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3056. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3057. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3058. }
  3059. else
  3060. {
  3061. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3062. , (((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*/))
  3063. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3064. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3065. }
  3066. }
  3067. }
  3068. #endif
  3069. sprintf(message + strlen(message), "]}}]");
  3070. }
  3071. LWS_Send(message);
  3072. result = TRUE;
  3073. return result;
  3074. }
  3075. int sendGetConfigurationConfirmation(char *uuid)
  3076. {
  3077. mtrace();
  3078. int result = FAIL;
  3079. int MaxKeySupported = 0;
  3080. int sentConfigurationNumber= 0;
  3081. int sentunConfigurationNumber= 0;
  3082. char message[4000]={0};
  3083. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3084. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3085. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3086. ,MESSAGE_TYPE_CALLRESULT
  3087. ,uuid );
  3088. //configuration key
  3089. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3090. {
  3091. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3092. {
  3093. if (sentConfigurationNumber == 0)
  3094. {
  3095. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3096. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3097. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3098. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3099. }
  3100. else
  3101. {
  3102. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3103. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3104. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3105. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3106. }
  3107. sentConfigurationNumber = sentConfigurationNumber + 1;
  3108. }
  3109. }
  3110. sprintf(message + strlen(message), "]");
  3111. if(UnknownKeynum != 0)
  3112. {
  3113. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3114. //unkown key
  3115. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3116. {
  3117. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3118. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3119. if(sentunConfigurationNumber == 0)
  3120. {
  3121. sprintf(message + strlen(message), "\"%s\""
  3122. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3123. }
  3124. else
  3125. {
  3126. sprintf(message + strlen(message), ",\"%s\""
  3127. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3128. }
  3129. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3130. }
  3131. sprintf(message + strlen(message), "]");
  3132. }
  3133. sprintf(message + strlen(message), "} ]");
  3134. LWS_Send(message);
  3135. #if 0
  3136. printf("error 1-0\n");
  3137. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3138. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3139. #endif
  3140. return result;
  3141. }
  3142. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3143. {
  3144. mtrace();
  3145. int result = FAIL;
  3146. char message[400]={0};
  3147. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3148. if(strcmp(payload,"")==0)
  3149. {
  3150. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3151. }
  3152. else
  3153. {
  3154. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3155. }
  3156. LWS_Send(message);
  3157. result = TRUE;
  3158. return result;
  3159. }
  3160. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3161. {
  3162. mtrace();
  3163. int result = FAIL;
  3164. char message[80]={0};
  3165. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3166. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3167. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3168. LWS_Send(message);
  3169. result = TRUE;
  3170. return result;
  3171. }
  3172. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3173. {
  3174. mtrace();
  3175. int result = FAIL;
  3176. char message[80]={0};
  3177. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3178. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3179. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3180. LWS_Send(message);
  3181. result = TRUE;
  3182. return result;
  3183. }
  3184. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3185. {
  3186. mtrace();
  3187. int result = FAIL;
  3188. char message[80]={0};
  3189. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3190. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3191. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3192. LWS_Send(message);
  3193. result = TRUE;
  3194. return result;
  3195. }
  3196. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3197. {
  3198. mtrace();
  3199. int result = FAIL;
  3200. char message[80]={0};
  3201. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3202. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3203. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3204. LWS_Send(message);
  3205. result = TRUE;
  3206. return result;
  3207. }
  3208. int sendResetConfirmation(char *uuid,char *payload)
  3209. {
  3210. mtrace();
  3211. int result = FAIL;
  3212. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3213. char message[80]={0};
  3214. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3215. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3216. LWS_Send(message);
  3217. result = TRUE;
  3218. return result;
  3219. }
  3220. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3221. {
  3222. mtrace();
  3223. int result = FAIL;
  3224. char message[500]={0};
  3225. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3226. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3227. LWS_Send(message);
  3228. result = TRUE;
  3229. return result;
  3230. }
  3231. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3232. {
  3233. mtrace();
  3234. int result = FAIL;
  3235. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3236. char message[80]={0};
  3237. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3238. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3239. LWS_Send(message);
  3240. result = TRUE;
  3241. return result;
  3242. }
  3243. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3244. {
  3245. mtrace();
  3246. int result = FAIL;
  3247. char message[80]={0};
  3248. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3249. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3250. LWS_Send(message);
  3251. result = TRUE;
  3252. return result;
  3253. }
  3254. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3255. {
  3256. mtrace();
  3257. int result = FAIL;
  3258. char message[80]={0};
  3259. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3260. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3261. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3262. LWS_Send(message);
  3263. result = TRUE;
  3264. return result;
  3265. }
  3266. int sendUpdateFirmwareConfirmation(char *uuid)
  3267. {
  3268. mtrace();
  3269. int result = FAIL;
  3270. char message[60]={0};
  3271. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3272. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3273. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3274. LWS_Send(message);
  3275. result = TRUE;
  3276. return result;
  3277. }
  3278. //==========================================
  3279. // send CallError routine
  3280. //==========================================
  3281. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3282. {
  3283. mtrace();
  3284. //int result = FAIL;
  3285. char message[220]={0};
  3286. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3287. #ifdef SystemLogMessage
  3288. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3289. uniqueId, action, errorCode, errorDescription);
  3290. #endif
  3291. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3292. LWS_Send(message);
  3293. //result = TRUE;
  3294. }
  3295. //==========================================
  3296. // Handle server request routine Start
  3297. //==========================================
  3298. #define GUN_NUM 1
  3299. int handleCancelReservationRequest(char *uuid, char *payload)
  3300. {
  3301. mtrace();
  3302. int result = FAIL;
  3303. int gunNO = 0;
  3304. int reservationIdInt =0;
  3305. char comfirmstr[20];
  3306. int c = 0;
  3307. char *loc;
  3308. char sstr[100]={0};
  3309. DEBUG_INFO("handle CancelReservationRequest\n");
  3310. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3311. c = 0;
  3312. loc = strstr(payload, "reservationId");
  3313. memset(sstr ,0, sizeof(sstr) );
  3314. while (loc[strlen("reservationId")+2+c] != '}')
  3315. {
  3316. sstr[c] = loc[strlen("reservationId")+2+c];
  3317. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3318. c++;
  3319. }
  3320. sstr[c] = '\0';
  3321. reservationIdInt = atoi(sstr);
  3322. memset(comfirmstr, 0, sizeof comfirmstr);
  3323. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3324. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3325. //check Transaction active
  3326. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3327. {
  3328. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3329. {
  3330. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3331. {
  3332. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3333. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3334. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3335. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3336. goto end;
  3337. }
  3338. }
  3339. for (int index = 0; index < CCS_QUANTITY; index++)
  3340. {
  3341. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3342. {
  3343. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3344. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3345. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3346. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3347. goto end;
  3348. }
  3349. }
  3350. for (int index = 0; index < GB_QUANTITY; index++)
  3351. {
  3352. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3353. {
  3354. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3355. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3356. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3357. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3358. goto end;
  3359. }
  3360. }
  3361. }
  3362. else
  3363. {
  3364. for (int index = 0; index < AC_QUANTITY; index++)
  3365. {
  3366. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3367. {
  3368. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3369. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3370. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3371. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3372. goto end;
  3373. }
  3374. }
  3375. }// END FOR AC ELSE
  3376. //The reservationId does NOT match the reservationId
  3377. sendCancelReservationConfirmation(uuid, comfirmstr);
  3378. end:
  3379. // Fill in ocpp packet uuid
  3380. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3381. return result;
  3382. }
  3383. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3384. {
  3385. mtrace();
  3386. int result = FAIL;
  3387. int gunIndex = 0;
  3388. char sstr[90]={0};
  3389. char typeStr[16]={0};
  3390. char comfirmstr[20];
  3391. int specificId = FALSE;
  3392. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3393. char *loc;
  3394. //int intervalInt = 0;
  3395. int c = 0;
  3396. /*** connectorId ****/
  3397. c = 0;
  3398. loc = strstr(payload, "connectorId");
  3399. memset(sstr ,0, sizeof(sstr) );
  3400. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3401. {
  3402. sstr[c] = loc[strlen("connectorId")+2+c];
  3403. c++;
  3404. }
  3405. sstr[c] = '\0';
  3406. gunIndex = atoi(sstr);
  3407. /***type ****/
  3408. loc = strstr(payload, "type");
  3409. memset(sstr ,0, sizeof(sstr) );
  3410. c = 0;
  3411. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3412. {
  3413. sstr[c] = loc[3+strlen("type")+c];
  3414. c++;
  3415. }
  3416. sstr[c] = '\0';
  3417. strcpy(typeStr, sstr);
  3418. if(gunIndex != 0)
  3419. {
  3420. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3421. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3422. }
  3423. else
  3424. {
  3425. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3426. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3427. }
  3428. memset(comfirmstr, 0, sizeof comfirmstr);
  3429. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3430. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3431. {
  3432. specificId = TRUE;
  3433. }
  3434. if(specificId == FALSE)
  3435. goto end;
  3436. if(gunIndex != 0)
  3437. {
  3438. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3439. }
  3440. else
  3441. {
  3442. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3443. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3444. }
  3445. /*
  3446. enum _SYSTEM_STATUS
  3447. {
  3448. S_BOOTING = 0,
  3449. S_IDLE, = 1
  3450. S_AUTHORIZING, =2
  3451. S_REASSIGN_CHECK, =3
  3452. S_REASSIGN, =4
  3453. S_PRECHARGE, =5
  3454. S_PREPARING_FOR_EV, =6
  3455. S_PREPARING_FOR_EVSE, =7
  3456. S_CHARGING, =8
  3457. S_TERMINATING, =9
  3458. S_COMPLETE, =10
  3459. S_ALARM, =11
  3460. S_FAULT =12
  3461. }
  3462. */
  3463. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3464. {
  3465. //check Transaction active
  3466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3467. {
  3468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3469. {
  3470. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3471. {
  3472. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3473. {
  3474. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3475. }
  3476. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3477. {
  3478. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3479. }
  3480. else
  3481. {
  3482. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3483. }
  3484. goto end;
  3485. }
  3486. }//END FOR CHAdeMO_QUANTITY
  3487. for (int index = 0; index < CCS_QUANTITY; index++)
  3488. {
  3489. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3490. {
  3491. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3492. {
  3493. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3494. }
  3495. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3496. {
  3497. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3498. }
  3499. else
  3500. {
  3501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3502. }
  3503. goto end;
  3504. }
  3505. }//END FOR CCS_QUANTITY
  3506. for (int index = 0; index < GB_QUANTITY; index++)
  3507. {
  3508. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3509. {
  3510. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3511. {
  3512. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3513. }
  3514. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3515. {
  3516. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3517. }
  3518. else
  3519. {
  3520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3521. }
  3522. goto end;
  3523. }
  3524. }// END FOR GB_QUANTITY
  3525. }
  3526. else
  3527. {
  3528. for (int index = 0; index < AC_QUANTITY; index++)
  3529. {
  3530. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3531. {
  3532. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3533. {
  3534. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3535. }
  3536. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3537. {
  3538. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3539. }
  3540. else
  3541. {
  3542. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3543. }
  3544. goto end;
  3545. }
  3546. }//END FOR AC_QUANTITY
  3547. }// END FOR AC ELSE
  3548. }//END FOR AvailabilityTypeStr[Inoperative]
  3549. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3550. {
  3551. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3552. //check Transaction active
  3553. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3554. {
  3555. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3556. {
  3557. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3558. {
  3559. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3560. goto end;
  3561. }
  3562. }//END FOR CHAdeMO_QUANTITY
  3563. for (int index = 0; index < CCS_QUANTITY; index++)
  3564. {
  3565. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3566. {
  3567. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3568. goto end;
  3569. }
  3570. }//END FOR CCS_QUANTITY
  3571. for (int index = 0; index < GB_QUANTITY; index++)
  3572. {
  3573. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3574. {
  3575. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3577. goto end;
  3578. }
  3579. }// END FOR GB_QUANTITY
  3580. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3581. }
  3582. else
  3583. {
  3584. for (int index = 0; index < AC_QUANTITY; index++)
  3585. {
  3586. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3587. {
  3588. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3589. goto end;
  3590. }
  3591. }//END FOR CHAdeMO_QUANTITY
  3592. }//END FOR AC ELSE
  3593. }//END FOR AvailabilityTypeStr[Operative]
  3594. end:
  3595. if(gunIndex != 0)
  3596. {
  3597. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3598. }
  3599. else
  3600. {
  3601. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3602. }
  3603. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3604. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3605. return result;
  3606. }
  3607. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3608. {
  3609. mtrace();
  3610. int result = FAIL;
  3611. char sstr[100]={0};
  3612. char keystr[40]={0};
  3613. char valuestr[16]={0};
  3614. char *loc;
  3615. int c = 0;
  3616. char comfirmstr[20];
  3617. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3618. /***key ****/
  3619. loc = strstr(payload, "key");
  3620. memset(sstr ,0, sizeof(sstr) );
  3621. c = 0;
  3622. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3623. {
  3624. sstr[c] = loc[3+strlen("key")+c];
  3625. c++;
  3626. }
  3627. sstr[c] = '\0';
  3628. strcpy(keystr, sstr);
  3629. /***value ****/
  3630. loc = strstr(payload, "value");
  3631. memset(sstr ,0, sizeof(sstr) );
  3632. c = 0;
  3633. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3634. {
  3635. sstr[c] = loc[3+strlen("value")+c];
  3636. c++;
  3637. }
  3638. sstr[c] = '\0';
  3639. strcpy(valuestr, sstr);
  3640. if((uuid==NULL) || (payload ==NULL) )
  3641. {
  3642. #ifdef Debug
  3643. DEBUG_INFO("payload is null\n");
  3644. #endif
  3645. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3646. }
  3647. else
  3648. {
  3649. int status = setKeyValue(keystr, valuestr);
  3650. switch(status)
  3651. {
  3652. case ConfigurationStatus_Accepted:
  3653. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3654. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3655. break;
  3656. case ConfigurationStatus_Rejected:
  3657. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3658. break;
  3659. case RebootRequired:
  3660. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3661. break;
  3662. case NotSupported:
  3663. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3664. break;
  3665. default:
  3666. break;
  3667. }
  3668. }
  3669. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3670. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3671. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3672. return result;
  3673. }
  3674. int handleClearCacheRequest(char *uuid, char *payload)
  3675. {
  3676. mtrace();
  3677. int result = FAIL;
  3678. char comfirmstr[20];
  3679. int fd;
  3680. char rmFileCmd[100]={0};
  3681. struct stat stats;
  3682. DEBUG_ERROR("handle ClearCacheRequest\n");
  3683. stat("../Storage/OCPP", &stats);
  3684. // Check for directory existence
  3685. if (S_ISDIR(stats.st_mode) == 1)
  3686. {
  3687. //DEBUG_ERROR("\n OCPP directory exist \n");
  3688. }
  3689. else
  3690. {
  3691. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3692. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3693. system(rmFileCmd);
  3694. }
  3695. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3696. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3697. {
  3698. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3699. }
  3700. else
  3701. {
  3702. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3703. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3704. if(log == NULL)
  3705. {
  3706. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3707. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3708. goto end;
  3709. }
  3710. else
  3711. {
  3712. fclose(log);
  3713. }
  3714. }
  3715. fd = open(AuthorizationCache_JSON,O_RDWR);
  3716. if(fd < 0)
  3717. {
  3718. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3719. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3720. }
  3721. else
  3722. {
  3723. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3724. //* 清空? 件 */
  3725. ftruncate(fd,0);
  3726. //* ? 新设置? 件? 移??*/
  3727. lseek(fd,0,SEEK_SET);
  3728. close(fd);
  3729. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3730. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3731. }
  3732. end:
  3733. sendClearCacheConfirmation(uuid, comfirmstr);
  3734. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3735. return result;
  3736. }
  3737. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3738. {
  3739. mtrace();
  3740. int result = FAIL;
  3741. int resultRename;
  3742. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3743. char chargingProfilePurposeStr[26]={0};
  3744. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3745. char tempchargingProfilePurposeStr[26]={0};
  3746. char sstr[160]={0};//sstr[200]={ 0 };
  3747. char str[100]={0};
  3748. int c = 0;
  3749. //int i = 0;
  3750. //char * pch;
  3751. char *loc;
  3752. char fname[200];
  3753. char comfirmstr[20]={0};
  3754. char word[1000]={0};
  3755. int clearflag = FALSE;
  3756. int chargingProfileIdIsNULL = FALSE;
  3757. int connectorIsNULL = FALSE;
  3758. int chargingProfilePurposeIsNULL = FALSE;
  3759. int stackLevelIsNULL = FALSE;
  3760. FILE *fptr1, *fptr2;
  3761. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3762. int n_chargingProfile=0;
  3763. char sLineWord[1060]={0};
  3764. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3765. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3766. //***id ****/
  3767. c = 0;
  3768. loc = strstr(payload, "id");
  3769. memset(sstr ,0, sizeof(sstr) );
  3770. if(loc == NULL)
  3771. {
  3772. chargingProfileIdIsNULL = TRUE;
  3773. }
  3774. else
  3775. {
  3776. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3777. {
  3778. sstr[c] = loc[strlen("id")+2+c];
  3779. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3780. c++;
  3781. }
  3782. sstr[c] = '\0';
  3783. chargingProfileIdInt = atoi(sstr);
  3784. }
  3785. //***connectorId ****/
  3786. c=0;
  3787. loc = strstr(payload, "connectorId");
  3788. memset(sstr ,0, sizeof(sstr) );
  3789. if(loc == NULL)
  3790. {
  3791. connectorIsNULL = TRUE;
  3792. }
  3793. else
  3794. {
  3795. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3796. {
  3797. sstr[c] = loc[strlen("connectorId")+2+c];
  3798. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3799. c++;
  3800. }
  3801. sstr[c] = '\0';
  3802. connectorIdInt = atoi(sstr);
  3803. }
  3804. //***chargingProfilePurpose ****/
  3805. loc = strstr(payload, "chargingProfilePurpose");
  3806. memset(sstr ,0, sizeof(sstr) );
  3807. c = 0;
  3808. if(loc == NULL)
  3809. {
  3810. chargingProfilePurposeIsNULL = TRUE;
  3811. }
  3812. else
  3813. {
  3814. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3815. {
  3816. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3817. c++;
  3818. }
  3819. sstr[c] = '\0';
  3820. strcpy(chargingProfilePurposeStr, sstr);
  3821. }
  3822. //***stackLevel ****/
  3823. c=0;
  3824. loc = strstr(payload, "stackLevel");
  3825. memset(sstr ,0, sizeof(sstr) );
  3826. if(loc == NULL)
  3827. {
  3828. stackLevelIsNULL = TRUE;
  3829. }
  3830. else
  3831. {
  3832. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3833. {
  3834. sstr[c] = loc[strlen("stackLevel")+2+c];
  3835. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3836. c++;
  3837. }
  3838. sstr[c] = '\0';
  3839. stackLevelInt = atoi(sstr);
  3840. }
  3841. if(connectorIsNULL == FALSE)
  3842. {
  3843. switch(connectorIdInt)
  3844. {
  3845. case 0:
  3846. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3847. {
  3848. strcpy(fname, ChargePointMaxProfile_JSON);
  3849. }
  3850. // else
  3851. // {
  3852. // strcpy(fname, TxDefaultProfile_0_JSON);
  3853. // }
  3854. break;
  3855. case 1:
  3856. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3857. {
  3858. strcpy(fname, TxDefaultProfile_1_JSON);
  3859. }
  3860. // else
  3861. // {
  3862. // strcpy(fname, TxProfile_1_JSON);
  3863. // }
  3864. break;
  3865. case 2:
  3866. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3867. {
  3868. strcpy(fname, TxDefaultProfile_2_JSON);
  3869. }
  3870. // else
  3871. // {
  3872. // strcpy(fname, TxProfile_2_JSON);
  3873. // }
  3874. break;
  3875. default:
  3876. strcpy(fname, ChargePointMaxProfile_JSON );
  3877. break;
  3878. }
  3879. }
  3880. else
  3881. {
  3882. strcpy(fname, ChargePointMaxProfile_JSON );
  3883. }
  3884. fptr1 = fopen(fname, "r");
  3885. if (!fptr1)
  3886. {
  3887. //file not exist
  3888. DEBUG_ERROR("Unable to open the input file!!\n");
  3889. fptr1 = fopen(fname, "w+");
  3890. }
  3891. fclose(fptr1);
  3892. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3893. {
  3894. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3895. goto end;
  3896. }
  3897. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3898. {
  3899. //clear the whole contents of a file in C
  3900. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3901. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3902. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3903. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3904. fclose(fopen(TxProfile_1_JSON, "w"));
  3905. fclose(fopen(TxProfile_2_JSON, "w"));
  3906. #if 0
  3907. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3908. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3909. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3910. #endif
  3911. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3912. }
  3913. else
  3914. {
  3915. fptr1 = fopen(fname, "r");
  3916. fptr2 = fopen(temp, "w+");
  3917. while(fscanf(fptr1, "%s", word) != EOF)
  3918. {
  3919. //DEBUG_INFO("word=%s\n",word);
  3920. if(strcmp(word, "chargingProfileId") == 0)
  3921. {
  3922. n_chargingProfile = n_chargingProfile + 1;
  3923. DEBUG_INFO("chargingProfileId Found\n");
  3924. }
  3925. }
  3926. rewind(fptr1);
  3927. //search Charging Profile Element
  3928. //int i= 0;
  3929. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3930. {
  3931. //*************************tempconnectorIdInt*********************************/
  3932. loc = strstr(sLineWord, "connectorId");
  3933. c = 0;
  3934. memset(sstr ,0, sizeof(sstr) );
  3935. while (loc[strlen("connectorId")+2+c] != ',')
  3936. {
  3937. sstr[c] = loc[strlen("connectorId")+2+c];
  3938. c++;
  3939. }
  3940. sstr[c] = '\0';
  3941. tempconnectorIdInt = atoi(sstr);
  3942. //chargingProfileId
  3943. c = 0;
  3944. loc = strstr(sLineWord, "chargingProfileId");
  3945. memset(sstr ,0, sizeof(sstr) );
  3946. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3947. {
  3948. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3949. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3950. c++;
  3951. }
  3952. sstr[c] = '\0';
  3953. tempchargingProfileIdInt = atoi(sstr);
  3954. //stackLevel
  3955. c = 0;
  3956. loc = strstr(sLineWord, "stackLevel");
  3957. memset(sstr ,0, sizeof(sstr) );
  3958. while (loc[strlen("stackLevel")+2+c] != ',')
  3959. {
  3960. sstr[c] = loc[strlen("stackLevel")+2+c];
  3961. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3962. c++;
  3963. }
  3964. sstr[c] = '\0';
  3965. tempstackLevelInt = atoi(sstr);
  3966. c = 0;
  3967. loc = strstr(sLineWord, "chargingProfilePurpose");
  3968. memset(sstr ,0, sizeof(sstr) );
  3969. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3970. {
  3971. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3972. c++;
  3973. }
  3974. sstr[c] = '\0';
  3975. strcpy(tempchargingProfilePurposeStr, sstr);
  3976. if(chargingProfileIdIsNULL == FALSE)
  3977. {
  3978. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3979. {
  3980. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3981. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3982. clearflag = TRUE;
  3983. continue;
  3984. }
  3985. else
  3986. {
  3987. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3988. //json_object_array_add(newHeatMap, jsonitem);
  3989. fprintf(fptr2, sLineWord);//writing data into file
  3990. }
  3991. }
  3992. else
  3993. {
  3994. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3995. {
  3996. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3997. {
  3998. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3999. clearflag = TRUE;
  4000. continue;
  4001. }
  4002. }
  4003. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4004. {
  4005. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  4006. {
  4007. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  4008. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  4009. {
  4010. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4011. clearflag = TRUE;
  4012. continue;
  4013. }
  4014. }
  4015. }
  4016. else
  4017. {
  4018. //json_object_array_add(newHeatMap, jsonitem);
  4019. fprintf(fptr2, sLineWord);//writing data into file
  4020. }
  4021. }
  4022. memset(sLineWord, 0, sizeof sLineWord);
  4023. }
  4024. if(clearflag == FALSE)
  4025. {
  4026. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4027. goto end;
  4028. }
  4029. fclose(fptr1);
  4030. fclose(fptr2);
  4031. sprintf(str,"rm -f %s",fname);
  4032. system(str);
  4033. resultRename = rename(temp, fname);
  4034. if(resultRename == 0)
  4035. {
  4036. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4037. }
  4038. else
  4039. {
  4040. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4041. }
  4042. }
  4043. end:
  4044. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4045. return result;
  4046. }
  4047. int handleDataTransferRequest(char *uuid, char *payload)
  4048. {
  4049. mtrace();
  4050. int result = FAIL;
  4051. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4052. char tempvendorId[255]={0};
  4053. char tempmessageId[50]={0};
  4054. char tempdata[50]={0};
  4055. char sstr[160]={0};//sstr[200]={ 0 };
  4056. char message[80]={0};
  4057. int c = 0;
  4058. char *loc;
  4059. DEBUG_INFO("handle DataTransferRequest\n");
  4060. if((uuid != NULL) && (payload != NULL))
  4061. {
  4062. //===============================
  4063. // vendorId
  4064. //===============================
  4065. c = 0;
  4066. loc = strstr(payload, "vendorId");
  4067. while (loc[strlen("vendorId")+3+c] != '\"')
  4068. {
  4069. sstr[c] = loc[strlen("vendorId")+3+c];
  4070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4071. c++;
  4072. }
  4073. sstr[c] = '\0';
  4074. strcpy(tempvendorId,sstr);
  4075. //===============================
  4076. // messageId
  4077. //===============================
  4078. memset(sstr ,0, sizeof(sstr) );
  4079. c = 0;
  4080. loc = strstr(payload, "messageId");
  4081. while (loc[strlen("messageId")+3+c] != '\"')
  4082. {
  4083. sstr[c] = loc[strlen("messageId")+3+c];
  4084. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4085. c++;
  4086. }
  4087. sstr[c] = '\0';
  4088. strcpy(tempmessageId,sstr);
  4089. //===============================
  4090. // data
  4091. //===============================
  4092. memset(sstr ,0, sizeof(sstr) );
  4093. c = 0;
  4094. loc = strstr(payload, "data");
  4095. printf("loc=%s\n",loc);
  4096. while (loc[strlen("data")+3+c] != '\"')
  4097. {
  4098. sstr[c] = loc[strlen("data")+3+c];
  4099. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4100. c++;
  4101. }
  4102. sstr[c] = '\0';
  4103. strcpy(tempdata,sstr);
  4104. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4105. }
  4106. else
  4107. {
  4108. char guid[37]={0};
  4109. random_uuid(guid);
  4110. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4111. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4112. }
  4113. LWS_Send(message);
  4114. return result;
  4115. }
  4116. #if 0
  4117. long long diff_tm(struct tm *a, struct tm *b) {
  4118. return a->tm_sec - b->tm_sec
  4119. + 60LL * (a->tm_min - b->tm_min)
  4120. + 3600LL * (a->tm_hour - b->tm_hour)
  4121. + 86400LL * (a->tm_yday - b->tm_yday)
  4122. + (a->tm_year - 70) * 31536000LL
  4123. - (a->tm_year - 69) / 4 * 86400LL
  4124. + (a->tm_year - 1) / 100 * 86400LL
  4125. - (a->tm_year + 299) / 400 * 86400LL
  4126. - (b->tm_year - 70) * 31536000LL
  4127. + (b->tm_year - 69) / 4 * 86400LL
  4128. - (b->tm_year - 1) / 100 * 86400LL
  4129. + (b->tm_year + 299) /400 * 86400LL;
  4130. }
  4131. #endif
  4132. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4133. {
  4134. mtrace();
  4135. int result = FAIL;
  4136. int connectorIdInt, durationInt;
  4137. char chargingRateUnitStr[4]={0};
  4138. //int tempconnectorIdInt,
  4139. int tempdurationInt;
  4140. float tempminChargingRateFloat = 0.0;
  4141. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4142. int tempStartPeriodInt=0;
  4143. float tempLimitInt=0.0;//0.1;
  4144. int tempNumberPhasesInt=0;
  4145. char fname[200];
  4146. char comfirmstr[20];
  4147. //float totallimit =0.0;
  4148. float MinChargingRate =0.0;
  4149. double diff_t;
  4150. struct tm tp;
  4151. //int clearflag = FALSE;
  4152. FILE *fptr1;//, *fptr2;
  4153. //char temp[] = "../Storage/OCPP/temp.json";
  4154. int c = 0;
  4155. //int i = 0;
  4156. char * pch;
  4157. char *loc;
  4158. char sstr[200]={ 0 };
  4159. int n_chargingProfile = 0;
  4160. int n_SchedulePeriods = 0;
  4161. char SchedulePeriodList[10][200]={0};
  4162. char sLineWord[800]={0};
  4163. //int n_periods = 0;
  4164. char word[1000]={0};
  4165. int confirmPeriods = 0;
  4166. struct StructProfile ChargePointMaxProfile;
  4167. struct StructProfile TxDefaultProfile;
  4168. struct StructProfile TxProfile;
  4169. struct StructProfile TxDefaultProfiletemp[2]={0};
  4170. int TxDefaultProfileFileIsNull=FALSE;
  4171. int ChargePointMaxProfileIsNull=FALSE;
  4172. int TxProfileIsNull=FALSE;
  4173. int CompositeSceduleIndex = 0;
  4174. char ChargePointMaxProfileScheduleStr[30]={0};
  4175. char TxDefaultProfileScheduleStr[30]={0};
  4176. char TxProfileScheduleStr[30]={0};
  4177. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4178. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4179. memset(&TxProfile,0,sizeof(struct StructProfile));
  4180. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4181. c=0;
  4182. loc = strstr(payload, "connectorId");
  4183. memset(sstr ,0, sizeof(sstr) );
  4184. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4185. {
  4186. sstr[c] = loc[strlen("connectorId")+2+c];
  4187. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4188. c++;
  4189. }
  4190. sstr[c] = '\0';
  4191. connectorIdInt = atoi(sstr);
  4192. c=0;
  4193. loc = strstr(payload, "duration");
  4194. memset(sstr ,0, sizeof(sstr) );
  4195. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4196. {
  4197. sstr[c] = loc[strlen("duration")+2+c];
  4198. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4199. c++;
  4200. }
  4201. sstr[c] = '\0';
  4202. durationInt = atoi(sstr);
  4203. c = 0;
  4204. loc = strstr(payload, "chargingRateUnit");
  4205. memset(sstr ,0, sizeof(sstr) );
  4206. if(loc == NULL)
  4207. {
  4208. }
  4209. else
  4210. {
  4211. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4212. {
  4213. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4214. c++;
  4215. }
  4216. sstr[c] = '\0';
  4217. strcpy(chargingRateUnitStr, sstr);
  4218. }
  4219. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4220. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4221. if(connectorIdInt==0) // connectorId is 0
  4222. {
  4223. //******************************ChargePointMaxProfile*****************************************************/
  4224. strcpy(fname, ChargePointMaxProfile_JSON );
  4225. char word[30]={0};
  4226. char sLineWord[1060]={0};
  4227. int n_chargingProfile=0;
  4228. ChargePointMaxProfileIsNull=TRUE;
  4229. if((access(fname,F_OK))!=-1)
  4230. {
  4231. fptr1 = fopen(fname, "r");
  4232. int c;
  4233. c = fgetc(fptr1);
  4234. //DEBUG_INFO("c:%d\n",c);
  4235. rewind(fptr1);
  4236. if(c == EOF)
  4237. {
  4238. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4239. ChargePointMaxProfileIsNull=TRUE;
  4240. fclose(fptr1);
  4241. }
  4242. else
  4243. {
  4244. ChargePointMaxProfileIsNull=FALSE;
  4245. while(fscanf(fptr1, "%s", word) != EOF)
  4246. {
  4247. if(strcmp(word, "chargingProfileId") == 0)
  4248. {
  4249. n_chargingProfile = n_chargingProfile + 1;
  4250. printf("Found\n");
  4251. }
  4252. }
  4253. rewind(fptr1);
  4254. //search Charging Profile Element
  4255. int i= 0;
  4256. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4257. #if 0
  4258. /***********connectorId****************/
  4259. c = 0;
  4260. loc = strstr(sLineWord, "connectorId");
  4261. // printf("loc=%s\n",loc);
  4262. memset(sstr ,0, sizeof(sstr) );
  4263. while (loc[strlen("connectorId")+2+c] != ',')
  4264. {
  4265. sstr[c] = loc[strlen("connectorId")+2+c];
  4266. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4267. c++;
  4268. }
  4269. sstr[c] = '\0';
  4270. tempconnectorIdInt = atoi(sstr);
  4271. #endif
  4272. //***********validFrom**************/
  4273. c = 0;
  4274. loc = strstr(sLineWord, "validFrom");
  4275. //DEBUG_INFO("loc=%s\n",loc);
  4276. memset(sstr ,0, sizeof(sstr) );
  4277. if(loc != NULL)
  4278. {
  4279. while (loc[3+strlen("validFrom")+c] != '\"')
  4280. {
  4281. sstr[c] = loc[3+strlen("validFrom")+c];
  4282. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4283. c++;
  4284. }
  4285. sstr[c] = '\0';
  4286. DEBUG_INFO("validFrom=%s\n",sstr);
  4287. strcpy(tempvalidFromStr,sstr);
  4288. }
  4289. else
  4290. {
  4291. strcpy(tempvalidFromStr,"");
  4292. }
  4293. //**********startSchedule**********/
  4294. c = 0;
  4295. loc = strstr(sLineWord, "startSchedule");
  4296. //DEBUG_INFO("loc=%s\n",loc);
  4297. memset(sstr ,0, sizeof(sstr) );
  4298. while (loc[3+strlen("startSchedule")+c] != '\"')
  4299. {
  4300. sstr[c] = loc[3+strlen("startSchedule")+c];
  4301. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4302. c++;
  4303. }
  4304. sstr[c] = '\0';
  4305. strcpy(tempstartScheduleStr, sstr);
  4306. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4307. //**********chargingRateUnit**********/
  4308. c = 0;
  4309. loc = strstr(sLineWord, "chargingRateUnit");
  4310. memset(sstr ,0, sizeof(sstr) );
  4311. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4312. {
  4313. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4314. c++;
  4315. }
  4316. sstr[c] = '\0';
  4317. strcpy(tempchargingRateUnitStr, sstr);
  4318. //**********minChargingRate*******/
  4319. c = 0;
  4320. loc = strstr(sLineWord, "minChargingRate");
  4321. //printf("loc=%s\n",loc);
  4322. if(loc != NULL)
  4323. {
  4324. memset(sstr ,0, sizeof(sstr) );
  4325. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4326. {
  4327. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4328. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4329. c++;
  4330. }
  4331. sstr[c] = '\0';
  4332. tempminChargingRateFloat = atof(sstr);
  4333. }
  4334. else
  4335. {
  4336. tempminChargingRateFloat = 0.0;
  4337. }
  4338. //
  4339. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4340. tp.tm_isdst = -1;
  4341. time_t utc = mktime(&tp);
  4342. // current time
  4343. time_t t = time(NULL);
  4344. diff_t = difftime(t, utc);
  4345. //parsing strings to words
  4346. i = 0;
  4347. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4348. loc = loc+3+strlen("chargingSchedulePeriod");
  4349. pch = strtok(loc ,"{");
  4350. while (pch != NULL)
  4351. {
  4352. strcpy(SchedulePeriodList[i], pch);
  4353. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4354. //printf ("%s\n",pch);
  4355. pch = strtok (NULL, "{");
  4356. i = i + 1;
  4357. }
  4358. n_SchedulePeriods = i;
  4359. for(int i=0;i<n_SchedulePeriods;i++)
  4360. {
  4361. //*************startPeriod****************/
  4362. c = 0;
  4363. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4364. memset(sstr ,0, sizeof(sstr) );
  4365. while (loc[strlen("startPeriod")+2+c] != ',')
  4366. {
  4367. sstr[c] = loc[strlen("startPeriod")+2+c];
  4368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4369. c++;
  4370. }
  4371. sstr[c] = '\0';
  4372. tempStartPeriodInt = atoi(sstr);
  4373. //*************limit****************/
  4374. c = 0;
  4375. loc = strstr(SchedulePeriodList[i], "limit");
  4376. memset(sstr ,0, sizeof(sstr) );
  4377. while (loc[strlen("limit")+2+c] != ',')
  4378. {
  4379. sstr[c] = loc[strlen("limit")+2+c];
  4380. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4381. c++;
  4382. }
  4383. sstr[c] = '\0';
  4384. tempLimitInt = atof(sstr);
  4385. //*************numberPhases****************/
  4386. c = 0;
  4387. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4388. memset(sstr ,0, sizeof(sstr) );
  4389. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4390. {
  4391. sstr[c] = loc[strlen("numberPhases")+2+c];
  4392. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4393. c++;
  4394. }
  4395. sstr[c] = '\0';
  4396. tempNumberPhasesInt = atoi(sstr);
  4397. ChargePointMaxProfile.Duration = durationInt;
  4398. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4399. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4400. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4401. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4402. }
  4403. if(MinChargingRate < tempminChargingRateFloat)
  4404. MinChargingRate = tempminChargingRateFloat;
  4405. }
  4406. }// End of file ChargingProfile
  4407. } //THE END OF ACCESS ChargePointMaxProfile
  4408. //******************************TxDefaultProfile***********************************************/
  4409. strcpy(fname, TxDefaultProfile_0_JSON);
  4410. memset(word, 0, 30);
  4411. memset(sLineWord, 0, 1060);
  4412. //char word[30]={0};
  4413. //char sLineWord[1060]={0};
  4414. n_chargingProfile=0;
  4415. TxDefaultProfileFileIsNull=TRUE;
  4416. if((access(fname,F_OK))!=-1)
  4417. {
  4418. fptr1 = fopen(fname, "r");
  4419. c = 0;
  4420. c = fgetc(fptr1);
  4421. //DEBUG_INFO("c:%d\n",c);
  4422. rewind(fptr1);
  4423. if(c == EOF)
  4424. {
  4425. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4426. TxDefaultProfileFileIsNull=TRUE;
  4427. fclose(fptr1);
  4428. }
  4429. else
  4430. {
  4431. TxDefaultProfileFileIsNull=FALSE;
  4432. while(fscanf(fptr1, "%s", word) != EOF)
  4433. {
  4434. if(strcmp(word, "chargingProfileId") == 0)
  4435. {
  4436. n_chargingProfile = n_chargingProfile + 1;
  4437. printf("Found\n");
  4438. }
  4439. }
  4440. rewind(fptr1);
  4441. //search Charging Profile Element
  4442. int i= 0;
  4443. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4444. #if 0
  4445. /***********connectorId****************/
  4446. c = 0;
  4447. loc = strstr(sLineWord, "connectorId");
  4448. // printf("loc=%s\n",loc);
  4449. memset(sstr ,0, sizeof(sstr) );
  4450. while (loc[strlen("connectorId")+2+c] != ',')
  4451. {
  4452. sstr[c] = loc[strlen("connectorId")+2+c];
  4453. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4454. c++;
  4455. }
  4456. sstr[c] = '\0';
  4457. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4458. tempconnectorIdInt = atoi(sstr);
  4459. #endif
  4460. //***********validFrom**************/
  4461. c = 0;
  4462. loc = strstr(sLineWord, "validFrom");
  4463. //DEBUG_INFO("loc=%s\n",loc);
  4464. memset(sstr ,0, sizeof(sstr) );
  4465. if(loc != NULL)
  4466. {
  4467. while (loc[3+strlen("validFrom")+c] != '\"')
  4468. {
  4469. sstr[c] = loc[3+strlen("validFrom")+c];
  4470. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4471. c++;
  4472. }
  4473. sstr[c] = '\0';
  4474. DEBUG_INFO("validFrom=%s\n",sstr);
  4475. strcpy(tempvalidFromStr,sstr);
  4476. }
  4477. else
  4478. {
  4479. strcpy(tempvalidFromStr,"");
  4480. }
  4481. //**********startSchedule**********/
  4482. c = 0;
  4483. loc = strstr(sLineWord, "startSchedule");
  4484. //DEBUG_INFO("loc=%s\n",loc);
  4485. memset(sstr ,0, sizeof(sstr) );
  4486. while (loc[3+strlen("startSchedule")+c] != '\"')
  4487. {
  4488. sstr[c] = loc[3+strlen("startSchedule")+c];
  4489. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4490. c++;
  4491. }
  4492. sstr[c] = '\0';
  4493. strcpy(tempstartScheduleStr, sstr);
  4494. strcpy(TxDefaultProfileScheduleStr, sstr);
  4495. DEBUG_INFO(" debug 3-1\n");
  4496. //**********chargingRateUnit**********/
  4497. c = 0;
  4498. loc = strstr(sLineWord, "chargingRateUnit");
  4499. memset(sstr ,0, sizeof(sstr) );
  4500. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4501. {
  4502. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4503. c++;
  4504. }
  4505. sstr[c] = '\0';
  4506. strcpy(tempchargingRateUnitStr, sstr);
  4507. //**********minChargingRate*******/
  4508. c = 0;
  4509. loc = strstr(sLineWord, "minChargingRate");
  4510. //printf("loc=%s\n",loc);
  4511. if(loc != NULL)
  4512. {
  4513. memset(sstr ,0, sizeof(sstr) );
  4514. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4515. {
  4516. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4517. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4518. c++;
  4519. }
  4520. sstr[c] = '\0';
  4521. tempminChargingRateFloat = atof(sstr);
  4522. }
  4523. else
  4524. {
  4525. tempminChargingRateFloat = 0.0;
  4526. }
  4527. //
  4528. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4529. tp.tm_isdst = -1;
  4530. time_t utc = mktime(&tp);
  4531. // current time
  4532. time_t t = time(NULL);
  4533. diff_t = difftime(t, utc);
  4534. //parsing strings to words
  4535. i = 0;
  4536. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4537. loc = loc+3+strlen("chargingSchedulePeriod");
  4538. pch = strtok(loc ,"{");
  4539. while (pch != NULL)
  4540. {
  4541. strcpy(SchedulePeriodList[i], pch);
  4542. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4543. //printf ("%s\n",pch);
  4544. pch = strtok (NULL, "{");
  4545. i = i + 1;
  4546. }
  4547. n_SchedulePeriods = i;
  4548. for(int i=0;i<n_SchedulePeriods;i++)
  4549. {
  4550. //*************startPeriod****************/
  4551. c = 0;
  4552. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4553. memset(sstr ,0, sizeof(sstr) );
  4554. while (loc[strlen("startPeriod")+2+c] != ',')
  4555. {
  4556. sstr[c] = loc[strlen("startPeriod")+2+c];
  4557. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4558. c++;
  4559. }
  4560. sstr[c] = '\0';
  4561. tempStartPeriodInt = atoi(sstr);
  4562. //*************limit****************/
  4563. c = 0;
  4564. loc = strstr(SchedulePeriodList[i], "limit");
  4565. memset(sstr ,0, sizeof(sstr) );
  4566. while (loc[strlen("limit")+2+c] != ',')
  4567. {
  4568. sstr[c] = loc[strlen("limit")+2+c];
  4569. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4570. c++;
  4571. }
  4572. sstr[c] = '\0';
  4573. tempLimitInt = atof(sstr);
  4574. //*************numberPhases****************/
  4575. c = 0;
  4576. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4577. memset(sstr ,0, sizeof(sstr) );
  4578. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4579. {
  4580. sstr[c] = loc[strlen("numberPhases")+2+c];
  4581. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4582. c++;
  4583. }
  4584. sstr[c] = '\0';
  4585. tempNumberPhasesInt = atoi(sstr);
  4586. TxDefaultProfile.Duration = durationInt;
  4587. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4588. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4589. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4590. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4591. }
  4592. if(MinChargingRate < tempminChargingRateFloat)
  4593. MinChargingRate = tempminChargingRateFloat;
  4594. }
  4595. }
  4596. }// the end of ACCESS TxDefaultProfile
  4597. // Composite Schedule
  4598. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4599. {
  4600. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4601. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4602. {
  4603. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4604. {
  4605. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4606. }
  4607. else
  4608. {
  4609. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4610. }
  4611. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4612. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4613. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4614. }
  4615. }
  4616. //* Define temporary variables */
  4617. struct tm *gtime;
  4618. time_t now;
  4619. char buf[28];
  4620. /* Read the current system time */
  4621. time(&now);
  4622. /* Convert the system time to GMT (now UTC) */
  4623. gtime = gmtime(&now);
  4624. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4625. // make .conf
  4626. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4627. //MaxChargingProfilesInstalled is 10
  4628. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4629. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4630. //nPeriod = 1;
  4631. if(chargingRateUnitStr[0] != 0)
  4632. {
  4633. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4634. }
  4635. else
  4636. {
  4637. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4638. }
  4639. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4640. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4641. confirmPeriods = 1;
  4642. }
  4643. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4644. {
  4645. //*****************************ChargePointMaxProfile******************************************/
  4646. strcpy(fname, ChargePointMaxProfile_JSON);
  4647. ChargePointMaxProfileIsNull=TRUE;
  4648. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4649. {
  4650. fptr1 = fopen(fname, "r");
  4651. int c;
  4652. c = fgetc(fptr1);
  4653. //DEBUG_INFO("c:%d\n",c);
  4654. rewind(fptr1);
  4655. if(c == EOF)
  4656. {
  4657. DEBUG_INFO("\n End of file reached.");
  4658. ChargePointMaxProfileIsNull=TRUE;
  4659. fclose(fptr1);
  4660. }
  4661. else
  4662. {
  4663. ChargePointMaxProfileIsNull=FALSE;
  4664. while(fscanf(fptr1, "%s", word) != EOF)
  4665. {
  4666. if(strcmp(word, "chargingProfileId") == 0)
  4667. {
  4668. n_chargingProfile = n_chargingProfile + 1;
  4669. }
  4670. }
  4671. rewind(fptr1);
  4672. //search Charging Profile Element
  4673. int i = 0;
  4674. int j = 0;
  4675. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4676. #if 0
  4677. /***********connectorId****************/
  4678. c = 0;
  4679. loc = strstr(sLineWord, "connectorId");
  4680. memset(sstr ,0, sizeof(sstr) );
  4681. while (loc[strlen("connectorId")+2+c] != ',')
  4682. {
  4683. sstr[c] = loc[strlen("connectorId")+2+c];
  4684. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4685. c++;
  4686. }
  4687. sstr[c] = '\0';
  4688. tempconnectorIdInt = atoi(sstr);
  4689. #endif
  4690. //***********validFrom**************/
  4691. c = 0;
  4692. loc = strstr(sLineWord, "validFrom");
  4693. if(loc != NULL)
  4694. {
  4695. memset(sstr ,0, sizeof(sstr) );
  4696. while (loc[3+strlen("validFrom")+c] != '\"')
  4697. {
  4698. sstr[c] = loc[3+strlen("validFrom")+c];
  4699. c++;
  4700. }
  4701. sstr[c] = '\0';
  4702. strcpy(tempvalidFromStr,sstr);
  4703. }
  4704. else
  4705. {
  4706. strcpy(tempvalidFromStr,"");
  4707. }
  4708. //***********validFrom**************/
  4709. c = 0;
  4710. loc = strstr(sLineWord, "duration");
  4711. if(loc != NULL)
  4712. {
  4713. memset(sstr ,0, sizeof(sstr) );
  4714. while (loc[2+strlen("duration")+c] != ',')
  4715. {
  4716. sstr[c] = loc[2+strlen("duration")+c];
  4717. c++;
  4718. }
  4719. sstr[c] = '\0';
  4720. tempdurationInt = atoi(sstr);
  4721. }
  4722. else
  4723. {
  4724. tempdurationInt = 0;
  4725. }
  4726. //**********startSchedule**********/
  4727. c = 0;
  4728. loc = strstr(sLineWord, "startSchedule");
  4729. memset(sstr ,0, sizeof(sstr) );
  4730. while (loc[3+strlen("startSchedule")+c] != '\"')
  4731. {
  4732. sstr[c] = loc[3+strlen("startSchedule")+c];
  4733. c++;
  4734. }
  4735. sstr[c] = '\0';
  4736. strcpy(tempstartScheduleStr, sstr);
  4737. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4738. //**********chargingRateUnit**********/
  4739. c = 0;
  4740. loc = strstr(sLineWord, "chargingRateUnit");
  4741. memset(sstr ,0, sizeof(sstr) );
  4742. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4743. {
  4744. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4745. c++;
  4746. }
  4747. sstr[c] = '\0';
  4748. strcpy(tempchargingRateUnitStr, sstr);
  4749. //**********minChargingRate*******/
  4750. c = 0;
  4751. loc = strstr(sLineWord, "minChargingRate");
  4752. if(loc != NULL)
  4753. {
  4754. memset(sstr ,0, sizeof(sstr) );
  4755. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4756. {
  4757. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4758. c++;
  4759. }
  4760. sstr[c] = '\0';
  4761. tempminChargingRateFloat = atof(sstr);
  4762. }
  4763. else
  4764. {
  4765. tempminChargingRateFloat = 0.0;
  4766. }
  4767. //
  4768. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4769. tp.tm_isdst = -1;
  4770. time_t utc = mktime(&tp);
  4771. time_t t = time(NULL);
  4772. diff_t = difftime(t, utc);
  4773. DEBUG_INFO("diff_t=%f\n",diff_t);
  4774. DEBUG_INFO(" debug 5 -1\n");
  4775. //parsing strings to words
  4776. i = 0;
  4777. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4778. loc = loc+3+strlen("chargingSchedulePeriod");
  4779. pch = strtok(loc ,"{");
  4780. while (pch != NULL)
  4781. {
  4782. strcpy(SchedulePeriodList[i], pch);
  4783. pch = strtok (NULL, "{");
  4784. i = i + 1;
  4785. }
  4786. n_SchedulePeriods = i;
  4787. for(int i=0;i<n_SchedulePeriods;i++)
  4788. {
  4789. //*************startPeriod****************/
  4790. c = 0;
  4791. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4792. memset(sstr ,0, sizeof(sstr) );
  4793. while (loc[strlen("startPeriod")+2+c] != ',')
  4794. {
  4795. sstr[c] = loc[strlen("startPeriod")+2+c];
  4796. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4797. c++;
  4798. }
  4799. sstr[c] = '\0';
  4800. tempStartPeriodInt = atoi(sstr);
  4801. //*************limit****************/
  4802. c = 0;
  4803. loc = strstr(SchedulePeriodList[i], "limit");
  4804. memset(sstr ,0, sizeof(sstr) );
  4805. while (loc[strlen("limit")+2+c] != ',')
  4806. {
  4807. sstr[c] = loc[strlen("limit")+2+c];
  4808. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4809. c++;
  4810. }
  4811. sstr[c] = '\0';
  4812. tempLimitInt = atof(sstr);
  4813. //*************numberPhases****************/
  4814. c = 0;
  4815. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4816. memset(sstr ,0, sizeof(sstr) );
  4817. while (loc[strlen("numberPhases")+2+c] != '}')
  4818. {
  4819. sstr[c] = loc[strlen("numberPhases")+2+c];
  4820. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4821. c++;
  4822. }
  4823. sstr[c] = '\0';
  4824. tempNumberPhasesInt = atoi(sstr);
  4825. if(j == 0)
  4826. {
  4827. ChargePointMaxProfile.Duration = tempdurationInt;
  4828. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4829. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4830. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4831. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4832. }
  4833. }
  4834. if(MinChargingRate < tempminChargingRateFloat)
  4835. {
  4836. MinChargingRate = tempminChargingRateFloat;
  4837. }
  4838. if(confirmPeriods < n_SchedulePeriods)
  4839. {
  4840. confirmPeriods = n_SchedulePeriods;
  4841. }
  4842. j = j + 1;
  4843. }
  4844. fclose(fptr1);
  4845. }
  4846. }// the end of access file ChargePointMaxProfile
  4847. //****************************TxDefaultProfile************************************************/
  4848. switch(connectorIdInt)
  4849. {
  4850. case 0:
  4851. break;
  4852. case 1:
  4853. strcpy(fname, TxDefaultProfile_1_JSON );
  4854. break;
  4855. case 2:
  4856. strcpy(fname, TxDefaultProfile_2_JSON );
  4857. break;
  4858. default:
  4859. strcpy(fname, TxDefaultProfile_1_JSON );
  4860. break;
  4861. }
  4862. TxDefaultProfileFileIsNull=TRUE;
  4863. if((access(fname,F_OK))!=-1)
  4864. {
  4865. fptr1 = fopen(fname, "r");
  4866. c = 0;
  4867. c = fgetc(fptr1);
  4868. //DEBUG_INFO("c:%d\n",c);
  4869. rewind(fptr1);
  4870. if(c == EOF)
  4871. {
  4872. DEBUG_INFO("\n End of file reached.");
  4873. TxDefaultProfileFileIsNull=TRUE;
  4874. fclose(fptr1);
  4875. }
  4876. else
  4877. {
  4878. TxDefaultProfileFileIsNull=FALSE;
  4879. while(fscanf(fptr1, "%s", word) != EOF)
  4880. {
  4881. if(strcmp(word, "chargingProfileId") == 0)
  4882. {
  4883. n_chargingProfile = n_chargingProfile + 1;
  4884. }
  4885. }
  4886. rewind(fptr1);
  4887. //search Charging Profile Element
  4888. int i = 0;
  4889. int j = 0;
  4890. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4891. //DEBUG_INFO(" 1-1\n");
  4892. #if 0
  4893. /***********connectorId****************/
  4894. c = 0;
  4895. loc = strstr(sLineWord, "connectorId");
  4896. memset(sstr ,0, sizeof(sstr) );
  4897. while (loc[strlen("connectorId")+2+c] != ',')
  4898. {
  4899. sstr[c] = loc[strlen("connectorId")+2+c];
  4900. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4901. c++;
  4902. }
  4903. sstr[c] = '\0';
  4904. tempconnectorIdInt = atoi(sstr);
  4905. #endif
  4906. //***********validFrom**************/
  4907. c = 0;
  4908. loc = strstr(sLineWord, "validFrom");
  4909. if(loc != NULL)
  4910. {
  4911. memset(sstr ,0, sizeof(sstr) );
  4912. while (loc[3+strlen("validFrom")+c] != '\"')
  4913. {
  4914. sstr[c] = loc[3+strlen("validFrom")+c];
  4915. c++;
  4916. }
  4917. sstr[c] = '\0';
  4918. strcpy(tempvalidFromStr,sstr);
  4919. }
  4920. else
  4921. {
  4922. strcpy(tempvalidFromStr,"");
  4923. }
  4924. //***********validFrom**************/
  4925. c = 0;
  4926. loc = strstr(sLineWord, "duration");
  4927. if(loc != NULL)
  4928. {
  4929. memset(sstr ,0, sizeof(sstr) );
  4930. while (loc[2+strlen("duration")+c] != ',')
  4931. {
  4932. sstr[c] = loc[2+strlen("duration")+c];
  4933. c++;
  4934. }
  4935. sstr[c] = '\0';
  4936. tempdurationInt = atoi(sstr);
  4937. }
  4938. else
  4939. {
  4940. tempdurationInt = 0;
  4941. }
  4942. //**********startSchedule**********/
  4943. c = 0;
  4944. loc = strstr(sLineWord, "startSchedule");
  4945. memset(sstr ,0, sizeof(sstr) );
  4946. while (loc[3+strlen("startSchedule")+c] != '\"')
  4947. {
  4948. sstr[c] = loc[3+strlen("startSchedule")+c];
  4949. c++;
  4950. }
  4951. sstr[c] = '\0';
  4952. strcpy(tempstartScheduleStr, sstr);
  4953. strcpy(TxDefaultProfileScheduleStr, sstr);
  4954. //**********chargingRateUnit**********/
  4955. c = 0;
  4956. loc = strstr(sLineWord, "chargingRateUnit");
  4957. memset(sstr ,0, sizeof(sstr) );
  4958. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4959. {
  4960. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4961. c++;
  4962. }
  4963. sstr[c] = '\0';
  4964. strcpy(tempchargingRateUnitStr, sstr);
  4965. //**********minChargingRate*******/
  4966. c = 0;
  4967. loc = strstr(sLineWord, "minChargingRate");
  4968. if(loc != NULL)
  4969. {
  4970. memset(sstr ,0, sizeof(sstr) );
  4971. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4972. {
  4973. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4974. c++;
  4975. }
  4976. sstr[c] = '\0';
  4977. tempminChargingRateFloat = atof(sstr);
  4978. }
  4979. else
  4980. {
  4981. tempminChargingRateFloat = 0.0;
  4982. }
  4983. //
  4984. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4985. tp.tm_isdst = -1;
  4986. time_t utc = mktime(&tp);
  4987. time_t t = time(NULL);
  4988. diff_t = difftime(t, utc);
  4989. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4990. //parsing strings to words
  4991. i = 0;
  4992. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4993. loc = loc+3+strlen("chargingSchedulePeriod");
  4994. pch = strtok(loc ,"{");
  4995. while (pch != NULL)
  4996. {
  4997. strcpy(SchedulePeriodList[i], pch);
  4998. pch = strtok (NULL, "{");
  4999. i = i + 1;
  5000. }
  5001. n_SchedulePeriods = i;
  5002. for(int i=0;i<n_SchedulePeriods;i++)
  5003. {
  5004. //*************startPeriod****************/
  5005. c = 0;
  5006. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5007. memset(sstr ,0, sizeof(sstr) );
  5008. while (loc[strlen("startPeriod")+2+c] != ',')
  5009. {
  5010. sstr[c] = loc[strlen("startPeriod")+2+c];
  5011. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5012. c++;
  5013. }
  5014. sstr[c] = '\0';
  5015. tempStartPeriodInt = atoi(sstr);
  5016. //*************limit****************/
  5017. c = 0;
  5018. loc = strstr(SchedulePeriodList[i], "limit");
  5019. memset(sstr ,0, sizeof(sstr) );
  5020. while (loc[strlen("limit")+2+c] != ',')
  5021. {
  5022. sstr[c] = loc[strlen("limit")+2+c];
  5023. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5024. c++;
  5025. }
  5026. sstr[c] = '\0';
  5027. tempLimitInt = atof(sstr);
  5028. //*************numberPhases****************/
  5029. c = 0;
  5030. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5031. memset(sstr ,0, sizeof(sstr) );
  5032. while (loc[strlen("numberPhases")+2+c] != '}')
  5033. {
  5034. sstr[c] = loc[strlen("numberPhases")+2+c];
  5035. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5036. c++;
  5037. }
  5038. sstr[c] = '\0';
  5039. tempNumberPhasesInt = atoi(sstr);
  5040. if(j == 0)
  5041. {
  5042. TxDefaultProfile.Duration = tempdurationInt;
  5043. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5044. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5045. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5046. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5047. }
  5048. else
  5049. {
  5050. //other stack level charging Profile
  5051. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5052. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5053. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5054. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5055. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5056. }
  5057. }
  5058. if(MinChargingRate < tempminChargingRateFloat)
  5059. MinChargingRate = tempminChargingRateFloat;
  5060. if(confirmPeriods < n_SchedulePeriods)
  5061. confirmPeriods = n_SchedulePeriods;
  5062. j = j + 1;
  5063. //DEBUG_INFO(" 1-2\n");
  5064. }
  5065. fclose(fptr1);
  5066. //Stacking Charging Profiles
  5067. for(int l=0; l <(j-1) ;l++)
  5068. {
  5069. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5070. {
  5071. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5072. {
  5073. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5074. {
  5075. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5076. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5077. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5078. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5079. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5080. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5081. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5082. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5083. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5084. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5085. }
  5086. else
  5087. {
  5088. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5089. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5090. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5091. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5092. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5093. }
  5094. }
  5095. }
  5096. }
  5097. //end of Stacking Charging Profiles
  5098. }
  5099. }// the end of ACCESS TxDefaultProfile
  5100. //****************************TxProfile************************************************/
  5101. switch(connectorIdInt)
  5102. {
  5103. case 0:
  5104. break;
  5105. case 1:
  5106. strcpy(fname, TxProfile_1_JSON );
  5107. break;
  5108. case 2:
  5109. strcpy(fname, TxProfile_2_JSON );
  5110. break;
  5111. default:
  5112. strcpy(fname, TxProfile_1_JSON );
  5113. break;
  5114. }
  5115. TxProfileIsNull=TRUE;
  5116. if((access(fname,F_OK))!=-1)
  5117. {
  5118. fptr1 = fopen(fname, "r");
  5119. c = 0;
  5120. c = fgetc(fptr1);
  5121. //DEBUG_INFO("c:%d\n",c);
  5122. rewind(fptr1);
  5123. if(c == EOF)
  5124. {
  5125. DEBUG_INFO("\n End of file reached.");
  5126. TxProfileIsNull=TRUE;
  5127. fclose(fptr1);
  5128. }
  5129. else
  5130. {
  5131. TxProfileIsNull=FALSE;
  5132. while(fscanf(fptr1, "%s", word) != EOF)
  5133. {
  5134. if(strcmp(word, "chargingProfileId") == 0)
  5135. {
  5136. n_chargingProfile = n_chargingProfile + 1;
  5137. }
  5138. }
  5139. rewind(fptr1);
  5140. //search Charging Profile Element
  5141. int i= 0;
  5142. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5143. #if 0
  5144. /***********connectorId****************/
  5145. c = 0;
  5146. loc = strstr(sLineWord, "connectorId");
  5147. memset(sstr ,0, sizeof(sstr) );
  5148. while (loc[strlen("connectorId")+2+c] != ',')
  5149. {
  5150. sstr[c] = loc[strlen("connectorId")+2+c];
  5151. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5152. c++;
  5153. }
  5154. sstr[c] = '\0';
  5155. tempconnectorIdInt = atoi(sstr);
  5156. #endif
  5157. //***********validFrom**************/
  5158. c = 0;
  5159. loc = strstr(sLineWord, "validFrom");
  5160. if(loc != NULL)
  5161. {
  5162. memset(sstr ,0, sizeof(sstr) );
  5163. while (loc[3+strlen("validFrom")+c] != '\"')
  5164. {
  5165. sstr[c] = loc[3+strlen("validFrom")+c];
  5166. c++;
  5167. }
  5168. sstr[c] = '\0';
  5169. strcpy(tempvalidFromStr,sstr);
  5170. }
  5171. else
  5172. {
  5173. strcpy(tempvalidFromStr,"");
  5174. }
  5175. //**********startSchedule**********/
  5176. c = 0;
  5177. loc = strstr(sLineWord, "startSchedule");
  5178. memset(sstr ,0, sizeof(sstr) );
  5179. while (loc[3+strlen("startSchedule")+c] != '\"')
  5180. {
  5181. sstr[c] = loc[3+strlen("startSchedule")+c];
  5182. c++;
  5183. }
  5184. sstr[c] = '\0';
  5185. strcpy(tempstartScheduleStr, sstr);
  5186. strcpy(TxProfileScheduleStr, sstr);
  5187. //**********chargingRateUnit**********/
  5188. c = 0;
  5189. loc = strstr(sLineWord, "chargingRateUnit");
  5190. memset(sstr ,0, sizeof(sstr) );
  5191. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5192. {
  5193. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5194. c++;
  5195. }
  5196. sstr[c] = '\0';
  5197. strcpy(tempchargingRateUnitStr, sstr);
  5198. //**********minChargingRate*******/
  5199. c = 0;
  5200. loc = strstr(sLineWord, "minChargingRate");
  5201. if(loc != NULL)
  5202. {
  5203. memset(sstr ,0, sizeof(sstr) );
  5204. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5205. {
  5206. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5207. c++;
  5208. }
  5209. sstr[c] = '\0';
  5210. tempminChargingRateFloat = atof(sstr);
  5211. }
  5212. else
  5213. {
  5214. tempminChargingRateFloat = 0.0;
  5215. }
  5216. //
  5217. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5218. tp.tm_isdst = -1;
  5219. time_t utc = mktime(&tp);
  5220. time_t t = time(NULL);
  5221. diff_t = difftime(t, utc);
  5222. DEBUG_INFO("diff_t=%f\n",diff_t);
  5223. //parsing strings to words
  5224. i = 0;
  5225. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5226. loc = loc+3+strlen("chargingSchedulePeriod");
  5227. pch = strtok(loc ,"{");
  5228. while (pch != NULL)
  5229. {
  5230. strcpy(SchedulePeriodList[i], pch);
  5231. pch = strtok (NULL, "{");
  5232. i = i + 1;
  5233. }
  5234. n_SchedulePeriods = i;
  5235. for(int i=0;i<n_SchedulePeriods;i++)
  5236. {
  5237. //*************startPeriod****************/
  5238. c = 0;
  5239. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5240. memset(sstr ,0, sizeof(sstr) );
  5241. while (loc[strlen("startPeriod")+2+c] != ',')
  5242. {
  5243. sstr[c] = loc[strlen("startPeriod")+2+c];
  5244. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5245. c++;
  5246. }
  5247. sstr[c] = '\0';
  5248. tempStartPeriodInt = atoi(sstr);
  5249. //*************limit****************/
  5250. c = 0;
  5251. loc = strstr(SchedulePeriodList[i], "limit");
  5252. memset(sstr ,0, sizeof(sstr) );
  5253. while (loc[strlen("limit")+2+c] != ',')
  5254. {
  5255. sstr[c] = loc[strlen("limit")+2+c];
  5256. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5257. c++;
  5258. }
  5259. sstr[c] = '\0';
  5260. tempLimitInt = atof(sstr);
  5261. //*************numberPhases****************/
  5262. c = 0;
  5263. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5264. memset(sstr ,0, sizeof(sstr) );
  5265. while (loc[strlen("numberPhases")+2+c] != '}')
  5266. {
  5267. sstr[c] = loc[strlen("numberPhases")+2+c];
  5268. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5269. c++;
  5270. }
  5271. sstr[c] = '\0';
  5272. tempNumberPhasesInt = atoi(sstr);
  5273. TxProfile.Duration = durationInt;
  5274. TxProfile.TotalPeriod = n_SchedulePeriods;
  5275. TxProfile.Period[i].Limit = tempLimitInt;
  5276. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5277. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5278. }
  5279. if(MinChargingRate < tempminChargingRateFloat)
  5280. MinChargingRate = tempminChargingRateFloat;
  5281. if(confirmPeriods < n_SchedulePeriods)
  5282. confirmPeriods = n_SchedulePeriods;
  5283. }
  5284. fclose(fptr1);
  5285. }
  5286. }// the end of ACCESS TxProfile
  5287. //CompositeSchedule
  5288. int period=0;
  5289. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5290. {
  5291. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5292. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5293. {
  5294. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5295. {
  5296. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5297. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5298. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5299. period = period + 1;
  5300. }
  5301. else
  5302. {
  5303. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5304. {
  5305. }
  5306. else
  5307. {
  5308. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5309. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5310. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5311. period = period + 1;
  5312. }
  5313. }
  5314. }
  5315. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5316. {
  5317. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5318. {
  5319. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5320. {
  5321. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5322. }
  5323. else
  5324. {
  5325. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5326. }
  5327. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5328. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5329. period = period + 1;
  5330. }
  5331. }
  5332. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5333. {
  5334. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5335. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5336. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5337. period = period + 1;
  5338. }
  5339. }
  5340. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5341. {
  5342. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5343. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5344. {
  5345. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5346. {
  5347. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5348. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5349. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5350. period = period + 1;
  5351. }
  5352. else
  5353. {
  5354. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5355. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5356. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5357. period = period + 1;
  5358. }
  5359. }
  5360. }
  5361. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5362. {
  5363. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5364. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5365. {
  5366. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5367. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5368. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5369. period = period + 1;
  5370. }
  5371. }
  5372. confirmPeriods = period;
  5373. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5374. //* Define temporary variables */
  5375. struct tm *gtime;
  5376. time_t now;
  5377. char buf[28];
  5378. //* Read the current system time */
  5379. time(&now);
  5380. //* Convert the system time to GMT (now UTC) */
  5381. gtime = gmtime(&now);
  5382. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5383. // make .conf
  5384. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5385. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5386. //DEBUG_INFO(" debug 11\n");
  5387. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5388. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5389. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5390. }
  5391. else
  5392. {
  5393. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5394. }
  5395. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5396. return result;
  5397. }
  5398. int handleGetConfigurationRequest(char *uuid, char *payload)
  5399. {
  5400. mtrace();
  5401. int result = FAIL;
  5402. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5403. //struct json_object *jsonitem;
  5404. int MaxKeySupported = 0;
  5405. int n_keys = 0;
  5406. char requestKey[43][50]={0};
  5407. char search[]="[";
  5408. char sstr[500]={ 0 };
  5409. //int pos;
  5410. int l, c = 0;
  5411. int i = 0;
  5412. char *delim = "\",\"";
  5413. char * pch;
  5414. char *loc = strstr(payload, search);
  5415. //********************* Parsing String ***********************************/
  5416. if(loc == NULL) {
  5417. DEBUG_INFO("no key match in Configuration \n");
  5418. }
  5419. else {
  5420. //pos = loc - payload;
  5421. l = strlen(loc)-4;
  5422. while (c < l)
  5423. {
  5424. sstr[c] = loc[c+2];
  5425. c++;
  5426. }
  5427. sstr[c] = '\0';
  5428. //parsing strings to words
  5429. pch = strtok(sstr,delim);
  5430. if(pch == NULL)
  5431. {
  5432. strcpy(requestKey[0], sstr);
  5433. }
  5434. else
  5435. {
  5436. while (pch != NULL)
  5437. {
  5438. strcpy(requestKey[i], pch);
  5439. pch = strtok (NULL, delim);
  5440. i = i + 1;
  5441. }
  5442. n_keys = i;
  5443. }
  5444. }
  5445. UnknownKeynum = 0;
  5446. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5447. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5448. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5449. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5450. if(n_keys != 0)
  5451. {
  5452. for(int i=0;i<n_keys;i++)
  5453. {
  5454. getKeyValue(requestKey[i]);
  5455. //json_object_put(jsonitem);
  5456. }
  5457. }
  5458. else
  5459. {
  5460. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5461. getKeyValue("");
  5462. }
  5463. processUnkownKey();
  5464. sendGetConfigurationConfirmation(uuid);
  5465. return result;
  5466. }
  5467. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5468. {
  5469. mtrace();
  5470. int result = FAIL;
  5471. //void *ret; //
  5472. char fnamePlusPath[50]="";
  5473. char fname[16]="";
  5474. pthread_t t; // pthread 變數
  5475. time_t rawtime;
  5476. struct tm * timeinfo;
  5477. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5478. system("exec /root/logPackTools 'log' 6");
  5479. //char buffer [128];
  5480. time (&rawtime);
  5481. //printf("%ld\n", rawtime);
  5482. timeinfo = localtime (&rawtime);
  5483. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5484. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5485. if((access(fnamePlusPath,F_OK))!=-1)
  5486. {
  5487. DEBUG_INFO("fnamePlusPath exist.\n");
  5488. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5489. }
  5490. else
  5491. {
  5492. DEBUG_INFO("fnamePlusPath not exist!\n");
  5493. }
  5494. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5495. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5496. pthread_join(t, NULL/*&ret*/);
  5497. return result;
  5498. }
  5499. void* GetDiagnosticsProcess(void* data)
  5500. {
  5501. mtrace();
  5502. int retriesInt=0, retryIntervalInt=0;
  5503. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5504. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5505. 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};
  5506. int port=0;
  5507. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5508. char fname[16]="";
  5509. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5510. int c = 0;
  5511. char *loc;
  5512. int isSuccess = FALSE;
  5513. char ftpbuf[200]={0};
  5514. //char temp[100]={0};
  5515. char * pch;
  5516. // [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"}]
  5517. char *str = (char*) data; // ? ?輸入資 ?
  5518. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5519. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5520. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5521. //****************location*******************/
  5522. c = 0;
  5523. memset(sstr ,0, sizeof(sstr) );
  5524. loc = strstr(str, "location");
  5525. while (loc[3+strlen("location")+c] != '\"')
  5526. {
  5527. sstr[c] = loc[3+strlen("location")+c];
  5528. c++;
  5529. }
  5530. sstr[c] = '\0';
  5531. strcpy(locationstr,sstr);
  5532. if(strcmp(locationstr,"")==0)
  5533. {
  5534. DEBUG_INFO("location is <Empty>!\n");
  5535. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5536. goto end;
  5537. }
  5538. //****************retries*******************/
  5539. c = 0;
  5540. loc = strstr(str, "retries");
  5541. if(loc == NULL)
  5542. {
  5543. retriesIsNULL = TRUE;
  5544. }
  5545. else
  5546. {
  5547. while (loc[strlen("retries")+2+c] != ',')
  5548. {
  5549. sstr[c] = loc[strlen("retries")+2+c];
  5550. c++;
  5551. }
  5552. sstr[c] = '\0';
  5553. retriesInt = atoi(sstr);
  5554. }
  5555. if(retriesIsNULL == TRUE)
  5556. {
  5557. retriesInt = 0;
  5558. }
  5559. //****************retryInterval*******************/
  5560. c = 0;
  5561. loc = strstr(str, "retryInterval");
  5562. if(loc == NULL)
  5563. {
  5564. retryIntervalIsNULL = TRUE;
  5565. }
  5566. else
  5567. {
  5568. while (loc[strlen("retryInterval")+2+c] != ',')
  5569. {
  5570. sstr[c] = loc[strlen("retryInterval")+2+c];
  5571. c++;
  5572. }
  5573. sstr[c] = '\0';
  5574. retryIntervalInt = atoi(sstr);
  5575. }
  5576. //****************startTime*******************/
  5577. c = 0;
  5578. memset(sstr ,0, sizeof(sstr) );
  5579. loc = strstr(str, "startTime");
  5580. if(loc == NULL)
  5581. {
  5582. startTimeIsNULL = TRUE;
  5583. }
  5584. else
  5585. {
  5586. while (loc[3+strlen("startTime")+c] != '\"')
  5587. {
  5588. sstr[c] = loc[3+strlen("startTime")+c];
  5589. c++;
  5590. }
  5591. sstr[c] = '\0';
  5592. strcpy(startTimestr,sstr);
  5593. }
  5594. //****************stopTime*******************/
  5595. c = 0;
  5596. memset(sstr ,0, sizeof(sstr) );
  5597. loc = strstr(str, "stopTime");
  5598. if(loc == NULL)
  5599. {
  5600. stopTimeIsNULL = TRUE;
  5601. }
  5602. else
  5603. {
  5604. while (loc[3+strlen("stopTime")+c] != '\"')
  5605. {
  5606. sstr[c] = loc[3+strlen("stopTime")+c];
  5607. c++;
  5608. }
  5609. sstr[c] = '\0';
  5610. strcpy(stopTimestr,sstr);
  5611. }
  5612. memset(protocol, 0, sizeof(protocol));
  5613. memset(user, 0, sizeof(user) );
  5614. memset(password, 0, sizeof(password));
  5615. memset(host, 0, sizeof(host));
  5616. memset(path, 0, sizeof(path));
  5617. memset(ftppath, 0, sizeof(ftppath));
  5618. memset(host1, 0, sizeof(host1));
  5619. memset(path1, 0, sizeof(path1));
  5620. /*location: ftp://user:password@host:port/path*/
  5621. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5622. // protocol, user, password, host, &port, path);
  5623. #if 0 // remove for temporally
  5624. //zip files in /Storage
  5625. system("exec /root/logPackTools 'log' 6");
  5626. #endif
  5627. // system("exec /root/Module_WebService 'log' 6");
  5628. time_t rawtime;
  5629. struct tm * timeinfo;
  5630. //char buffer [128];
  5631. time (&rawtime);
  5632. //printf("%ld\n", rawtime);
  5633. timeinfo = localtime (&rawtime);
  5634. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5635. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5636. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5637. if((access(fnamePlusPath,F_OK))!=-1)
  5638. {
  5639. DEBUG_INFO("fnamePlusPath exist.\n");
  5640. }
  5641. else
  5642. {
  5643. DEBUG_INFO("fnamePlusPath not exist!\n");
  5644. goto end;
  5645. }
  5646. pch=strchr(locationstr,'@');
  5647. if(pch==NULL)
  5648. {
  5649. sscanf(locationstr,
  5650. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5651. protocol, host, &port, path);
  5652. strcpy(user,"anonymous");
  5653. strcpy(password,"");
  5654. }
  5655. else
  5656. {
  5657. DEBUG_INFO("pch=%s\n", pch);
  5658. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5659. protocol, user, password, host, &port, path);
  5660. }
  5661. if(strcmp(protocol,"ftp")!=0)
  5662. {
  5663. DEBUG_INFO("protocol is not ftp!\n");
  5664. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5665. goto end;
  5666. }
  5667. sscanf(host,"%[^/]%s",host1, path1);
  5668. sprintf(ftppath,"%s", path1);
  5669. DEBUG_INFO("protocol =%s\n",protocol);
  5670. DEBUG_INFO("user =%s\n",user);
  5671. DEBUG_INFO("password =%s\n",password);
  5672. DEBUG_INFO("host1 =%s\n",host1);
  5673. DEBUG_INFO("port =%d\n",port);
  5674. DEBUG_INFO("path1 =%s\n",path1);
  5675. DEBUG_INFO("ftppath=%s\n",ftppath);
  5676. int ftppathlen=strlen(ftppath);
  5677. int i=1;
  5678. char filenametemp[50];
  5679. while(i < ftppathlen)
  5680. {
  5681. int len=ftppathlen-i;
  5682. if(ftppath[len]== 47) // '/' ascll code: 47
  5683. {
  5684. DEBUG_INFO("find '/' all right\n");
  5685. break;
  5686. }
  5687. i=i+1;
  5688. }
  5689. memset(filenametemp, 0, sizeof(filenametemp));
  5690. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5691. filenametemp[i+1] = 0;
  5692. //httpDownLoadFile(host, ftppath, fname);
  5693. memset(ftpbuf, 0, sizeof(ftpbuf));
  5694. if(port == 0)
  5695. port = 21;
  5696. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5697. do{
  5698. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5699. sleep(retryIntervalInt);
  5700. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5701. if(!isSuccess)
  5702. {
  5703. //BulldogUtil.sleepMs(interval*1000);
  5704. DEBUG_INFO("Diagnostics fail.\n");
  5705. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5706. }
  5707. else
  5708. {
  5709. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5710. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5711. //isUpdateRequest = TRUE;
  5712. }
  5713. end:
  5714. // json_object_put(obj);
  5715. DiagnosticsStatusNotificationStatus = 0; //Idle
  5716. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5717. }
  5718. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5719. {
  5720. mtrace();
  5721. int result = FAIL;
  5722. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5723. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5724. {
  5725. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5726. localversion = -1;
  5727. }
  5728. else
  5729. {
  5730. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5731. OCPP_getListVerion();
  5732. }
  5733. //from db.OCPP_getListVerion
  5734. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5735. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5736. sendGetLocalListVersionConfirmation(uuid,"");
  5737. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5738. return result;
  5739. }
  5740. int handleRemoteStartRequest(char *uuid, char *payload)
  5741. {
  5742. mtrace();
  5743. int result = FAIL;
  5744. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5745. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5746. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5747. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5748. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5749. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5750. int chargingSchedulePeriodCount = 0;
  5751. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5752. int c = 0;
  5753. char *loc;
  5754. char comfirmstr[20]={0};
  5755. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5756. if(server_pending == TRUE)
  5757. {
  5758. return 0;
  5759. }
  5760. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5761. //**********connectorId****************/
  5762. c = 0;
  5763. memset(sstr ,0, sizeof(sstr) );
  5764. loc = strstr(payload, "connectorId");
  5765. if(loc == NULL)
  5766. {
  5767. connectorIdIsNULL = TRUE;
  5768. }
  5769. else
  5770. {
  5771. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5772. {
  5773. sstr[c] = loc[strlen("connectorId")+2+c];
  5774. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5775. c++;
  5776. }
  5777. sstr[c] = '\0';
  5778. connectorIdInt = atoi(sstr);
  5779. }
  5780. if(connectorIdIsNULL == TRUE) // need to discussion
  5781. {
  5782. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5783. goto end;
  5784. }
  5785. //****************idTag*******************/
  5786. c = 0;
  5787. memset(sstr ,0, sizeof(sstr) );
  5788. loc = strstr(payload, "idTag");
  5789. while (loc[3+strlen("idTag")+c] != '\"')
  5790. {
  5791. sstr[c] = loc[3+strlen("idTag")+c];
  5792. c++;
  5793. }
  5794. sstr[c] = '\0';
  5795. strcpy(idTagstr,sstr);
  5796. //****************chargingProfile*******************/
  5797. c = 0;
  5798. memset(sstr ,0, sizeof(sstr) );
  5799. loc = strstr(payload, "chargingProfile");
  5800. if(loc == NULL)
  5801. {
  5802. chargingProfileIsNULL = TRUE;
  5803. }
  5804. else
  5805. {
  5806. //****************chargingProfileId*******************/
  5807. c=0;
  5808. loc = strstr(payload, "chargingProfileId");
  5809. memset(sstr ,0, sizeof(sstr) );
  5810. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5811. {
  5812. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5813. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5814. c++;
  5815. }
  5816. sstr[c] = '\0';
  5817. chargingProfileIdInt = atoi(sstr);
  5818. //****************transactionId*******************/
  5819. loc = strstr(payload, "transactionId");
  5820. if(loc == NULL)
  5821. {
  5822. transactionIdIsNULL = TRUE;
  5823. }
  5824. else
  5825. {
  5826. c=0;
  5827. memset(sstr ,0, sizeof(sstr) );
  5828. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5829. {
  5830. sstr[c] = loc[strlen("transactionId")+2+c];
  5831. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5832. c++;
  5833. }
  5834. sstr[c] = '\0';
  5835. transactionIdInt = atoi(sstr);
  5836. }
  5837. //****************stackLevel*******************/
  5838. c=0;
  5839. loc = strstr(payload, "stackLevel");
  5840. memset(sstr ,0, sizeof(sstr) );
  5841. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5842. {
  5843. sstr[c] = loc[strlen("stackLevel")+2+c];
  5844. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5845. c++;
  5846. }
  5847. sstr[c] = '\0';
  5848. stackLevelInt = atoi(sstr);
  5849. //****************chargingProfilePurpose*******************/
  5850. c = 0;
  5851. memset(sstr ,0, sizeof(sstr) );
  5852. loc = strstr(payload, "chargingProfilePurpose");
  5853. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5854. {
  5855. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5856. c++;
  5857. }
  5858. sstr[c] = '\0';
  5859. strcpy(chargingProfilePurposestr,sstr);
  5860. //****************chargingProfileKind*******************/
  5861. c = 0;
  5862. memset(sstr ,0, sizeof(sstr) );
  5863. loc = strstr(payload, "chargingProfileKind");
  5864. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5865. {
  5866. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5867. c++;
  5868. }
  5869. sstr[c] = '\0';
  5870. strcpy(chargingProfileKindstr,sstr);
  5871. //****************recurrencyKind*******************/
  5872. loc = strstr(payload, "recurrencyKind");
  5873. if(loc == NULL)
  5874. {
  5875. recurrencyKindIsNULL = TRUE;
  5876. }
  5877. else
  5878. {
  5879. c = 0;
  5880. memset(sstr ,0, sizeof(sstr) );
  5881. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5882. {
  5883. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5884. c++;
  5885. }
  5886. sstr[c] = '\0';
  5887. strcpy(recurrencyKindstr,sstr);
  5888. }
  5889. //****************validFrom*******************/
  5890. loc = strstr(payload, "validFrom");
  5891. if(loc == NULL)
  5892. {
  5893. validFromIsNULL = TRUE;
  5894. }
  5895. else
  5896. {
  5897. c = 0;
  5898. memset(sstr ,0, sizeof(sstr) );
  5899. while (loc[3+strlen("validFrom")+c] != '\"')
  5900. {
  5901. sstr[c] = loc[3+strlen("validFrom")+c];
  5902. c++;
  5903. }
  5904. sstr[c] = '\0';
  5905. strcpy(validFromstr,sstr);
  5906. }
  5907. //****************validTo*******************/
  5908. loc = strstr(payload, "validTo");
  5909. if(loc == NULL)
  5910. {
  5911. validToIsNULL = TRUE;
  5912. }
  5913. else
  5914. {
  5915. c = 0;
  5916. memset(sstr ,0, sizeof(sstr) );
  5917. while (loc[3+strlen("validTo")+c] != '\"')
  5918. {
  5919. sstr[c] = loc[3+strlen("validTo")+c];
  5920. c++;
  5921. }
  5922. sstr[c] = '\0';
  5923. strcpy(validTostr,sstr);
  5924. }
  5925. //****************chargingSchedule*******************/
  5926. loc = strstr(payload, "chargingSchedule");
  5927. if(loc != NULL)
  5928. {
  5929. //****************duration*******************/
  5930. loc = strstr(payload, "duration");
  5931. if(loc == NULL)
  5932. {
  5933. durationIsNULL = TRUE;
  5934. }
  5935. else
  5936. {
  5937. c=0;
  5938. memset(sstr ,0, sizeof(sstr) );
  5939. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5940. {
  5941. sstr[c] = loc[strlen("duration")+2+c];
  5942. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5943. c++;
  5944. }
  5945. sstr[c] = '\0';
  5946. durationInt = atoi(sstr);
  5947. }
  5948. //****************startSchedule******************/
  5949. loc = strstr(payload, "startSchedule");
  5950. if(loc == NULL)
  5951. {
  5952. startScheduleIsNULL = TRUE;
  5953. }
  5954. else
  5955. {
  5956. c = 0;
  5957. memset(sstr ,0, sizeof(sstr) );
  5958. while (loc[3+strlen("startSchedule")+c] != '\"')
  5959. {
  5960. sstr[c] = loc[3+strlen("startSchedule")+c];
  5961. c++;
  5962. }
  5963. sstr[c] = '\0';
  5964. strcpy(startSchedulestr,sstr);
  5965. }
  5966. //****************chargingRateUnit*******************/
  5967. c = 0;
  5968. memset(sstr ,0, sizeof(sstr) );
  5969. loc = strstr(payload, "chargingRateUnit");
  5970. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5971. {
  5972. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5973. c++;
  5974. }
  5975. sstr[c] = '\0';
  5976. strcpy(chargingRateUnitstr,sstr);
  5977. //****************minChargingRate*******************/
  5978. loc = strstr(payload, "minChargingRate");
  5979. if(loc == NULL)
  5980. {
  5981. minChargingRateIsNULL = TRUE;
  5982. }
  5983. else
  5984. {
  5985. c=0;
  5986. memset(sstr ,0, sizeof(sstr) );
  5987. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5988. {
  5989. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5990. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5991. c++;
  5992. }
  5993. sstr[c] = '\0';
  5994. minChargingRateflaot = atof(sstr);
  5995. }
  5996. //****************chargingSchedulePeriod count*******************/
  5997. int what_len = strlen("startPeriod");
  5998. char *where = payload;
  5999. while ((where = strstr(where, "startPeriod"))) {
  6000. where += what_len;
  6001. chargingSchedulePeriodCount++;
  6002. }
  6003. where = payload;
  6004. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6005. {
  6006. //****************startPeriod*******************/
  6007. c=0;
  6008. loc = strstr(where, "startPeriod");
  6009. memset(sstr ,0, sizeof(sstr) );
  6010. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6011. {
  6012. sstr[c] = loc[strlen("startPeriod")+2+c];
  6013. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6014. c++;
  6015. }
  6016. sstr[c] = '\0';
  6017. startPeriodInt[periodNums] = atoi(sstr);
  6018. //****************limit*******************/
  6019. c=0;
  6020. loc = strstr(where, "limit");
  6021. memset(sstr ,0, sizeof(sstr) );
  6022. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6023. {
  6024. sstr[c] = loc[strlen("limit")+2+c];
  6025. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6026. c++;
  6027. }
  6028. sstr[c] = '\0';
  6029. limitflaot[periodNums] = atof(sstr);
  6030. //****************numberPhases*******************/
  6031. loc = strstr(where, "numberPhases");
  6032. if(loc == NULL)
  6033. {
  6034. numberPhasesIsNULL = TRUE;
  6035. }
  6036. else
  6037. {
  6038. c=0;
  6039. memset(sstr ,0, sizeof(sstr) );
  6040. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6041. {
  6042. sstr[c] = loc[strlen("numberPhases")+2+c];
  6043. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6044. c++;
  6045. }
  6046. sstr[c] = '\0';
  6047. numberPhasesInt[periodNums] = atoi(sstr);
  6048. }
  6049. where = loc;
  6050. }
  6051. }
  6052. }
  6053. /*
  6054. enum _SYSTEM_STATUS
  6055. {
  6056. S_BOOTING = 0,
  6057. S_IDLE, = 1
  6058. S_AUTHORIZING, =2
  6059. S_REASSIGN_CHECK, =3
  6060. S_REASSIGN, =4
  6061. S_PRECHARGE, =5
  6062. S_PREPARING_FOR_EV, =6
  6063. S_PREPARING_FOR_EVSE, =7
  6064. S_CHARGING, =8
  6065. S_TERMINATING, =9
  6066. S_COMPLETE, =10
  6067. S_ALARM, =11
  6068. S_FAULT =12
  6069. }
  6070. */
  6071. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6072. {
  6073. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6074. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6075. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6076. //check Transaction active
  6077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6078. {
  6079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6080. {
  6081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6082. {
  6083. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6084. {
  6085. //Reserved
  6086. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6087. }
  6088. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6089. {
  6090. //Reserved
  6091. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6092. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6093. goto end;
  6094. }
  6095. else
  6096. {
  6097. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6098. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6099. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6100. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6101. {
  6102. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6103. goto end;
  6104. }
  6105. }//END FOR ELSE
  6106. }
  6107. }// END FOR CHAdeMO_QUANTITY
  6108. for (int index = 0; index < CCS_QUANTITY; index++)
  6109. {
  6110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6111. {
  6112. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6113. {
  6114. //Reserved
  6115. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6116. }
  6117. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6118. {
  6119. //Reserved
  6120. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6121. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6122. goto end;
  6123. }
  6124. else
  6125. {
  6126. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6127. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6128. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6129. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6130. {
  6131. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6132. goto end;
  6133. }
  6134. }// END FOR ELSE
  6135. }
  6136. }// END FOR CCS_QUANTITY
  6137. for (int index = 0; index < GB_QUANTITY; index++)
  6138. {
  6139. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6140. {
  6141. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6142. {
  6143. //Reserved
  6144. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6145. }
  6146. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6147. {
  6148. //Reserved
  6149. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6150. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6151. goto end;
  6152. }
  6153. else
  6154. {
  6155. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6156. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6157. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6158. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6159. {
  6160. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6161. goto end;
  6162. }
  6163. }// END FOR ELSE
  6164. }
  6165. } // END FOR GB_QUANTITY
  6166. }
  6167. else
  6168. {
  6169. for (int index = 0; index < AC_QUANTITY; index++)
  6170. {
  6171. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6172. {
  6173. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6174. {
  6175. //Reserved
  6176. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6177. }
  6178. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6179. {
  6180. //Reserved
  6181. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6182. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6183. goto end;
  6184. }
  6185. else
  6186. {
  6187. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6188. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6189. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6190. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6191. {
  6192. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6193. goto end;
  6194. }
  6195. }//END FOR ELSE
  6196. }
  6197. }// END FOR AC_QUANTITY
  6198. }
  6199. if(chargingProfileIsNULL == FALSE)
  6200. {
  6201. //ChargingProfile
  6202. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6203. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6204. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6205. if(recurrencyKindIsNULL == FALSE) //OPTION
  6206. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6207. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6208. if(transactionIdIsNULL == FALSE) // OPTION
  6209. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6210. if(validFromIsNULL == FALSE) // OPTION
  6211. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6212. if(validToIsNULL == FALSE) //OPTION
  6213. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6214. //ChargingSchedule
  6215. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6216. if(durationIsNULL == FALSE) //OPTION
  6217. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6218. if(minChargingRateIsNULL == FALSE) //OPTION
  6219. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6220. if(startScheduleIsNULL == FALSE) //OPTION
  6221. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6222. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6223. {
  6224. //ChargingSchedulePeriod
  6225. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6226. if(numberPhasesIsNULL == FALSE)
  6227. {
  6228. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6229. }
  6230. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6231. }
  6232. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6233. {
  6234. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6235. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6236. //memset idTag
  6237. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6238. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6239. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6240. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6241. }
  6242. else
  6243. {
  6244. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6245. }
  6246. }
  6247. else
  6248. {
  6249. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6250. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6251. //memset idTag
  6252. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6253. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6254. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6255. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6256. }
  6257. }
  6258. else
  6259. {
  6260. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6261. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6262. }
  6263. end:
  6264. if(connectorIdIsNULL == FALSE)
  6265. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6266. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6267. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6268. //OCPP send RemoteStartConfirmation by first.
  6269. sendRemoteStartConfirmation(uuid, comfirmstr);
  6270. return result;
  6271. }
  6272. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6273. {
  6274. mtrace();
  6275. int result = FAIL;
  6276. int match = FALSE;
  6277. int GunNO = 0;
  6278. int transactionIdInt=0;
  6279. int transactionIdIsNULL= FALSE;
  6280. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6281. int c = 0;
  6282. char *loc;
  6283. char comfirmstr[20];
  6284. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6285. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6286. if(server_pending == TRUE)
  6287. {
  6288. return 0;
  6289. }
  6290. c=0;
  6291. loc = strstr(payload, "transactionId");
  6292. if(loc == NULL)
  6293. {
  6294. transactionIdIsNULL= TRUE;
  6295. }
  6296. else
  6297. {
  6298. memset(sstr ,0, sizeof(sstr) );
  6299. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6300. {
  6301. sstr[c] = loc[strlen("transactionId")+2+c];
  6302. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6303. c++;
  6304. }
  6305. sstr[c] = '\0';
  6306. transactionIdInt = atoi(sstr);
  6307. }
  6308. if(transactionIdIsNULL == FALSE)
  6309. {
  6310. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6311. {
  6312. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6313. {
  6314. //check Transaction active
  6315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6316. {
  6317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6318. {
  6319. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6320. {
  6321. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6322. {
  6323. match = TRUE;
  6324. GunNO = gun_index;
  6325. }
  6326. }
  6327. }// END FOR CHAdeMO_QUANTITY
  6328. for (int index = 0; index < CCS_QUANTITY; index++)
  6329. {
  6330. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6331. {
  6332. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6333. {
  6334. match = TRUE;
  6335. GunNO = gun_index;
  6336. }
  6337. }
  6338. }// END FOR CCS_QUANTITY
  6339. for (int index = 0; index < GB_QUANTITY; index++)
  6340. {
  6341. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6342. {
  6343. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6344. {
  6345. match = TRUE;
  6346. GunNO = gun_index;
  6347. }
  6348. }
  6349. }// END FOR GB_QUANTITY
  6350. }
  6351. else
  6352. {
  6353. for (int index = 0; index < AC_QUANTITY; index++)
  6354. {
  6355. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6356. {
  6357. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6358. {
  6359. match = TRUE;
  6360. GunNO = gun_index;
  6361. }
  6362. }
  6363. }// END FOR CHAdeMO_QUANTITY
  6364. }// END FOR AC ELSE
  6365. }// CHECK IF ResponseTransactionId == transactionIdInt
  6366. }//END FOR
  6367. if( match == TRUE)
  6368. {
  6369. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6370. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6371. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6372. }
  6373. else
  6374. {
  6375. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6376. }
  6377. }
  6378. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6379. return result;
  6380. }
  6381. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6382. {
  6383. mtrace();
  6384. int result = FAIL;
  6385. int connectorIdInt=0, reservationIdInt=0;
  6386. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6387. char comfirmstr[20]={0};
  6388. char sstr[180]={ 0 };
  6389. int c = 0;
  6390. char *loc;
  6391. //char *ptr;
  6392. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6393. //***(1)connectorId ****/
  6394. c=0;
  6395. loc = strstr(payload, "connectorId");
  6396. memset(sstr ,0, sizeof(sstr) );
  6397. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6398. {
  6399. sstr[c] = loc[strlen("connectorId")+2+c];
  6400. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6401. c++;
  6402. }
  6403. sstr[c] = '\0';
  6404. connectorIdInt = atoi(sstr);
  6405. //***(2)expiryDate ****/
  6406. loc = strstr(payload, "expiryDate");
  6407. memset(sstr ,0, sizeof(sstr) );
  6408. c = 0;
  6409. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6410. {
  6411. sstr[c] = loc[3+strlen("expiryDate")+c];
  6412. c++;
  6413. }
  6414. sstr[c] = '\0';
  6415. strcpy(expiryDatestr, sstr);
  6416. //***(3)idTag ****/
  6417. loc = strstr(payload, "idTag");
  6418. memset(sstr ,0, sizeof(sstr) );
  6419. c = 0;
  6420. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6421. {
  6422. sstr[c] = loc[3+strlen("idTag")+c];
  6423. c++;
  6424. }
  6425. sstr[c] = '\0';
  6426. strcpy(idTagstr, sstr);
  6427. //***(4)parentIdTag ****/
  6428. loc = strstr(payload, "parentIdTag");
  6429. memset(sstr ,0, sizeof(sstr) );
  6430. c = 0;
  6431. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6432. {
  6433. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6434. c++;
  6435. }
  6436. sstr[c] = '\0';
  6437. strcpy(parentIdTagstr, sstr);
  6438. //***(5)reservationId ****/
  6439. c=0;
  6440. loc = strstr(payload, "reservationId");
  6441. memset(sstr ,0, sizeof(sstr) );
  6442. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6443. {
  6444. sstr[c] = loc[strlen("reservationId")+2+c];
  6445. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6446. c++;
  6447. }
  6448. sstr[c] = '\0';
  6449. reservationIdInt = atoi(sstr);
  6450. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6451. /*
  6452. enum _SYSTEM_STATUS
  6453. {
  6454. S_BOOTING = 0,
  6455. S_IDLE, = 1
  6456. S_AUTHORIZING, =2
  6457. S_REASSIGN_CHECK, =3
  6458. S_REASSIGN, =4
  6459. S_PRECHARGE, =5
  6460. S_PREPARING_FOR_EV, =6
  6461. S_PREPARING_FOR_EVSE, =7
  6462. S_CHARGING, =8
  6463. S_TERMINATING, =9
  6464. S_COMPLETE, =10
  6465. S_ALARM, =11
  6466. S_FAULT =12
  6467. }
  6468. */
  6469. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6470. {
  6471. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6472. goto end;
  6473. }
  6474. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6475. {
  6476. //check Transaction active
  6477. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6478. {
  6479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6480. {
  6481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6482. {
  6483. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6484. {
  6485. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6486. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6487. {
  6488. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6489. {
  6490. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6492. }
  6493. 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'))
  6494. {
  6495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6496. }
  6497. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6498. {
  6499. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6500. }
  6501. else
  6502. {
  6503. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6504. }
  6505. }
  6506. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6507. {
  6508. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6509. }
  6510. }
  6511. else
  6512. {
  6513. //replace reservation
  6514. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6515. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6516. }
  6517. }
  6518. } // END FOR CHAdeMO_QUANTITY
  6519. for (int index = 0; index < CCS_QUANTITY; index++)
  6520. {
  6521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6522. {
  6523. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6524. {
  6525. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6526. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6527. {
  6528. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6529. {
  6530. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6532. }
  6533. 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'))
  6534. {
  6535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6536. }
  6537. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6538. {
  6539. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6540. }
  6541. else
  6542. {
  6543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6544. }
  6545. }
  6546. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6547. {
  6548. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6549. }
  6550. }
  6551. else
  6552. {
  6553. //replace reservation
  6554. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6556. }
  6557. }
  6558. } // END FOR CCS_QUANTITY
  6559. for (int index = 0; index < GB_QUANTITY; index++)
  6560. {
  6561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6562. {
  6563. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6564. {
  6565. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6566. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6567. {
  6568. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6569. {
  6570. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6571. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6572. }
  6573. 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'))
  6574. {
  6575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6576. }
  6577. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6578. {
  6579. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6580. }
  6581. else
  6582. {
  6583. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6584. }
  6585. }
  6586. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6587. {
  6588. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6589. }
  6590. }
  6591. else
  6592. {
  6593. //replace reservation
  6594. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6596. }
  6597. }
  6598. }// END FOR GB_QUANTITY
  6599. }
  6600. else
  6601. {
  6602. for (int index = 0; index < AC_QUANTITY; index++)
  6603. {
  6604. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6605. {
  6606. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6607. {
  6608. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6609. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6610. {
  6611. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6612. {
  6613. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6615. }
  6616. 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'))
  6617. {
  6618. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6619. }
  6620. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6621. {
  6622. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6623. }
  6624. else
  6625. {
  6626. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6627. }
  6628. }
  6629. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6630. {
  6631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6632. }
  6633. }
  6634. else
  6635. {
  6636. //replace reservation
  6637. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6638. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6639. }
  6640. }
  6641. } // END FOR AC_QUANTITY
  6642. }//END FOR AC ELSE
  6643. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6644. }
  6645. else if(connectorIdInt == 0)
  6646. {
  6647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6648. {
  6649. //check Transaction active
  6650. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6651. {
  6652. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6653. {
  6654. 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'))
  6655. {
  6656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6657. goto end;
  6658. }
  6659. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6660. {
  6661. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6662. goto end;
  6663. }
  6664. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6665. {
  6666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6667. goto end;
  6668. }
  6669. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6670. {
  6671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6672. goto end;
  6673. }
  6674. }
  6675. }// END FOR CHAdeMO_QUANTITY
  6676. for (int index = 0; index < CCS_QUANTITY; index++)
  6677. {
  6678. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6679. {
  6680. 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'))
  6681. {
  6682. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6683. }
  6684. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6685. {
  6686. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6687. }
  6688. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6689. {
  6690. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6691. }
  6692. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6693. {
  6694. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6695. }
  6696. }
  6697. } // END FOR CCS_QUANTITY
  6698. for (int index = 0; index < GB_QUANTITY; index++)
  6699. {
  6700. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6701. {
  6702. 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'))
  6703. {
  6704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6705. }
  6706. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6707. {
  6708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6709. }
  6710. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6711. {
  6712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6713. }
  6714. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6715. {
  6716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6717. }
  6718. }
  6719. } // END FOR GB_QUANTITY
  6720. }
  6721. else
  6722. {
  6723. for (int index = 0; index < AC_QUANTITY; index++)
  6724. {
  6725. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6726. {
  6727. 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'))
  6728. {
  6729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6730. goto end;
  6731. }
  6732. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6733. {
  6734. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6735. goto end;
  6736. }
  6737. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6738. {
  6739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6740. goto end;
  6741. }
  6742. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6743. {
  6744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6745. goto end;
  6746. }
  6747. }
  6748. }// END FOR AC_QUANTITY
  6749. }
  6750. //The connectorId is 0
  6751. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6753. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6754. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6755. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6756. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6757. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6758. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6759. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6760. result = TRUE;
  6761. return result;
  6762. }
  6763. else
  6764. {
  6765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6766. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6767. }
  6768. if(strcmp(comfirmstr,"Accepted") == 0)
  6769. {
  6770. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6771. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6772. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6773. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6774. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6775. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6776. result = TRUE;
  6777. return result;
  6778. }
  6779. end:
  6780. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6781. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6782. return result;
  6783. }
  6784. int handleResetRequest(char *uuid, char *payload)
  6785. {
  6786. mtrace();
  6787. int result = FAIL;
  6788. char sstr[10]={0};
  6789. char typestr[10]={0};
  6790. char comfirmstr[20]={0};
  6791. int c = 0;
  6792. char *loc;
  6793. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6794. DEBUG_INFO("handleResetRequest ...\n");
  6795. loc = strstr(payload, "type");
  6796. memset(sstr ,0, sizeof(sstr) );
  6797. c = 0;
  6798. while (loc[3+strlen("type")+c] != '\"')
  6799. {
  6800. sstr[c] = loc[3+strlen("type")+c];
  6801. c++;
  6802. }
  6803. sstr[c] = '\0';
  6804. strcpy(typestr,sstr);
  6805. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6806. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6807. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6808. {
  6809. //check Transaction active
  6810. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6811. {
  6812. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6813. {
  6814. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6815. {
  6816. //0: unplug, 1: Plug-in
  6817. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6818. }
  6819. }
  6820. for (int index = 0; index < CCS_QUANTITY; index++)
  6821. {
  6822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6823. {
  6824. //0: unplug, 1: Plug-in
  6825. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6826. }
  6827. }
  6828. for (int index = 0; index < GB_QUANTITY; index++)
  6829. {
  6830. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6831. {
  6832. //0: unplug, 1: Plug-in
  6833. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6834. }
  6835. }
  6836. }
  6837. else
  6838. {
  6839. for (int index = 0; index < AC_QUANTITY; index++)
  6840. {
  6841. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6842. {
  6843. //0: unplug, 1: Plug-in
  6844. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6845. }
  6846. }
  6847. }// END FOR AC ELSE
  6848. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6849. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6850. result = TRUE;
  6851. return result;
  6852. }
  6853. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6854. {
  6855. //check Transaction active
  6856. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6857. {
  6858. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6859. {
  6860. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6861. {
  6862. //0: unplug, 1: Plug-in
  6863. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6864. }
  6865. }
  6866. for (int index = 0; index < CCS_QUANTITY; index++)
  6867. {
  6868. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6869. {
  6870. //0: unplug, 1: Plug-in
  6871. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6872. }
  6873. }
  6874. for (int index = 0; index < GB_QUANTITY; index++)
  6875. {
  6876. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6877. {
  6878. //0: unplug, 1: Plug-in
  6879. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6880. }
  6881. }
  6882. }
  6883. else
  6884. {
  6885. for (int index = 0; index < AC_QUANTITY; index++)
  6886. {
  6887. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6888. {
  6889. //0: unplug, 1: Plug-in
  6890. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6891. }
  6892. }
  6893. }// END FOR AC ELSE
  6894. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6895. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6896. result = TRUE;
  6897. return result;
  6898. }
  6899. else
  6900. {
  6901. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6902. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6903. goto errorend;
  6904. }
  6905. errorend:
  6906. sendResetConfirmation(uuid, comfirmstr);
  6907. return result;
  6908. }
  6909. int handleSendLocalListRequest(char *uuid, char *payload)
  6910. {
  6911. mtrace();
  6912. int result = FAIL;
  6913. int listVersionInt;
  6914. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6915. char listsearch[]="listVersion";
  6916. char updateTypesearch[]="updateType";
  6917. char localAuthorizationListsearch[]="localAuthorizationList";
  6918. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6919. char CardList[500][160]={0};
  6920. char updateTypestr[15]={0};
  6921. char idTagstr[20]={0};
  6922. char parentIdTag[20]={0};
  6923. char expiryDate[30]={0};
  6924. char idTagstatus[16]={0};
  6925. int c = 0;
  6926. int i = 0;
  6927. char *delim1 = "}";
  6928. char * pch;
  6929. char *loc;
  6930. //char *ptr;
  6931. char comfirmstr[20];
  6932. //int n_localAuthorizations = 0;
  6933. int checkState_Faulted = FALSE;
  6934. DEBUG_INFO("handleSendLocalListRequest\n");
  6935. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6936. {
  6937. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6938. goto end;
  6939. }
  6940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6941. {
  6942. //check Charge Point state
  6943. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6944. {
  6945. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6946. {
  6947. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6948. }
  6949. }
  6950. for (int index = 0; index < CCS_QUANTITY; index++)
  6951. {
  6952. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6953. {
  6954. checkState_Faulted = TRUE; //OCPP Status
  6955. }
  6956. }
  6957. for (int index = 0; index < GB_QUANTITY; index++)
  6958. {
  6959. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6960. {
  6961. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6962. }
  6963. }
  6964. }
  6965. else
  6966. {
  6967. //check Charge Point state
  6968. for (int index = 0; index < AC_QUANTITY; index++)
  6969. {
  6970. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6971. {
  6972. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6973. }
  6974. }
  6975. }// END FOR AC ELSE
  6976. if(checkState_Faulted == TRUE)
  6977. {
  6978. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6979. goto end;
  6980. }
  6981. //listVersion
  6982. c = 0;
  6983. loc = strstr(payload, listsearch);
  6984. while (loc[strlen("listVersion")+2+c] != ',')
  6985. {
  6986. sstr[c] = loc[strlen("listVersion")+2+c];
  6987. c++;
  6988. }
  6989. sstr[c] = '\0';
  6990. listVersionInt = atoi(sstr);
  6991. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6992. //updateType
  6993. loc = strstr(payload, updateTypesearch);
  6994. c = 0;
  6995. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6996. {
  6997. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6998. c++;
  6999. }
  7000. sstr[c] = '\0';
  7001. strcpy(updateTypestr, sstr);
  7002. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7003. //localAuthorizationList
  7004. memset(sstr ,0, sizeof(sstr) );
  7005. loc = strstr(payload, localAuthorizationListsearch);
  7006. if(loc != NULL) // localAuthorizationList is not NULL
  7007. {
  7008. //Check UpdateType
  7009. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7010. {
  7011. //Local list full update
  7012. printf("Local list full update.\n");
  7013. OCPP_cleanLocalList();
  7014. }
  7015. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7016. {
  7017. //Local list different update
  7018. printf("Local list different update.\n");
  7019. OCPP_getListVerion();
  7020. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7021. {
  7022. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7023. goto end;
  7024. }
  7025. }
  7026. else
  7027. {
  7028. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7029. goto end;
  7030. }
  7031. c = 0;
  7032. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7033. {
  7034. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7035. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7036. c++;
  7037. }
  7038. sstr[c] = '\0';
  7039. //parsing strings to words
  7040. i = 0;
  7041. pch = strtok(sstr,delim1);
  7042. while (pch != NULL)
  7043. {
  7044. strcpy(CardList[i], pch);
  7045. pch = strtok (NULL, delim1);
  7046. i = i + 1;
  7047. }
  7048. //local Authorizations List Numbers
  7049. //n_localAuthorizations = i;
  7050. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7051. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7052. c= 0;
  7053. while(c < i)
  7054. {
  7055. //Search "IdToken"
  7056. memset(sstr ,0, sizeof(sstr) );
  7057. loc = strstr(CardList[c], "idTag");
  7058. int j = 0;
  7059. while (loc[3+strlen("idTag")+j] != '\"')
  7060. {
  7061. sstr[j] = loc[3+strlen("idTag")+j];
  7062. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7063. j++;
  7064. }
  7065. sstr[j] = '\0';
  7066. strcpy(idTagstr, sstr);
  7067. //Search "expiryDate"
  7068. memset(sstr ,0, sizeof(sstr) );
  7069. loc = strstr(CardList[c], "expiryDate");
  7070. j = 0;
  7071. while (loc[3+strlen("expiryDate")+j] != '\"')
  7072. {
  7073. sstr[j] = loc[3+strlen("expiryDate")+j];
  7074. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7075. j++;
  7076. }
  7077. sstr[j] = '\0';
  7078. strcpy(expiryDate, sstr);
  7079. //Search "parentIdTag"
  7080. memset(sstr ,0, sizeof(sstr) );
  7081. loc = strstr(CardList[c], "parentIdTag");
  7082. j = 0;
  7083. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7084. {
  7085. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7086. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7087. j++;
  7088. }
  7089. sstr[j] = '\0';
  7090. strcpy(parentIdTag, sstr);
  7091. //Search "status"
  7092. memset(sstr ,0, sizeof(sstr) );
  7093. loc = strstr(CardList[c], "status");
  7094. j = 0;
  7095. while (loc[3+strlen("status")+j] != '\"')
  7096. {
  7097. sstr[j] = loc[3+strlen("status")+j];
  7098. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7099. j++;
  7100. }
  7101. sstr[j] = '\0';
  7102. strcpy(idTagstatus, sstr);
  7103. OCPP_getIdTag(idTagstr);
  7104. //OCPP_getIdTag("test"); For Test
  7105. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7106. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7107. {
  7108. //Local list full update
  7109. DEBUG_INFO("Local list full update.\n");
  7110. // update list
  7111. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7112. OCPP_get_TableAuthlocalAllData();
  7113. }
  7114. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7115. {
  7116. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7117. {
  7118. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7119. }
  7120. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7121. {
  7122. OCPP_deleteIdTag(idTagstr);
  7123. }
  7124. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7125. {
  7126. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7127. }
  7128. }
  7129. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7130. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7131. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7132. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7133. c++;
  7134. }
  7135. }
  7136. else
  7137. {
  7138. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7139. {
  7140. //Local list different update
  7141. DEBUG_INFO("Local list different update.\n");
  7142. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7143. goto end;
  7144. }
  7145. }
  7146. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7147. end:
  7148. sendSendLocalListConfirmation(uuid, comfirmstr);
  7149. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7150. #if 0
  7151. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7152. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7153. #endif
  7154. return result;
  7155. }
  7156. /*
  7157. enum _SYSTEM_STATUS
  7158. {
  7159. S_BOOTING = 0,
  7160. S_IDLE, =1
  7161. S_AUTHORIZING, =2
  7162. S_REASSIGN_CHECK, =3
  7163. S_REASSIGN, =4
  7164. S_PRECHARGE, =5
  7165. S_PREPARING_FOR_EV, =6
  7166. S_PREPARING_FOR_EVSE, =7
  7167. S_CHARGING, =8
  7168. S_TERMINATING, =9
  7169. S_COMPLETE, =10
  7170. S_ALARM, =11
  7171. S_FAULT =12
  7172. };
  7173. */
  7174. #define MAX 200
  7175. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7176. {
  7177. mtrace();
  7178. int result = FAIL;
  7179. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7180. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7181. char chargingProfilePurposeStr[30]={0};
  7182. char chargingProfileKindStr[16]={0};
  7183. char recurrencyKindStr[10]={0};
  7184. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7185. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7186. int chargingSchedulePeriodCount = 0;
  7187. //int updateflag = FALSE;
  7188. char comfirmstr[20]={0};
  7189. int meet= FALSE;
  7190. char sstr[10]={0};
  7191. int c = 0;
  7192. char *loc;
  7193. FILE *fptr1;//, *fptr2;
  7194. //int lno=0;//, linectr = 0;
  7195. //int modifyflag = FALSE;
  7196. char filename[MAX]={0};
  7197. char tempfile[] = "../Storage/OCPP/temp.json";
  7198. //int resultRename=0;
  7199. char rmFileCmd[50]={0};
  7200. char tempchargingProfilePurposeStr[30]={0};
  7201. //[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}}}]
  7202. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7203. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7204. //*********************connectorId***************************/
  7205. loc = strstr(payload, "connectorId");
  7206. c = 0;
  7207. memset(sstr ,0, sizeof(sstr) );
  7208. while (loc[strlen("connectorId")+2+c] != ',')
  7209. {
  7210. sstr[c] = loc[strlen("connectorId")+2+c];
  7211. c++;
  7212. }
  7213. sstr[c] = '\0';
  7214. connectorIdInt = atoi(sstr);
  7215. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7216. {
  7217. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7218. }
  7219. else
  7220. {
  7221. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7222. }
  7223. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7224. //*********************chargingProfileId***************************/
  7225. loc = strstr(payload, "chargingProfileId");
  7226. c = 0;
  7227. memset(sstr ,0, sizeof(sstr) );
  7228. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7229. {
  7230. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7231. c++;
  7232. }
  7233. sstr[c] = '\0';
  7234. chargingProfileIdInt = atoi(sstr);
  7235. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7236. {
  7237. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7238. }
  7239. else
  7240. {
  7241. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7242. }
  7243. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7244. //*********************transactionId***************************/
  7245. loc = strstr(payload, "transactionId");
  7246. if(loc != NULL)
  7247. {
  7248. c = 0;
  7249. memset(sstr ,0, sizeof(sstr) );
  7250. while (loc[strlen("transactionId")+2+c] != ',')
  7251. {
  7252. sstr[c] = loc[strlen("transactionId")+2+c];
  7253. c++;
  7254. }
  7255. sstr[c] = '\0';
  7256. transactionIdInt = atoi(sstr);
  7257. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7258. {
  7259. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7260. }
  7261. else
  7262. {
  7263. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7264. }
  7265. }
  7266. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7267. //*********************stackLevel***************************/
  7268. loc = strstr(payload, "stackLevel");
  7269. c = 0;
  7270. memset(sstr ,0, sizeof(sstr) );
  7271. while (loc[strlen("stackLevel")+2+c] != ',')
  7272. {
  7273. sstr[c] = loc[strlen("stackLevel")+2+c];
  7274. c++;
  7275. }
  7276. sstr[c] = '\0';
  7277. stackLevelInt = atoi(sstr);
  7278. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7279. {
  7280. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7281. }
  7282. else
  7283. {
  7284. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7285. }
  7286. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7287. //*********************chargingProfilePurpose***************************/
  7288. loc = strstr(payload, "chargingProfilePurpose");
  7289. c = 0;
  7290. memset(sstr ,0, sizeof(sstr) );
  7291. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7292. {
  7293. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7294. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7295. c++;
  7296. }
  7297. sstr[c] = '\0';
  7298. strcpy(chargingProfilePurposeStr,sstr);
  7299. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7300. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7301. {
  7302. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7303. }
  7304. else
  7305. {
  7306. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7307. }
  7308. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7309. //*********************chargingProfileKind***************************/
  7310. loc = strstr(payload, "chargingProfileKind");
  7311. c = 0;
  7312. memset(sstr ,0, sizeof(sstr) );
  7313. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7314. {
  7315. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7316. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7317. c++;
  7318. }
  7319. sstr[c] = '\0';
  7320. strcpy(chargingProfileKindStr,sstr);
  7321. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7322. {
  7323. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7324. }
  7325. else
  7326. {
  7327. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7328. }
  7329. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7330. //*********************recurrencyKind***************************/
  7331. loc = strstr(payload, "recurrencyKind");
  7332. if(loc != NULL)
  7333. {
  7334. c = 0;
  7335. memset(sstr ,0, sizeof(sstr) );
  7336. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7337. {
  7338. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7339. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7340. c++;
  7341. }
  7342. sstr[c] = '\0';
  7343. strcpy(recurrencyKindStr,sstr);
  7344. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7345. {
  7346. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7347. }
  7348. else
  7349. {
  7350. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7351. }
  7352. }
  7353. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7354. //*********************validFrom***************************/
  7355. loc = strstr(payload, "validFrom");
  7356. if(loc != NULL)
  7357. {
  7358. c = 0;
  7359. memset(sstr ,0, sizeof(sstr) );
  7360. while (loc[3+strlen("validFrom")+c] != '\"')
  7361. {
  7362. sstr[c] = loc[3+strlen("validFrom")+c];
  7363. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7364. c++;
  7365. }
  7366. sstr[c] = '\0';
  7367. strcpy(validFromStr,sstr);
  7368. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7369. {
  7370. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7371. }
  7372. else
  7373. {
  7374. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7375. }
  7376. }
  7377. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7378. //*********************validTo***************************/
  7379. loc = strstr(payload, "validTo");
  7380. if(loc != NULL)
  7381. {
  7382. c = 0;
  7383. memset(sstr ,0, sizeof(sstr) );
  7384. while (loc[3+strlen("validTo")+c] != '\"')
  7385. {
  7386. sstr[c] = loc[3+strlen("validTo")+c];
  7387. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7388. c++;
  7389. }
  7390. sstr[c] = '\0';
  7391. strcpy(validToStr,sstr);
  7392. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7393. {
  7394. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7395. }
  7396. else
  7397. {
  7398. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7399. }
  7400. }
  7401. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7402. //*********************duration***************************/
  7403. loc = strstr(payload, "duration");
  7404. if(loc != NULL)
  7405. {
  7406. c = 0;
  7407. memset(sstr ,0, sizeof(sstr) );
  7408. while (loc[strlen("duration")+2+c] != ',')
  7409. {
  7410. sstr[c] = loc[strlen("duration")+2+c];
  7411. c++;
  7412. }
  7413. sstr[c] = '\0';
  7414. durationInt = atoi(sstr);
  7415. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7416. {
  7417. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7418. }
  7419. else
  7420. {
  7421. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7422. }
  7423. }
  7424. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7425. //*********************startSchedule***************************/
  7426. loc = strstr(payload, "startSchedule");
  7427. if(loc != NULL)
  7428. {
  7429. c = 0;
  7430. memset(sstr ,0, sizeof(sstr) );
  7431. while (loc[3+strlen("startSchedule")+c] != '\"')
  7432. {
  7433. sstr[c] = loc[3+strlen("startSchedule")+c];
  7434. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7435. c++;
  7436. }
  7437. sstr[c] = '\0';
  7438. strcpy(startScheduleStr,sstr);
  7439. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7440. {
  7441. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7442. }
  7443. else
  7444. {
  7445. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7446. }
  7447. }
  7448. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7449. //*********************chargingRateUnit***************************/
  7450. loc = strstr(payload, "chargingRateUnit");
  7451. if(loc != NULL)
  7452. {
  7453. c = 0;
  7454. memset(sstr ,0, sizeof(sstr) );
  7455. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7456. {
  7457. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7458. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7459. c++;
  7460. }
  7461. sstr[c] = '\0';
  7462. strcpy(chargingRateUnitStr,sstr);
  7463. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7464. {
  7465. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7466. }
  7467. else
  7468. {
  7469. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7470. }
  7471. }
  7472. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7473. //****************chargingSchedulePeriod count start*******************/
  7474. int what_len = strlen("startPeriod");
  7475. char *where = payload;
  7476. if (what_len)
  7477. while ((where = strstr(where, "startPeriod"))) {
  7478. where += what_len;
  7479. chargingSchedulePeriodCount++;
  7480. }
  7481. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7482. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7483. where = payload;
  7484. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7485. {
  7486. //****************startPeriod*******************/
  7487. c=0;
  7488. loc = strstr(where, "startPeriod");
  7489. memset(sstr ,0, sizeof(sstr) );
  7490. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7491. {
  7492. sstr[c] = loc[strlen("startPeriod")+2+c];
  7493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7494. c++;
  7495. }
  7496. sstr[c] = '\0';
  7497. startPeriodInt[periodNums] = atoi(sstr);
  7498. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7499. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7500. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7501. {
  7502. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7503. }
  7504. else
  7505. {
  7506. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7507. }
  7508. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7509. //****************limit*******************/
  7510. c=0;
  7511. loc = strstr(where, "limit");
  7512. memset(sstr ,0, sizeof(sstr) );
  7513. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7514. {
  7515. sstr[c] = loc[strlen("limit")+2+c];
  7516. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7517. c++;
  7518. }
  7519. sstr[c] = '\0';
  7520. limitflaot[periodNums] = atof(sstr);
  7521. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7522. {
  7523. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7524. }
  7525. else
  7526. {
  7527. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7528. }
  7529. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7530. //****************numberPhases*******************/
  7531. loc = strstr(where, "numberPhases");
  7532. if(loc != NULL)
  7533. {
  7534. c=0;
  7535. memset(sstr ,0, sizeof(sstr) );
  7536. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7537. {
  7538. sstr[c] = loc[strlen("numberPhases")+2+c];
  7539. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7540. c++;
  7541. }
  7542. sstr[c] = '\0';
  7543. numberPhasesInt[periodNums] = atoi(sstr);
  7544. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7545. {
  7546. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7547. }
  7548. else
  7549. {
  7550. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7551. }
  7552. }
  7553. where = loc;
  7554. }
  7555. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7556. //****************chargingSchedulePeriod count end*******************/
  7557. //*********************minChargingRate***************************/
  7558. loc = strstr(payload, "minChargingRate");
  7559. if(loc != NULL)
  7560. {
  7561. c = 0;
  7562. memset(sstr ,0, sizeof(sstr) );
  7563. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7564. {
  7565. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7566. c++;
  7567. }
  7568. sstr[c] = '\0';
  7569. minChargingRateFloat = atof(sstr);
  7570. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7571. {
  7572. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7573. }
  7574. else
  7575. {
  7576. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7577. }
  7578. }
  7579. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7580. {
  7581. //printf("set chargingProfile 1-2\n");
  7582. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7583. if(connectorIdInt != 0)
  7584. {
  7585. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7586. goto end;
  7587. }
  7588. strcpy(filename, ChargePointMaxProfile_JSON );
  7589. fptr1 = fopen(filename, "r");
  7590. if (!fptr1)
  7591. {
  7592. //file not exist
  7593. DEBUG_INFO("Unable to open the input file!!\n");
  7594. fptr1 = fopen(filename, "w+");
  7595. }
  7596. fclose(fptr1);
  7597. }
  7598. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7599. {
  7600. //printf("set chargingProfile 1-3\n");
  7601. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7602. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7603. {
  7604. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7605. goto end;
  7606. }
  7607. switch(connectorIdInt)
  7608. {
  7609. case 0:
  7610. strcpy(filename, TxDefaultProfile_0_JSON );
  7611. break;
  7612. case 1:
  7613. strcpy(filename, TxDefaultProfile_1_JSON );
  7614. break;
  7615. case 2:
  7616. strcpy(filename, TxDefaultProfile_2_JSON );
  7617. break;
  7618. default:
  7619. strcpy(filename, TxDefaultProfile_0_JSON );
  7620. break;
  7621. }
  7622. fptr1 = fopen(filename, "r");
  7623. if (!fptr1)
  7624. {
  7625. //file not exist
  7626. //DEBUG_INFO("Unable to open the input file!!\n");
  7627. fptr1 = fopen(filename, "w+");
  7628. }
  7629. fclose(fptr1);
  7630. }
  7631. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7632. {
  7633. //printf("set chargingProfile 1-4\n");
  7634. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7635. //check Transaction active
  7636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7637. {
  7638. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7639. {
  7640. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7641. {
  7642. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7643. {
  7644. meet = TRUE;
  7645. break;
  7646. }
  7647. }
  7648. }
  7649. }
  7650. for (int index = 0; index < CCS_QUANTITY; index++)
  7651. {
  7652. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7653. {
  7654. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7655. {
  7656. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7657. {
  7658. meet = TRUE;
  7659. break;
  7660. }
  7661. }
  7662. }
  7663. }
  7664. for (int index = 0; index < GB_QUANTITY; index++)
  7665. {
  7666. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7667. {
  7668. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7669. {
  7670. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7671. {
  7672. meet = TRUE;
  7673. break;
  7674. }
  7675. }
  7676. }
  7677. }
  7678. if(meet == FALSE)
  7679. {
  7680. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7681. goto end;
  7682. }
  7683. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7684. {
  7685. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7686. goto end;
  7687. }
  7688. switch(connectorIdInt)
  7689. {
  7690. case 0:
  7691. break;
  7692. case 1:
  7693. strcpy(filename, TxProfile_1_JSON);
  7694. break;
  7695. case 2:
  7696. strcpy(filename, TxProfile_2_JSON);
  7697. break;
  7698. default:
  7699. strcpy(filename, TxProfile_1_JSON);
  7700. break;
  7701. }
  7702. fptr1 = fopen(filename, "r");
  7703. if (!fptr1)
  7704. {
  7705. //file not exist
  7706. DEBUG_INFO("Unable to open the input file!!\n");
  7707. fptr1 = fopen(filename, "w+");
  7708. }
  7709. fclose(fptr1);
  7710. }
  7711. //**********************************Write to File********************************************************/
  7712. FILE *infile;
  7713. FILE *outfile;
  7714. // open file for writing
  7715. infile = fopen (filename, "r");
  7716. outfile = fopen (tempfile, "w");
  7717. int d =0;
  7718. d = fgetc(infile);
  7719. //DEBUG_INFO("d:%d\n",d);
  7720. rewind(infile);
  7721. //*检测到文件结束标识返回1,否则返回0。*/
  7722. if(d == EOF)
  7723. {
  7724. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7725. fprintf(outfile,"%s\n",payload);
  7726. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7727. fclose(infile);
  7728. fclose(outfile);
  7729. sprintf(rmFileCmd,"rm -f %s",filename);
  7730. system(rmFileCmd);
  7731. rename(tempfile, filename);
  7732. #if 0
  7733. resultRename = rename(tempfile, filename);
  7734. if(resultRename == 0)
  7735. {
  7736. DEBUG_INFO("File chargingProfile renamed successfully");
  7737. }
  7738. else
  7739. {
  7740. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7741. }
  7742. #endif
  7743. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7744. //system(rmFileCmd);
  7745. }
  7746. else
  7747. {
  7748. char buf[1000]={0};
  7749. int ChargingProfileAdded = FALSE;
  7750. while (fgets(buf, sizeof(buf), infile) != NULL)
  7751. {
  7752. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7753. //*************************tempconnectorIdInt*********************************/
  7754. loc = strstr(buf, "connectorId");
  7755. c = 0;
  7756. memset(sstr ,0, sizeof(sstr) );
  7757. while (loc[strlen("connectorId")+2+c] != ',')
  7758. {
  7759. sstr[c] = loc[strlen("connectorId")+2+c];
  7760. c++;
  7761. }
  7762. sstr[c] = '\0';
  7763. tempconnectorIdInt = atoi(sstr);
  7764. //*************************tempchargingProfileIdInt*********************************/
  7765. loc = strstr(buf, "chargingProfileId");
  7766. c = 0;
  7767. memset(sstr ,0, sizeof(sstr) );
  7768. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7769. {
  7770. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7771. c++;
  7772. }
  7773. sstr[c] = '\0';
  7774. tempchargingProfileIdInt = atoi(sstr);
  7775. //*************************tempstackLevelInt*********************************/
  7776. loc = strstr(buf, "stackLevel");
  7777. c = 0;
  7778. memset(sstr ,0, sizeof(sstr) );
  7779. while (loc[strlen("stackLevel")+2+c] != ',')
  7780. {
  7781. sstr[c] = loc[strlen("stackLevel")+2+c];
  7782. c++;
  7783. }
  7784. sstr[c] = '\0';
  7785. tempstackLevelInt = atoi(sstr);
  7786. //*************************tempchargingProfilePurposeStr*********************************/
  7787. loc = strstr(payload, "chargingProfilePurpose");
  7788. c = 0;
  7789. memset(sstr ,0, sizeof(sstr) );
  7790. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7791. {
  7792. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7793. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7794. c++;
  7795. }
  7796. sstr[c] = '\0';
  7797. strcpy(tempchargingProfilePurposeStr,sstr);
  7798. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7799. {
  7800. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7801. {
  7802. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7803. if(ChargingProfileAdded == FALSE)
  7804. {
  7805. fprintf(outfile,"%s\n",payload);
  7806. ChargingProfileAdded = TRUE;
  7807. }
  7808. }
  7809. else
  7810. {
  7811. if(tempstackLevelInt < stackLevelInt)
  7812. {
  7813. if(ChargingProfileAdded == FALSE)
  7814. {
  7815. fprintf(outfile,"%s\n",payload);
  7816. ChargingProfileAdded = TRUE;
  7817. fprintf(outfile,"%s\n",buf);
  7818. }
  7819. else
  7820. {
  7821. fprintf(outfile,"%s\n",buf);
  7822. }
  7823. }
  7824. else
  7825. {
  7826. if(ChargingProfileAdded == FALSE)
  7827. {
  7828. fprintf(outfile,"%s\n",buf);
  7829. fprintf(outfile,"%s\n",payload);
  7830. ChargingProfileAdded = TRUE;
  7831. }
  7832. else
  7833. {
  7834. fprintf(outfile,"%s\n",buf);
  7835. }
  7836. }
  7837. }
  7838. }
  7839. else
  7840. {
  7841. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7842. {
  7843. if(ChargingProfileAdded == FALSE)
  7844. {
  7845. fprintf(outfile,"%s\n",payload);
  7846. ChargingProfileAdded = TRUE;
  7847. fprintf(outfile,"%s\n",buf);
  7848. }
  7849. else
  7850. {
  7851. fprintf(outfile,"%s\n",buf);
  7852. }
  7853. }
  7854. else if(tempstackLevelInt < stackLevelInt)
  7855. {
  7856. if(ChargingProfileAdded == FALSE)
  7857. {
  7858. fprintf(outfile,"%s\n",payload);
  7859. ChargingProfileAdded = TRUE;
  7860. fprintf(outfile,"%s\n",buf);
  7861. }
  7862. else
  7863. {
  7864. fprintf(outfile,"%s\n",buf);
  7865. }
  7866. }
  7867. else
  7868. {
  7869. if(ChargingProfileAdded == FALSE)
  7870. {
  7871. fprintf(outfile,"%s\n",buf);
  7872. fprintf(outfile,"%s\n",payload);
  7873. ChargingProfileAdded = TRUE;
  7874. }
  7875. else
  7876. {
  7877. fprintf(outfile,"%s\n",buf);
  7878. }
  7879. }
  7880. }
  7881. } // end of while loop
  7882. fclose(infile);
  7883. fclose(outfile);
  7884. sprintf(rmFileCmd,"rm -f %s",filename);
  7885. system(rmFileCmd);
  7886. rename(tempfile, filename);
  7887. #if 0
  7888. resultRename = rename(tempfile, filename);
  7889. if(resultRename == 0)
  7890. {
  7891. DEBUG_INFO("File chargingProfile renamed successfully");
  7892. }
  7893. else
  7894. {
  7895. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7896. }
  7897. #endif
  7898. result = TRUE;
  7899. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7900. }
  7901. end:
  7902. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7903. return result;
  7904. return result;
  7905. }
  7906. int handleTriggerMessageRequest(char *uuid, char *payload)
  7907. {
  7908. mtrace();
  7909. int result = FAIL;
  7910. int connectorIdIsNULL = FALSE;
  7911. int connectorIdInt =0;
  7912. char sstr[40]={0};
  7913. char requestedMessagestr[40]={0};
  7914. char comfirmstr[20]={0};
  7915. int c = 0;
  7916. char *loc;
  7917. DEBUG_INFO("handleTriggerMessageRequest\n");
  7918. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7919. c = 0;
  7920. loc = strstr(payload, "requestedMessage");
  7921. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7922. {
  7923. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7924. c++;
  7925. }
  7926. sstr[c] = '\0';
  7927. strcpy(requestedMessagestr, sstr);
  7928. c = 0;
  7929. loc = strstr(payload, "connectorId");
  7930. if(loc == NULL)
  7931. {
  7932. connectorIdIsNULL = TRUE;
  7933. }
  7934. else
  7935. {
  7936. memset(sstr ,0, sizeof(sstr) );
  7937. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7938. {
  7939. sstr[c] = loc[strlen("connectorId")+2+c];
  7940. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7941. c++;
  7942. }
  7943. sstr[c] = '\0';
  7944. connectorIdInt = atoi(sstr);
  7945. }
  7946. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7947. {
  7948. //connectorIdInt = json_object_get_int(connectorId);
  7949. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7950. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7951. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7952. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7953. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7954. }
  7955. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7956. {
  7957. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7958. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7959. return TRUE;
  7960. }
  7961. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7962. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7963. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7964. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7965. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7966. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7967. {
  7968. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7969. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7970. return TRUE;
  7971. }
  7972. else
  7973. {
  7974. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7975. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7976. }
  7977. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7978. {
  7979. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  7980. {
  7981. FirmwareStatusNotificationStatus = 3;
  7982. }
  7983. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7984. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7985. }
  7986. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7987. {
  7988. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7989. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7990. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7991. }
  7992. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7993. {
  7994. sendBootNotificationRequest();
  7995. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7996. }
  7997. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7998. {
  7999. sendHeartbeatRequest(connectorIdInt);
  8000. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8001. }
  8002. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8003. {
  8004. if(connectorIdIsNULL == FALSE)
  8005. {
  8006. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8007. {
  8008. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8009. sendMeterValuesRequest(connectorIdInt -1);
  8010. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8011. }
  8012. }
  8013. else
  8014. {
  8015. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8016. {
  8017. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8018. sendMeterValuesRequest(idx);
  8019. }
  8020. }
  8021. }
  8022. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8023. {
  8024. if(connectorIdIsNULL == FALSE)
  8025. {
  8026. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8027. {
  8028. sendStatusNotificationRequest(connectorIdInt -1);
  8029. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8030. }
  8031. }
  8032. else
  8033. {
  8034. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8035. sendStatusNotificationRequest(idx);
  8036. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8037. }
  8038. }
  8039. return result;
  8040. }
  8041. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8042. {
  8043. mtrace();
  8044. int result = FAIL;
  8045. char sstr[6]={0};
  8046. int connectorIdInt =0;
  8047. char comfirmstr[20]={0};
  8048. int c = 0;
  8049. char *loc;
  8050. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8051. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8052. c = 0;
  8053. loc = strstr(payload, "connectorId");
  8054. memset(sstr ,0, sizeof(sstr) );
  8055. while (loc[strlen("connectorId")+2+c] != '}')
  8056. {
  8057. sstr[c] = loc[strlen("connectorId")+2+c];
  8058. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8059. c++;
  8060. }
  8061. sstr[c] = '\0';
  8062. connectorIdInt = atoi(sstr);
  8063. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8064. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8065. {
  8066. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8067. goto end;
  8068. }
  8069. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8070. {
  8071. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8072. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8073. goto end;
  8074. }
  8075. else
  8076. {
  8077. //check Transaction active
  8078. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8079. {
  8080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8081. {
  8082. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8083. {
  8084. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8085. }
  8086. }
  8087. for (int index = 0; index < CCS_QUANTITY; index++)
  8088. {
  8089. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8090. {
  8091. //stop Transaction
  8092. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8093. }
  8094. }
  8095. for (int index = 0; index < GB_QUANTITY; index++)
  8096. {
  8097. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8098. {
  8099. //stop Transaction
  8100. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8101. }
  8102. }
  8103. }
  8104. else
  8105. {
  8106. for (int index = 0; index < AC_QUANTITY; index++)
  8107. {
  8108. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8109. {
  8110. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8111. }
  8112. }
  8113. }// END FOR AC ELSE
  8114. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8115. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8116. result = TRUE;
  8117. return result;
  8118. }
  8119. end:
  8120. //json_object_put(obj); --- remove temporally
  8121. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8122. return result;
  8123. }
  8124. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8125. {
  8126. mtrace();
  8127. int result = FAIL;
  8128. pthread_t t;
  8129. sendUpdateFirmwareConfirmation(uuid);
  8130. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8131. ////pthread_join(t, NULL); //
  8132. pthread_detach(t);
  8133. //sendUpdateFirmwareConfirmation(uuid);
  8134. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8135. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8136. return result;
  8137. }
  8138. void *UpdateFirmwareProcess(void *data)
  8139. {
  8140. mtrace();
  8141. int retriesInt =0, retryIntervalInt=0;
  8142. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8143. int port=0;
  8144. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8145. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8146. //char comfirmstr[20];
  8147. int isSuccess = 0;
  8148. char ftpbuf[200];
  8149. char temp[100];
  8150. char * pch;
  8151. int retriesISNULL=FALSE;
  8152. int retryInterval=FALSE;
  8153. int c = 0;
  8154. //int i = 0;
  8155. char *loc;
  8156. char sstr[300]={ 0 };
  8157. char *str = (char*) data; // ? ?輸入資 ?
  8158. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8159. //***************location **************/
  8160. loc = strstr(str, "location");
  8161. memset(sstr ,0, sizeof(sstr) );
  8162. c = 0;
  8163. while (loc[3+strlen("location")+c] != '\"')
  8164. {
  8165. sstr[c] = loc[3+strlen("location")+c];
  8166. c++;
  8167. }
  8168. sstr[c] = '\0';
  8169. strcpy(locationstr, sstr);
  8170. //***************retries**************/
  8171. c = 0;
  8172. loc = strstr(str, "retries");
  8173. if(loc == NULL)
  8174. {
  8175. retriesISNULL=TRUE;
  8176. }
  8177. else
  8178. {
  8179. memset(sstr ,0, sizeof(sstr) );
  8180. while (loc[strlen("retries")+2+c] != ',')
  8181. {
  8182. sstr[c] = loc[strlen("retries")+2+c];
  8183. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8184. c++;
  8185. }
  8186. sstr[c] = '\0';
  8187. }
  8188. if(retriesISNULL == FALSE)
  8189. {
  8190. retriesInt = atoi(sstr);
  8191. }
  8192. //***************retrieveDate **************/
  8193. loc = strstr(str, "retrieveDate");
  8194. memset(sstr ,0, sizeof(sstr) );
  8195. c = 0;
  8196. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8197. {
  8198. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8199. c++;
  8200. }
  8201. sstr[c] = '\0';
  8202. strcpy(retrieveDatestr, sstr);
  8203. //***************retryInterval **************/
  8204. c = 0;
  8205. loc = strstr(str, "retryInterval");
  8206. memset(sstr ,0, sizeof(sstr) );
  8207. if(loc == NULL)
  8208. {
  8209. retryInterval=TRUE;
  8210. }
  8211. else
  8212. {
  8213. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8214. {
  8215. sstr[c] = loc[strlen("retryInterval")+2+c];
  8216. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8217. c++;
  8218. }
  8219. sstr[c] = '\0';
  8220. }
  8221. if(retryInterval==FALSE)
  8222. {
  8223. retryIntervalInt = atoi(sstr);
  8224. }
  8225. memset(ftppath, 0, sizeof(ftppath));
  8226. memset(path, 0, sizeof(path));
  8227. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8228. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8229. if(strncmp(locationstr,"http", 4) == 0)
  8230. {
  8231. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8232. protocol, host, path);
  8233. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8234. // protocol, user, password, host, path);
  8235. sprintf(ftppath,"/%s", path);
  8236. DEBUG_INFO("protocol =%s\n",protocol);
  8237. DEBUG_INFO("host =%s\n",host);
  8238. DEBUG_INFO("path =%s\n",path);
  8239. DEBUG_INFO("ftppath=%s\n",ftppath);
  8240. int ftppathlen=strlen(ftppath);
  8241. int i=1;
  8242. char filenametemp[50];
  8243. while(i < ftppathlen)
  8244. {
  8245. int len=ftppathlen-i;
  8246. if(ftppath[len]== 47) // '/' ascll code: 47
  8247. {
  8248. DEBUG_INFO("compare '/' all right\n");
  8249. break;
  8250. }
  8251. i=i+1;
  8252. }
  8253. memset(filenametemp, 0, sizeof(filenametemp));
  8254. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8255. filenametemp[i+1] = 0;
  8256. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8257. do{
  8258. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8259. sleep(retryIntervalInt);
  8260. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8261. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8262. if(!isSuccess)
  8263. {
  8264. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8265. }
  8266. else
  8267. {
  8268. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8269. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8270. isUpdateRequest = TRUE;
  8271. }
  8272. }
  8273. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8274. {
  8275. memset(ftpbuf, 0, sizeof(ftpbuf));
  8276. memset(temp, 0, sizeof(temp));
  8277. DEBUG_INFO("locationstr=%s\n",locationstr);
  8278. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8279. int ftppathlen=strlen(ftpbuf);
  8280. int i=1;
  8281. char filenametemp[50];
  8282. while(i < ftppathlen)
  8283. {
  8284. int len=ftppathlen-i;
  8285. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8286. {
  8287. DEBUG_INFO(" compare '/' all right\n");
  8288. break;
  8289. }
  8290. i=i+1;
  8291. }
  8292. memset(filenametemp, 0, sizeof(filenametemp));
  8293. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8294. filenametemp[i+1] = 0;
  8295. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8296. pch=strchr(temp,'@');
  8297. if(pch==NULL)
  8298. {
  8299. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8300. protocol, host, &port, path);
  8301. strcpy(user,"anonymous");
  8302. strcpy(password,"");
  8303. }
  8304. else
  8305. {
  8306. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8307. protocol, user, password, host, &port, path);
  8308. }
  8309. sscanf(host,"%[^/]%s",host1, path1);
  8310. sprintf(ftppath,"%s", path1);
  8311. DEBUG_INFO("protocol =%s\n",protocol);
  8312. DEBUG_INFO("user =%s\n",user);
  8313. DEBUG_INFO("password =%s\n",password);
  8314. DEBUG_INFO("host1 =%s\n",host1);
  8315. DEBUG_INFO("port =%d\n",port);
  8316. DEBUG_INFO("path1 =%s\n",path1);
  8317. DEBUG_INFO("ftppath=%s\n",ftppath);
  8318. //ftpFile(host, user, password, port, ftppath, fname);
  8319. //download firmware pthred
  8320. if(port == 0)
  8321. {
  8322. port = 21;
  8323. }
  8324. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8325. do{
  8326. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8327. sleep(retryIntervalInt);
  8328. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8329. if(!isSuccess)
  8330. {
  8331. //BulldogUtil.sleepMs(interval*1000);
  8332. DEBUG_INFO("Update firmware request and download file fail.\n");
  8333. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8334. }
  8335. else
  8336. {
  8337. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8338. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8339. isUpdateRequest = TRUE;
  8340. }
  8341. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8342. }
  8343. else
  8344. {
  8345. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8346. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8347. }
  8348. pthread_exit(NULL);
  8349. }
  8350. //==========================================
  8351. // Handle server response routine
  8352. //==========================================
  8353. void handleAuthorizeResponse(char *payload, int gun_index)
  8354. {
  8355. mtrace();
  8356. char expiryDatestr[30]={0};
  8357. char parentIdTagstr[20]={0};
  8358. char statusstr[20]={0};
  8359. char expiryDatestrtemp[30]={0};
  8360. char parentIdTagstrtemp[20]={0};
  8361. char IdTagstrtemp[20]={0};
  8362. char statusstrtemp[20]={0};
  8363. int expiryDateISNULL=FALSE;
  8364. int parentIdTagISNULL=FALSE;
  8365. char sstr[160]={ 0 };
  8366. char* filename = AuthorizationCache_JSON;
  8367. char tempfile[] = "../Storage/OCPP/temp.json";
  8368. int c = 0;
  8369. char *loc;
  8370. int resultRename=0;
  8371. int responseIdTagInfoAsZero= 0;
  8372. char rmFileCmd[50]={0};
  8373. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8374. //***********expiryDate*************/
  8375. loc = strstr(payload, "expiryDate");
  8376. memset(sstr ,0, sizeof(sstr) );
  8377. c = 0;
  8378. if(loc == NULL)
  8379. {
  8380. expiryDateISNULL = TRUE;
  8381. }
  8382. else
  8383. {
  8384. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8385. {
  8386. sstr[c] = loc[3+strlen("expiryDate")+c];
  8387. c++;
  8388. }
  8389. sstr[c] = '\0';
  8390. strcpy(expiryDatestr, sstr);
  8391. }
  8392. //***********parentIdTag*************/
  8393. loc = strstr(payload, "parentIdTag");
  8394. memset(sstr ,0, sizeof(sstr) );
  8395. c = 0;
  8396. if(loc == NULL)
  8397. {
  8398. parentIdTagISNULL = TRUE;
  8399. }
  8400. else
  8401. {
  8402. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8403. {
  8404. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8405. c++;
  8406. }
  8407. sstr[c] = '\0';
  8408. strcpy(parentIdTagstr, sstr);
  8409. }
  8410. //***********status*************/
  8411. loc = strstr(payload, "status");
  8412. memset(sstr ,0, sizeof(sstr) );
  8413. c = 0;
  8414. while (loc[3+strlen("status")+c] != '\"')
  8415. {
  8416. sstr[c] = loc[3+strlen("status")+c];
  8417. c++;
  8418. }
  8419. sstr[c] = '\0';
  8420. strcpy(statusstr, sstr);
  8421. //#ifdef SystemLogMessage
  8422. // if(expiryDateISNULL == FALSE)
  8423. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8424. // if(parentIdTagISNULL == FALSE)
  8425. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8426. // DEBUG_INFO("status: %s\n", statusstr);
  8427. //#endif
  8428. if(expiryDateISNULL == FALSE)
  8429. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8430. if(parentIdTagISNULL == FALSE)
  8431. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8432. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8433. //Update idTag information to authorization cache if supproted
  8434. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8435. {
  8436. if((access(filename,F_OK))!=-1)
  8437. {
  8438. DEBUG_INFO("AuthorizationCache exist.\n");
  8439. }
  8440. else
  8441. {
  8442. DEBUG_INFO("AuthorizationCache not exist\n");
  8443. FILE *log = fopen(filename, "w+");
  8444. if(log == NULL)
  8445. {
  8446. DEBUG_INFO("log is NULL\n");
  8447. goto out;
  8448. }
  8449. else
  8450. {
  8451. fclose(log);
  8452. }
  8453. }
  8454. FILE *infile;
  8455. FILE *outfile;
  8456. // open file for writing
  8457. infile = fopen (filename, "r");
  8458. outfile = fopen (tempfile, "w");
  8459. //*检测到文件结束标识返回1,否则返回0。*/
  8460. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8461. int c;
  8462. c = fgetc(infile);
  8463. //DEBUG_INFO("c:%d\n",c);
  8464. rewind(infile);
  8465. if(c == EOF)
  8466. {
  8467. DEBUG_INFO("Orignal File is NULL\n");
  8468. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8469. {
  8470. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8471. }
  8472. else
  8473. {
  8474. strcpy(expiryDatestrtemp, "");
  8475. }
  8476. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8477. {
  8478. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8479. }
  8480. else
  8481. {
  8482. //write Authorize IdTag
  8483. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8484. }
  8485. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8486. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8487. fclose(infile);
  8488. fclose(outfile);
  8489. sprintf(rmFileCmd,"rm -f %s",filename);
  8490. system(rmFileCmd);
  8491. resultRename = rename(tempfile, filename);
  8492. if(resultRename == 0)
  8493. {
  8494. DEBUG_INFO("File renamed successfully");
  8495. }
  8496. else
  8497. {
  8498. DEBUG_INFO("Error: unable to rename the file");
  8499. }
  8500. }
  8501. else
  8502. {
  8503. char buf[160]={0};
  8504. //DEBUG_INFO("Orignal File is not NULL\n");
  8505. while (fgets(buf, sizeof(buf), infile) != NULL)
  8506. {
  8507. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8508. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8509. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8510. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8511. memset(statusstr, 0, sizeof(statusstrtemp));
  8512. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8513. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8514. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8515. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8516. //------------------IdTag-----------------------
  8517. loc = strstr(buf, "idTag");
  8518. memset(sstr ,0, sizeof(sstr) );
  8519. c = 0;
  8520. while (loc[3+strlen("idTag")+c] != '\"')
  8521. {
  8522. sstr[c] = loc[3+strlen("idTag")+c];
  8523. c++;
  8524. }
  8525. sstr[c] = '\0';
  8526. strcpy(IdTagstrtemp,sstr);
  8527. //*********************expiryDate***************/
  8528. loc = strstr(buf, "expiryDate");
  8529. memset(sstr ,0, sizeof(sstr) );
  8530. c = 0;
  8531. while (loc[3+strlen("expiryDate")+c] != '\"')
  8532. {
  8533. sstr[c] = loc[3+strlen("expiryDate")+c];
  8534. c++;
  8535. }
  8536. sstr[c] = '\0';
  8537. strcpy(expiryDatestr,sstr);
  8538. //*********************parentIdTag***************/
  8539. loc = strstr(buf, "parentIdTag");
  8540. memset(sstr ,0, sizeof(sstr) );
  8541. c = 0;
  8542. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8543. {
  8544. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8545. c++;
  8546. }
  8547. sstr[c] = '\0';
  8548. strcpy(parentIdTagstr,sstr);
  8549. //*********************status***************/
  8550. loc = strstr(buf, "status");
  8551. memset(sstr ,0, sizeof(sstr) );
  8552. c = 0;
  8553. while (loc[3+strlen("status")+c] != '\"')
  8554. {
  8555. sstr[c] = loc[3+strlen("status")+c];
  8556. c++;
  8557. }
  8558. sstr[c] = '\0';
  8559. strcpy(statusstr,sstr);
  8560. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8561. {
  8562. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8563. responseIdTagInfoAsZero = 1;
  8564. }
  8565. else
  8566. {
  8567. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8568. }
  8569. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8570. {
  8571. //modify item
  8572. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8573. {
  8574. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8575. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8576. }
  8577. else
  8578. {
  8579. strcpy(expiryDatestrtemp, "");
  8580. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8581. }
  8582. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8583. {
  8584. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8585. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8586. }
  8587. else
  8588. {
  8589. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8590. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8591. }
  8592. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8593. }
  8594. else
  8595. {
  8596. //wrie original item
  8597. strcpy(expiryDatestrtemp, expiryDatestr);
  8598. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8599. strcpy(statusstrtemp, statusstr);
  8600. }
  8601. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8602. }
  8603. fclose(infile);
  8604. fclose(outfile);
  8605. sprintf(rmFileCmd,"rm -f %s",filename);
  8606. system(rmFileCmd);
  8607. resultRename = rename(tempfile, filename);
  8608. if(resultRename == 0)
  8609. {
  8610. DEBUG_INFO("File renamed successfully");
  8611. }
  8612. else
  8613. {
  8614. DEBUG_INFO("Error: unable to rename the file");
  8615. }
  8616. }
  8617. }
  8618. out:
  8619. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8620. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8621. authorizeRetryTimes = 0;
  8622. }
  8623. void handleBootNotificationResponse(char *payload, int gun_index)
  8624. {
  8625. mtrace();
  8626. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8627. char statusStr[12]={0};
  8628. char currentTimeStr[30]={0};
  8629. char *loc;
  8630. int intervalInt = 0;
  8631. int c = 0;
  8632. //double diff_t;
  8633. struct tm tp;
  8634. char buf[28]={0};
  8635. char timebuf[50]={0};
  8636. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8637. //*** interval ****/
  8638. c = 0;
  8639. loc = strstr(payload, "interval");
  8640. //printf("loc=%s\n",loc);
  8641. memset(sstr ,0, sizeof(sstr) );
  8642. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8643. {
  8644. sstr[c] = loc[strlen("interval")+2+c];
  8645. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8646. c++;
  8647. }
  8648. sstr[c] = '\0';
  8649. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8650. intervalInt = atoi(sstr);
  8651. //***status ****/
  8652. loc = strstr(payload, "status");
  8653. memset(sstr ,0, sizeof(sstr) );
  8654. c = 0;
  8655. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8656. {
  8657. sstr[c] = loc[3+strlen("status")+c];
  8658. c++;
  8659. }
  8660. sstr[c] = '\0';
  8661. strcpy(statusStr, sstr);
  8662. //***currentTime ****/
  8663. loc = strstr(payload, "currentTime");
  8664. //printf("loc=%s\n",loc);
  8665. memset(sstr ,0, sizeof(sstr) );
  8666. c = 0;
  8667. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8668. {
  8669. sstr[c] = loc[3+strlen("currentTime")+c];
  8670. c++;
  8671. }
  8672. sstr[c] = '\0';
  8673. strcpy(currentTimeStr, sstr);
  8674. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8675. HeartBeatWaitTime = BootNotificationInterval;
  8676. //#ifdef SystemLogMessage
  8677. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8678. // DEBUG_INFO("interval: %d\n", intervalInt);
  8679. // DEBUG_INFO("status: %s\n", statusStr);
  8680. //#endif
  8681. //write back to ShmOCPP16Data->BootNotification
  8682. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8683. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8684. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8685. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8686. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8687. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8688. {
  8689. server_sign = TRUE;
  8690. server_pending =FALSE;
  8691. }
  8692. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8693. {
  8694. server_pending = TRUE;
  8695. }
  8696. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8697. tp.tm_isdst = -1;
  8698. //time_t utc = mktime(&tp);
  8699. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8700. memset(timebuf, 0, sizeof timebuf);
  8701. sprintf(timebuf,"date -s '%s'",buf);
  8702. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8703. system(timebuf);
  8704. //==============================================
  8705. // RTC sync
  8706. //==============================================
  8707. system("/sbin/hwclock -w --systohc");
  8708. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8709. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8710. }
  8711. void handleDataTransferResponse(char *payload, int gun_index)
  8712. {
  8713. char sstr[160]={0};//sstr[200]={ 0 };
  8714. int c = 0;
  8715. char *loc;
  8716. DEBUG_INFO("handleDataTransferResponse ...\n");
  8717. loc = strstr(payload, "status");
  8718. printf("loc=%s\n",loc);
  8719. c = 0;
  8720. while (loc[3+strlen("status")+c] != '\"')
  8721. {
  8722. sstr[c] = loc[3+strlen("status")+c];
  8723. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8724. c++;
  8725. }
  8726. sstr[c] = '\0';
  8727. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8728. //#ifdef SystemLogMessage
  8729. //DEBUG_INFO("data: %s\n", payload);
  8730. //#endif
  8731. }
  8732. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8733. {
  8734. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8735. //struct json_object *obj;
  8736. // obj = json_tokener_parse(payload);
  8737. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8738. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8739. //No fields are defined.
  8740. }
  8741. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8742. {
  8743. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8744. //struct json_object *obj;
  8745. // obj = json_tokener_parse(payload);
  8746. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8747. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8748. //No fields are defined.
  8749. }
  8750. void handleHeartbeatResponse(char *payload, int gun_index)
  8751. {
  8752. mtrace();
  8753. //double diff_t;
  8754. struct tm tp;
  8755. char buf[28]={0};
  8756. char timebuf[50]={0};
  8757. char sstr[30]={ 0 };
  8758. int c = 0;
  8759. char *loc;
  8760. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8761. if((HeartBeatCount%360) == 0)
  8762. {
  8763. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8764. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8765. }
  8766. HeartBeatCount = HeartBeatCount + 1;
  8767. c = 0;
  8768. loc = strstr(payload, "currentTime");
  8769. memset(sstr ,0, sizeof(sstr) );
  8770. while (loc[3+strlen("currentTime")+c] != '\"')
  8771. {
  8772. sstr[c] = loc[3+strlen("currentTime")+c];
  8773. c++;
  8774. }
  8775. sstr[c] = '\0';
  8776. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8777. // #ifdef SystemLogMessage
  8778. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8779. // #endif
  8780. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8781. tp.tm_isdst = -1;
  8782. //time_t utc = mktime(&tp);
  8783. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8784. memset(timebuf, 0, sizeof timebuf);
  8785. sprintf(timebuf,"date -s '%s'",buf);
  8786. system(timebuf);
  8787. //==============================================
  8788. // RTC sync
  8789. //==============================================
  8790. system("/sbin/hwclock -w --systohc");
  8791. if(FirstHeartBeat == 0)
  8792. {
  8793. FirstHeartBeat = 1;
  8794. }
  8795. HeartBeatWithNOResponse = 0;
  8796. }
  8797. void handleMeterValuesResponse(char *payload, int gun_index)
  8798. {
  8799. mtrace();
  8800. //struct json_object *obj;
  8801. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8802. //No fields are defined.
  8803. }
  8804. void handleStartTransactionResponse(char *payload, int gun_index)
  8805. {
  8806. mtrace();
  8807. char sstr[28]={ 0 };
  8808. int c = 0;
  8809. char *loc;
  8810. int transactionIdInt = 0;
  8811. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8812. DEBUG_INFO("handleStartTransactionResponse\n");
  8813. //****************expiryDate********************/
  8814. loc = strstr(payload, "expiryDate");
  8815. if(loc == NULL)
  8816. {
  8817. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8818. }
  8819. else
  8820. {
  8821. c = 0;
  8822. memset(sstr ,0, sizeof(sstr) );
  8823. while (loc[3+strlen("expiryDate")+c] != '\"')
  8824. {
  8825. sstr[c] = loc[3+strlen("expiryDate")+c];
  8826. c++;
  8827. }
  8828. sstr[c] = '\0';
  8829. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8830. }
  8831. //****************parentIdTag********************/
  8832. loc = strstr(payload, "parentIdTag");
  8833. if(loc == NULL)
  8834. {
  8835. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8836. }
  8837. else
  8838. {
  8839. c = 0;
  8840. memset(sstr ,0, sizeof(sstr) );
  8841. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8842. {
  8843. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8844. c++;
  8845. }
  8846. sstr[c] = '\0';
  8847. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8848. }
  8849. //****************status********************/
  8850. loc = strstr(payload, "status");
  8851. if(loc == NULL)
  8852. {
  8853. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8854. }
  8855. else
  8856. {
  8857. c = 0;
  8858. memset(sstr ,0, sizeof(sstr) );
  8859. while (loc[3+strlen("status")+c] != '\"')
  8860. {
  8861. sstr[c] = loc[3+strlen("status")+c];
  8862. c++;
  8863. }
  8864. sstr[c] = '\0';
  8865. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8866. }
  8867. //****************transactionId********************/
  8868. c=0;
  8869. loc = strstr(payload, "transactionId");
  8870. memset(sstr ,0, sizeof(sstr) );
  8871. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8872. {
  8873. sstr[c] = loc[strlen("transactionId")+2+c];
  8874. c++;
  8875. }
  8876. sstr[c] = '\0';
  8877. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8878. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8879. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8880. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8881. #ifdef SystemLogMessage
  8882. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8883. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8884. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8885. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8886. #endif
  8887. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8888. {
  8889. //add Charging Record
  8890. SettingChargingRecord(gun_index, transactionIdInt);
  8891. }
  8892. DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8893. }
  8894. void handleStatusNotificationResponse(char *payload, int gun_index)
  8895. {
  8896. mtrace();
  8897. printf("handleStatusNotificationResponse\n");
  8898. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8899. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8900. }
  8901. void handleStopTransactionnResponse(char *payload, int gun_index)
  8902. {
  8903. mtrace();
  8904. char sstr[30]={ 0 };
  8905. int c = 0;
  8906. char *loc;
  8907. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8908. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8909. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8910. loc = strstr(payload, "idTagInfo");
  8911. //***********************idTagInfo************************/
  8912. if(loc != NULL)
  8913. {
  8914. //***********************expiryDate************************/
  8915. loc = strstr(payload, "expiryDate");
  8916. if(loc != NULL)
  8917. {
  8918. memset(sstr ,0, sizeof(sstr) );
  8919. c = 0;
  8920. while (loc[3+strlen("expiryDate")+c] != '\"')
  8921. {
  8922. sstr[c] = loc[3+strlen("expiryDate")+c];
  8923. c++;
  8924. }
  8925. sstr[c] = '\0';
  8926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8927. }
  8928. //***********************parentIdTag************************/
  8929. loc = strstr(payload, "parentIdTag");
  8930. if(loc != NULL)
  8931. {
  8932. memset(sstr ,0, sizeof(sstr) );
  8933. c = 0;
  8934. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8935. {
  8936. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8937. c++;
  8938. }
  8939. sstr[c] = '\0';
  8940. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8941. }
  8942. //***********************status************************/
  8943. loc = strstr(payload, "status");
  8944. memset(sstr ,0, sizeof(sstr) );
  8945. c = 0;
  8946. while (loc[3+strlen("status")+c] != '\"')
  8947. {
  8948. sstr[c] = loc[3+strlen("status")+c];
  8949. c++;
  8950. }
  8951. sstr[c] = '\0';
  8952. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8953. }
  8954. #ifdef SystemLogMessage
  8955. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8956. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8957. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8958. #endif
  8959. }
  8960. //==========================================
  8961. // Handle Error routine
  8962. //==========================================
  8963. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8964. {
  8965. mtrace();
  8966. #ifdef SystemLogMessage
  8967. DEBUG_INFO("errorCode: %s\n", errorCode);
  8968. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8969. DEBUG_INFO("errorDetails: %s\n", payload);
  8970. #endif
  8971. }
  8972. //===============================================
  8973. // Common routine
  8974. //===============================================
  8975. int initialConfigurationTable(void)
  8976. {
  8977. printf("initialConfigurationTable \n");
  8978. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8979. /*Core Profile*/
  8980. //AllowOfflineTxForUnknownId
  8981. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8982. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8985. //AuthorizationCacheEnabled
  8986. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8989. //AuthorizeRemoteTxRequests
  8990. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8993. //BlinkRepeat
  8994. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8997. //ClockAlignedDataInterval
  8998. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9001. //ConnectionTimeOut
  9002. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  9005. //GetConfigurationMaxKeys
  9006. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9009. // HeartbeatInterval
  9010. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9013. // LightIntensity
  9014. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9017. // LocalAuthorizeOffline
  9018. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9021. // LocalPreAuthorize
  9022. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9025. // MaxEnergyOnInvalidId
  9026. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9029. // MeterValuesAlignedData
  9030. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9033. // MeterValuesAlignedDataMaxLength
  9034. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9037. // MeterValuesSampledData
  9038. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9041. // MeterValuesSampledDataMaxLength
  9042. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9045. // MeterValueSampleInterval
  9046. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9049. // MinimumStatusDuration
  9050. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9053. // NumberOfConnectors
  9054. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  9057. // ResetRetries
  9058. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9061. // ConnectorPhaseRotation
  9062. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  9065. // ConnectorPhaseRotationMaxLength
  9066. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9069. // StopTransactionOnEVSideDisconnect
  9070. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9073. // StopTransactionOnInvalidId
  9074. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9077. // StopTxnAlignedData
  9078. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9081. // StopTxnAlignedDataMaxLength
  9082. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9085. // StopTxnSampledData
  9086. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9089. // StopTxnSampledDataMaxLength
  9090. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9093. // SupportedFeatureProfiles
  9094. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9097. // SupportedFeatureProfilesMaxLength
  9098. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9101. // TransactionMessageAttempts
  9102. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9105. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9106. // TransactionMessageRetryInterval
  9107. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9110. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9111. // UnlockConnectorOnEVSideDisconnect
  9112. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9115. // WebSocketPingInterval
  9116. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9119. //* Local Auth List Management Profile*/
  9120. #if 0
  9121. //For OCTT Test Case
  9122. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9125. #endif
  9126. #if 1
  9127. //LocalAuthListEnabled
  9128. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9131. #endif
  9132. //LocalAuthListMaxLength
  9133. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9136. //SendLocalListMaxLength
  9137. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9140. //ReserveConnectorZeroSupported
  9141. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9144. //* Smart Charging Profile */
  9145. //ChargeProfileMaxStackLevel
  9146. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9149. // ChargingScheduleAllowedChargingRateUnit
  9150. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9153. // ChargingScheduleMaxPeriods
  9154. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9157. // ConnectorSwitch3to1PhaseSupported
  9158. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9161. // MaxChargingProfilesInstalled
  9162. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9164. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9165. return 0;
  9166. }
  9167. void getKeyValue(char *keyReq)
  9168. {
  9169. int isEmpty = FALSE;
  9170. int isKnowKey = FALSE;
  9171. //int unKnowIndex = 0;
  9172. DEBUG_INFO("getKeyValue \n");
  9173. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9174. isEmpty = TRUE;
  9175. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9176. {
  9177. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9180. {
  9181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9182. }
  9183. else
  9184. {
  9185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9186. }
  9187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9188. isKnowKey = TRUE;
  9189. }
  9190. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9191. {
  9192. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9195. {
  9196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9197. }
  9198. else
  9199. {
  9200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9201. }
  9202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9203. isKnowKey = TRUE;
  9204. }
  9205. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9206. {
  9207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9210. {
  9211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9212. }
  9213. else
  9214. {
  9215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9216. }
  9217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9218. isKnowKey = TRUE;
  9219. }
  9220. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9221. {
  9222. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9225. {
  9226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9227. }
  9228. else
  9229. {
  9230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9231. }
  9232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9233. isKnowKey = TRUE;
  9234. }
  9235. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9236. {
  9237. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9240. {
  9241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9242. }
  9243. else
  9244. {
  9245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9246. }
  9247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9248. isKnowKey = TRUE;
  9249. }
  9250. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9251. {
  9252. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9255. {
  9256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9257. }
  9258. else
  9259. {
  9260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9261. }
  9262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9263. isKnowKey = TRUE;
  9264. }
  9265. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9266. {
  9267. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9270. {
  9271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9272. }
  9273. else
  9274. {
  9275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9276. }
  9277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9278. isKnowKey = TRUE;
  9279. }
  9280. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9281. {
  9282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9285. {
  9286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9287. }
  9288. else
  9289. {
  9290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9291. }
  9292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9293. isKnowKey = TRUE;
  9294. }
  9295. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9296. {
  9297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9300. {
  9301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9302. }
  9303. else
  9304. {
  9305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9306. }
  9307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9308. isKnowKey = TRUE;
  9309. }
  9310. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9311. {
  9312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9315. {
  9316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9317. }
  9318. else
  9319. {
  9320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9321. }
  9322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9323. isKnowKey = TRUE;
  9324. }
  9325. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9326. {
  9327. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9330. {
  9331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9332. }
  9333. else
  9334. {
  9335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9336. }
  9337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9338. isKnowKey = TRUE;
  9339. }
  9340. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9341. {
  9342. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9345. {
  9346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9347. }
  9348. else
  9349. {
  9350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9351. }
  9352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9353. isKnowKey = TRUE;
  9354. }
  9355. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9356. {
  9357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9360. {
  9361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9362. }
  9363. else
  9364. {
  9365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9366. }
  9367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9368. isKnowKey = TRUE;
  9369. }
  9370. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9371. {
  9372. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9375. {
  9376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9377. }
  9378. else
  9379. {
  9380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9381. }
  9382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9383. isKnowKey = TRUE;
  9384. }
  9385. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9386. {
  9387. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9390. {
  9391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9392. }
  9393. else
  9394. {
  9395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9396. }
  9397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9398. isKnowKey = TRUE;
  9399. }
  9400. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9401. {
  9402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9405. {
  9406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9407. }
  9408. else
  9409. {
  9410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9411. }
  9412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9413. isKnowKey = TRUE;
  9414. }
  9415. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9416. {
  9417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9420. {
  9421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9422. }
  9423. else
  9424. {
  9425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9426. }
  9427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9428. isKnowKey = TRUE;
  9429. }
  9430. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9431. {
  9432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9435. {
  9436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9437. }
  9438. else
  9439. {
  9440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9441. }
  9442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9443. isKnowKey = TRUE;
  9444. }
  9445. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9446. {
  9447. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9450. {
  9451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9452. }
  9453. else
  9454. {
  9455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9456. }
  9457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9458. isKnowKey = TRUE;
  9459. }
  9460. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9461. {
  9462. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9465. {
  9466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9467. }
  9468. else
  9469. {
  9470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9471. }
  9472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9473. isKnowKey = TRUE;
  9474. }
  9475. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9476. {
  9477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9480. {
  9481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9482. }
  9483. else
  9484. {
  9485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9486. }
  9487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9488. isKnowKey = TRUE;
  9489. }
  9490. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9491. {
  9492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9495. {
  9496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9497. }
  9498. else
  9499. {
  9500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9501. }
  9502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9503. isKnowKey = TRUE;
  9504. }
  9505. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9506. {
  9507. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9510. {
  9511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9512. }
  9513. else
  9514. {
  9515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9516. }
  9517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9518. isKnowKey = TRUE;
  9519. }
  9520. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9521. {
  9522. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9525. {
  9526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9527. }
  9528. else
  9529. {
  9530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9531. }
  9532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9533. isKnowKey = TRUE;
  9534. }
  9535. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9536. {
  9537. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9539. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9540. {
  9541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9542. }
  9543. else
  9544. {
  9545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9546. }
  9547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9548. isKnowKey = TRUE;
  9549. }
  9550. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9551. {
  9552. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9555. {
  9556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9557. }
  9558. else
  9559. {
  9560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9561. }
  9562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9563. isKnowKey = TRUE;
  9564. }
  9565. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9566. {
  9567. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9569. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9570. {
  9571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9572. }
  9573. else
  9574. {
  9575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9576. }
  9577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9578. isKnowKey = TRUE;
  9579. }
  9580. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9581. {
  9582. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9585. {
  9586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9587. }
  9588. else
  9589. {
  9590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9591. }
  9592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9593. isKnowKey = TRUE;
  9594. }
  9595. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9596. {
  9597. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9599. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9600. {
  9601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9602. }
  9603. else
  9604. {
  9605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9606. }
  9607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9608. isKnowKey = TRUE;
  9609. }
  9610. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9611. {
  9612. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9614. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9615. {
  9616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9617. }
  9618. else
  9619. {
  9620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9621. }
  9622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9623. isKnowKey = TRUE;
  9624. }
  9625. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9626. {
  9627. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9630. {
  9631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9632. }
  9633. else
  9634. {
  9635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9636. }
  9637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9638. isKnowKey = TRUE;
  9639. }
  9640. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9641. {
  9642. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9644. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9645. {
  9646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9647. }
  9648. else
  9649. {
  9650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9651. }
  9652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9653. isKnowKey = TRUE;
  9654. }
  9655. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9656. {
  9657. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9659. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9660. {
  9661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9662. }
  9663. else
  9664. {
  9665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9666. }
  9667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9668. isKnowKey = TRUE;
  9669. }
  9670. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9671. {
  9672. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9674. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9675. {
  9676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9677. }
  9678. else
  9679. {
  9680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9681. }
  9682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9683. isKnowKey = TRUE;
  9684. }
  9685. #if 0
  9686. //For OCTT Test Case
  9687. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9688. {
  9689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9691. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9692. {
  9693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9694. }
  9695. else
  9696. {
  9697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9698. }
  9699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9700. isKnowKey = TRUE;
  9701. }
  9702. #endif
  9703. #if 1
  9704. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9705. {
  9706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9708. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9709. {
  9710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9711. }
  9712. else
  9713. {
  9714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9715. }
  9716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9717. isKnowKey = TRUE;
  9718. }
  9719. #endif
  9720. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9721. {
  9722. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9724. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9725. {
  9726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9727. }
  9728. else
  9729. {
  9730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9731. }
  9732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9733. isKnowKey = TRUE;
  9734. }
  9735. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9736. {
  9737. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9739. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9740. {
  9741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9742. }
  9743. else
  9744. {
  9745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9746. }
  9747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9748. isKnowKey = TRUE;
  9749. }
  9750. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9751. {
  9752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9754. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9755. {
  9756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9757. }
  9758. else
  9759. {
  9760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9761. }
  9762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9763. isKnowKey = TRUE;
  9764. }
  9765. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9766. {
  9767. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9769. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9770. {
  9771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9772. }
  9773. else
  9774. {
  9775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9776. }
  9777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9778. isKnowKey = TRUE;
  9779. }
  9780. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9781. {
  9782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9784. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9785. {
  9786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9787. }
  9788. else
  9789. {
  9790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9791. }
  9792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9793. isKnowKey = TRUE;
  9794. }
  9795. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9796. {
  9797. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9799. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9800. {
  9801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9802. }
  9803. else
  9804. {
  9805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9806. }
  9807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9808. isKnowKey = TRUE;
  9809. }
  9810. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9811. {
  9812. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9814. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9815. {
  9816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9817. }
  9818. else
  9819. {
  9820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9821. }
  9822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9823. isKnowKey = TRUE;
  9824. }
  9825. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9826. {
  9827. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9829. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9830. {
  9831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9832. }
  9833. else
  9834. {
  9835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9836. }
  9837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9838. isKnowKey = TRUE;
  9839. }
  9840. //=========================================================
  9841. if(!isEmpty && !isKnowKey)
  9842. {
  9843. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9844. strcpy(unknownkey[UnknownKeynum], keyReq);
  9845. UnknownKeynum = UnknownKeynum + 1;
  9846. }
  9847. }
  9848. void processUnkownKey(void)
  9849. {
  9850. DEBUG_INFO("processUnkownKey\n");
  9851. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9852. for(int index=0; index < UnknownKeynum; index++)
  9853. {
  9854. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9855. {
  9856. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9857. }
  9858. }
  9859. }
  9860. int setKeyValue(char *key, char *value)
  9861. {
  9862. int isSuccess = NotSupported;
  9863. int check_ascii=0;
  9864. #ifdef Debug
  9865. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9866. #endif
  9867. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9868. {
  9869. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9871. {
  9872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9873. isSuccess = ConfigurationStatus_Accepted;
  9874. }
  9875. else
  9876. {
  9877. isSuccess = ConfigurationStatus_Rejected;
  9878. }
  9879. }
  9880. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9881. {
  9882. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9884. {
  9885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9886. isSuccess = ConfigurationStatus_Accepted;
  9887. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9888. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9889. }
  9890. else
  9891. {
  9892. isSuccess = ConfigurationStatus_Rejected;
  9893. }
  9894. }
  9895. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9896. {
  9897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9898. {
  9899. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9901. isSuccess = ConfigurationStatus_Accepted;
  9902. }
  9903. else
  9904. {
  9905. isSuccess = ConfigurationStatus_Rejected;
  9906. }
  9907. }
  9908. if(strcmp(key, "BlinkRepeat") == 0)
  9909. {
  9910. //Charger.BlinkRepeat = Integer.parseInt(value);
  9911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9912. {
  9913. check_ascii = value[0];
  9914. if( (check_ascii < 48) || (check_ascii > 57) )
  9915. {
  9916. isSuccess = ConfigurationStatus_Rejected;
  9917. }
  9918. else
  9919. {
  9920. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9921. isSuccess = ConfigurationStatus_Accepted;
  9922. }
  9923. }
  9924. else
  9925. {
  9926. isSuccess = ConfigurationStatus_Rejected;
  9927. }
  9928. }
  9929. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9930. {
  9931. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9932. {
  9933. check_ascii = value[0];
  9934. if( (check_ascii < 48) || (check_ascii > 57) )
  9935. {
  9936. isSuccess = ConfigurationStatus_Rejected;
  9937. }
  9938. else
  9939. {
  9940. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9942. isSuccess = ConfigurationStatus_Accepted;
  9943. }
  9944. }
  9945. else
  9946. {
  9947. isSuccess = ConfigurationStatus_Rejected;
  9948. }
  9949. }
  9950. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9951. {
  9952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9953. {
  9954. check_ascii = value[0];
  9955. if( (check_ascii < 48) || (check_ascii > 57) )
  9956. {
  9957. isSuccess = ConfigurationStatus_Rejected;
  9958. }
  9959. else
  9960. {
  9961. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9962. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9963. isSuccess = ConfigurationStatus_Accepted;
  9964. }
  9965. }
  9966. else
  9967. {
  9968. isSuccess = ConfigurationStatus_Rejected;
  9969. }
  9970. }
  9971. if(strcmp(key, "HeartbeatInterval") == 0)
  9972. {
  9973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9974. {
  9975. check_ascii = value[0];
  9976. if( (check_ascii < 48) || (check_ascii > 57) )
  9977. {
  9978. isSuccess = ConfigurationStatus_Rejected;
  9979. }
  9980. else
  9981. {
  9982. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9984. HeartBeatWaitTime = atoi(value);
  9985. isSuccess = ConfigurationStatus_Accepted;
  9986. }
  9987. }
  9988. else
  9989. {
  9990. isSuccess = ConfigurationStatus_Rejected;
  9991. }
  9992. }
  9993. if(strcmp(key, "LightIntensity") == 0)
  9994. {
  9995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9996. {
  9997. check_ascii = value[0];
  9998. if( (check_ascii < 48) || (check_ascii > 57) )
  9999. {
  10000. isSuccess = ConfigurationStatus_Rejected;
  10001. }
  10002. else
  10003. {
  10004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10005. isSuccess = ConfigurationStatus_Accepted;
  10006. }
  10007. }
  10008. else
  10009. {
  10010. isSuccess = ConfigurationStatus_Rejected;
  10011. }
  10012. }
  10013. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10014. {
  10015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10016. {
  10017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10018. isSuccess = ConfigurationStatus_Accepted;
  10019. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10020. }
  10021. else
  10022. {
  10023. isSuccess = ConfigurationStatus_Rejected;
  10024. }
  10025. }
  10026. if(strcmp(key, "LocalPreAuthorize") == 0)
  10027. {
  10028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10029. {
  10030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10031. isSuccess = ConfigurationStatus_Accepted;
  10032. }
  10033. else
  10034. {
  10035. isSuccess = ConfigurationStatus_Rejected;
  10036. }
  10037. }
  10038. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10039. {
  10040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10041. {
  10042. check_ascii = value[0];
  10043. if( (check_ascii < 48) || (check_ascii > 57) )
  10044. {
  10045. isSuccess = ConfigurationStatus_Rejected;
  10046. }
  10047. else
  10048. {
  10049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10050. isSuccess = ConfigurationStatus_Accepted;
  10051. }
  10052. }
  10053. else
  10054. {
  10055. isSuccess = ConfigurationStatus_Rejected;
  10056. }
  10057. }
  10058. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10059. {
  10060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10061. {
  10062. //int valueLength = strlen(value);
  10063. for(int i = 0; value[i]; i++){
  10064. value[i] = tolower(value[i]);
  10065. }
  10066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10067. isSuccess = ConfigurationStatus_Accepted;
  10068. }
  10069. else
  10070. {
  10071. isSuccess = ConfigurationStatus_Rejected;
  10072. }
  10073. }
  10074. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10075. {
  10076. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10077. {
  10078. //int valueLength = strlen(value);
  10079. for(int i = 0; value[i]; i++){
  10080. value[i] = tolower(value[i]);
  10081. }
  10082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10083. isSuccess = ConfigurationStatus_Accepted;
  10084. }
  10085. else
  10086. {
  10087. isSuccess = ConfigurationStatus_Rejected;
  10088. }
  10089. }
  10090. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10091. {
  10092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10093. {
  10094. check_ascii = value[0];
  10095. if( (check_ascii < 48) || (check_ascii > 57) )
  10096. {
  10097. isSuccess = ConfigurationStatus_Rejected;
  10098. }
  10099. else
  10100. {
  10101. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10103. isSuccess = ConfigurationStatus_Accepted;
  10104. }
  10105. #ifdef Debug
  10106. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10107. #endif
  10108. }
  10109. else
  10110. {
  10111. isSuccess = ConfigurationStatus_Rejected;
  10112. #ifdef Debug
  10113. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10114. #endif
  10115. }
  10116. }
  10117. if(strcmp(key, "MinimumStatusDuration") == 0)
  10118. {
  10119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10120. {
  10121. check_ascii = value[0];
  10122. if( (check_ascii < 48) || (check_ascii > 57) )
  10123. {
  10124. isSuccess = ConfigurationStatus_Rejected;
  10125. }
  10126. else
  10127. {
  10128. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10130. isSuccess = ConfigurationStatus_Accepted;
  10131. }
  10132. }
  10133. else
  10134. {
  10135. isSuccess = ConfigurationStatus_Rejected;
  10136. }
  10137. }
  10138. if(strcmp(key, "ResetRetries") == 0)
  10139. {
  10140. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10141. {
  10142. check_ascii = value[0];
  10143. if( (check_ascii < 48) || (check_ascii > 57) )
  10144. {
  10145. isSuccess = ConfigurationStatus_Rejected;
  10146. }
  10147. else
  10148. {
  10149. //Charger.ResetRetries = Integer.parseInt(value);
  10150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10151. isSuccess = ConfigurationStatus_Accepted;
  10152. }
  10153. }
  10154. else
  10155. {
  10156. isSuccess = ConfigurationStatus_Rejected;
  10157. }
  10158. }
  10159. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10160. {
  10161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10162. {
  10163. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10164. //int valueLength = strlen(value);
  10165. for(int i = 0; value[i]; i++){
  10166. value[i] = tolower(value[i]);
  10167. }
  10168. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10169. isSuccess = ConfigurationStatus_Accepted;
  10170. }
  10171. else
  10172. {
  10173. isSuccess = ConfigurationStatus_Rejected;
  10174. }
  10175. }
  10176. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10177. {
  10178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10179. {
  10180. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10182. isSuccess = ConfigurationStatus_Accepted;
  10183. }
  10184. else
  10185. {
  10186. isSuccess = ConfigurationStatus_Rejected;
  10187. }
  10188. }
  10189. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10190. {
  10191. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10192. {
  10193. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10195. isSuccess = ConfigurationStatus_Accepted;
  10196. }
  10197. else
  10198. {
  10199. isSuccess = ConfigurationStatus_Rejected;
  10200. }
  10201. }
  10202. if(strcmp(key, "StopTxnAlignedData") == 0)
  10203. {
  10204. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10205. {
  10206. //Charger.StopTxnAlignedData = value.toLowerCase();
  10207. //int valueLength = strlen(value);
  10208. for(int i = 0; value[i]; i++){
  10209. value[i] = tolower(value[i]);
  10210. }
  10211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10212. isSuccess = ConfigurationStatus_Accepted;
  10213. }
  10214. else
  10215. {
  10216. isSuccess = ConfigurationStatus_Rejected;
  10217. }
  10218. }
  10219. if(strcmp(key, "StopTxnSampledData") == 0)
  10220. {
  10221. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10222. {
  10223. //Charger.StopTxnSampledData = value.toLowerCase();
  10224. //int valueLength = strlen(value);
  10225. for(int i = 0; value[i]; i++){
  10226. value[i] = tolower(value[i]);
  10227. }
  10228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10229. isSuccess = ConfigurationStatus_Accepted;
  10230. }
  10231. else
  10232. {
  10233. isSuccess = ConfigurationStatus_Rejected;
  10234. }
  10235. }
  10236. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10237. {
  10238. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10239. {
  10240. check_ascii = value[0];
  10241. if( (check_ascii < 48) || (check_ascii > 57) )
  10242. {
  10243. isSuccess = ConfigurationStatus_Rejected;
  10244. }
  10245. else
  10246. {
  10247. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10249. TransactionMessageAttemptsValue = atoi(value);
  10250. isSuccess = ConfigurationStatus_Accepted;
  10251. }
  10252. }
  10253. else
  10254. {
  10255. isSuccess = ConfigurationStatus_Rejected;
  10256. }
  10257. }
  10258. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10259. {
  10260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10261. {
  10262. check_ascii = value[0];
  10263. if( (check_ascii < 48) || (check_ascii > 57) )
  10264. {
  10265. isSuccess = ConfigurationStatus_Rejected;
  10266. }
  10267. else
  10268. {
  10269. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10271. TransactionMessageRetryIntervalValue = atoi(value);
  10272. isSuccess = ConfigurationStatus_Accepted;
  10273. }
  10274. }
  10275. else
  10276. {
  10277. isSuccess = ConfigurationStatus_Rejected;
  10278. }
  10279. }
  10280. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10281. {
  10282. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10283. {
  10284. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10286. isSuccess = ConfigurationStatus_Accepted;
  10287. }
  10288. else
  10289. {
  10290. isSuccess = ConfigurationStatus_Rejected;
  10291. }
  10292. }
  10293. if(strcmp(key, "WebSocketPingInterval") == 0)
  10294. {
  10295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10296. {
  10297. check_ascii = value[0];
  10298. if( (check_ascii < 48) || (check_ascii > 57) )
  10299. {
  10300. isSuccess = ConfigurationStatus_Rejected;
  10301. }
  10302. else
  10303. {
  10304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10305. isSuccess = ConfigurationStatus_Accepted;
  10306. }
  10307. }
  10308. else
  10309. {
  10310. isSuccess = ConfigurationStatus_Rejected;
  10311. }
  10312. }
  10313. #if 0
  10314. //For OCPP Test Case
  10315. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10316. {
  10317. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10318. {
  10319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10320. isSuccess = ConfigurationStatus_Accepted;
  10321. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10322. }
  10323. else
  10324. {
  10325. isSuccess = ConfigurationStatus_Rejected;
  10326. }
  10327. }
  10328. #endif
  10329. #if 1
  10330. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10331. {
  10332. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10333. {
  10334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10335. isSuccess = ConfigurationStatus_Accepted;
  10336. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10337. }
  10338. else
  10339. {
  10340. isSuccess = ConfigurationStatus_Rejected;
  10341. }
  10342. }
  10343. #endif
  10344. return isSuccess;
  10345. }
  10346. int updateSetting(char *key, char *value)
  10347. {
  10348. mtrace();
  10349. int isSuccess = FALSE;
  10350. char string[1000]={0}, buffer[1000]={0};
  10351. char strtemp[50]={0};
  10352. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10353. int pos, c = 0;
  10354. char *loc;
  10355. int pos1=0;
  10356. FILE *f = fopen("/var/www/settings1", "r");
  10357. if(f == NULL)
  10358. {
  10359. #ifdef Debug
  10360. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10361. #endif
  10362. return isSuccess;
  10363. }
  10364. fseek(f, 0, SEEK_END);
  10365. long fsize = ftell(f);
  10366. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10367. fread(string, 1, fsize, f);
  10368. fclose(f);
  10369. string[fsize] = 0;
  10370. loc = strstr(string, key);
  10371. if(loc != NULL)
  10372. {
  10373. DEBUG_INFO("key exist!\n");
  10374. pos = loc - string-1;
  10375. f = fopen("/var/www/settings1", "w");
  10376. strncpy(buffer, string, pos);
  10377. fprintf(f, "%s", buffer);
  10378. memset(sstr ,0, sizeof(sstr) );
  10379. c = 0;
  10380. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10381. {
  10382. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10383. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10384. c++;
  10385. }
  10386. sstr[c] = '\0';
  10387. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10388. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10389. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10390. memset(buffer ,0, sizeof(buffer) );
  10391. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10392. //printf("buffer=%s",buffer);
  10393. fprintf(f, "%s", buffer);
  10394. fclose(f);
  10395. }
  10396. else
  10397. {
  10398. printf("key not exist!\n");
  10399. f = fopen("/var/www/settings1", "w+");
  10400. fputs(string, f);
  10401. fseek(f, -1, SEEK_CUR);
  10402. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10403. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10404. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10405. fclose(f);
  10406. }
  10407. isSuccess = TRUE;
  10408. return isSuccess;
  10409. }
  10410. int TransactionMessageAttemptsGet(void)
  10411. {
  10412. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10413. }
  10414. int FirstHeartBeatResponse(void)
  10415. {
  10416. return FirstHeartBeat;
  10417. }
  10418. int TransactionMessageRetryIntervalGet(void)
  10419. {
  10420. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10421. }
  10422. #define SA struct sockaddr
  10423. #define MAXBUF 1024
  10424. //static int m_socket_data;
  10425. //static int sockfd;
  10426. int ReadHttpStatus(int sock){
  10427. //char c;
  10428. char buff[1024]="",*ptr=buff+1;
  10429. int bytes_received, status;
  10430. DEBUG_INFO("Begin Response ..\n");
  10431. while((bytes_received = recv(sock, ptr, 1, 0))){
  10432. if(bytes_received==-1){
  10433. perror("ReadHttpStatus");
  10434. exit(1);
  10435. }
  10436. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10437. ptr++;
  10438. }
  10439. *ptr=0;
  10440. ptr=buff+1;
  10441. sscanf(ptr,"%*s %d ", &status);
  10442. DEBUG_INFO("%s\n",ptr);
  10443. DEBUG_INFO("status=%d\n",status);
  10444. DEBUG_INFO("End Response ..\n");
  10445. return (bytes_received>0)?status:0;
  10446. }
  10447. //the only filed that it parsed is 'Content-Length'
  10448. int ParseHeader(int sock){
  10449. //char c;
  10450. char buff[1024]="",*ptr=buff+4;
  10451. int bytes_received;
  10452. DEBUG_INFO("Begin HEADER ..\n");
  10453. while((bytes_received = recv(sock, ptr, 1, 0))){
  10454. if(bytes_received==-1){
  10455. perror("Parse Header");
  10456. exit(1);
  10457. }
  10458. if(
  10459. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10460. (ptr[-1]=='\r') && (*ptr=='\n' )
  10461. ) break;
  10462. ptr++;
  10463. }
  10464. *ptr=0;
  10465. ptr=buff+4;
  10466. //printf("%s",ptr);
  10467. if(bytes_received){
  10468. ptr=strstr(ptr,"Content-Length:");
  10469. if(ptr){
  10470. sscanf(ptr,"%*s %d",&bytes_received);
  10471. }else
  10472. bytes_received=-1; //unknown size
  10473. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10474. }
  10475. DEBUG_INFO("End HEADER ..\n");
  10476. return bytes_received ;
  10477. }
  10478. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10479. {
  10480. char rmFileCmd[100]={0};
  10481. char FilePath[100]={0};
  10482. char ftpbuf[200];
  10483. int systemresult;
  10484. DEBUG_INFO("filename=%s\n",filename);
  10485. DEBUG_INFO("url=%s\n",url);
  10486. sprintf(FilePath,"../mnt/%s",filename);
  10487. if((access(FilePath,F_OK))!=-1)
  10488. {
  10489. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10490. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10491. system(rmFileCmd);
  10492. }
  10493. memset(ftpbuf, 0, sizeof(ftpbuf));
  10494. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10495. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10496. systemresult = system(ftpbuf);
  10497. DEBUG_INFO("systemresult=%d\n",systemresult);
  10498. if(systemresult != 0)
  10499. {
  10500. DEBUG_INFO("http DownLoad error!\n");
  10501. return FALSE;
  10502. }
  10503. return TRUE;
  10504. }
  10505. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10506. {
  10507. char rmFileCmd[100]={0};
  10508. char FilePath[100]={0};
  10509. char ftpbuf[200];
  10510. int systemresult;
  10511. //char temp[100];
  10512. #if 0
  10513. struct hostent* server;
  10514. char *IPbuffer;
  10515. server = gethostbyname(location);
  10516. // To convert an Internet network
  10517. // address into ASCII string
  10518. IPbuffer = inet_ntoa(*((struct in_addr*)
  10519. server->h_addr_list[0]));
  10520. #endif
  10521. sprintf(FilePath,"../mnt/%s",filename);
  10522. if((access(FilePath,F_OK))!=-1)
  10523. {
  10524. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10525. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10526. system(rmFileCmd);
  10527. }
  10528. memset(ftpbuf, 0, sizeof(ftpbuf));
  10529. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10530. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10531. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10532. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10533. systemresult = system(ftpbuf);
  10534. DEBUG_INFO("systemresult=%d\n",systemresult);
  10535. if(systemresult != 0)
  10536. {
  10537. printf("ftpget error!\n");
  10538. return FALSE;
  10539. }
  10540. return TRUE;
  10541. }
  10542. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10543. {
  10544. struct hostent* server;
  10545. char *IPbuffer;
  10546. char ftpbuf[200];
  10547. int systemresult;
  10548. // To retrieve host information
  10549. server = gethostbyname(location);
  10550. // To convert an Internet network
  10551. // address into ASCII string
  10552. IPbuffer = inet_ntoa(*((struct in_addr*)
  10553. server->h_addr_list[0]));
  10554. memset(ftpbuf, 0, sizeof(ftpbuf));
  10555. /* format : ftpput -u username -p passwd IP target source*/
  10556. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10557. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10558. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10559. systemresult = system(ftpbuf);
  10560. DEBUG_INFO("systemresult=%d\n",systemresult);
  10561. if(systemresult != 0)
  10562. {
  10563. DEBUG_INFO("ftpput error!\n");
  10564. return FALSE;
  10565. }
  10566. return TRUE;
  10567. }
  10568. int SettingChargingRecord(int target, int transactionId)
  10569. {
  10570. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10571. {
  10572. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10573. {
  10574. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10575. {
  10576. addBuff(target, transactionId, 0);
  10577. return TRUE;
  10578. }
  10579. }
  10580. for (int index = 0; index < CCS_QUANTITY; index++)
  10581. {
  10582. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10583. {
  10584. addBuff(target, transactionId, 0);
  10585. return TRUE;
  10586. }
  10587. }
  10588. for (int index = 0; index < GB_QUANTITY; index++)
  10589. {
  10590. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10591. {
  10592. addBuff(target, transactionId, 0);
  10593. return TRUE;
  10594. }
  10595. }
  10596. }
  10597. else
  10598. {
  10599. for (int index = 0; index < AC_QUANTITY; index++)
  10600. {
  10601. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10602. {
  10603. addBuff(target, transactionId, 0);
  10604. return TRUE;
  10605. }
  10606. }
  10607. }
  10608. return FALSE;
  10609. }
  10610. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10611. {
  10612. int isSuccess = FALSE;
  10613. //char *query = NULL;
  10614. sqlite3_stmt *stmt;
  10615. int rc; // return code
  10616. char str[20];
  10617. sprintf(str,"%d",user_id);
  10618. 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 */
  10619. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10620. rc = sqlite3_step(stmt); /* 3 */
  10621. if (rc != SQLITE_DONE) {
  10622. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10623. goto out;
  10624. }
  10625. sqlite3_finalize(stmt);
  10626. // free(query);
  10627. out:
  10628. //----------------------
  10629. // close SQLite database
  10630. //----------------------
  10631. sqlite3_close(db);
  10632. printf("database closed.\n");
  10633. return isSuccess;
  10634. }
  10635. /**
  10636. * Place the contents of the specified file into a memory buffer
  10637. *
  10638. * @param[in] filename The path and name of the file to read
  10639. * @param[out] filebuffer A pointer to the contents in memory
  10640. * @return status 0 success, 1 on failure
  10641. */
  10642. int get_file_contents(const char* filename, char** outbuffer) {
  10643. FILE* file = NULL;
  10644. long filesize;
  10645. const int blocksize = 1;
  10646. size_t readsize;
  10647. char* filebuffer;
  10648. // Open the file
  10649. file = fopen(filename, "r");
  10650. if (NULL == file)
  10651. {
  10652. printf("'%s' not opened\n", filename);
  10653. exit(EXIT_FAILURE);
  10654. }
  10655. // Determine the file size
  10656. fseek(file, 0, SEEK_END);
  10657. filesize = ftell(file);
  10658. rewind (file);
  10659. // Allocate memory for the file contents
  10660. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10661. *outbuffer = filebuffer;
  10662. if (filebuffer == NULL)
  10663. {
  10664. fputs ("malloc out-of-memory", stderr);
  10665. exit(EXIT_FAILURE);
  10666. }
  10667. // Read in the file
  10668. readsize = fread(filebuffer, blocksize, filesize, file);
  10669. if (readsize != filesize)
  10670. {
  10671. fputs ("didn't read file completely",stderr);
  10672. exit(EXIT_FAILURE);
  10673. }
  10674. // Clean exit
  10675. fclose(file);
  10676. return EXIT_SUCCESS;
  10677. }
  10678. static int selectSqlCount = 0;
  10679. static int callback(void *data, int argc, char **argv, char **azColName){
  10680. int i;
  10681. printf("%s: ", (const char*)data);
  10682. selectSqlCount = argc;
  10683. for(i = 0; i<argc; i++){
  10684. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10685. }
  10686. printf("\n");
  10687. return 0;
  10688. }
  10689. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10690. //int i;
  10691. //printf("%s:\n", (const char*)data);
  10692. localversion = argv[5] ? atoi(argv[5]) : 0;
  10693. printf("localversion=%d\n", localversion);
  10694. return 0;
  10695. }
  10696. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10697. //int i;
  10698. //printf("%s:\n", (const char*)data);
  10699. //idTag
  10700. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10701. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10702. //parentIdTag
  10703. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10704. //expir_date
  10705. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10706. //status
  10707. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10708. //version
  10709. idTagQuery.listVersionInt = atoi(argv[5]);
  10710. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10711. return 0;
  10712. }
  10713. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10714. int i;
  10715. //printf("%s:\n", (const char*)data);
  10716. #if 1
  10717. for(i=0; i<argc; i++){
  10718. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10719. }
  10720. //printf("");
  10721. #endif
  10722. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10723. // printf("localversion=%d\n", localversion);
  10724. return 0;
  10725. }
  10726. /** sqlite3_exec的回调。
  10727. *
  10728. * 向控制台打印查询的结果。
  10729. *
  10730. * @param in data 传递给回调函数的数据。
  10731. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10732. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10733. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10734. * @return 状态码。
  10735. */
  10736. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10737. {
  10738. for (int i = 0; i < n_columns; i++)
  10739. {
  10740. DEBUG_INFO("%s/t", col_values[i]);
  10741. }
  10742. DEBUG_INFO("/n");
  10743. return 0;
  10744. }
  10745. void OCPP_getListVerion()
  10746. {
  10747. int rc = 0;
  10748. // const char* data = "Callback function called";
  10749. char sql[100];
  10750. char zErrMsg[100];
  10751. memset(sql, 0, 100);
  10752. memset(zErrMsg, 0, 100);
  10753. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10754. /* Execute SQL statement */
  10755. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10756. DEBUG_INFO("rc=%d\n",rc);
  10757. if( rc != SQLITE_OK ){
  10758. DEBUG_INFO("SQL error: %s", zErrMsg);
  10759. //sqlite3_free(zErrMsg);
  10760. }else{
  10761. DEBUG_INFO("Operation done successfully");
  10762. }
  10763. }
  10764. void OCPP_getIdTag(char *idTag)
  10765. {
  10766. int rc = 0;
  10767. // const char* data = "Callback function called";
  10768. char sql[100];
  10769. char zErrMsg[100];
  10770. memset(sql, 0, 100);
  10771. memset(zErrMsg, 0, 100);
  10772. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10773. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10774. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10775. /* Execute SQL statement */
  10776. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10777. if( rc != SQLITE_OK ){
  10778. DEBUG_INFO("SQL error: %s", zErrMsg);
  10779. //sqlite3_free(zErrMsg);
  10780. }else{
  10781. printf("Operation done successfully");
  10782. }
  10783. //return ver;
  10784. }
  10785. void OCPP_get_TableAuthlocalAllData(void)
  10786. {
  10787. int rc = 0;
  10788. // const char* data = "Callback function called";
  10789. char sql[100];
  10790. char zErrMsg[100];
  10791. memset(sql, 0, 100);
  10792. memset(zErrMsg, 0, 100);
  10793. sprintf(sql,"select * from ocpp_auth_local ");
  10794. /* Execute SQL statement */
  10795. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10796. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10797. if( rc != SQLITE_OK ){
  10798. DEBUG_INFO("SQL error: %s", zErrMsg);
  10799. //sqlite3_free(zErrMsg);
  10800. }else{
  10801. DEBUG_INFO("Operation done successfully");
  10802. }
  10803. //return ver;
  10804. }
  10805. int OCPP_cleanLocalList()
  10806. {
  10807. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10808. char *errMsg = 0;
  10809. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10810. if (SQLITE_OK != rc)
  10811. {
  10812. DEBUG_INFO("%s\n",errMsg);
  10813. return FALSE;
  10814. }
  10815. else
  10816. {
  10817. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10818. }
  10819. return TRUE;
  10820. }
  10821. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10822. {
  10823. int isSuccess = FALSE;
  10824. int ret = 0;
  10825. //const char* data = "Callback function called";
  10826. char sql[200];
  10827. char zErrMsg[100];
  10828. memset(sql, 0, 200);
  10829. memset(zErrMsg, 0, 100);
  10830. 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);
  10831. //* Execute SQL statement */
  10832. //zErrMsg = 0;
  10833. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10834. if( ret != SQLITE_OK ){
  10835. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10836. // free(zErrMsg);
  10837. // free(sql);
  10838. return isSuccess;
  10839. }
  10840. DEBUG_INFO("successfully Insert records created\n");
  10841. isSuccess = TRUE;
  10842. return isSuccess;
  10843. }
  10844. void OCPP_deleteIdTag(char *idTag)
  10845. {
  10846. //int ver = 0;
  10847. //int isSuccess = FALSE;
  10848. int rc = 0;
  10849. char sql[100];
  10850. char zErrMsg[100];
  10851. memset(sql, 0, 100);
  10852. memset(zErrMsg, 0, 100);
  10853. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10854. //* Execute SQL statement */
  10855. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10856. if( rc != SQLITE_OK ){
  10857. DEBUG_INFO("SQL error: %s", zErrMsg);
  10858. //sqlite3_free(zErrMsg);
  10859. }else{
  10860. DEBUG_INFO("Operation done successfully");
  10861. }
  10862. }
  10863. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10864. {
  10865. int isSuccess = FALSE;
  10866. int ret = 0;
  10867. const char* data = "Callback function called";
  10868. char sql[200];
  10869. char zErrMsg[100];
  10870. memset(sql, 0, 200);
  10871. memset(zErrMsg, 0, 100);
  10872. //* selectFromTable */
  10873. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10874. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10875. //* Execute SQL statement */
  10876. selectSqlCount = 0;
  10877. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10878. if( ret != SQLITE_OK ){
  10879. printf("Error SQL: %s\n", zErrMsg);
  10880. }
  10881. printf("successfully select operation done\n");
  10882. memset(sql, 0, 200);
  10883. memset(zErrMsg, 0, 100);
  10884. if(selectSqlCount == 0)
  10885. {
  10886. //Insert
  10887. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  10888. 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);
  10889. DEBUG_INFO("sql:%s\n", sql);
  10890. //* Execute SQL statement */
  10891. //zErrMsg = 0;
  10892. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10893. if( ret != SQLITE_OK ){
  10894. printf("SQL error: %s\n", zErrMsg);
  10895. return isSuccess;
  10896. }
  10897. DEBUG_INFO("successfully Insert records created\n");
  10898. isSuccess = TRUE;
  10899. }
  10900. else
  10901. {
  10902. //Update
  10903. //* Create merged SQL statement */
  10904. 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);
  10905. /* Execute SQL statement */
  10906. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10907. if( ret != SQLITE_OK ){
  10908. printf("SQL error: %s\n", zErrMsg);
  10909. //sqlite3_free(zErrMsg);
  10910. //sqlite3_free(sql);
  10911. return isSuccess;
  10912. }
  10913. DEBUG_INFO("Successfully operation done \n");
  10914. isSuccess = TRUE;
  10915. }
  10916. return isSuccess;
  10917. }
  10918. char *GetOcppServerURL()
  10919. {
  10920. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10921. memset(OcppHost, 0, sizeof(OcppHost));
  10922. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10923. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  10924. {
  10925. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  10926. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  10927. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10928. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10929. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10930. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10931. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10932. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10933. goto End;
  10934. }
  10935. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  10936. {
  10937. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  10938. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10939. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10940. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10941. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10942. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10943. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10944. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10945. goto End;
  10946. }
  10947. else
  10948. {
  10949. strcpy(OcppHost,"");
  10950. }
  10951. End:
  10952. return OcppHost;
  10953. }
  10954. char *GetOcppPath()
  10955. {
  10956. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  10957. {
  10958. if(OcppTempPath == NULL)
  10959. {
  10960. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10961. }
  10962. else
  10963. {
  10964. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10965. }
  10966. goto End;
  10967. }
  10968. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  10969. {
  10970. if(OcppTempPath == NULL)
  10971. {
  10972. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10973. }
  10974. else
  10975. {
  10976. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10977. }
  10978. goto End;
  10979. }
  10980. else
  10981. {
  10982. strcpy(OcppHost,"");
  10983. }
  10984. End:
  10985. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10986. return OcppPath;
  10987. }
  10988. int GetOcppPort()
  10989. {
  10990. return OcppPort;
  10991. }
  10992. int GetOcppConnStatus(void)
  10993. {
  10994. return ShmOCPP16Data->OcppConnStatus;
  10995. }
  10996. void SetOcppConnStatus(uint8_t status)
  10997. {
  10998. ShmOCPP16Data->OcppConnStatus = status;
  10999. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  11000. if(status == FALSE)
  11001. {
  11002. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11003. {
  11004. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  11005. }
  11006. else
  11007. {
  11008. SystemInitial = AC_QUANTITY;
  11009. }
  11010. }
  11011. }
  11012. int GetHeartBeatWithNOResponse(void)
  11013. {
  11014. return HeartBeatWithNOResponse;
  11015. }
  11016. void SetHeartBeatWithNOResponse(void)
  11017. {
  11018. HeartBeatWithNOResponse = 0;
  11019. }
  11020. int InternetDisconnect(void)
  11021. {
  11022. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  11023. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  11024. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  11025. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  11026. }
  11027. void GetChargingProfileRequest(int gunindex)
  11028. {
  11029. mtrace();
  11030. //int connectorIdInt, durationInt;
  11031. //char chargingRateUnitStr[4]={0};
  11032. int tempdurationInt = 0;
  11033. int tempchargingProfileId = 0;
  11034. int tempstackLevel = 0;
  11035. int temptransactionId = 0;
  11036. float tempminChargingRateFloat = 0.0;
  11037. char tempchargingProfilePurposeStr[24]={0};
  11038. char tempchargingProfileKindStr[12]={0};
  11039. char temprecurrencyKindStr[8]={0};
  11040. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  11041. char tempvalidToStr[28]={0};
  11042. int tempStartPeriodInt = 0;
  11043. float tempLimitInt = 0.0;//0.1;
  11044. int tempNumberPhasesInt=0;
  11045. char fname[200];
  11046. //char comfirmstr[20];
  11047. float MinChargingRate =0.0;
  11048. double diff_t;
  11049. struct tm tp;
  11050. FILE *fptr1;//, *fptr2;
  11051. int c = 0;
  11052. char * pch;
  11053. char *loc;
  11054. char sstr[200]={ 0 };
  11055. int n_chargingProfile = 0;
  11056. int n_SchedulePeriods = 0;
  11057. char SchedulePeriodList[10][200]={0};
  11058. char sLineWord[800]={0};
  11059. char word[1000]={0};
  11060. int confirmPeriods = 0;
  11061. struct StructProfile ChargePointMaxProfile;
  11062. struct StructProfile TxDefaultProfile;
  11063. struct StructProfile TxProfile;
  11064. struct StructProfile TxDefaultProfiletemp[2]={0};
  11065. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  11066. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  11067. struct StructChargingProfile TxProfile_TEMP={0};
  11068. int TxDefaultProfileFileIsNull=FALSE;
  11069. int ChargePointMaxProfileIsNull=FALSE;
  11070. int TxProfileIsNull=FALSE;
  11071. // int CompositeSceduleIndex = 0;
  11072. char ChargePointMaxProfileScheduleStr[30]={0};
  11073. char TxDefaultProfileScheduleStr[30]={0};
  11074. char TxProfileScheduleStr[30]={0};
  11075. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  11076. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  11077. memset(&TxProfile,0,sizeof(struct StructProfile));
  11078. DEBUG_INFO("GetChargingProfileRequest\n");
  11079. //*****************************ChargePointMaxProfile******************************************/
  11080. strcpy(fname, ChargePointMaxProfile_JSON);
  11081. ChargePointMaxProfileIsNull=TRUE;
  11082. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  11083. {
  11084. fptr1 = fopen(fname, "r");
  11085. int c;
  11086. c = fgetc(fptr1);
  11087. //DEBUG_INFO("c:%d\n",c);
  11088. rewind(fptr1);
  11089. if(c == EOF)
  11090. {
  11091. DEBUG_INFO("\n End of file reached.");
  11092. ChargePointMaxProfileIsNull=TRUE;
  11093. fclose(fptr1);
  11094. }
  11095. else
  11096. {
  11097. ChargePointMaxProfileIsNull=FALSE;
  11098. while(fscanf(fptr1, "%s", word) != EOF)
  11099. {
  11100. if(strcmp(word, "chargingProfileId") == 0)
  11101. {
  11102. n_chargingProfile = n_chargingProfile + 1;
  11103. }
  11104. }
  11105. rewind(fptr1);
  11106. //search Charging Profile Element
  11107. int i = 0;
  11108. int j = 0;
  11109. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11110. //***********chargingProfileId**************/
  11111. c = 0;
  11112. loc = strstr(sLineWord, "chargingProfileId");
  11113. //DEBUG_INFO("loc=%s\n",loc);
  11114. memset(sstr ,0, sizeof(sstr) );
  11115. if(loc != NULL)
  11116. {
  11117. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11118. {
  11119. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11120. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11121. c++;
  11122. }
  11123. sstr[c] = '\0';
  11124. tempchargingProfileId = atoi(sstr);
  11125. }
  11126. else
  11127. {
  11128. tempchargingProfileId = 0;
  11129. }
  11130. //***********stackLevel**************/
  11131. c = 0;
  11132. loc = strstr(sLineWord, "stackLevel");
  11133. //DEBUG_INFO("loc=%s\n",loc);
  11134. memset(sstr ,0, sizeof(sstr) );
  11135. if(loc != NULL)
  11136. {
  11137. while (loc[2+strlen("stackLevel")+c] != '\"')
  11138. {
  11139. sstr[c] = loc[2+strlen("stackLevel")+c];
  11140. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11141. c++;
  11142. }
  11143. sstr[c] = '\0';
  11144. tempstackLevel = atoi(sstr);
  11145. }
  11146. else
  11147. {
  11148. tempstackLevel = 0;
  11149. }
  11150. //***********chargingProfilePurpose **************/
  11151. c = 0;
  11152. loc = strstr(sLineWord, "chargingProfilePurpose");
  11153. //DEBUG_INFO("loc=%s\n",loc);
  11154. memset(sstr ,0, sizeof(sstr) );
  11155. if(loc != NULL)
  11156. {
  11157. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11158. {
  11159. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11160. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11161. c++;
  11162. }
  11163. sstr[c] = '\0';
  11164. strcpy(tempchargingProfilePurposeStr,sstr);
  11165. }
  11166. else
  11167. {
  11168. strcpy(tempchargingProfilePurposeStr,"");
  11169. }
  11170. //***********chargingProfileKind **************/
  11171. c = 0;
  11172. loc = strstr(sLineWord, "chargingProfileKind");
  11173. //DEBUG_INFO("loc=%s\n",loc);
  11174. memset(sstr ,0, sizeof(sstr) );
  11175. if(loc != NULL)
  11176. {
  11177. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11178. {
  11179. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11180. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11181. c++;
  11182. }
  11183. sstr[c] = '\0';
  11184. strcpy(tempchargingProfileKindStr,sstr);
  11185. }
  11186. else
  11187. {
  11188. strcpy(tempchargingProfileKindStr,"");
  11189. }
  11190. //***********recurrencyKind **************/
  11191. c = 0;
  11192. loc = strstr(sLineWord, "recurrencyKind");
  11193. //DEBUG_INFO("loc=%s\n",loc);
  11194. memset(sstr ,0, sizeof(sstr) );
  11195. if(loc != NULL)
  11196. {
  11197. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11198. {
  11199. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11200. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11201. c++;
  11202. }
  11203. sstr[c] = '\0';
  11204. strcpy(temprecurrencyKindStr,sstr);
  11205. }
  11206. else
  11207. {
  11208. strcpy(temprecurrencyKindStr,"");
  11209. }
  11210. //***********validFrom**************/
  11211. c = 0;
  11212. loc = strstr(sLineWord, "validFrom");
  11213. //DEBUG_INFO("loc=%s\n",loc);
  11214. memset(sstr ,0, sizeof(sstr) );
  11215. if(loc != NULL)
  11216. {
  11217. while (loc[3+strlen("validFrom")+c] != '\"')
  11218. {
  11219. sstr[c] = loc[3+strlen("validFrom")+c];
  11220. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11221. c++;
  11222. }
  11223. sstr[c] = '\0';
  11224. strcpy(tempvalidFromStr,sstr);
  11225. }
  11226. else
  11227. {
  11228. strcpy(tempvalidFromStr,"");
  11229. }
  11230. //***********validTo **************/
  11231. c = 0;
  11232. loc = strstr(sLineWord, "validTo");
  11233. //DEBUG_INFO("loc=%s\n",loc);
  11234. memset(sstr ,0, sizeof(sstr) );
  11235. if(loc != NULL)
  11236. {
  11237. while (loc[3+strlen("validTo")+c] != '\"')
  11238. {
  11239. sstr[c] = loc[3+strlen("validTo")+c];
  11240. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11241. c++;
  11242. }
  11243. sstr[c] = '\0';
  11244. strcpy(tempvalidToStr,sstr);
  11245. }
  11246. else
  11247. {
  11248. strcpy(tempvalidToStr,"");
  11249. }
  11250. //***********validFrom**************/
  11251. c = 0;
  11252. loc = strstr(sLineWord, "validFrom");
  11253. if(loc != NULL)
  11254. {
  11255. memset(sstr ,0, sizeof(sstr) );
  11256. while (loc[3+strlen("validFrom")+c] != '\"')
  11257. {
  11258. sstr[c] = loc[3+strlen("validFrom")+c];
  11259. c++;
  11260. }
  11261. sstr[c] = '\0';
  11262. strcpy(tempvalidFromStr,sstr);
  11263. }
  11264. else
  11265. {
  11266. strcpy(tempvalidFromStr,"");
  11267. }
  11268. //***********duration**************/
  11269. c = 0;
  11270. loc = strstr(sLineWord, "duration");
  11271. if(loc != NULL)
  11272. {
  11273. memset(sstr ,0, sizeof(sstr) );
  11274. while (loc[2+strlen("duration")+c] != ',')
  11275. {
  11276. sstr[c] = loc[2+strlen("duration")+c];
  11277. c++;
  11278. }
  11279. sstr[c] = '\0';
  11280. tempdurationInt = atoi(sstr);
  11281. }
  11282. else
  11283. {
  11284. tempdurationInt = 0;
  11285. }
  11286. //**********startSchedule**********/
  11287. c = 0;
  11288. loc = strstr(sLineWord, "startSchedule");
  11289. memset(sstr ,0, sizeof(sstr) );
  11290. while (loc[3+strlen("startSchedule")+c] != '\"')
  11291. {
  11292. sstr[c] = loc[3+strlen("startSchedule")+c];
  11293. c++;
  11294. }
  11295. sstr[c] = '\0';
  11296. strcpy(tempstartScheduleStr, sstr);
  11297. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  11298. //**********chargingRateUnit**********/
  11299. c = 0;
  11300. loc = strstr(sLineWord, "chargingRateUnit");
  11301. memset(sstr ,0, sizeof(sstr) );
  11302. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  11303. {
  11304. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  11305. c++;
  11306. }
  11307. sstr[c] = '\0';
  11308. strcpy(tempchargingRateUnitStr, sstr);
  11309. //**********minChargingRate*******/
  11310. c = 0;
  11311. loc = strstr(sLineWord, "minChargingRate");
  11312. if(loc != NULL)
  11313. {
  11314. memset(sstr ,0, sizeof(sstr) );
  11315. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  11316. {
  11317. sstr[c] = loc[2+strlen("minChargingRate")+c];
  11318. c++;
  11319. }
  11320. sstr[c] = '\0';
  11321. tempminChargingRateFloat = atof(sstr);
  11322. }
  11323. else
  11324. {
  11325. tempminChargingRateFloat = 0.0;
  11326. }
  11327. //
  11328. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  11329. tp.tm_isdst = -1;
  11330. time_t utc = mktime(&tp);
  11331. time_t t = time(NULL);
  11332. diff_t = difftime(t, utc);
  11333. //DEBUG_INFO("diff_t=%f\n",diff_t);
  11334. //parsing strings to words
  11335. i = 0;
  11336. loc = strstr(sLineWord, "chargingSchedulePeriod");
  11337. loc = loc+3+strlen("chargingSchedulePeriod");
  11338. pch = strtok(loc ,"{");
  11339. while (pch != NULL)
  11340. {
  11341. strcpy(SchedulePeriodList[i], pch);
  11342. pch = strtok (NULL, "{");
  11343. i = i + 1;
  11344. }
  11345. n_SchedulePeriods = i;
  11346. for(int i=0;i<n_SchedulePeriods;i++)
  11347. {
  11348. //*************startPeriod****************/
  11349. c = 0;
  11350. loc = strstr(SchedulePeriodList[i], "startPeriod");
  11351. memset(sstr ,0, sizeof(sstr) );
  11352. while (loc[strlen("startPeriod")+2+c] != ',')
  11353. {
  11354. sstr[c] = loc[strlen("startPeriod")+2+c];
  11355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11356. c++;
  11357. }
  11358. sstr[c] = '\0';
  11359. tempStartPeriodInt = atoi(sstr);
  11360. //*************limit****************/
  11361. c = 0;
  11362. loc = strstr(SchedulePeriodList[i], "limit");
  11363. memset(sstr ,0, sizeof(sstr) );
  11364. while (loc[strlen("limit")+2+c] != ',')
  11365. {
  11366. sstr[c] = loc[strlen("limit")+2+c];
  11367. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11368. c++;
  11369. }
  11370. sstr[c] = '\0';
  11371. tempLimitInt = atof(sstr);
  11372. //*************numberPhases****************/
  11373. c = 0;
  11374. loc = strstr(SchedulePeriodList[i], "numberPhases");
  11375. memset(sstr ,0, sizeof(sstr) );
  11376. while (loc[strlen("numberPhases")+2+c] != '}')
  11377. {
  11378. sstr[c] = loc[strlen("numberPhases")+2+c];
  11379. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11380. c++;
  11381. }
  11382. sstr[c] = '\0';
  11383. tempNumberPhasesInt = atoi(sstr);
  11384. if(j == 0)
  11385. {
  11386. ChargePointMaxProfile.Duration = tempdurationInt;
  11387. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  11388. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  11389. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  11390. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  11391. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  11392. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  11393. ChargePointMaxProfile_TEMP.TransactionId = 0;
  11394. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  11395. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  11396. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  11397. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  11398. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  11399. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  11400. }
  11401. }
  11402. if(MinChargingRate < tempminChargingRateFloat)
  11403. {
  11404. MinChargingRate = tempminChargingRateFloat;
  11405. }
  11406. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  11407. if(confirmPeriods < n_SchedulePeriods)
  11408. {
  11409. confirmPeriods = n_SchedulePeriods;
  11410. }
  11411. j = j + 1;
  11412. }
  11413. fclose(fptr1);
  11414. }
  11415. }// the end of access file ChargePointMaxProfile
  11416. //****************************TxDefaultProfile************************************************/
  11417. switch(gunindex + 1)
  11418. {
  11419. case 0:
  11420. break;
  11421. case 1:
  11422. strcpy(fname, TxDefaultProfile_1_JSON );
  11423. break;
  11424. case 2:
  11425. strcpy(fname, TxDefaultProfile_2_JSON );
  11426. break;
  11427. default:
  11428. strcpy(fname, TxDefaultProfile_1_JSON );
  11429. break;
  11430. }
  11431. TxDefaultProfileFileIsNull=TRUE;
  11432. if((access(fname,F_OK))!=-1)
  11433. {
  11434. fptr1 = fopen(fname, "r");
  11435. c = 0;
  11436. c = fgetc(fptr1);
  11437. //DEBUG_INFO("c:%d\n",c);
  11438. rewind(fptr1);
  11439. if(c == EOF)
  11440. {
  11441. DEBUG_INFO("\n End of file reached.");
  11442. TxDefaultProfileFileIsNull=TRUE;
  11443. fclose(fptr1);
  11444. }
  11445. else
  11446. {
  11447. TxDefaultProfileFileIsNull=FALSE;
  11448. while(fscanf(fptr1, "%s", word) != EOF)
  11449. {
  11450. if(strcmp(word, "chargingProfileId") == 0)
  11451. {
  11452. n_chargingProfile = n_chargingProfile + 1;
  11453. }
  11454. }
  11455. rewind(fptr1);
  11456. //search Charging Profile Element
  11457. int i = 0;
  11458. int j = 0;
  11459. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11460. #if 0
  11461. /***********connectorId****************/
  11462. c = 0;
  11463. loc = strstr(sLineWord, "connectorId");
  11464. memset(sstr ,0, sizeof(sstr) );
  11465. while (loc[strlen("connectorId")+2+c] != ',')
  11466. {
  11467. sstr[c] = loc[strlen("connectorId")+2+c];
  11468. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11469. c++;
  11470. }
  11471. sstr[c] = '\0';
  11472. tempconnectorIdInt = atoi(sstr);
  11473. #endif
  11474. //***********chargingProfileId**************/
  11475. c = 0;
  11476. loc = strstr(sLineWord, "chargingProfileId");
  11477. //DEBUG_INFO("loc=%s\n",loc);
  11478. memset(sstr ,0, sizeof(sstr) );
  11479. if(loc != NULL)
  11480. {
  11481. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11482. {
  11483. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11484. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11485. c++;
  11486. }
  11487. sstr[c] = '\0';
  11488. tempchargingProfileId = atoi(sstr);
  11489. }
  11490. else
  11491. {
  11492. tempchargingProfileId = 0;
  11493. }
  11494. //***********stackLevel**************/
  11495. c = 0;
  11496. loc = strstr(sLineWord, "stackLevel");
  11497. //DEBUG_INFO("loc=%s\n",loc);
  11498. memset(sstr ,0, sizeof(sstr) );
  11499. if(loc != NULL)
  11500. {
  11501. while (loc[2+strlen("stackLevel")+c] != '\"')
  11502. {
  11503. sstr[c] = loc[2+strlen("stackLevel")+c];
  11504. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11505. c++;
  11506. }
  11507. sstr[c] = '\0';
  11508. tempstackLevel = atoi(sstr);
  11509. }
  11510. else
  11511. {
  11512. tempstackLevel = 0;
  11513. }
  11514. //***********chargingProfilePurpose **************/
  11515. c = 0;
  11516. loc = strstr(sLineWord, "chargingProfilePurpose");
  11517. //DEBUG_INFO("loc=%s\n",loc);
  11518. memset(sstr ,0, sizeof(sstr) );
  11519. if(loc != NULL)
  11520. {
  11521. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11522. {
  11523. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11524. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11525. c++;
  11526. }
  11527. sstr[c] = '\0';
  11528. strcpy(tempchargingProfilePurposeStr,sstr);
  11529. }
  11530. else
  11531. {
  11532. strcpy(tempchargingProfilePurposeStr,"");
  11533. }
  11534. //***********chargingProfileKind **************/
  11535. c = 0;
  11536. loc = strstr(sLineWord, "chargingProfileKind");
  11537. //DEBUG_INFO("loc=%s\n",loc);
  11538. memset(sstr ,0, sizeof(sstr) );
  11539. if(loc != NULL)
  11540. {
  11541. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11542. {
  11543. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11544. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11545. c++;
  11546. }
  11547. sstr[c] = '\0';
  11548. strcpy(tempchargingProfileKindStr,sstr);
  11549. }
  11550. else
  11551. {
  11552. strcpy(tempchargingProfileKindStr,"");
  11553. }
  11554. //***********recurrencyKind **************/
  11555. c = 0;
  11556. loc = strstr(sLineWord, "recurrencyKind");
  11557. //DEBUG_INFO("loc=%s\n",loc);
  11558. memset(sstr ,0, sizeof(sstr) );
  11559. if(loc != NULL)
  11560. {
  11561. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11562. {
  11563. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11564. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11565. c++;
  11566. }
  11567. sstr[c] = '\0';
  11568. strcpy(temprecurrencyKindStr,sstr);
  11569. }
  11570. else
  11571. {
  11572. strcpy(temprecurrencyKindStr,"");
  11573. }
  11574. //***********validFrom**************/
  11575. c = 0;
  11576. loc = strstr(sLineWord, "validFrom");
  11577. if(loc != NULL)
  11578. {
  11579. memset(sstr ,0, sizeof(sstr) );
  11580. while (loc[3+strlen("validFrom")+c] != '\"')
  11581. {
  11582. sstr[c] = loc[3+strlen("validFrom")+c];
  11583. c++;
  11584. }
  11585. sstr[c] = '\0';
  11586. strcpy(tempvalidFromStr,sstr);
  11587. }
  11588. else
  11589. {
  11590. strcpy(tempvalidFromStr,"");
  11591. }
  11592. //***********validFrom**************/
  11593. c = 0;
  11594. loc = strstr(sLineWord, "duration");
  11595. if(loc != NULL)
  11596. {
  11597. memset(sstr ,0, sizeof(sstr) );
  11598. while (loc[2+strlen("duration")+c] != ',')
  11599. {
  11600. sstr[c] = loc[2+strlen("duration")+c];
  11601. c++;
  11602. }
  11603. sstr[c] = '\0';
  11604. tempdurationInt = atoi(sstr);
  11605. }
  11606. else
  11607. {
  11608. tempdurationInt = 0;
  11609. }
  11610. //**********startSchedule**********/
  11611. c = 0;
  11612. loc = strstr(sLineWord, "startSchedule");
  11613. memset(sstr ,0, sizeof(sstr) );
  11614. while (loc[3+strlen("startSchedule")+c] != '\"')
  11615. {
  11616. sstr[c] = loc[3+strlen("startSchedule")+c];
  11617. c++;
  11618. }
  11619. sstr[c] = '\0';
  11620. strcpy(tempstartScheduleStr, sstr);
  11621. strcpy(TxDefaultProfileScheduleStr, sstr);
  11622. //**********chargingRateUnit**********/
  11623. c = 0;
  11624. loc = strstr(sLineWord, "chargingRateUnit");
  11625. memset(sstr ,0, sizeof(sstr) );
  11626. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  11627. {
  11628. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  11629. c++;
  11630. }
  11631. sstr[c] = '\0';
  11632. strcpy(tempchargingRateUnitStr, sstr);
  11633. //**********minChargingRate*******/
  11634. c = 0;
  11635. loc = strstr(sLineWord, "minChargingRate");
  11636. if(loc != NULL)
  11637. {
  11638. memset(sstr ,0, sizeof(sstr) );
  11639. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  11640. {
  11641. sstr[c] = loc[2+strlen("minChargingRate")+c];
  11642. c++;
  11643. }
  11644. sstr[c] = '\0';
  11645. tempminChargingRateFloat = atof(sstr);
  11646. }
  11647. else
  11648. {
  11649. tempminChargingRateFloat = 0.0;
  11650. }
  11651. //
  11652. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  11653. tp.tm_isdst = -1;
  11654. time_t utc = mktime(&tp);
  11655. time_t t = time(NULL);
  11656. diff_t = difftime(t, utc);
  11657. printf("diff between startScheduleStr and now =%f\n",diff_t);
  11658. //parsing strings to words
  11659. i = 0;
  11660. loc = strstr(sLineWord, "chargingSchedulePeriod");
  11661. loc = loc+3+strlen("chargingSchedulePeriod");
  11662. pch = strtok(loc ,"{");
  11663. while (pch != NULL)
  11664. {
  11665. strcpy(SchedulePeriodList[i], pch);
  11666. pch = strtok (NULL, "{");
  11667. i = i + 1;
  11668. }
  11669. n_SchedulePeriods = i;
  11670. for(int i=0;i<n_SchedulePeriods;i++)
  11671. {
  11672. //*************startPeriod****************/
  11673. c = 0;
  11674. loc = strstr(SchedulePeriodList[i], "startPeriod");
  11675. memset(sstr ,0, sizeof(sstr) );
  11676. while (loc[strlen("startPeriod")+2+c] != ',')
  11677. {
  11678. sstr[c] = loc[strlen("startPeriod")+2+c];
  11679. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11680. c++;
  11681. }
  11682. sstr[c] = '\0';
  11683. tempStartPeriodInt = atoi(sstr);
  11684. //*************limit****************/
  11685. c = 0;
  11686. loc = strstr(SchedulePeriodList[i], "limit");
  11687. memset(sstr ,0, sizeof(sstr) );
  11688. while (loc[strlen("limit")+2+c] != ',')
  11689. {
  11690. sstr[c] = loc[strlen("limit")+2+c];
  11691. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11692. c++;
  11693. }
  11694. sstr[c] = '\0';
  11695. tempLimitInt = atof(sstr);
  11696. //*************numberPhases****************/
  11697. c = 0;
  11698. loc = strstr(SchedulePeriodList[i], "numberPhases");
  11699. memset(sstr ,0, sizeof(sstr) );
  11700. while (loc[strlen("numberPhases")+2+c] != '}')
  11701. {
  11702. sstr[c] = loc[strlen("numberPhases")+2+c];
  11703. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11704. c++;
  11705. }
  11706. sstr[c] = '\0';
  11707. tempNumberPhasesInt = atoi(sstr);
  11708. if(j == 0)
  11709. {
  11710. TxDefaultProfile.Duration = tempdurationInt;
  11711. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  11712. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  11713. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  11714. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  11715. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  11716. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  11717. TxDefaultProfile_TEMP.TransactionId = 0;
  11718. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  11719. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  11720. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  11721. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  11722. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  11723. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  11724. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  11725. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  11726. }
  11727. else
  11728. {
  11729. //other stack level charging Profile
  11730. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  11731. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  11732. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  11733. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  11734. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  11735. }
  11736. }
  11737. if(MinChargingRate < tempminChargingRateFloat)
  11738. {
  11739. MinChargingRate = tempminChargingRateFloat;
  11740. }
  11741. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  11742. if(confirmPeriods < n_SchedulePeriods)
  11743. confirmPeriods = n_SchedulePeriods;
  11744. j = j + 1;
  11745. }
  11746. fclose(fptr1);
  11747. //Stacking Charging Profiles
  11748. for(int l=0; l <(j-1) ;l++)
  11749. {
  11750. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  11751. {
  11752. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  11753. {
  11754. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  11755. {
  11756. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  11757. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  11758. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  11759. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11760. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11761. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  11762. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  11763. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  11764. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11765. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11766. }
  11767. else
  11768. {
  11769. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  11770. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  11771. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  11772. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11773. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11774. }
  11775. }
  11776. }
  11777. }
  11778. //end of Stacking Charging Profiles
  11779. }
  11780. }// the end of ACCESS TxDefaultProfile
  11781. //****************************TxProfile************************************************/
  11782. switch(gunindex + 1)
  11783. {
  11784. case 0:
  11785. break;
  11786. case 1:
  11787. strcpy(fname, TxProfile_1_JSON );
  11788. break;
  11789. case 2:
  11790. strcpy(fname, TxProfile_2_JSON );
  11791. break;
  11792. default:
  11793. strcpy(fname, TxProfile_1_JSON );
  11794. break;
  11795. }
  11796. TxProfileIsNull=TRUE;
  11797. if((access(fname,F_OK))!=-1)
  11798. {
  11799. fptr1 = fopen(fname, "r");
  11800. c = 0;
  11801. c = fgetc(fptr1);
  11802. //DEBUG_INFO("c:%d\n",c);
  11803. rewind(fptr1);
  11804. if(c == EOF)
  11805. {
  11806. DEBUG_INFO("\n End of file reached.");
  11807. TxProfileIsNull=TRUE;
  11808. fclose(fptr1);
  11809. }
  11810. else
  11811. {
  11812. TxProfileIsNull=FALSE;
  11813. while(fscanf(fptr1, "%s", word) != EOF)
  11814. {
  11815. if(strcmp(word, "chargingProfileId") == 0)
  11816. {
  11817. n_chargingProfile = n_chargingProfile + 1;
  11818. }
  11819. }
  11820. rewind(fptr1);
  11821. //search Charging Profile Element
  11822. int i= 0;
  11823. int j= 0;
  11824. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11825. #if 0
  11826. /***********connectorId****************/
  11827. c = 0;
  11828. loc = strstr(sLineWord, "connectorId");
  11829. memset(sstr ,0, sizeof(sstr) );
  11830. while (loc[strlen("connectorId")+2+c] != ',')
  11831. {
  11832. sstr[c] = loc[strlen("connectorId")+2+c];
  11833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11834. c++;
  11835. }
  11836. sstr[c] = '\0';
  11837. tempconnectorIdInt = atoi(sstr);
  11838. #endif
  11839. //***********chargingProfileId**************/
  11840. c = 0;
  11841. loc = strstr(sLineWord, "chargingProfileId");
  11842. memset(sstr ,0, sizeof(sstr) );
  11843. if(loc != NULL)
  11844. {
  11845. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11846. {
  11847. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11848. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11849. c++;
  11850. }
  11851. sstr[c] = '\0';
  11852. tempchargingProfileId = atoi(sstr);
  11853. }
  11854. else
  11855. {
  11856. tempchargingProfileId = 0;
  11857. }
  11858. //***********transactionId **************/
  11859. c = 0;
  11860. loc = strstr(sLineWord, "transactionId");
  11861. //DEBUG_INFO("loc=%s\n",loc);
  11862. memset(sstr ,0, sizeof(sstr) );
  11863. if(loc != NULL)
  11864. {
  11865. while (loc[2+strlen("transactionId")+c] != '\"')
  11866. {
  11867. sstr[c] = loc[2+strlen("transactionId")+c];
  11868. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11869. c++;
  11870. }
  11871. sstr[c] = '\0';
  11872. temptransactionId = atoi(sstr);
  11873. }
  11874. else
  11875. {
  11876. temptransactionId = 0;
  11877. }
  11878. //***********stackLevel**************/
  11879. c = 0;
  11880. loc = strstr(sLineWord, "stackLevel");
  11881. //DEBUG_INFO("loc=%s\n",loc);
  11882. memset(sstr ,0, sizeof(sstr) );
  11883. if(loc != NULL)
  11884. {
  11885. while (loc[2+strlen("stackLevel")+c] != '\"')
  11886. {
  11887. sstr[c] = loc[2+strlen("stackLevel")+c];
  11888. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11889. c++;
  11890. }
  11891. sstr[c] = '\0';
  11892. tempstackLevel = atoi(sstr);
  11893. }
  11894. else
  11895. {
  11896. tempstackLevel = 0;
  11897. }
  11898. //***********chargingProfilePurpose **************/
  11899. c = 0;
  11900. loc = strstr(sLineWord, "chargingProfilePurpose");
  11901. //DEBUG_INFO("loc=%s\n",loc);
  11902. memset(sstr ,0, sizeof(sstr) );
  11903. if(loc != NULL)
  11904. {
  11905. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11906. {
  11907. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11908. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11909. c++;
  11910. }
  11911. sstr[c] = '\0';
  11912. strcpy(tempchargingProfilePurposeStr,sstr);
  11913. }
  11914. else
  11915. {
  11916. strcpy(tempchargingProfilePurposeStr,"");
  11917. }
  11918. //***********chargingProfileKind **************/
  11919. c = 0;
  11920. loc = strstr(sLineWord, "chargingProfileKind");
  11921. //DEBUG_INFO("loc=%s\n",loc);
  11922. memset(sstr ,0, sizeof(sstr) );
  11923. if(loc != NULL)
  11924. {
  11925. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11926. {
  11927. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11928. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11929. c++;
  11930. }
  11931. sstr[c] = '\0';
  11932. strcpy(tempchargingProfileKindStr,sstr);
  11933. }
  11934. else
  11935. {
  11936. strcpy(tempchargingProfileKindStr,"");
  11937. }
  11938. //***********recurrencyKind **************/
  11939. c = 0;
  11940. loc = strstr(sLineWord, "recurrencyKind");
  11941. //DEBUG_INFO("loc=%s\n",loc);
  11942. memset(sstr ,0, sizeof(sstr) );
  11943. if(loc != NULL)
  11944. {
  11945. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11946. {
  11947. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11948. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11949. c++;
  11950. }
  11951. sstr[c] = '\0';
  11952. strcpy(temprecurrencyKindStr,sstr);
  11953. }
  11954. else
  11955. {
  11956. strcpy(temprecurrencyKindStr,"");
  11957. }
  11958. //***********validFrom**************/
  11959. c = 0;
  11960. loc = strstr(sLineWord, "validFrom");
  11961. if(loc != NULL)
  11962. {
  11963. memset(sstr ,0, sizeof(sstr) );
  11964. while (loc[3+strlen("validFrom")+c] != '\"')
  11965. {
  11966. sstr[c] = loc[3+strlen("validFrom")+c];
  11967. c++;
  11968. }
  11969. sstr[c] = '\0';
  11970. strcpy(tempvalidFromStr,sstr);
  11971. }
  11972. else
  11973. {
  11974. strcpy(tempvalidFromStr,"");
  11975. }
  11976. //***********duration**************/
  11977. c = 0;
  11978. loc = strstr(sLineWord, "duration");
  11979. //DEBUG_INFO("loc=%s\n",loc);
  11980. memset(sstr ,0, sizeof(sstr) );
  11981. if(loc != NULL)
  11982. {
  11983. while (loc[2+strlen("duration")+c] != '\"')
  11984. {
  11985. sstr[c] = loc[2+strlen("duration")+c];
  11986. c++;
  11987. }
  11988. sstr[c] = '\0';
  11989. tempdurationInt = atoi(sstr);
  11990. }
  11991. else
  11992. {
  11993. tempdurationInt = 0;
  11994. }
  11995. //**********startSchedule**********/
  11996. c = 0;
  11997. loc = strstr(sLineWord, "startSchedule");
  11998. memset(sstr ,0, sizeof(sstr) );
  11999. while (loc[3+strlen("startSchedule")+c] != '\"')
  12000. {
  12001. sstr[c] = loc[3+strlen("startSchedule")+c];
  12002. c++;
  12003. }
  12004. sstr[c] = '\0';
  12005. strcpy(tempstartScheduleStr, sstr);
  12006. strcpy(TxProfileScheduleStr, sstr);
  12007. //**********chargingRateUnit**********/
  12008. c = 0;
  12009. loc = strstr(sLineWord, "chargingRateUnit");
  12010. memset(sstr ,0, sizeof(sstr) );
  12011. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12012. {
  12013. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12014. c++;
  12015. }
  12016. sstr[c] = '\0';
  12017. strcpy(tempchargingRateUnitStr, sstr);
  12018. //**********minChargingRate*******/
  12019. c = 0;
  12020. loc = strstr(sLineWord, "minChargingRate");
  12021. if(loc != NULL)
  12022. {
  12023. memset(sstr ,0, sizeof(sstr) );
  12024. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12025. {
  12026. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12027. c++;
  12028. }
  12029. sstr[c] = '\0';
  12030. tempminChargingRateFloat = atof(sstr);
  12031. }
  12032. else
  12033. {
  12034. tempminChargingRateFloat = 0.0;
  12035. }
  12036. //
  12037. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12038. tp.tm_isdst = -1;
  12039. time_t utc = mktime(&tp);
  12040. time_t t = time(NULL);
  12041. diff_t = difftime(t, utc);
  12042. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12043. //parsing strings to words
  12044. i = 0;
  12045. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12046. loc = loc+3+strlen("chargingSchedulePeriod");
  12047. pch = strtok(loc ,"{");
  12048. while (pch != NULL)
  12049. {
  12050. strcpy(SchedulePeriodList[i], pch);
  12051. pch = strtok (NULL, "{");
  12052. i = i + 1;
  12053. }
  12054. n_SchedulePeriods = i;
  12055. for(int i=0;i<n_SchedulePeriods;i++)
  12056. {
  12057. //*************startPeriod****************/
  12058. c = 0;
  12059. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12060. memset(sstr ,0, sizeof(sstr) );
  12061. while (loc[strlen("startPeriod")+2+c] != ',')
  12062. {
  12063. sstr[c] = loc[strlen("startPeriod")+2+c];
  12064. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12065. c++;
  12066. }
  12067. sstr[c] = '\0';
  12068. tempStartPeriodInt = atoi(sstr);
  12069. //*************limit****************/
  12070. c = 0;
  12071. loc = strstr(SchedulePeriodList[i], "limit");
  12072. memset(sstr ,0, sizeof(sstr) );
  12073. while (loc[strlen("limit")+2+c] != ',')
  12074. {
  12075. sstr[c] = loc[strlen("limit")+2+c];
  12076. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12077. c++;
  12078. }
  12079. sstr[c] = '\0';
  12080. tempLimitInt = atof(sstr);
  12081. //*************numberPhases****************/
  12082. c = 0;
  12083. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12084. memset(sstr ,0, sizeof(sstr) );
  12085. while (loc[strlen("numberPhases")+2+c] != '}')
  12086. {
  12087. sstr[c] = loc[strlen("numberPhases")+2+c];
  12088. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12089. c++;
  12090. }
  12091. sstr[c] = '\0';
  12092. tempNumberPhasesInt = atoi(sstr);
  12093. //TxProfile.Duration = durationInt;
  12094. TxProfile.TotalPeriod = n_SchedulePeriods;
  12095. TxProfile.Period[i].Limit = tempLimitInt;
  12096. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12097. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12098. }
  12099. if(MinChargingRate < tempminChargingRateFloat)
  12100. {
  12101. MinChargingRate = tempminChargingRateFloat;
  12102. }
  12103. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12104. if(confirmPeriods < n_SchedulePeriods)
  12105. confirmPeriods = n_SchedulePeriods;
  12106. if(j == 0)
  12107. {
  12108. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12109. TxProfile_TEMP.StackLevel = tempstackLevel;
  12110. TxProfile_TEMP.TransactionId = 0;
  12111. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  12112. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12113. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12114. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12115. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12116. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12117. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12118. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12119. }
  12120. }
  12121. fclose(fptr1);
  12122. }
  12123. }// the end of ACCESS TxProfile
  12124. //CompositeSchedule
  12125. int period=0;
  12126. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  12127. {
  12128. //TxProfile
  12129. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  12130. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  12131. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  12132. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  12133. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  12134. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  12135. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  12136. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  12137. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  12138. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  12139. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  12140. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  12141. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  12142. for(int k=0; k < TxProfile.TotalPeriod;k++)
  12143. {
  12144. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  12145. {
  12146. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  12147. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12148. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12149. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  12150. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12151. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12152. period = period + 1;
  12153. }
  12154. else
  12155. {
  12156. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  12157. {
  12158. }
  12159. else
  12160. {
  12161. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12162. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12163. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12164. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12165. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12166. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12167. period = period + 1;
  12168. }
  12169. }
  12170. }
  12171. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12172. {
  12173. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  12174. {
  12175. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  12176. {
  12177. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  12178. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  12179. }
  12180. else
  12181. {
  12182. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12183. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12184. }
  12185. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12186. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12187. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12188. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12189. period = period + 1;
  12190. }
  12191. }
  12192. }
  12193. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  12194. {
  12195. //TxDefaultProfile
  12196. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  12197. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  12198. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12199. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  12200. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  12201. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  12202. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  12203. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  12204. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  12205. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  12206. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  12207. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  12208. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  12209. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12210. {
  12211. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  12212. {
  12213. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12214. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12215. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12216. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12217. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12218. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12219. period = period + 1;
  12220. }
  12221. else
  12222. {
  12223. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  12224. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12225. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12226. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  12227. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12228. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12229. period = period + 1;
  12230. }
  12231. }
  12232. }
  12233. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  12234. {
  12235. //TxDefaultProfile
  12236. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  12237. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  12238. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12239. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  12240. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  12241. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  12242. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  12243. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  12244. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  12245. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  12246. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  12247. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  12248. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12249. {
  12250. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12251. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12252. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12253. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12254. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12255. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12256. period = period + 1;
  12257. }
  12258. }
  12259. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  12260. {
  12261. //ChargePointMaxProfile
  12262. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  12263. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  12264. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12265. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  12266. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  12267. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  12268. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  12269. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  12270. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  12271. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  12272. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  12273. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  12274. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  12275. {
  12276. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  12277. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  12278. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  12279. period = period + 1;
  12280. }
  12281. }
  12282. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  12283. {
  12284. //TxProfile
  12285. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  12286. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  12287. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  12288. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  12289. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  12290. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  12291. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  12292. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  12293. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  12294. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  12295. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  12296. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  12297. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  12298. for(int k=0; k < TxProfile.TotalPeriod;k++)
  12299. {
  12300. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  12301. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  12302. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  12303. }
  12304. }
  12305. confirmPeriods = period;
  12306. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  12307. 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,"
  12308. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  12309. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  12310. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  12311. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  12312. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  12313. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  12314. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  12315. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  12316. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  12317. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  12318. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  12319. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  12320. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  12321. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  12322. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  12323. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  12324. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  12325. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  12326. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  12327. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  12328. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  12329. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  12330. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  12331. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  12332. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  12333. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  12334. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  12335. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  12336. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  12337. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  12338. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  12339. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  12340. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  12341. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  12342. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  12343. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  12344. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  12345. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  12346. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  12347. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  12348. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  12349. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  12350. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  12351. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  12352. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  12353. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  12354. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  12355. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  12356. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  12357. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  12358. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  12359. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  12360. }
  12361. void LWS_Send(char * str)
  12362. {
  12363. //=====================================================
  12364. // Check InternetConn 0: disconnected, 1: connected
  12365. //====================================================
  12366. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  12367. {
  12368. DEBUG_INFO("\n offline now !!!\n");
  12369. return;
  12370. }
  12371. pthread_mutex_lock(&lock);
  12372. memset(SendBuffer,0,SendBufLen);
  12373. sprintf((char *)SendBuffer, "%s", str);
  12374. pthread_mutex_unlock(&lock);
  12375. lws_callback_on_writable(wsi_client);
  12376. lws_service(context, 10000);//timeout_ms
  12377. }