MessageHandler.c 511 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456
  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. extern struct lws *wsi_client;
  146. extern struct lws_context *context;
  147. #if 0
  148. extern unsigned char *SendBuffer;
  149. #endif
  150. extern unsigned char SendBuffer[4096];
  151. extern int SendBufLen;
  152. //extern map_t hashMap;
  153. //extern data_struct_t* mapItem; --- remove for temporally
  154. //extern data_struct_t mapItem[0];
  155. extern char *random_uuid( char buf[37] );
  156. extern void split(char **arr, char *str, const char *del);
  157. extern pthread_mutex_t mutex1;
  158. extern struct Charger_Info Charger;
  159. extern sqlite3 *db;
  160. int TransactionMessageAttemptsGet(void);
  161. int TransactionMessageRetryIntervalGet(void);
  162. int GetOcppConnStatus(void);
  163. void SetOcppConnStatus(uint8_t status);
  164. int updateSetting(char *key, char *value);
  165. int setKeyValue(char *key, char *value);
  166. void OCPP_get_TableAuthlocalAllData(void);
  167. void processUnkownKey(void);
  168. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  169. struct StructOCPPMeterValue
  170. {
  171. unsigned char TimeStamp[28];
  172. struct StructSampledValue SampledValue[10];
  173. };
  174. struct ClientTime
  175. {
  176. unsigned int Heartbeat;
  177. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  178. unsigned int StartTransaction;
  179. unsigned int StopTransaction;
  180. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  181. }clientTime;
  182. typedef union
  183. {
  184. //Operations Initiated by Central System
  185. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  186. struct
  187. {
  188. //CsMsgValue[0]
  189. unsigned char StatusNotificationReq :1; //bit 0,
  190. unsigned char StatusNotificationConf :1; //bit 0,
  191. unsigned char :6; //bit 2~7
  192. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  193. }CpinitiateMsg;
  194. CpinitiateMsg cpinitateMsg;
  195. //==========================================
  196. // Init all Enumeration & Mapping String
  197. //==========================================
  198. /*ChargePointErrorCode*/
  199. typedef enum {
  200. ConnectorLockFailure,
  201. EVCommunicationError,
  202. GroundFailure,
  203. HighTemperature,
  204. InternalError,
  205. LocalListConflict,
  206. NoError,
  207. OtherError,
  208. OverCurrentFailure,
  209. OverVoltage,
  210. PowerMeterFailure,
  211. PowerSwitchFailure,
  212. ReaderFailure,
  213. ResetFailure,
  214. UnderVoltage,
  215. WeakSignal
  216. } ChargePointErrorCode;
  217. #if 0
  218. static char *ChargePointErrorCodeStr[] = {
  219. MACROSTR(ConnectorLockFailure),
  220. MACROSTR(EVCommunicationError),
  221. MACROSTR(GroundFailure),
  222. MACROSTR(HighTemperature),
  223. MACROSTR(InternalError),
  224. MACROSTR(LocalListConflict),
  225. MACROSTR(NoError),
  226. MACROSTR(OtherError),
  227. MACROSTR(OverCurrentFailure),
  228. MACROSTR(OverVoltage),
  229. MACROSTR(PowerMeterFailure),
  230. MACROSTR(PowerSwitchFailure),
  231. MACROSTR(ReaderFailure),
  232. MACROSTR(ResetFailure),
  233. MACROSTR(UnderVoltage),
  234. MACROSTR(WeakSignal)
  235. };
  236. #endif
  237. /*ChargePointStatus*/
  238. typedef enum {
  239. Available =0,
  240. Preparing,
  241. Charging,
  242. SuspendedEVSE,
  243. SuspendedEV,
  244. Finishing,
  245. Reserved,
  246. Unavailable,
  247. Faulted
  248. } ChargePointStatus;
  249. static char * ChargePointStatusStr[] = {
  250. MACROSTR(Available),
  251. MACROSTR(Preparing),
  252. MACROSTR(Charging),
  253. MACROSTR(SuspendedEVSE),
  254. MACROSTR(SuspendedEV),
  255. MACROSTR(Finishing),
  256. MACROSTR(Reserved),
  257. MACROSTR(Unavailable),
  258. MACROSTR(Faulted)
  259. };
  260. /*AvailabilityType*/
  261. typedef enum {
  262. RegistrationStatus_Accepted,
  263. RegistrationStatus_Pending,
  264. RegistrationStatus_Rejected
  265. } RegistrationStatus;
  266. static char *RegistrationStatusStr[] = {
  267. MACROSTR(Accepted),
  268. MACROSTR(Pending),
  269. MACROSTR(Rejected)
  270. };
  271. /*AvailabilityType*/
  272. typedef enum {
  273. Inoperative,
  274. Operative
  275. } AvailabilityType;
  276. static char *AvailabilityTypeStr[] = {
  277. MACROSTR(Inoperative),
  278. MACROSTR(Operative)
  279. };
  280. /*AvailabilityStatus*/
  281. typedef enum {
  282. Accepted,
  283. Rejected,
  284. Scheduled
  285. } AvailabilityStatus;
  286. static char *AvailabilityStatusStr[] = {
  287. MACROSTR(Accepted),
  288. MACROSTR(Rejected),
  289. MACROSTR(Scheduled)
  290. };
  291. /*ConfigurationStatus*/
  292. typedef enum {
  293. ConfigurationStatus_Accepted,
  294. ConfigurationStatus_Rejected,
  295. RebootRequired,
  296. NotSupported
  297. } ConfigurationStatus;
  298. static char *ConfigurationStatusStr[] = {
  299. MACROSTR(Accepted),
  300. MACROSTR(Rejected),
  301. MACROSTR(RebootRequired),
  302. MACROSTR(NotSupported)
  303. };
  304. /*ClearCacheStatus*/
  305. typedef enum {
  306. ClearCacheStatus_Accepted,
  307. ClearCacheStatus_Rejected
  308. } ClearCacheStatus;
  309. static char *ClearCacheStatusStr[] = {
  310. MACROSTR(Accepted),
  311. MACROSTR(Rejected)
  312. };
  313. /*ChargingProfilePurposeType*/
  314. typedef enum {
  315. ChargePointMaxProfile,
  316. TxDefaultProfile,
  317. TxProfile
  318. } ChargingProfilePurposeType;
  319. static char *ChargingProfilePurposeTypeStr[] = {
  320. MACROSTR(ChargePointMaxProfile),
  321. MACROSTR(TxDefaultProfile),
  322. MACROSTR(TxProfile)
  323. };
  324. /*ChargingProfileStatus*/
  325. typedef enum {
  326. ChargingProfileStatus_Accepted,
  327. ChargingProfileStatus_Rejected,
  328. ChargingProfileStatus_NotSupported
  329. } ChargingProfileStatus;
  330. static char *ChargingProfileStatusStr[] = {
  331. MACROSTR(Accepted),
  332. MACROSTR(Rejected),
  333. MACROSTR(NotSupported)
  334. };
  335. /*ClearChargingProfileStatus*/
  336. typedef enum {
  337. ClearChargingProfileStatus_Accepted,
  338. ClearChargingProfileStatus_Unknown
  339. } ClearChargingProfileStatus;
  340. static char *ClearChargingProfileStatusStr[] = {
  341. MACROSTR(Accepted),
  342. MACROSTR(Unknown)
  343. };
  344. /*GetCompositeScheduleStatus*/
  345. typedef enum {
  346. GetCompositeScheduleStatus_Accepted,
  347. GetCompositeScheduleStatus_Rejected
  348. } GetCompositeScheduleStatus;
  349. static char *GetCompositeScheduleStatusStr[] = {
  350. MACROSTR(Accepted),
  351. MACROSTR(Rejected)
  352. };
  353. /*ChargingRateUnitType*/
  354. typedef enum {
  355. ChargingRateUnitType_W,
  356. ChargingRateUnitType_A
  357. } ChargingRateUnitType;
  358. /*AuthorizationStatus*/
  359. typedef enum {
  360. AuthorizationStatus_Accepted ,
  361. AuthorizationStatus_Blocked ,
  362. AuthorizationStatus_Expired ,
  363. AuthorizationStatus_Invalid ,
  364. AuthorizationStatus_ConcurrentTx
  365. } AuthorizationStatus;
  366. /*UpdateType*/
  367. typedef enum {
  368. Differential ,
  369. Full
  370. } UpdateType;
  371. static char *UpdateTypeStr[] = {
  372. MACROSTR(Differential),
  373. MACROSTR(Full)
  374. };
  375. /*UpdateStatus*/
  376. typedef enum {
  377. UpdateStatus_Accepted ,
  378. UpdateStatus_Failed ,
  379. UpdateStatus_NotSupported ,
  380. UpdateStatus_VersionMismatch
  381. } UpdateStatus;
  382. static char *UpdateStatusStr[] = {
  383. MACROSTR(Accepted),
  384. MACROSTR(Failed),
  385. MACROSTR(NotSupported),
  386. MACROSTR(VersionMismatch)
  387. };
  388. /*RemoteStartStopStatus*/
  389. typedef enum {
  390. RemoteStartStopStatus_Accepted,
  391. RemoteStartStopStatus_Rejected
  392. } RemoteStartStopStatus;
  393. static char *RemoteStartStopStatusStr[] = {
  394. MACROSTR(Accepted),
  395. MACROSTR(Rejected)
  396. };
  397. /*ReservationStatus*/
  398. typedef enum {
  399. ReservationStatus_Accepted,
  400. ReservationStatus_Faulted,
  401. ReservationStatus_Occupied,
  402. ReservationStatus_Rejected,
  403. ReservationStatus_Unavailable
  404. } ReservationStatus;
  405. static char *ReservationStatusStr[] = {
  406. MACROSTR(Accepted),
  407. MACROSTR(Faulted),
  408. MACROSTR(Occupied),
  409. MACROSTR(Rejected),
  410. MACROSTR(Unavailable)
  411. };
  412. /*ResetType*/
  413. typedef enum {
  414. Hard,
  415. Soft
  416. } ResetType;
  417. static char *ResetTypeStr[] = {
  418. MACROSTR(Hard),
  419. MACROSTR(Soft)
  420. };
  421. /*ResetStatus*/
  422. typedef enum {
  423. ResetStatus_Accepted,
  424. ResetStatus_Rejected
  425. } ResetStatus;
  426. static char *ResetStatusStr[] = {
  427. MACROSTR(Accepted),
  428. MACROSTR(Rejected)
  429. };
  430. /*DiagnosticsStatus*/
  431. typedef enum {
  432. DiagnosticsStatus_Idle,
  433. DiagnosticsStatus_Uploaded,
  434. DiagnosticsStatus_UploadFailed,
  435. DiagnosticsStatus_Uploading
  436. } DiagnosticsStatus;
  437. static char * DiagnosticsStatusStr[] = {
  438. MACROSTR(Idle),
  439. MACROSTR(Uploaded),
  440. MACROSTR(UploadFailed),
  441. MACROSTR(Uploading)
  442. };
  443. /*FirmwareStatus*/
  444. typedef enum {
  445. FirmwareStatus_Downloaded,
  446. FirmwareStatus_DownloadFailed,
  447. FirmwareStatus_Downloading,
  448. FirmwareStatus_Idle,
  449. FirmwareStatus_InstallationFailed,
  450. FirmwareStatus_Installing,
  451. FirmwareStatus_Installed
  452. } FirmwareStatus;
  453. static char * FirmwareStatusStr[] = {
  454. MACROSTR(Downloaded),
  455. MACROSTR(DownloadFailed),
  456. MACROSTR(Downloading),
  457. MACROSTR(Idle),
  458. MACROSTR(InstallationFailed),
  459. MACROSTR(Installing),
  460. MACROSTR(Installed)
  461. };
  462. /*MessageTrigger*/
  463. typedef enum {
  464. BootNotification,
  465. DiagnosticsStatusNotification,
  466. FirmwareStatusNotification,
  467. Heartbeat,
  468. MeterValues,
  469. StatusNotification
  470. } MessageTrigger;
  471. static char * MessageTriggerStr[] = {
  472. MACROSTR(BootNotification),
  473. MACROSTR(DiagnosticsStatusNotification),
  474. MACROSTR(FirmwareStatusNotification),
  475. MACROSTR(Heartbeat),
  476. MACROSTR(MeterValues),
  477. MACROSTR(StatusNotification)
  478. };
  479. /*TriggerMessageStatus*/
  480. typedef enum {
  481. TriggerMessageStatus_Accepted ,
  482. TriggerMessageStatus_Rejected ,
  483. TriggerMessageStatus_NotImplemented
  484. } TriggerMessageStatus;
  485. static char * TriggerMessageStatusStr[] = {
  486. MACROSTR(Accepted),
  487. MACROSTR(Rejected),
  488. MACROSTR(NotImplemented)
  489. };
  490. /*UnlockStatus*/
  491. typedef enum {
  492. Unlocked,
  493. UnlockFailed,
  494. UnlockStatus_NotSupported
  495. } UnlockStatus;
  496. static char * UnlockStatusStr[] = {
  497. MACROSTR(Unlocked),
  498. MACROSTR(UnlockFailed),
  499. MACROSTR(NotSupported)
  500. };
  501. /*StopTransactionReason*/
  502. typedef enum {
  503. EmergencyStop,
  504. EVDisconnected,
  505. HardReset,
  506. Local,
  507. Other,
  508. PowerLoss,
  509. Reboot,
  510. Remote,
  511. SoftReset,
  512. UnlockCommand,
  513. DeAuthorized
  514. } StopTransactionReason;
  515. static char * StopTransactionReasonStr[] = {
  516. MACROSTR(EmergencyStop),
  517. MACROSTR(EVDisconnected),
  518. MACROSTR(HardReset),
  519. MACROSTR(Local),
  520. MACROSTR(Other),
  521. MACROSTR(PowerLoss),
  522. MACROSTR(Reboot),
  523. MACROSTR(Remote),
  524. MACROSTR(SoftReset),
  525. MACROSTR(UnlockCommand),
  526. MACROSTR(DeAuthorized)
  527. };
  528. /*CancelReservationStatus*/
  529. typedef enum {
  530. CancelReservationStatus_Accepted,
  531. CancelReservationStatus_Rejected
  532. } CancelReservationStatus;
  533. static char * CancelReservationStatusStr[] = {
  534. MACROSTR(Accepted),
  535. MACROSTR(Rejected)
  536. };
  537. /*ReadingContext*/
  538. typedef enum {
  539. ReadingContext_Interruption_Begin,
  540. ReadingContext_Interruption_End,
  541. ReadingContext_Other,
  542. ReadingContext_Sample_Clock,
  543. ReadingContext_Sample_Periodic ,
  544. ReadingContext_Transaction_Begin ,
  545. ReadingContext_Transaction_End,
  546. ReadingContext_Trigger
  547. } ReadingContext;
  548. static char * ReadingContextStr[] = {
  549. MACROSTR(Interruption.Begin),
  550. MACROSTR(Interruption.End),
  551. MACROSTR(Other),
  552. MACROSTR(Sample.Clock),
  553. MACROSTR(Sample.Periodic),
  554. MACROSTR(Transaction.Begin),
  555. MACROSTR(Transaction.End),
  556. MACROSTR(Trigger)
  557. };
  558. /*ValueFormat*/
  559. typedef enum {
  560. Raw,
  561. SignedData
  562. } ValueFormat;
  563. static char * ValueFormatStr[] = {
  564. MACROSTR(Raw),
  565. MACROSTR(SignedData)
  566. };
  567. /*Measurand*/
  568. typedef enum {
  569. Current_Export ,
  570. Current_Import,
  571. Current_Offered,
  572. Energy_Active_Export_Register,
  573. Energy_Active_Import_Register,
  574. Energy_Reactive_Export_Register,
  575. Energy_Reactive_Import_Register,
  576. Energy_Active_Export_Interval,
  577. Energy_Active_Import_Interval,
  578. Energy_Reactive_Export_Interval,
  579. Energy_Reactive_Import_Interval,
  580. Frequency,
  581. Power_Active_Export ,
  582. Power_Active_Import,
  583. Power_Factor,
  584. Power_Offered,
  585. Power_Reactive_Export,
  586. Power_Reactive_Import,
  587. RPM,
  588. SoC,
  589. Temperature ,
  590. Voltage
  591. } Measurand;
  592. static char * MeasurandStr[] = {
  593. MACROSTR(Current.Export),
  594. MACROSTR(Current.Import),
  595. MACROSTR(Current.Offered),
  596. MACROSTR(Energy.Active.Export.Register),
  597. MACROSTR(Energy.Active.Import.Register),
  598. MACROSTR(Energy.Reactive.Export.Register),
  599. MACROSTR(Energy.Reactive.Import.Register),
  600. MACROSTR(Energy.Active.Export.Interval),
  601. MACROSTR(Energy.Active.Import.Interval),
  602. MACROSTR(Energy.Reactive.Export.Interval),
  603. MACROSTR(Energy.Reactive.Import.Interval),
  604. MACROSTR(Frequency),
  605. MACROSTR(Power.Active.Export),
  606. MACROSTR(Power.Active.Import),
  607. MACROSTR(Power.Factor),
  608. MACROSTR(Power.Offered),
  609. MACROSTR(Power.Reactive.ExportMACROSTR),
  610. MACROSTR(Power.Reactive.Import),
  611. MACROSTR(RPM),
  612. MACROSTR(SoC),
  613. MACROSTR(Temperature),
  614. MACROSTR(Voltage)
  615. };
  616. /*Location*/
  617. typedef enum {
  618. Location_Body,
  619. Location_Cable,
  620. Location_EV,
  621. Location_Inlet ,
  622. Location_Outlet
  623. } Location;
  624. static char * LocationStr[] = {
  625. MACROSTR(Body),
  626. MACROSTR(Cable),
  627. MACROSTR(EV),
  628. MACROSTR(Inlet),
  629. MACROSTR(Outlet)
  630. };
  631. /*Phase*/
  632. typedef enum {
  633. L1,
  634. L2,
  635. L3,
  636. N,
  637. L1_N,
  638. L2_N,
  639. L3_N,
  640. L1_L2,
  641. L2_L3,
  642. L3_L1
  643. } Phase;
  644. static char * PhaseStr[] = {
  645. MACROSTR(L1),
  646. MACROSTR(L2),
  647. MACROSTR(L3),
  648. MACROSTR(N),
  649. MACROSTR(L1-N),
  650. MACROSTR(L2-N),
  651. MACROSTR(L3-N),
  652. MACROSTR(L1-L2),
  653. MACROSTR(L2-L3),
  654. MACROSTR(L3-L1)
  655. };
  656. /*UnitOfMeasure*/
  657. typedef enum {
  658. UnitOfMeasure_Wh,
  659. UnitOfMeasure_kWh ,
  660. UnitOfMeasure_varh ,
  661. UnitOfMeasure_kvarh ,
  662. UnitOfMeasure_W ,
  663. UnitOfMeasure_kW ,
  664. UnitOfMeasure_VA ,
  665. UnitOfMeasure_kVA ,
  666. UnitOfMeasure_var ,
  667. UnitOfMeasure_kvar ,
  668. UnitOfMeasure_A ,
  669. UnitOfMeasure_V ,
  670. UnitOfMeasure_Celsius ,
  671. UnitOfMeasure_Fahrenheit ,
  672. UnitOfMeasure_K ,
  673. UnitOfMeasure_Percent
  674. } UnitOfMeasure;
  675. static char * UnitOfMeasureStr[] = {
  676. MACROSTR(Wh),
  677. MACROSTR(kWh),
  678. MACROSTR(varh),
  679. MACROSTR(kvarh),
  680. MACROSTR(W),
  681. MACROSTR(kW),
  682. MACROSTR(VA),
  683. MACROSTR(kVA),
  684. MACROSTR(var),
  685. MACROSTR(kvar),
  686. MACROSTR(A),
  687. MACROSTR(V),
  688. MACROSTR(Celsius),
  689. MACROSTR(Fahrenheit),
  690. MACROSTR(K),
  691. MACROSTR(Percent)
  692. };
  693. /*Configuration enum*/
  694. enum CoreProfile {
  695. AllowOfflineTxForUnknownId=0,
  696. AuthorizationCacheEnabled,
  697. AuthorizeRemoteTxRequests,
  698. BlinkRepeat,
  699. ClockAlignedDataInterval,
  700. ConnectionTimeOut,
  701. GetConfigurationMaxKeys,
  702. HeartbeatInterval,
  703. LightIntensity,
  704. LocalAuthorizeOffline,
  705. LocalPreAuthorize,
  706. MaxEnergyOnInvalidId,
  707. MeterValuesAlignedData,
  708. MeterValuesAlignedDataMaxLength,
  709. MeterValuesSampledData,
  710. MeterValuesSampledDataMaxLength,
  711. MeterValueSampleInterval,
  712. MinimumStatusDuration,
  713. NumberOfConnectors,
  714. ResetRetries,
  715. ConnectorPhaseRotation,
  716. ConnectorPhaseRotationMaxLength,
  717. StopTransactionOnEVSideDisconnect,
  718. StopTransactionOnInvalidId,
  719. StopTxnAlignedData,
  720. StopTxnAlignedDataMaxLength,
  721. StopTxnSampledData,
  722. StopTxnSampledDataMaxLength,
  723. SupportedFeatureProfiles,
  724. SupportedFeatureProfilesMaxLength,
  725. TransactionMessageAttempts,
  726. TransactionMessageRetryInterval,
  727. UnlockConnectorOnEVSideDisconnect,
  728. WebSocketPingInterval,
  729. _CoreProfile_CNT
  730. };
  731. enum LocalAuthListManagementProfile{
  732. LocalAuthListEnabled=0,
  733. LocalAuthListMaxLength,
  734. SendLocalListMaxLength,
  735. _LocalAuthListManagementProfile_CNT
  736. };
  737. enum ReservationProfile{
  738. ReserveConnectorZeroSupported
  739. };
  740. enum SmartChargingProfile{
  741. ChargeProfileMaxStackLevel,
  742. ChargingScheduleAllowedChargingRateUnit,
  743. ChargingScheduleMaxPeriods,
  744. ConnectorSwitch3to1PhaseSupported,
  745. MaxChargingProfilesInstalled
  746. };
  747. enum ChargerSystemStatus{
  748. ChargerSystemStatus_Booting,
  749. ChargerSystemStatus_Idle,
  750. ChargerSystemStatus_Authorizing,
  751. ChargerSystemStatus_Preparing,
  752. ChargerSystemStatus_Charging,
  753. ChargerSystemStatus_Terminating,
  754. ChargerSystemStatus_Alarm,
  755. ChargerSystemStatus_Fault
  756. };
  757. enum GetConfigurationKey {
  758. GetConfiguration_AllowOfflineTxForUnknownId=0,
  759. GetConfiguration_AuthorizationCacheEnabled,
  760. GetConfiguration_AuthorizeRemoteTxRequests,
  761. GetConfiguration_BlinkRepeat,
  762. GetConfiguration_ClockAlignedDataInterval,
  763. GetConfiguration_ConnectionTimeOut,
  764. GetConfiguration_GetConfigurationMaxKeys,
  765. GetConfiguration_HeartbeatInterval,
  766. GetConfiguration_LightIntensity,
  767. GetConfiguration_LocalAuthorizeOffline,
  768. GetConfiguration_LocalPreAuthorize,
  769. GetConfiguration_MaxEnergyOnInvalidId,
  770. GetConfiguration_MeterValuesAlignedData,
  771. GetConfiguration_MeterValuesAlignedDataMaxLength,
  772. GetConfiguration_MeterValuesSampledData,
  773. GetConfiguration_MeterValuesSampledDataMaxLength,
  774. GetConfiguration_MeterValueSampleInterval,
  775. GetConfiguration_MinimumStatusDuration,
  776. GetConfiguration_NumberOfConnectors,
  777. GetConfiguration_ResetRetries,
  778. GetConfiguration_ConnectorPhaseRotation,
  779. GetConfiguration_ConnectorPhaseRotationMaxLength,
  780. GetConfiguration_StopTransactionOnEVSideDisconnect,
  781. GetConfiguration_StopTransactionOnInvalidId,
  782. GetConfiguration_StopTxnAlignedData,
  783. GetConfiguration_StopTxnAlignedDataMaxLength,
  784. GetConfiguration_StopTxnSampledData,
  785. GetConfiguration_StopTxnSampledDataMaxLength,
  786. GetConfiguration_SupportedFeatureProfiles,
  787. GetConfiguration_SupportedFeatureProfilesMaxLength,
  788. GetConfiguration_TransactionMessageAttempts,
  789. GetConfiguration_TransactionMessageRetryInterval,
  790. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  791. GetConfiguration_WebSocketPingInterval,
  792. GetConfiguration_LocalAuthListEnabled,
  793. GetConfiguration_LocalAuthListMaxLength,
  794. GetConfiguration_SendLocalListMaxLength,
  795. GetConfiguration_ReserveConnectorZeroSupported,
  796. GetConfiguration_ChargeProfileMaxStackLevel,
  797. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  798. GetConfiguration_ChargingScheduleMaxPeriods,
  799. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  800. GetConfiguration_MaxChargingProfilesInstalled,
  801. };
  802. //GetConfiguration Array
  803. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  804. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  805. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  806. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  807. //==========================================
  808. // Init all share memory
  809. //==========================================
  810. int InitShareMemory()
  811. {
  812. int result = PASS;
  813. int MeterSMId;
  814. //printf("1\n");
  815. //creat ShmSysConfigAndInfo
  816. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  817. {
  818. #ifdef SystemLogMessage
  819. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  820. #endif
  821. result = FAIL;
  822. }
  823. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  824. {
  825. #ifdef SystemLogMessage
  826. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  827. #endif
  828. result = FAIL;
  829. }
  830. else
  831. {}
  832. //printf("2\n");
  833. //creat ShmStatusCodeData
  834. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  835. {
  836. #ifdef SystemLogMessage
  837. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  838. #endif
  839. result = FAIL;
  840. }
  841. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  842. {
  843. #ifdef SystemLogMessage
  844. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  845. #endif
  846. result = FAIL;
  847. }
  848. else
  849. {}
  850. //printf("3\n");
  851. //creat ShmPsuData
  852. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  853. {
  854. #ifdef SystemLogMessage
  855. DEBUG_ERROR("shmget ShmPsuData NG\n");
  856. #endif
  857. result = FAIL;
  858. }
  859. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  860. {
  861. #ifdef SystemLogMessage
  862. DEBUG_ERROR("shmat ShmPsuData NG\n");
  863. #endif
  864. result = FAIL;
  865. }
  866. else
  867. {}
  868. //creat ShmOCPP16Data
  869. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  870. {
  871. #ifdef SystemLogMessage
  872. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  873. #endif
  874. result = FAIL;
  875. }
  876. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  877. {
  878. #ifdef SystemLogMessage
  879. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  880. #endif
  881. result = FAIL;
  882. }
  883. else
  884. {}
  885. /****************************** For Initial Settings************************************************/
  886. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  887. //memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY));
  888. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  889. {
  890. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  891. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  892. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  893. }
  894. // Charger PRE_SYS_MODE
  895. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  896. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  897. clientTime.Heartbeat=time((time_t*)NULL);
  898. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  899. {
  900. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  901. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  902. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  903. }
  904. //HeartBeatWaitTime = 10;
  905. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  906. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  907. // allocate Configuration memory address
  908. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  909. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  910. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  911. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  912. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  913. {
  914. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  915. DEBUG_INFO("DC ...\n");
  916. }
  917. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  918. {
  919. SystemInitial = AC_QUANTITY;
  920. DEBUG_INFO("AC ...\n");
  921. }
  922. //Status Setting
  923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  924. {
  925. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  926. }
  927. for (int index = 0; index < CCS_QUANTITY; index++)
  928. {
  929. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  930. }
  931. for (int index = 0; index < GB_QUANTITY; index++)
  932. {
  933. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  934. }
  935. for (int index = 0; index < AC_QUANTITY; index++)
  936. {
  937. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  938. }
  939. //memset(unknownkey, 0, 10);
  940. return result;
  941. }
  942. int ProcessShareMemory()
  943. {
  944. if(InitShareMemory() == FAIL)
  945. {
  946. #ifdef SystemLogMessage
  947. DEBUG_ERROR("InitShareMemory NG\n");
  948. #endif
  949. if(ShmStatusCodeData!=NULL)
  950. {
  951. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  952. }
  953. sleep(5);
  954. return FAIL;
  955. }
  956. return PASS;
  957. }
  958. //---------------------------------------------
  959. // new:
  960. // enum SYSTEM_STATUS
  961. // {
  962. // SYS_MODE_BOOTING = 0,
  963. // SYS_MODE_IDLE = 1,
  964. // SYS_MODE_AUTHORIZING = 2,
  965. // SYS_MODE_PREPARING = 3,
  966. // SYS_MODE_CHARGING = 4,
  967. // SYS_MODE_TERMINATING = 5,
  968. // SYS_MODE_ALARM = 6,
  969. // SYS_MODE_FAULT = 7,
  970. // SYS_MODE_RESERVATION = 8,
  971. // SYS_MODE_BOOKING = 9,
  972. // SYS_MODE_MAINTAIN = 10,
  973. // SYS_MODE_DEBUG = 11,
  974. // SYS_MODE_REASSIGN_CHECK = 12,
  975. // SYS_MODE_REASSIGN = 13,
  976. // SYS_MODE_PRECHARGE = 14,
  977. // SYS_MODE_PREPARING_EV = 15,
  978. // SYS_MODE_PREPARING_EVSE = 16,
  979. // SYS_MODE_COMPLETE = 17
  980. // };
  981. //
  982. // old:
  983. // enum _SYSTEM_STATUS
  984. // {
  985. // S_BOOTING = 0,
  986. // S_IDLE, =1
  987. // S_AUTHORIZING, =2
  988. // S_REASSIGN_CHECK, =3
  989. // S_REASSIGN, =4
  990. // S_PRECHARGE, =5
  991. // S_PREPARING_FOR_EV, =6
  992. // S_PREPARING_FOR_EVSE, =7
  993. // S_CHARGING, =8
  994. // S_TERMINATING, =9
  995. // S_COMPLETE, =10
  996. // S_ALARM, =11
  997. // S_FAULT =12
  998. // };
  999. //
  1000. //-----------------------------------------
  1001. void CheckSystemValue(void)
  1002. {
  1003. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1004. int IdleModeCnt = 0;
  1005. char filenmae[100]={0};
  1006. char str[100]={0};
  1007. //===============================
  1008. // send Heartbeat
  1009. //===============================
  1010. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1011. {
  1012. //parameter for test
  1013. sendHeartbeatRequest(0);
  1014. //==============================================
  1015. // Reset Waiting Time
  1016. //==============================================
  1017. clientTime.Heartbeat=time((time_t*)NULL);
  1018. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1019. }
  1020. //==============================================
  1021. // Update firmware request
  1022. //==============================================
  1023. if(isUpdateRequest == TRUE )
  1024. {
  1025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1026. {
  1027. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1028. {
  1029. //check SystemStatus
  1030. /*************************DC*******************************/
  1031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1032. {
  1033. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1034. {
  1035. IdleModeCnt = IdleModeCnt + 1;
  1036. }
  1037. }
  1038. for (int index = 0; index < CCS_QUANTITY; index++)
  1039. {
  1040. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1041. {
  1042. IdleModeCnt = IdleModeCnt + 1;
  1043. }
  1044. }
  1045. for (int index = 0; index < GB_QUANTITY; index++)
  1046. {
  1047. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1048. {
  1049. IdleModeCnt = IdleModeCnt + 1;
  1050. }
  1051. }
  1052. }
  1053. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1054. {
  1055. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1056. isUpdateRequest = FALSE;
  1057. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1058. }
  1059. }
  1060. else
  1061. {
  1062. /*************************AC*******************************/
  1063. for (int index = 0; index < AC_QUANTITY; index++)
  1064. {
  1065. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1066. {
  1067. IdleModeCnt = IdleModeCnt + 1;
  1068. }
  1069. }
  1070. if(IdleModeCnt == AC_QUANTITY)
  1071. {
  1072. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1073. isUpdateRequest = FALSE;
  1074. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1075. }
  1076. }
  1077. }
  1078. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1079. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1080. {
  1081. //===============================
  1082. // CSU Trigger Reset Conf
  1083. //===============================
  1084. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1085. {
  1086. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1087. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1088. {
  1089. server_sign = FALSE;
  1090. }
  1091. }
  1092. //===============================
  1093. // CSU Trigger Authorize Request
  1094. //===============================
  1095. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1096. {
  1097. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1098. {
  1099. sendAuthorizeRequest(0);
  1100. authorizeRetryTimes = authorizeRetryTimes + 1;
  1101. // authenrequest = TRUE
  1102. if(authorizeRetryTimes < 3)
  1103. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1104. }
  1105. }
  1106. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1107. {
  1108. authorizeRetryTimes = 0;
  1109. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1110. server_sign = FALSE;
  1111. }
  1112. //===============================
  1113. // CSU Trigger Smart Charging Profilw
  1114. //===============================
  1115. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1116. {
  1117. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1118. GetChargingProfileRequest(gun_index);
  1119. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1120. }
  1121. //==============================================
  1122. // Charger start transaction
  1123. //==============================================
  1124. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1125. {
  1126. sendStartTransactionRequest(gun_index);
  1127. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1128. clientTime.StartTransaction = time((time_t*)NULL);
  1129. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1130. }
  1131. //==============================================
  1132. // Charger stop transaction
  1133. //==============================================
  1134. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1135. {
  1136. sendStopTransactionRequest(gun_index);
  1137. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1138. clientTime.StopTransaction = time((time_t*)NULL);
  1139. }
  1140. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1141. //==============================================
  1142. // Charger status report
  1143. //==============================================
  1144. /* Check Mode Change */
  1145. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1146. {
  1147. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1148. {
  1149. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1150. {
  1151. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1152. {
  1153. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1154. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1155. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1156. statusModeChage[gun_index] = TRUE;
  1157. }
  1158. }
  1159. }
  1160. for (int index = 0; index < CCS_QUANTITY; index++)
  1161. {
  1162. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1163. {
  1164. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1165. {
  1166. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1167. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1168. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1169. statusModeChage[gun_index] = TRUE;
  1170. }
  1171. }
  1172. }
  1173. for (int index = 0; index < GB_QUANTITY; index++)
  1174. {
  1175. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1176. {
  1177. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1178. {
  1179. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1180. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1181. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1182. statusModeChage[gun_index] = TRUE;
  1183. }
  1184. }
  1185. }
  1186. }
  1187. else //AC
  1188. {
  1189. for (int index = 0; index < AC_QUANTITY; index++)
  1190. {
  1191. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1192. {
  1193. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1194. {
  1195. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1196. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1197. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1198. statusModeChage[gun_index] = TRUE;
  1199. }
  1200. }
  1201. }// END OF FOR
  1202. }// END OF ELSE
  1203. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1204. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1205. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1206. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1207. {
  1208. if(SystemInitial != 0)
  1209. SystemInitial = SystemInitial -1;
  1210. //GunStatusInterval= GunStatusInterval* gun_index;
  1211. sendStatusNotificationRequest(gun_index);
  1212. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1213. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1214. statusModeChage[gun_index] = FALSE;
  1215. //sleep(30); // sleep for 30 seconds
  1216. }
  1217. //==============================================
  1218. // Meter report
  1219. //==============================================
  1220. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1221. {
  1222. //check Transaction active
  1223. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1224. {
  1225. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1226. {
  1227. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1228. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1229. {
  1230. meterValueSend[gun_index] =1;
  1231. }
  1232. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1233. {
  1234. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1235. if((access(filenmae,F_OK))!=-1)
  1236. {
  1237. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1238. sprintf(str,"rm -f %s",filenmae);
  1239. system(str);
  1240. }
  1241. }
  1242. }// End for CHAdeMO
  1243. for (int index = 0; index < CCS_QUANTITY; index++)
  1244. {
  1245. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1246. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1247. {
  1248. meterValueSend[gun_index] =1;
  1249. }
  1250. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1251. {
  1252. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1253. if((access(filenmae,F_OK))!=-1)
  1254. {
  1255. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1256. sprintf(str,"rm -f %s",filenmae);
  1257. system(str);
  1258. }
  1259. }
  1260. } // End for CCS
  1261. for (int index = 0; index < GB_QUANTITY; index++)
  1262. {
  1263. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1264. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1265. {
  1266. meterValueSend[gun_index] =1;
  1267. }
  1268. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1269. {
  1270. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1271. if((access(filenmae,F_OK))!=-1)
  1272. {
  1273. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1274. sprintf(str,"rm -f %s",filenmae);
  1275. system(str);
  1276. }
  1277. }
  1278. }// End for GB
  1279. }
  1280. else
  1281. {
  1282. for (int index = 0; index < AC_QUANTITY; index++)
  1283. {
  1284. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1285. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1286. {
  1287. meterValueSend[gun_index] =1;
  1288. }
  1289. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1290. {
  1291. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1292. if((access(filenmae,F_OK))!=-1)
  1293. {
  1294. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1295. sprintf(str,"rm -f %s",filenmae);
  1296. system(str);
  1297. }
  1298. }
  1299. }//End for AC
  1300. }//END OF ELSE
  1301. // sleep(1);
  1302. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1303. if(meterValueSend[gun_index] == 1)
  1304. sendMeterValuesRequest(gun_index);
  1305. }
  1306. //==============================================
  1307. // Check Connector reserved
  1308. //==============================================
  1309. //===============================
  1310. // Check if Reserve is expired
  1311. //===============================
  1312. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1313. {
  1314. double diff_t;
  1315. struct tm tp;
  1316. // current time
  1317. time_t t = time(NULL);
  1318. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1319. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1320. tp.tm_isdst = -1;
  1321. time_t utc = mktime(&tp);
  1322. diff_t = difftime(utc, t);
  1323. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1324. if(diff_t <= 0)
  1325. {
  1326. DEBUG_INFO("reserve expired !!! \n");
  1327. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1328. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1329. }
  1330. #if 0
  1331. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1332. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1333. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1334. {
  1335. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1336. }
  1337. else
  1338. {
  1339. //check Transaction active
  1340. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1341. {
  1342. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1343. {
  1344. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1345. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1346. {
  1347. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1348. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1349. {
  1350. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1351. }
  1352. }
  1353. }
  1354. for (int index = 0; index < CCS_QUANTITY; index++)
  1355. {
  1356. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1357. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1358. {
  1359. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1360. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1361. {
  1362. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1363. }
  1364. }
  1365. }
  1366. for (int index = 0; index < GB_QUANTITY; index++)
  1367. {
  1368. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1369. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1370. {
  1371. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1372. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1373. {
  1374. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1375. }
  1376. }
  1377. }
  1378. }
  1379. else //AC
  1380. {
  1381. for (int index = 0; index < AC_QUANTITY; index++)
  1382. {
  1383. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1384. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1385. {
  1386. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1387. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1388. {
  1389. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1390. }
  1391. }
  1392. }
  1393. }// END OF ELSE
  1394. }// END OF check Transaction active
  1395. #endif
  1396. }//END OF Check if Reserve is expired
  1397. //==========================================
  1398. // csu trigger FirmwareStatusNotificationReq
  1399. //==========================================
  1400. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1401. {
  1402. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1403. }
  1404. //==========================================
  1405. // csu trigger CancelReservationConf
  1406. //==========================================
  1407. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1408. {
  1409. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1410. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1411. }
  1412. //==========================================
  1413. // csu trigger ChangeAvailabilityConf
  1414. //==========================================
  1415. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1416. {
  1417. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1418. }
  1419. //==========================================
  1420. // csu trigger UnlockConnectorConf
  1421. //==========================================
  1422. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1423. {
  1424. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1425. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1426. }
  1427. //==========================================
  1428. // csu trigger ReserveNowConf
  1429. //==========================================
  1430. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1431. {
  1432. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1433. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1434. }
  1435. //==========================================
  1436. // csu trigger DataTransferReq
  1437. //==========================================
  1438. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1439. {
  1440. sendDataTransferRequest(gun_index);
  1441. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1442. }
  1443. }
  1444. }
  1445. //==========================================
  1446. // send request routine
  1447. //==========================================
  1448. int sendAuthorizeRequest(int gun_index)
  1449. {
  1450. mtrace();
  1451. int result = FAIL;
  1452. char message[100]={0};
  1453. char guid[37];
  1454. char tempdata[65]={0};
  1455. DEBUG_INFO("sendAuthorizeRequest \n");
  1456. //Local Authorize
  1457. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1458. {
  1459. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1460. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1461. {
  1462. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1463. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1464. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1465. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1466. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1467. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1468. authorizeRetryTimes = 0;
  1469. return result;
  1470. }
  1471. else
  1472. {
  1473. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1474. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1475. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1476. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1477. result = PASS;
  1478. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1479. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1480. authorizeRetryTimes = 0;
  1481. return result;
  1482. }
  1483. }
  1484. //initailize struct Authorize
  1485. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1486. //get data from shared memory
  1487. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1488. random_uuid(guid);
  1489. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1490. LWS_Send(message);
  1491. sprintf(tempdata, "Authorize,%d", gun_index);
  1492. if(hashmap_operation(0, guid, tempdata) == 1)
  1493. {
  1494. result = PASS;
  1495. DEBUG_ERROR("Authorize mapItem pass\n");
  1496. }
  1497. //#ifdef SystemLogMessage
  1498. //DEBUG_INFO(">>>>>Authorize request\n");
  1499. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1500. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1501. //#endif
  1502. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1503. return result;
  1504. }
  1505. int sendBootNotificationRequest(void)
  1506. {
  1507. mtrace();
  1508. int result = FAIL;
  1509. char message[500]={0}, payload[700]={0};
  1510. char guid[37]={0};
  1511. char tempdata[65]={0};
  1512. int IsGunCharging = FALSE;
  1513. //check Transaction active
  1514. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1515. {
  1516. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1517. {
  1518. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1519. {
  1520. IsGunCharging = TRUE;
  1521. }
  1522. }
  1523. for (int index = 0; index < CCS_QUANTITY; index++)
  1524. {
  1525. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1526. {
  1527. IsGunCharging = TRUE;
  1528. }
  1529. }
  1530. for (int index = 0; index < GB_QUANTITY; index++)
  1531. {
  1532. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1533. {
  1534. IsGunCharging = TRUE;
  1535. }
  1536. }
  1537. }
  1538. else
  1539. {
  1540. for (int index = 0; index < AC_QUANTITY; index++)
  1541. {
  1542. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1543. {
  1544. IsGunCharging = TRUE;
  1545. }
  1546. }
  1547. }
  1548. if(IsGunCharging == TRUE)
  1549. {
  1550. server_sign = TRUE;
  1551. return result;
  1552. }
  1553. // Fill BootNotification fields
  1554. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1555. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1556. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1557. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1558. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1559. ShmOCPP16Data->ChargeBoxId
  1560. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1561. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1562. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1563. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1564. ,ShmOCPP16Data->BootNotification.CpIccid
  1565. ,ShmOCPP16Data->BootNotification.CpImsi
  1566. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1567. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1568. random_uuid(guid);
  1569. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1570. LWS_Send(message);
  1571. sprintf(tempdata, "BootNotification,0");
  1572. 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*/)
  1573. {
  1574. result = PASS;
  1575. }
  1576. memset(queuedata, 0, sizeof(queuedata));
  1577. strcpy(queuedata,message);
  1578. //#ifdef SystemLogMessage
  1579. //DEBUG_INFO(">>>>>BootNotification request\n");
  1580. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1581. //#endif
  1582. return result;
  1583. }
  1584. int sendDataTransferRequest(int gun_index)
  1585. {
  1586. mtrace();
  1587. char message[1000]={0};
  1588. char guid[37]={0};
  1589. char tempdata[65]={0};
  1590. int result = FAIL;
  1591. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1592. random_uuid(guid);
  1593. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1594. MESSAGE_TYPE_CALL,
  1595. guid,
  1596. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1597. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1598. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1599. LWS_Send(message);
  1600. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1601. 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*/)
  1602. {
  1603. result = PASS;
  1604. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1605. }
  1606. //#ifdef SystemLogMessage
  1607. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1608. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1609. //#endif
  1610. return result;
  1611. }
  1612. int sendDiagnosticsStatusNotificationRequest(char *status)
  1613. {
  1614. mtrace();
  1615. int result = FAIL;
  1616. char message[110]={0};
  1617. char guid[37]={0};
  1618. char tempdata[65]={0};
  1619. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1620. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1621. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1622. random_uuid(guid);
  1623. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1624. LWS_Send(message);
  1625. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1626. if(hashmap_operation(0, guid, tempdata) == 1)
  1627. {
  1628. result = PASS;
  1629. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1630. }
  1631. //#ifdef SystemLogMessage
  1632. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1633. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1634. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1635. //#endif
  1636. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1637. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1638. //record status
  1639. if(strcmp(status,"Idle")==0)
  1640. {
  1641. DiagnosticsStatusNotificationStatus = 0;
  1642. }
  1643. else if(strcmp(status,"Uploaded")==0)
  1644. {
  1645. DiagnosticsStatusNotificationStatus = 1;
  1646. }
  1647. else if(strcmp(status,"UploadFailed")==0)
  1648. {
  1649. DiagnosticsStatusNotificationStatus = 2;
  1650. }
  1651. else if(strcmp(status,"Uploading")==0)
  1652. {
  1653. DiagnosticsStatusNotificationStatus = 3;
  1654. }
  1655. return result;
  1656. }
  1657. int sendFirmwareStatusNotificationRequest(char *status)
  1658. {
  1659. mtrace();
  1660. int result = FAIL;
  1661. char message[110]={0};
  1662. char guid[37]={0};
  1663. char tempdata[65]={0};
  1664. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1665. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1666. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1667. random_uuid(guid);
  1668. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1669. LWS_Send(message);
  1670. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1671. 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*/)
  1672. {
  1673. result = PASS;
  1674. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1675. }
  1676. //#ifdef SystemLogMessage
  1677. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1678. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1679. //#endif
  1680. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1681. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1682. //record status
  1683. if(strcmp(status,"Downloaded")==0)
  1684. {
  1685. FirmwareStatusNotificationStatus = 0;
  1686. }
  1687. else if(strcmp(status,"DownloadFailed")==0)
  1688. {
  1689. FirmwareStatusNotificationStatus = 1;
  1690. }
  1691. else if(strcmp(status,"Downloading")==0)
  1692. {
  1693. FirmwareStatusNotificationStatus = 2;
  1694. }
  1695. else if(strcmp(status,"Idle")==0)
  1696. {
  1697. FirmwareStatusNotificationStatus = 3;
  1698. }
  1699. else if(strcmp(status,"InstallationFailed")==0)
  1700. {
  1701. FirmwareStatusNotificationStatus = 4;
  1702. }
  1703. else if(strcmp(status,"Installing")==0)
  1704. {
  1705. FirmwareStatusNotificationStatus = 5;
  1706. }
  1707. else if(strcmp(status,"Installed")==0)
  1708. {
  1709. FirmwareStatusNotificationStatus = 6;
  1710. }
  1711. return result;
  1712. }
  1713. int sendHeartbeatRequest(int gun_index)
  1714. {
  1715. mtrace();
  1716. int result = FAIL;
  1717. char message[80]={0};
  1718. char guid[37]={0};
  1719. char tempdata[65]={0};
  1720. random_uuid(guid);
  1721. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1722. , MESSAGE_TYPE_CALL
  1723. , guid );
  1724. LWS_Send(message);
  1725. sprintf(tempdata, "Heartbeat,%d", 0);
  1726. 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*/)
  1727. {
  1728. result = PASS;
  1729. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1730. }
  1731. //#ifdef SystemLogMessage
  1732. //DEBUG_INFO(">>>>>Heartbeat request\n");
  1733. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1734. //#endif
  1735. return result;
  1736. }
  1737. int sendStartTransactionRequest(int gun_index)
  1738. {
  1739. mtrace();
  1740. int result = FAIL;
  1741. char message[250]={0};
  1742. char guid[37]={0};
  1743. struct timeval tmnow;
  1744. struct tm *tm;
  1745. char buf[28];//, usec_buf[6];
  1746. char tempdata[65]={0};
  1747. DEBUG_INFO("sendStartTransactionRequest...");
  1748. gettimeofday(&tmnow, NULL);
  1749. time_t t;
  1750. t = time(NULL);
  1751. /*UTC time and date*/
  1752. tm = gmtime(&t);
  1753. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1754. #if 0 // remove temporally
  1755. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1756. strcat(buf,".");
  1757. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1758. strcat(buf,usec_buf);
  1759. #endif
  1760. //printf("Start Charging Time :%s",buf);
  1761. // set value
  1762. //if(ShmOCPP16Data->OcppConnStatus == 1 )
  1763. //{
  1764. //memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1765. //}
  1766. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1767. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1768. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1769. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1770. {
  1771. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1772. {
  1773. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1774. {
  1775. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1776. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1777. }
  1778. }
  1779. for (int index = 0; index < CCS_QUANTITY; index++)
  1780. {
  1781. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1782. {
  1783. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1784. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1785. }
  1786. }
  1787. for (int index = 0; index < GB_QUANTITY; index++)
  1788. {
  1789. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1790. {
  1791. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1792. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1793. }
  1794. }
  1795. }
  1796. else
  1797. {
  1798. for (int index = 0; index < AC_QUANTITY; index++)
  1799. {
  1800. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1801. {
  1802. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1803. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1804. }
  1805. }
  1806. }//END OF ELSE
  1807. random_uuid(guid);
  1808. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1809. , MESSAGE_TYPE_CALL
  1810. , guid
  1811. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1812. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1813. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1814. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1815. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1816. LWS_Send(message);
  1817. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1818. 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*/)
  1819. {
  1820. result = PASS;
  1821. }
  1822. strcpy(queuedata, message);
  1823. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1824. //#ifdef SystemLogMessage
  1825. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1826. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1827. //#endif
  1828. return result;
  1829. }
  1830. int sendStatusNotificationRequest(int gun_index)
  1831. {
  1832. mtrace();
  1833. int result = FAIL;
  1834. char message[600]={0};
  1835. char guid[37];
  1836. int currentStatus = 0;
  1837. struct timeval tmnow;
  1838. struct tm *tm;
  1839. char buf[28];//, usec_buf[6];
  1840. char tempdata[65]={0};
  1841. gettimeofday(&tmnow, NULL);
  1842. time_t t;
  1843. t = time(NULL);
  1844. /*UTC time and date*/
  1845. tm = gmtime(&t);
  1846. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1847. #if 0 // remove temporally
  1848. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1849. strcat(buf,".");
  1850. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1851. strcat(buf,usec_buf);
  1852. #endif
  1853. printf("%s",buf);
  1854. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1855. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1856. // it's option
  1857. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1858. /*
  1859. enum _SYSTEM_STATUS
  1860. {
  1861. S_BOOTING = 0,
  1862. S_IDLE, = 1
  1863. S_AUTHORIZING, =2
  1864. S_REASSIGN_CHECK, =3
  1865. S_REASSIGN, =4
  1866. S_PRECHARGE, =5
  1867. S_PREPARING_FOR_EV, =6
  1868. S_PREPARING_FOR_EVSE, =7
  1869. S_CHARGING, =8
  1870. S_TERMINATING, =9
  1871. S_COMPLETE, =10
  1872. S_ALARM, =11
  1873. S_FAULT =12
  1874. }
  1875. */
  1876. //check Transaction active
  1877. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1878. {
  1879. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1880. {
  1881. //printf("gun_index=%d\n",gun_index);
  1882. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1883. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1884. {
  1885. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1886. currentStatus = 0; //OCPP Status
  1887. }
  1888. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1889. {
  1890. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1891. currentStatus = 1; //OCPP Status
  1892. }
  1893. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1894. {
  1895. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1896. currentStatus = 2; //OCPP Status
  1897. }
  1898. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1899. {
  1900. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1901. currentStatus = 5; //OCPP Status
  1902. }
  1903. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1904. {
  1905. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1906. currentStatus = 4; //OCPP Status
  1907. }
  1908. 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
  1909. {
  1910. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1911. currentStatus = 7; //OCPP Status: Unavailable
  1912. }
  1913. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1914. {
  1915. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1916. currentStatus = 8; //OCPP Status: Faulted
  1917. }
  1918. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1919. {
  1920. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1921. currentStatus = 6; //OCPP Status: Reserved
  1922. }
  1923. }//end of for CHAdeMO_QUANTITY
  1924. for (int index = 0; index < CCS_QUANTITY; index++)
  1925. {
  1926. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1927. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1928. {
  1929. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1930. currentStatus = 0; //OCPP Status
  1931. }
  1932. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1933. {
  1934. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1935. currentStatus = 1; //OCPP Status
  1936. }
  1937. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1938. {
  1939. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1940. currentStatus = 2; //OCPP Status
  1941. }
  1942. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1943. {
  1944. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1945. currentStatus = 5; //OCPP Status
  1946. }
  1947. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1948. {
  1949. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1950. currentStatus = 4; //OCPP Status
  1951. }
  1952. 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
  1953. {
  1954. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1955. currentStatus = 7; //OCPP Status
  1956. }
  1957. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1958. {
  1959. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1960. currentStatus = 8; //OCPP Status
  1961. }
  1962. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1963. {
  1964. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1965. currentStatus = 6; //OCPP Status
  1966. }
  1967. }
  1968. for (int index = 0; index < GB_QUANTITY; index++)
  1969. {
  1970. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1971. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1972. {
  1973. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1974. currentStatus = 0; //OCPP Status
  1975. }
  1976. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1977. {
  1978. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1979. currentStatus = 1; //OCPP Status
  1980. }
  1981. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1982. {
  1983. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1984. currentStatus = 2; //OCPP Status
  1985. }
  1986. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1987. {
  1988. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1989. currentStatus = 5; //OCPP Status
  1990. }
  1991. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1992. {
  1993. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1994. currentStatus = 4; //OCPP Status
  1995. }
  1996. 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
  1997. {
  1998. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1999. currentStatus = 7; //OCPP Status: Unavailable
  2000. }
  2001. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2002. {
  2003. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2004. currentStatus = 8; //OCPP Status: Faulted
  2005. }
  2006. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2007. {
  2008. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2009. currentStatus = 6; //OCPP Status: Faulted
  2010. }
  2011. }
  2012. }
  2013. else
  2014. {
  2015. for (int index = 0; index < AC_QUANTITY; index++)
  2016. {
  2017. //printf("gun_index=%d\n",gun_index);
  2018. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2019. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2020. {
  2021. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2022. currentStatus = 0; //OCPP Status
  2023. }
  2024. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2025. {
  2026. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2027. currentStatus = 1; //OCPP Status
  2028. }
  2029. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2030. {
  2031. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2032. currentStatus = 2; //OCPP Status
  2033. }
  2034. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2035. {
  2036. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2037. currentStatus = 5; //OCPP Status
  2038. }
  2039. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2040. {
  2041. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2042. currentStatus = 4; //OCPP Status
  2043. }
  2044. 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
  2045. {
  2046. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2047. currentStatus = 7; //OCPP Status: Unavailable
  2048. }
  2049. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2050. {
  2051. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2052. currentStatus = 8; //OCPP Status: Faulted
  2053. }
  2054. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2055. {
  2056. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2057. currentStatus = 6; //OCPP Status: Reserved
  2058. }
  2059. }//end of for AC_QUANTITY
  2060. }//END OF ELSE
  2061. //it's option
  2062. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2063. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2064. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2065. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2066. random_uuid(guid);
  2067. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2068. , MESSAGE_TYPE_CALL
  2069. , guid
  2070. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2071. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2072. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2073. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2074. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2075. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2076. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2077. LWS_Send(message);
  2078. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2079. 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*/)
  2080. {
  2081. //DEBUG_ERROR("statusNotification mapitem pass");
  2082. result = PASS;
  2083. }
  2084. //#ifdef SystemLogMessage
  2085. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2086. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2087. //#endif
  2088. return result;
  2089. }
  2090. int sendStopTransactionRequest(int gun_index)
  2091. {
  2092. mtrace();
  2093. int result = FAIL;
  2094. //char message[1500]={0};
  2095. char guid[37]={0};
  2096. char tempdata[65]={0};
  2097. //int idx_sample=0;
  2098. DEBUG_ERROR("sendStopTransactionRequest \n");
  2099. memset(queuedata, 0, sizeof(queuedata));
  2100. //ENERGY_ACTIVE_IMPORT_REGISTER
  2101. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2102. {
  2103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2104. {
  2105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2106. {
  2107. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2108. //Check Status
  2109. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2110. {
  2111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2112. }
  2113. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2114. }
  2115. }// END OF CHAdeMO_QUANTITY
  2116. for (int index = 0; index < CCS_QUANTITY; index++)
  2117. {
  2118. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2119. {
  2120. //for test
  2121. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2122. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2123. //Check Status
  2124. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2125. {
  2126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2127. }
  2128. else
  2129. {
  2130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2131. }
  2132. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2133. }
  2134. }// END OF CCS_QUANTITY
  2135. for (int index = 0; index < GB_QUANTITY; index++)
  2136. {
  2137. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2138. {
  2139. // for test
  2140. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2141. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2142. //Check Status
  2143. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2144. {
  2145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2146. }
  2147. else
  2148. {
  2149. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2150. }
  2151. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2152. }
  2153. }// END OF GB_QUANTITY
  2154. }
  2155. else
  2156. {
  2157. for (int index = 0; index < AC_QUANTITY; index++)
  2158. {
  2159. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2160. {
  2161. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2162. //Check Status
  2163. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2164. {
  2165. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2166. }
  2167. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2168. }
  2169. }// END OF AC_QUANTITY
  2170. }//END OF ELSE
  2171. //Stop Transaction Time
  2172. struct timeval tmnow;
  2173. struct tm *tm;
  2174. char buf[28];//, usec_buf[6];
  2175. gettimeofday(&tmnow, NULL);
  2176. time_t t;
  2177. t = time(NULL);
  2178. /*UTC time and date*/
  2179. tm = gmtime(&t);
  2180. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2181. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2183. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2184. random_uuid(guid);
  2185. /***********************************transactionData******************************************************/
  2186. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2187. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2188. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2190. //=================================
  2191. // Transaction_Begin
  2192. //=================================
  2193. // Energy.Active.Export.Interval
  2194. //idx_sample=0;
  2195. 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
  2196. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2198. 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*/]);
  2199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2200. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2202. //=================================
  2203. // Transaction_End
  2204. //=================================
  2205. //Current.Export
  2206. //idx_sample=1;
  2207. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2208. {
  2209. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2210. {
  2211. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2212. {
  2213. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2214. }
  2215. }
  2216. for (int index = 0; index < CCS_QUANTITY; index++)
  2217. {
  2218. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2219. {
  2220. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2221. }
  2222. }
  2223. for (int index = 0; index < GB_QUANTITY; index++)
  2224. {
  2225. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2226. {
  2227. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2228. }
  2229. }
  2230. }
  2231. else
  2232. {
  2233. for (int index = 0; index < AC_QUANTITY; index++)
  2234. {
  2235. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2236. {
  2237. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2238. }
  2239. }
  2240. }// END FOR AC ELSE
  2241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2247. //Energy.Active.Export.Interval
  2248. //idx_sample=2;
  2249. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2250. {
  2251. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2252. {
  2253. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2254. {
  2255. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2256. }
  2257. }
  2258. for (int index = 0; index < CCS_QUANTITY; index++)
  2259. {
  2260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2261. {
  2262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2263. }
  2264. }
  2265. for (int index = 0; index < GB_QUANTITY; index++)
  2266. {
  2267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2268. {
  2269. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2270. }
  2271. }
  2272. }
  2273. else
  2274. {
  2275. for (int index = 0; index < AC_QUANTITY; index++)
  2276. {
  2277. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2278. {
  2279. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2280. }
  2281. }
  2282. }// END FOR AC ELSE
  2283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2289. //Power.Active.Export
  2290. //idx_sample=3;
  2291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2292. {
  2293. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2294. {
  2295. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2296. {
  2297. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2298. }
  2299. }
  2300. for (int index = 0; index < CCS_QUANTITY; index++)
  2301. {
  2302. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2303. {
  2304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2305. }
  2306. }
  2307. for (int index = 0; index < GB_QUANTITY; index++)
  2308. {
  2309. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2310. {
  2311. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2312. }
  2313. }
  2314. }
  2315. else
  2316. {
  2317. for (int index = 0; index < AC_QUANTITY; index++)
  2318. {
  2319. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2320. {
  2321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2322. }
  2323. }
  2324. }// END FOR AC ELSE
  2325. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2329. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2331. //Voltage
  2332. //idx_sample=4;
  2333. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2334. {
  2335. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2336. {
  2337. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2338. {
  2339. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2340. }
  2341. }
  2342. for (int index = 0; index < CCS_QUANTITY; index++)
  2343. {
  2344. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2345. {
  2346. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2347. }
  2348. }
  2349. for (int index = 0; index < GB_QUANTITY; index++)
  2350. {
  2351. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2352. {
  2353. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2354. }
  2355. }
  2356. }
  2357. else
  2358. {
  2359. for (int index = 0; index < AC_QUANTITY; index++)
  2360. {
  2361. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2362. {
  2363. 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
  2364. }
  2365. }
  2366. }// END FOR AC ELSE
  2367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2373. //SoC
  2374. //idx_sample=5;
  2375. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2376. {
  2377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2378. {
  2379. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2380. {
  2381. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2382. }
  2383. }
  2384. for (int index = 0; index < CCS_QUANTITY; index++)
  2385. {
  2386. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2387. {
  2388. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2389. }
  2390. }
  2391. for (int index = 0; index < GB_QUANTITY; index++)
  2392. {
  2393. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2394. {
  2395. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2396. }
  2397. }
  2398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L1_N]);
  2402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2404. } // END FOR DC CASE
  2405. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2406. {
  2407. 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\" } ] } ] } ]"
  2408. ,MESSAGE_TYPE_CALL
  2409. ,guid
  2410. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2411. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2412. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2413. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2414. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2415. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2416. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2417. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2418. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2419. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2420. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2421. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2422. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2423. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2424. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2425. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2426. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2427. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2428. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2429. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2430. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2431. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2432. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2433. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2434. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2435. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2436. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2437. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2438. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2439. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2440. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2441. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2442. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2443. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2444. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2445. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2446. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2447. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2448. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2449. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2450. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2451. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2452. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2453. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2454. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2455. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2456. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2457. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2458. );
  2459. }
  2460. else
  2461. {
  2462. 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\" } ] } ] } ]"
  2463. ,MESSAGE_TYPE_CALL
  2464. ,guid
  2465. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2466. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2467. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2468. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2469. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2470. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2471. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2472. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2473. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2474. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2475. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2476. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2477. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2478. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2479. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2480. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2481. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2482. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2483. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2484. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2485. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2486. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2487. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2488. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2489. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2490. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2491. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2492. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2493. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2494. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2495. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2496. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2497. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2498. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2499. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2500. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2501. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2502. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2503. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2504. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2505. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2506. );
  2507. }
  2508. LWS_Send(queuedata);
  2509. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2510. if(hashmap_operation(0, guid, tempdata) == 1)
  2511. {
  2512. result = PASS;
  2513. DEBUG_INFO("StopTransaction mapitem pass\n");
  2514. }
  2515. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2516. //for test
  2517. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2518. return result;
  2519. }
  2520. int sendMeterValuesRequest(int gun_index)
  2521. {
  2522. mtrace();
  2523. int result = FAIL;
  2524. // char message[1500]={0};
  2525. char guid[37]={0};
  2526. //int idx_sample=0;
  2527. //int length = 0;
  2528. char tempdata[65]={0};
  2529. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2530. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2531. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2532. {
  2533. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2534. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2535. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2536. return result;
  2537. }
  2538. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2539. {
  2540. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2541. }
  2542. memset(queuedata, 0, sizeof(queuedata));
  2543. //set value
  2544. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2545. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2546. random_uuid(guid);
  2547. //UTC Date time
  2548. struct timeval tmnow;
  2549. struct tm *tm;
  2550. char buf[28];//, usec_buf[6];
  2551. gettimeofday(&tmnow, NULL);
  2552. time_t t;
  2553. t = time(NULL);
  2554. /*UTC time and date*/
  2555. tm = gmtime(&t);
  2556. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2557. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2558. //idx_sample=0;
  2559. //********************************(1)Current.Export************************************************/
  2560. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2561. {
  2562. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2563. {
  2564. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2565. {
  2566. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2567. }
  2568. }
  2569. for (int index = 0; index < CCS_QUANTITY; index++)
  2570. {
  2571. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2572. {
  2573. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2574. }
  2575. }
  2576. for (int index = 0; index < GB_QUANTITY; index++)
  2577. {
  2578. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2579. {
  2580. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2581. }
  2582. }
  2583. }
  2584. else
  2585. {
  2586. for (int index = 0; index < AC_QUANTITY; index++)
  2587. {
  2588. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2589. {
  2590. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2591. }
  2592. }
  2593. }// END FOR AC ELSE
  2594. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2595. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2596. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2597. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2598. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2599. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2600. //idx_sample=1;
  2601. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2602. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2603. {
  2604. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2605. {
  2606. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2607. {
  2608. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2609. }
  2610. }
  2611. for (int index = 0; index < CCS_QUANTITY; index++)
  2612. {
  2613. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2614. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2615. {
  2616. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2617. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2618. }
  2619. }
  2620. for (int index = 0; index < GB_QUANTITY; index++)
  2621. {
  2622. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2623. {
  2624. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2625. }
  2626. }
  2627. }
  2628. else
  2629. {
  2630. for (int index = 0; index < AC_QUANTITY; index++)
  2631. {
  2632. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2633. {
  2634. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2635. }
  2636. }
  2637. }//END FOR AC ELSE
  2638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2641. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1]);
  2642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2643. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2644. //idx_sample=2;
  2645. //********************************(4)Power.Active.Export************************************************/
  2646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2647. {
  2648. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2649. {
  2650. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2651. {
  2652. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2653. }
  2654. }
  2655. for (int index = 0; index < CCS_QUANTITY; index++)
  2656. {
  2657. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2658. {
  2659. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2660. }
  2661. }
  2662. for (int index = 0; index < GB_QUANTITY; index++)
  2663. {
  2664. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2665. {
  2666. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2667. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2668. }
  2669. }
  2670. }
  2671. else
  2672. {
  2673. for (int index = 0; index < AC_QUANTITY; index++)
  2674. {
  2675. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2676. {
  2677. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2678. }
  2679. }
  2680. }// END FOR AC ELSE
  2681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2684. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2685. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2686. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2687. //idx_sample=3;
  2688. //***********************************************(5)VOLTAGE******************************************************/
  2689. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2690. {
  2691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2692. {
  2693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2694. {
  2695. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2696. }
  2697. }
  2698. for (int index = 0; index < CCS_QUANTITY; index++)
  2699. {
  2700. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2701. {
  2702. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2703. }
  2704. }
  2705. for (int index = 0; index < GB_QUANTITY; index++)
  2706. {
  2707. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2708. {
  2709. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2710. }
  2711. }
  2712. }
  2713. else
  2714. {
  2715. for (int index = 0; index < AC_QUANTITY; index++)
  2716. {
  2717. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2718. {
  2719. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2720. }
  2721. }
  2722. }//END FOR AC ELSE
  2723. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2724. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2725. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2726. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2727. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2728. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2729. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2730. {
  2731. //idx_sample=4;
  2732. //sampledValue = NULL;
  2733. //***********************************************(6)SOC******************************************************/
  2734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2735. {
  2736. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2737. {
  2738. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2739. }
  2740. }
  2741. for (int index = 0; index < CCS_QUANTITY; index++)
  2742. {
  2743. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2744. {
  2745. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2746. }
  2747. }
  2748. for (int index = 0; index < GB_QUANTITY; index++)
  2749. {
  2750. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2751. {
  2752. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2753. }
  2754. }
  2755. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2756. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2758. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  2759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2761. }
  2762. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2763. {
  2764. 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\"}]}]}]"
  2765. ,MESSAGE_TYPE_CALL
  2766. ,guid
  2767. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2768. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2769. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2805. );
  2806. }
  2807. else
  2808. {
  2809. 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\"}]}]}]"
  2810. ,MESSAGE_TYPE_CALL
  2811. ,guid
  2812. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2813. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2814. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2832. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2833. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2834. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2835. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2836. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2837. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2838. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2839. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2840. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2841. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2842. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2843. );
  2844. }
  2845. LWS_Send(queuedata);
  2846. // Put request guid to hash map
  2847. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2848. 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*/)
  2849. {
  2850. result = PASS;
  2851. DEBUG_INFO("MeterValues mapitem pass\n");
  2852. }
  2853. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2854. return result;
  2855. }
  2856. //==========================================
  2857. // send confirm routine
  2858. //==========================================
  2859. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2860. {
  2861. mtrace();
  2862. int result = FAIL;
  2863. char message[100]={0};
  2864. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2865. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2866. LWS_Send(message);
  2867. result = TRUE;
  2868. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2869. return result;
  2870. }
  2871. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2872. {
  2873. mtrace();
  2874. int result = FAIL;
  2875. char message[100]={0};
  2876. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2877. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2878. LWS_Send(message);
  2879. result = TRUE;
  2880. return result;
  2881. }
  2882. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2883. {
  2884. mtrace();
  2885. int result = FAIL;
  2886. char message[100]={0};
  2887. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2888. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2889. LWS_Send(message);
  2890. result = TRUE;
  2891. return result;
  2892. }
  2893. int sendClearCacheConfirmation(char *uuid,char *payload)
  2894. {
  2895. mtrace();
  2896. int result = FAIL;
  2897. char message[500]={0};
  2898. // int count = 0;
  2899. // int gun_index = 0;
  2900. // char guid[37];
  2901. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2902. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2903. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2904. LWS_Send(message);
  2905. return result;
  2906. }
  2907. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2908. {
  2909. mtrace();
  2910. int result = FAIL;
  2911. char message[500]={0};
  2912. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2913. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2914. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2915. LWS_Send(message);
  2916. return result;
  2917. }
  2918. int sendDataTransferConfirmation(char *uuid,char *payload)
  2919. {
  2920. mtrace();
  2921. char statusStr[20]={0};
  2922. char dataStr[10]={0};
  2923. char sstr[20]={0};
  2924. int c = 0;
  2925. char *loc;
  2926. int result = FAIL;
  2927. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2928. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2929. /**********************status**************************/
  2930. loc = strstr(payload, "status");
  2931. memset(sstr ,0, sizeof(sstr) );
  2932. c = 0;
  2933. while (loc[3+strlen("status")+c] != '\"')
  2934. {
  2935. sstr[c] = loc[3+strlen("status")+c];
  2936. c++;
  2937. }
  2938. sstr[c] = '\0';
  2939. strcpy(statusStr, sstr);
  2940. /**********************data**************************/
  2941. loc = strstr(payload, "data");
  2942. memset(sstr ,0, sizeof(sstr) );
  2943. c = 0;
  2944. while (loc[3+strlen("data")+c] != '\"')
  2945. {
  2946. sstr[c] = loc[3+strlen("data")+c];
  2947. c++;
  2948. }
  2949. sstr[c] = '\0';
  2950. strcpy(dataStr, sstr);
  2951. return result;
  2952. }
  2953. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2954. {
  2955. mtrace();
  2956. int result = FAIL;
  2957. char message[1000]={0};
  2958. double diff_f = 0.0;
  2959. int diff_i = 0;
  2960. int diffSeconds = 0;
  2961. struct tm tp;
  2962. int TimeZero = FALSE;
  2963. int CompositeScheduleIndex = 0;
  2964. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2965. #if 0
  2966. if(connectorIdInt > 0)
  2967. {
  2968. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2969. {
  2970. TimeZero = TRUE;
  2971. }
  2972. else
  2973. {
  2974. strptime((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2975. }
  2976. }
  2977. else
  2978. {
  2979. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2980. {
  2981. TimeZero = TRUE;
  2982. }
  2983. else
  2984. {
  2985. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2986. }
  2987. }
  2988. DEBUG_INFO("ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule=%s\n",ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule);
  2989. #endif
  2990. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2991. {
  2992. TimeZero = TRUE;
  2993. }
  2994. else
  2995. {
  2996. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2997. }
  2998. if(TimeZero == FALSE)
  2999. {
  3000. tp.tm_isdst = -1;
  3001. time_t utc = mktime(&tp);
  3002. time_t t = time(NULL);
  3003. diff_f = difftime(t, utc);
  3004. diff_i = (int)diff_f;
  3005. diffSeconds = diff_i % 86400;//86400 seconds/day
  3006. }
  3007. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3008. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3009. #if 0 //remove temporally
  3010. 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}"
  3011. ,MESSAGE_TYPE_CALLRESULT
  3012. ,uuid
  3013. ,payload
  3014. ,connectorIdInt
  3015. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3016. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3017. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3018. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3019. #endif
  3020. if(nPeriod == 0)
  3021. {
  3022. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3023. ,MESSAGE_TYPE_CALLRESULT
  3024. ,uuid
  3025. ,payload
  3026. ,connectorIdInt
  3027. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3028. }
  3029. else
  3030. {
  3031. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3032. ,MESSAGE_TYPE_CALLRESULT
  3033. ,uuid
  3034. ,payload
  3035. ,connectorIdInt
  3036. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3037. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3038. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3039. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3040. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3041. #if 1 // remove temporally
  3042. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3043. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  3044. {
  3045. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3046. , 0
  3047. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3048. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3049. }
  3050. else
  3051. {
  3052. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3053. {
  3054. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  3055. {
  3056. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3057. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3058. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3059. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3060. }
  3061. else
  3062. {
  3063. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3064. , (((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*/))
  3065. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3066. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3067. }
  3068. }
  3069. }
  3070. #endif
  3071. sprintf(message + strlen(message), "]}}]");
  3072. }
  3073. LWS_Send(message);
  3074. result = TRUE;
  3075. return result;
  3076. }
  3077. int sendGetConfigurationConfirmation(char *uuid)
  3078. {
  3079. mtrace();
  3080. int result = FAIL;
  3081. int MaxKeySupported = 0;
  3082. int sentConfigurationNumber= 0;
  3083. int sentunConfigurationNumber= 0;
  3084. char message[4000]={0};
  3085. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3086. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3087. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3088. ,MESSAGE_TYPE_CALLRESULT
  3089. ,uuid );
  3090. //configuration key
  3091. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3092. {
  3093. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3094. {
  3095. if (sentConfigurationNumber == 0)
  3096. {
  3097. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3098. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3099. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3100. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3101. }
  3102. else
  3103. {
  3104. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3105. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3106. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3107. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3108. }
  3109. sentConfigurationNumber = sentConfigurationNumber + 1;
  3110. }
  3111. }
  3112. sprintf(message + strlen(message), "]");
  3113. if(UnknownKeynum != 0)
  3114. {
  3115. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3116. //unkown key
  3117. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3118. {
  3119. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3120. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3121. if(sentunConfigurationNumber == 0)
  3122. {
  3123. sprintf(message + strlen(message), "\"%s\""
  3124. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3125. }
  3126. else
  3127. {
  3128. sprintf(message + strlen(message), ",\"%s\""
  3129. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3130. }
  3131. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3132. }
  3133. sprintf(message + strlen(message), "]");
  3134. }
  3135. sprintf(message + strlen(message), "} ]");
  3136. LWS_Send(message);
  3137. #if 0
  3138. printf("error 1-0\n");
  3139. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3140. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3141. #endif
  3142. return result;
  3143. }
  3144. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3145. {
  3146. mtrace();
  3147. int result = FAIL;
  3148. char message[400]={0};
  3149. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3150. if(strcmp(payload,"")==0)
  3151. {
  3152. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3153. }
  3154. else
  3155. {
  3156. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3157. }
  3158. LWS_Send(message);
  3159. result = TRUE;
  3160. return result;
  3161. }
  3162. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3163. {
  3164. mtrace();
  3165. int result = FAIL;
  3166. char message[80]={0};
  3167. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3168. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3169. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3170. LWS_Send(message);
  3171. result = TRUE;
  3172. return result;
  3173. }
  3174. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3175. {
  3176. mtrace();
  3177. int result = FAIL;
  3178. char message[80]={0};
  3179. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3180. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3181. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3182. LWS_Send(message);
  3183. result = TRUE;
  3184. return result;
  3185. }
  3186. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3187. {
  3188. mtrace();
  3189. int result = FAIL;
  3190. char message[80]={0};
  3191. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3192. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3193. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3194. LWS_Send(message);
  3195. result = TRUE;
  3196. return result;
  3197. }
  3198. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3199. {
  3200. mtrace();
  3201. int result = FAIL;
  3202. char message[80]={0};
  3203. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3204. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3205. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3206. LWS_Send(message);
  3207. result = TRUE;
  3208. return result;
  3209. }
  3210. int sendResetConfirmation(char *uuid,char *payload)
  3211. {
  3212. mtrace();
  3213. int result = FAIL;
  3214. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3215. char message[80]={0};
  3216. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3217. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3218. LWS_Send(message);
  3219. result = TRUE;
  3220. return result;
  3221. }
  3222. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3223. {
  3224. mtrace();
  3225. int result = FAIL;
  3226. char message[500]={0};
  3227. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3228. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3229. LWS_Send(message);
  3230. result = TRUE;
  3231. return result;
  3232. }
  3233. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3234. {
  3235. mtrace();
  3236. int result = FAIL;
  3237. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3238. char message[80]={0};
  3239. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  3240. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3241. LWS_Send(message);
  3242. result = TRUE;
  3243. return result;
  3244. }
  3245. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3246. {
  3247. mtrace();
  3248. int result = FAIL;
  3249. char message[80]={0};
  3250. DEBUG_ERROR("sendTriggerMessageConfirmation\n");
  3251. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3252. LWS_Send(message);
  3253. result = TRUE;
  3254. return result;
  3255. }
  3256. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3257. {
  3258. mtrace();
  3259. int result = FAIL;
  3260. char message[80]={0};
  3261. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3262. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  3263. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3264. LWS_Send(message);
  3265. result = TRUE;
  3266. return result;
  3267. }
  3268. int sendUpdateFirmwareConfirmation(char *uuid)
  3269. {
  3270. mtrace();
  3271. int result = FAIL;
  3272. char message[60]={0};
  3273. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3274. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3275. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3276. LWS_Send(message);
  3277. result = TRUE;
  3278. return result;
  3279. }
  3280. //==========================================
  3281. // send CallError routine
  3282. //==========================================
  3283. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3284. {
  3285. mtrace();
  3286. //int result = FAIL;
  3287. char message[220]={0};
  3288. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3289. #ifdef SystemLogMessage
  3290. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3291. uniqueId, action, errorCode, errorDescription);
  3292. #endif
  3293. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3294. LWS_Send(message);
  3295. //result = TRUE;
  3296. }
  3297. //==========================================
  3298. // Handle server request routine Start
  3299. //==========================================
  3300. #define GUN_NUM 1
  3301. int handleCancelReservationRequest(char *uuid, char *payload)
  3302. {
  3303. mtrace();
  3304. int result = FAIL;
  3305. int gunNO = 0;
  3306. int reservationIdInt =0;
  3307. char comfirmstr[20];
  3308. int c = 0;
  3309. char *loc;
  3310. char sstr[100]={0};
  3311. DEBUG_INFO("handle CancelReservationRequest\n");
  3312. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3313. c = 0;
  3314. loc = strstr(payload, "reservationId");
  3315. memset(sstr ,0, sizeof(sstr) );
  3316. while (loc[strlen("reservationId")+2+c] != '}')
  3317. {
  3318. sstr[c] = loc[strlen("reservationId")+2+c];
  3319. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3320. c++;
  3321. }
  3322. sstr[c] = '\0';
  3323. reservationIdInt = atoi(sstr);
  3324. memset(comfirmstr, 0, sizeof comfirmstr);
  3325. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3326. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3327. //check Transaction active
  3328. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3329. {
  3330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3331. {
  3332. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3333. {
  3334. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3335. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3336. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3337. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3338. goto end;
  3339. }
  3340. }
  3341. for (int index = 0; index < CCS_QUANTITY; index++)
  3342. {
  3343. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3344. {
  3345. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3346. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3347. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3348. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3349. goto end;
  3350. }
  3351. }
  3352. for (int index = 0; index < GB_QUANTITY; index++)
  3353. {
  3354. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3355. {
  3356. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3357. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3358. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3359. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3360. goto end;
  3361. }
  3362. }
  3363. }
  3364. else
  3365. {
  3366. for (int index = 0; index < AC_QUANTITY; index++)
  3367. {
  3368. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3369. {
  3370. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3371. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3372. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3373. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3374. goto end;
  3375. }
  3376. }
  3377. }// END FOR AC ELSE
  3378. //The reservationId does NOT match the reservationId
  3379. sendCancelReservationConfirmation(uuid, comfirmstr);
  3380. end:
  3381. // Fill in ocpp packet uuid
  3382. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3383. return result;
  3384. }
  3385. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3386. {
  3387. mtrace();
  3388. int result = FAIL;
  3389. int gunIndex = 0;
  3390. char sstr[90]={0};
  3391. char typeStr[16]={0};
  3392. char comfirmstr[20];
  3393. int specificId = FALSE;
  3394. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3395. char *loc;
  3396. //int intervalInt = 0;
  3397. int c = 0;
  3398. /*** connectorId ****/
  3399. c = 0;
  3400. loc = strstr(payload, "connectorId");
  3401. memset(sstr ,0, sizeof(sstr) );
  3402. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3403. {
  3404. sstr[c] = loc[strlen("connectorId")+2+c];
  3405. c++;
  3406. }
  3407. sstr[c] = '\0';
  3408. gunIndex = atoi(sstr);
  3409. /***type ****/
  3410. loc = strstr(payload, "type");
  3411. memset(sstr ,0, sizeof(sstr) );
  3412. c = 0;
  3413. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3414. {
  3415. sstr[c] = loc[3+strlen("type")+c];
  3416. c++;
  3417. }
  3418. sstr[c] = '\0';
  3419. strcpy(typeStr, sstr);
  3420. if(gunIndex != 0)
  3421. {
  3422. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3423. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3424. }
  3425. else
  3426. {
  3427. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3428. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3429. }
  3430. memset(comfirmstr, 0, sizeof comfirmstr);
  3431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3432. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3433. {
  3434. specificId = TRUE;
  3435. }
  3436. if(specificId == FALSE)
  3437. goto end;
  3438. if(gunIndex != 0)
  3439. {
  3440. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3441. }
  3442. else
  3443. {
  3444. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3445. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3446. }
  3447. /*
  3448. enum _SYSTEM_STATUS
  3449. {
  3450. S_BOOTING = 0,
  3451. S_IDLE, = 1
  3452. S_AUTHORIZING, =2
  3453. S_REASSIGN_CHECK, =3
  3454. S_REASSIGN, =4
  3455. S_PRECHARGE, =5
  3456. S_PREPARING_FOR_EV, =6
  3457. S_PREPARING_FOR_EVSE, =7
  3458. S_CHARGING, =8
  3459. S_TERMINATING, =9
  3460. S_COMPLETE, =10
  3461. S_ALARM, =11
  3462. S_FAULT =12
  3463. }
  3464. */
  3465. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3466. {
  3467. //check Transaction active
  3468. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3469. {
  3470. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3471. {
  3472. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3473. {
  3474. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3475. {
  3476. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3477. }
  3478. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3479. {
  3480. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3481. }
  3482. else
  3483. {
  3484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3485. }
  3486. goto end;
  3487. }
  3488. }//END FOR CHAdeMO_QUANTITY
  3489. for (int index = 0; index < CCS_QUANTITY; index++)
  3490. {
  3491. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3492. {
  3493. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3494. {
  3495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3496. }
  3497. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3498. {
  3499. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3500. }
  3501. else
  3502. {
  3503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3504. }
  3505. goto end;
  3506. }
  3507. }//END FOR CCS_QUANTITY
  3508. for (int index = 0; index < GB_QUANTITY; index++)
  3509. {
  3510. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3511. {
  3512. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3513. {
  3514. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3515. }
  3516. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3517. {
  3518. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3519. }
  3520. else
  3521. {
  3522. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3523. }
  3524. goto end;
  3525. }
  3526. }// END FOR GB_QUANTITY
  3527. }
  3528. else
  3529. {
  3530. for (int index = 0; index < AC_QUANTITY; index++)
  3531. {
  3532. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3533. {
  3534. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3535. {
  3536. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3537. }
  3538. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3539. {
  3540. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3541. }
  3542. else
  3543. {
  3544. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3545. }
  3546. goto end;
  3547. }
  3548. }//END FOR AC_QUANTITY
  3549. }// END FOR AC ELSE
  3550. }//END FOR AvailabilityTypeStr[Inoperative]
  3551. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3552. {
  3553. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3554. //check Transaction active
  3555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3556. {
  3557. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3558. {
  3559. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3560. {
  3561. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3562. goto end;
  3563. }
  3564. }//END FOR CHAdeMO_QUANTITY
  3565. for (int index = 0; index < CCS_QUANTITY; index++)
  3566. {
  3567. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3568. {
  3569. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3570. goto end;
  3571. }
  3572. }//END FOR CCS_QUANTITY
  3573. for (int index = 0; index < GB_QUANTITY; index++)
  3574. {
  3575. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3576. {
  3577. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3578. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3579. goto end;
  3580. }
  3581. }// END FOR GB_QUANTITY
  3582. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3583. }
  3584. else
  3585. {
  3586. for (int index = 0; index < AC_QUANTITY; index++)
  3587. {
  3588. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3589. {
  3590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3591. goto end;
  3592. }
  3593. }//END FOR CHAdeMO_QUANTITY
  3594. }//END FOR AC ELSE
  3595. }//END FOR AvailabilityTypeStr[Operative]
  3596. end:
  3597. if(gunIndex != 0)
  3598. {
  3599. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3600. }
  3601. else
  3602. {
  3603. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3604. }
  3605. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3606. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3607. return result;
  3608. }
  3609. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3610. {
  3611. mtrace();
  3612. int result = FAIL;
  3613. char sstr[100]={0};
  3614. char keystr[40]={0};
  3615. char valuestr[16]={0};
  3616. char *loc;
  3617. int c = 0;
  3618. char comfirmstr[20];
  3619. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3620. /***key ****/
  3621. loc = strstr(payload, "key");
  3622. memset(sstr ,0, sizeof(sstr) );
  3623. c = 0;
  3624. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3625. {
  3626. sstr[c] = loc[3+strlen("key")+c];
  3627. c++;
  3628. }
  3629. sstr[c] = '\0';
  3630. strcpy(keystr, sstr);
  3631. /***value ****/
  3632. loc = strstr(payload, "value");
  3633. memset(sstr ,0, sizeof(sstr) );
  3634. c = 0;
  3635. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3636. {
  3637. sstr[c] = loc[3+strlen("value")+c];
  3638. c++;
  3639. }
  3640. sstr[c] = '\0';
  3641. strcpy(valuestr, sstr);
  3642. if((uuid==NULL) || (payload ==NULL) )
  3643. {
  3644. #ifdef Debug
  3645. DEBUG_INFO("payload is null\n");
  3646. #endif
  3647. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3648. }
  3649. else
  3650. {
  3651. int status = setKeyValue(keystr, valuestr);
  3652. switch(status)
  3653. {
  3654. case ConfigurationStatus_Accepted:
  3655. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3656. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3657. break;
  3658. case ConfigurationStatus_Rejected:
  3659. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3660. break;
  3661. case RebootRequired:
  3662. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3663. break;
  3664. case NotSupported:
  3665. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3666. break;
  3667. default:
  3668. break;
  3669. }
  3670. }
  3671. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3672. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3673. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3674. return result;
  3675. }
  3676. int handleClearCacheRequest(char *uuid, char *payload)
  3677. {
  3678. mtrace();
  3679. int result = FAIL;
  3680. char comfirmstr[20];
  3681. int fd;
  3682. char rmFileCmd[100]={0};
  3683. struct stat stats;
  3684. DEBUG_ERROR("handle ClearCacheRequest\n");
  3685. stat("../Storage/OCPP", &stats);
  3686. // Check for directory existence
  3687. if (S_ISDIR(stats.st_mode) == 1)
  3688. {
  3689. //DEBUG_ERROR("\n OCPP directory exist \n");
  3690. }
  3691. else
  3692. {
  3693. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3694. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3695. system(rmFileCmd);
  3696. }
  3697. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3698. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3699. {
  3700. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3701. }
  3702. else
  3703. {
  3704. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3705. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3706. if(log == NULL)
  3707. {
  3708. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3709. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3710. goto end;
  3711. }
  3712. else
  3713. {
  3714. fclose(log);
  3715. }
  3716. }
  3717. fd = open(AuthorizationCache_JSON,O_RDWR);
  3718. if(fd < 0)
  3719. {
  3720. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3721. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3722. }
  3723. else
  3724. {
  3725. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3726. //* 清空? 件 */
  3727. ftruncate(fd,0);
  3728. //* ? 新设置? 件? 移??*/
  3729. lseek(fd,0,SEEK_SET);
  3730. close(fd);
  3731. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3732. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3733. }
  3734. end:
  3735. sendClearCacheConfirmation(uuid, comfirmstr);
  3736. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3737. return result;
  3738. }
  3739. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3740. {
  3741. mtrace();
  3742. int result = FAIL;
  3743. int resultRename;
  3744. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3745. char chargingProfilePurposeStr[26]={0};
  3746. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3747. char tempchargingProfilePurposeStr[26]={0};
  3748. char sstr[160]={0};//sstr[200]={ 0 };
  3749. char str[100]={0};
  3750. int c = 0;
  3751. //int i = 0;
  3752. //char * pch;
  3753. char *loc;
  3754. char fname[200];
  3755. char comfirmstr[20]={0};
  3756. char word[1000]={0};
  3757. int clearflag = FALSE;
  3758. int chargingProfileIdIsNULL = FALSE;
  3759. int connectorIsNULL = FALSE;
  3760. int chargingProfilePurposeIsNULL = FALSE;
  3761. int stackLevelIsNULL = FALSE;
  3762. FILE *fptr1, *fptr2;
  3763. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3764. int n_chargingProfile=0;
  3765. char sLineWord[1060]={0};
  3766. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3767. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3768. //***id ****/
  3769. c = 0;
  3770. loc = strstr(payload, "id");
  3771. memset(sstr ,0, sizeof(sstr) );
  3772. if(loc == NULL)
  3773. {
  3774. chargingProfileIdIsNULL = TRUE;
  3775. }
  3776. else
  3777. {
  3778. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3779. {
  3780. sstr[c] = loc[strlen("id")+2+c];
  3781. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3782. c++;
  3783. }
  3784. sstr[c] = '\0';
  3785. chargingProfileIdInt = atoi(sstr);
  3786. }
  3787. //***connectorId ****/
  3788. c=0;
  3789. loc = strstr(payload, "connectorId");
  3790. memset(sstr ,0, sizeof(sstr) );
  3791. if(loc == NULL)
  3792. {
  3793. connectorIsNULL = TRUE;
  3794. }
  3795. else
  3796. {
  3797. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3798. {
  3799. sstr[c] = loc[strlen("connectorId")+2+c];
  3800. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3801. c++;
  3802. }
  3803. sstr[c] = '\0';
  3804. connectorIdInt = atoi(sstr);
  3805. }
  3806. //***chargingProfilePurpose ****/
  3807. loc = strstr(payload, "chargingProfilePurpose");
  3808. memset(sstr ,0, sizeof(sstr) );
  3809. c = 0;
  3810. if(loc == NULL)
  3811. {
  3812. chargingProfilePurposeIsNULL = TRUE;
  3813. }
  3814. else
  3815. {
  3816. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3817. {
  3818. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3819. c++;
  3820. }
  3821. sstr[c] = '\0';
  3822. strcpy(chargingProfilePurposeStr, sstr);
  3823. }
  3824. //***stackLevel ****/
  3825. c=0;
  3826. loc = strstr(payload, "stackLevel");
  3827. memset(sstr ,0, sizeof(sstr) );
  3828. if(loc == NULL)
  3829. {
  3830. stackLevelIsNULL = TRUE;
  3831. }
  3832. else
  3833. {
  3834. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3835. {
  3836. sstr[c] = loc[strlen("stackLevel")+2+c];
  3837. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3838. c++;
  3839. }
  3840. sstr[c] = '\0';
  3841. stackLevelInt = atoi(sstr);
  3842. }
  3843. if(connectorIsNULL == FALSE)
  3844. {
  3845. switch(connectorIdInt)
  3846. {
  3847. case 0:
  3848. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3849. {
  3850. strcpy(fname, ChargePointMaxProfile_JSON);
  3851. }
  3852. // else
  3853. // {
  3854. // strcpy(fname, TxDefaultProfile_0_JSON);
  3855. // }
  3856. break;
  3857. case 1:
  3858. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3859. {
  3860. strcpy(fname, TxDefaultProfile_1_JSON);
  3861. }
  3862. // else
  3863. // {
  3864. // strcpy(fname, TxProfile_1_JSON);
  3865. // }
  3866. break;
  3867. case 2:
  3868. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3869. {
  3870. strcpy(fname, TxDefaultProfile_2_JSON);
  3871. }
  3872. // else
  3873. // {
  3874. // strcpy(fname, TxProfile_2_JSON);
  3875. // }
  3876. break;
  3877. default:
  3878. strcpy(fname, ChargePointMaxProfile_JSON );
  3879. break;
  3880. }
  3881. }
  3882. else
  3883. {
  3884. strcpy(fname, ChargePointMaxProfile_JSON );
  3885. }
  3886. fptr1 = fopen(fname, "r");
  3887. if (!fptr1)
  3888. {
  3889. //file not exist
  3890. DEBUG_ERROR("Unable to open the input file!!\n");
  3891. fptr1 = fopen(fname, "w+");
  3892. }
  3893. fclose(fptr1);
  3894. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3895. {
  3896. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3897. goto end;
  3898. }
  3899. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3900. {
  3901. //clear the whole contents of a file in C
  3902. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3903. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3904. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3905. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3906. fclose(fopen(TxProfile_1_JSON, "w"));
  3907. fclose(fopen(TxProfile_2_JSON, "w"));
  3908. #if 0
  3909. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3910. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3911. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3912. #endif
  3913. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3914. }
  3915. else
  3916. {
  3917. fptr1 = fopen(fname, "r");
  3918. fptr2 = fopen(temp, "w+");
  3919. while(fscanf(fptr1, "%s", word) != EOF)
  3920. {
  3921. //DEBUG_INFO("word=%s\n",word);
  3922. if(strcmp(word, "chargingProfileId") == 0)
  3923. {
  3924. n_chargingProfile = n_chargingProfile + 1;
  3925. DEBUG_INFO("chargingProfileId Found\n");
  3926. }
  3927. }
  3928. rewind(fptr1);
  3929. //search Charging Profile Element
  3930. //int i= 0;
  3931. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3932. {
  3933. //*************************tempconnectorIdInt*********************************/
  3934. loc = strstr(sLineWord, "connectorId");
  3935. c = 0;
  3936. memset(sstr ,0, sizeof(sstr) );
  3937. while (loc[strlen("connectorId")+2+c] != ',')
  3938. {
  3939. sstr[c] = loc[strlen("connectorId")+2+c];
  3940. c++;
  3941. }
  3942. sstr[c] = '\0';
  3943. tempconnectorIdInt = atoi(sstr);
  3944. //chargingProfileId
  3945. c = 0;
  3946. loc = strstr(sLineWord, "chargingProfileId");
  3947. memset(sstr ,0, sizeof(sstr) );
  3948. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3949. {
  3950. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3951. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3952. c++;
  3953. }
  3954. sstr[c] = '\0';
  3955. tempchargingProfileIdInt = atoi(sstr);
  3956. //stackLevel
  3957. c = 0;
  3958. loc = strstr(sLineWord, "stackLevel");
  3959. memset(sstr ,0, sizeof(sstr) );
  3960. while (loc[strlen("stackLevel")+2+c] != ',')
  3961. {
  3962. sstr[c] = loc[strlen("stackLevel")+2+c];
  3963. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3964. c++;
  3965. }
  3966. sstr[c] = '\0';
  3967. tempstackLevelInt = atoi(sstr);
  3968. c = 0;
  3969. loc = strstr(sLineWord, "chargingProfilePurpose");
  3970. memset(sstr ,0, sizeof(sstr) );
  3971. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3972. {
  3973. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3974. c++;
  3975. }
  3976. sstr[c] = '\0';
  3977. strcpy(tempchargingProfilePurposeStr, sstr);
  3978. if(chargingProfileIdIsNULL == FALSE)
  3979. {
  3980. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3981. {
  3982. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3983. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3984. clearflag = TRUE;
  3985. continue;
  3986. }
  3987. else
  3988. {
  3989. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3990. //json_object_array_add(newHeatMap, jsonitem);
  3991. fprintf(fptr2, sLineWord);//writing data into file
  3992. }
  3993. }
  3994. else
  3995. {
  3996. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3997. {
  3998. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3999. {
  4000. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4001. clearflag = TRUE;
  4002. continue;
  4003. }
  4004. }
  4005. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4006. {
  4007. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  4008. {
  4009. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  4010. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  4011. {
  4012. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4013. clearflag = TRUE;
  4014. continue;
  4015. }
  4016. }
  4017. }
  4018. else
  4019. {
  4020. //json_object_array_add(newHeatMap, jsonitem);
  4021. fprintf(fptr2, sLineWord);//writing data into file
  4022. }
  4023. }
  4024. memset(sLineWord, 0, sizeof sLineWord);
  4025. }
  4026. if(clearflag == FALSE)
  4027. {
  4028. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4029. goto end;
  4030. }
  4031. fclose(fptr1);
  4032. fclose(fptr2);
  4033. sprintf(str,"rm -f %s",fname);
  4034. system(str);
  4035. resultRename = rename(temp, fname);
  4036. if(resultRename == 0)
  4037. {
  4038. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4039. }
  4040. else
  4041. {
  4042. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4043. }
  4044. }
  4045. end:
  4046. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4047. return result;
  4048. }
  4049. int handleDataTransferRequest(char *uuid, char *payload)
  4050. {
  4051. mtrace();
  4052. int result = FAIL;
  4053. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4054. char tempvendorId[255]={0};
  4055. char tempmessageId[50]={0};
  4056. char tempdata[50]={0};
  4057. char sstr[160]={0};//sstr[200]={ 0 };
  4058. char message[80]={0};
  4059. int c = 0;
  4060. char *loc;
  4061. DEBUG_INFO("handle DataTransferRequest\n");
  4062. if((uuid != NULL) && (payload != NULL))
  4063. {
  4064. //===============================
  4065. // vendorId
  4066. //===============================
  4067. c = 0;
  4068. loc = strstr(payload, "vendorId");
  4069. while (loc[strlen("vendorId")+3+c] != '\"')
  4070. {
  4071. sstr[c] = loc[strlen("vendorId")+3+c];
  4072. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4073. c++;
  4074. }
  4075. sstr[c] = '\0';
  4076. strcpy(tempvendorId,sstr);
  4077. //===============================
  4078. // messageId
  4079. //===============================
  4080. memset(sstr ,0, sizeof(sstr) );
  4081. c = 0;
  4082. loc = strstr(payload, "messageId");
  4083. while (loc[strlen("messageId")+3+c] != '\"')
  4084. {
  4085. sstr[c] = loc[strlen("messageId")+3+c];
  4086. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4087. c++;
  4088. }
  4089. sstr[c] = '\0';
  4090. strcpy(tempmessageId,sstr);
  4091. //===============================
  4092. // data
  4093. //===============================
  4094. memset(sstr ,0, sizeof(sstr) );
  4095. c = 0;
  4096. loc = strstr(payload, "data");
  4097. printf("loc=%s\n",loc);
  4098. while (loc[strlen("data")+3+c] != '\"')
  4099. {
  4100. sstr[c] = loc[strlen("data")+3+c];
  4101. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4102. c++;
  4103. }
  4104. sstr[c] = '\0';
  4105. strcpy(tempdata,sstr);
  4106. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4107. }
  4108. else
  4109. {
  4110. char guid[37]={0};
  4111. random_uuid(guid);
  4112. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4113. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4114. }
  4115. LWS_Send(message);
  4116. return result;
  4117. }
  4118. #if 0
  4119. long long diff_tm(struct tm *a, struct tm *b) {
  4120. return a->tm_sec - b->tm_sec
  4121. + 60LL * (a->tm_min - b->tm_min)
  4122. + 3600LL * (a->tm_hour - b->tm_hour)
  4123. + 86400LL * (a->tm_yday - b->tm_yday)
  4124. + (a->tm_year - 70) * 31536000LL
  4125. - (a->tm_year - 69) / 4 * 86400LL
  4126. + (a->tm_year - 1) / 100 * 86400LL
  4127. - (a->tm_year + 299) / 400 * 86400LL
  4128. - (b->tm_year - 70) * 31536000LL
  4129. + (b->tm_year - 69) / 4 * 86400LL
  4130. - (b->tm_year - 1) / 100 * 86400LL
  4131. + (b->tm_year + 299) /400 * 86400LL;
  4132. }
  4133. #endif
  4134. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4135. {
  4136. mtrace();
  4137. int result = FAIL;
  4138. int connectorIdInt, durationInt;
  4139. char chargingRateUnitStr[4]={0};
  4140. //int tempconnectorIdInt,
  4141. int tempdurationInt;
  4142. float tempminChargingRateFloat = 0.0;
  4143. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4144. int tempStartPeriodInt=0;
  4145. float tempLimitInt=0.0;//0.1;
  4146. int tempNumberPhasesInt=0;
  4147. char fname[200];
  4148. char comfirmstr[20];
  4149. //float totallimit =0.0;
  4150. float MinChargingRate =0.0;
  4151. double diff_t;
  4152. struct tm tp;
  4153. //int clearflag = FALSE;
  4154. FILE *fptr1;//, *fptr2;
  4155. //char temp[] = "../Storage/OCPP/temp.json";
  4156. int c = 0;
  4157. //int i = 0;
  4158. char * pch;
  4159. char *loc;
  4160. char sstr[200]={ 0 };
  4161. int n_chargingProfile = 0;
  4162. int n_SchedulePeriods = 0;
  4163. char SchedulePeriodList[10][200]={0};
  4164. char sLineWord[800]={0};
  4165. //int n_periods = 0;
  4166. char word[1000]={0};
  4167. int confirmPeriods = 0;
  4168. struct StructProfile ChargePointMaxProfile;
  4169. struct StructProfile TxDefaultProfile;
  4170. struct StructProfile TxProfile;
  4171. struct StructProfile TxDefaultProfiletemp[2]={0};
  4172. int TxDefaultProfileFileIsNull=FALSE;
  4173. int ChargePointMaxProfileIsNull=FALSE;
  4174. int TxProfileIsNull=FALSE;
  4175. int CompositeSceduleIndex = 0;
  4176. char ChargePointMaxProfileScheduleStr[30]={0};
  4177. char TxDefaultProfileScheduleStr[30]={0};
  4178. char TxProfileScheduleStr[30]={0};
  4179. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4180. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4181. memset(&TxProfile,0,sizeof(struct StructProfile));
  4182. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4183. c=0;
  4184. loc = strstr(payload, "connectorId");
  4185. memset(sstr ,0, sizeof(sstr) );
  4186. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4187. {
  4188. sstr[c] = loc[strlen("connectorId")+2+c];
  4189. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4190. c++;
  4191. }
  4192. sstr[c] = '\0';
  4193. connectorIdInt = atoi(sstr);
  4194. c=0;
  4195. loc = strstr(payload, "duration");
  4196. memset(sstr ,0, sizeof(sstr) );
  4197. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4198. {
  4199. sstr[c] = loc[strlen("duration")+2+c];
  4200. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4201. c++;
  4202. }
  4203. sstr[c] = '\0';
  4204. durationInt = atoi(sstr);
  4205. c = 0;
  4206. loc = strstr(payload, "chargingRateUnit");
  4207. memset(sstr ,0, sizeof(sstr) );
  4208. if(loc == NULL)
  4209. {
  4210. }
  4211. else
  4212. {
  4213. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4214. {
  4215. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4216. c++;
  4217. }
  4218. sstr[c] = '\0';
  4219. strcpy(chargingRateUnitStr, sstr);
  4220. }
  4221. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4222. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4223. if(connectorIdInt==0) // connectorId is 0
  4224. {
  4225. //******************************ChargePointMaxProfile*****************************************************/
  4226. strcpy(fname, ChargePointMaxProfile_JSON );
  4227. char word[30]={0};
  4228. char sLineWord[1060]={0};
  4229. int n_chargingProfile=0;
  4230. ChargePointMaxProfileIsNull=TRUE;
  4231. if((access(fname,F_OK))!=-1)
  4232. {
  4233. fptr1 = fopen(fname, "r");
  4234. int c;
  4235. c = fgetc(fptr1);
  4236. //DEBUG_INFO("c:%d\n",c);
  4237. rewind(fptr1);
  4238. if(c == EOF)
  4239. {
  4240. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4241. ChargePointMaxProfileIsNull=TRUE;
  4242. fclose(fptr1);
  4243. }
  4244. else
  4245. {
  4246. ChargePointMaxProfileIsNull=FALSE;
  4247. while(fscanf(fptr1, "%s", word) != EOF)
  4248. {
  4249. if(strcmp(word, "chargingProfileId") == 0)
  4250. {
  4251. n_chargingProfile = n_chargingProfile + 1;
  4252. printf("Found\n");
  4253. }
  4254. }
  4255. rewind(fptr1);
  4256. //search Charging Profile Element
  4257. int i= 0;
  4258. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4259. #if 0
  4260. /***********connectorId****************/
  4261. c = 0;
  4262. loc = strstr(sLineWord, "connectorId");
  4263. // printf("loc=%s\n",loc);
  4264. memset(sstr ,0, sizeof(sstr) );
  4265. while (loc[strlen("connectorId")+2+c] != ',')
  4266. {
  4267. sstr[c] = loc[strlen("connectorId")+2+c];
  4268. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4269. c++;
  4270. }
  4271. sstr[c] = '\0';
  4272. tempconnectorIdInt = atoi(sstr);
  4273. #endif
  4274. //***********validFrom**************/
  4275. c = 0;
  4276. loc = strstr(sLineWord, "validFrom");
  4277. //DEBUG_INFO("loc=%s\n",loc);
  4278. memset(sstr ,0, sizeof(sstr) );
  4279. if(loc != NULL)
  4280. {
  4281. while (loc[3+strlen("validFrom")+c] != '\"')
  4282. {
  4283. sstr[c] = loc[3+strlen("validFrom")+c];
  4284. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4285. c++;
  4286. }
  4287. sstr[c] = '\0';
  4288. DEBUG_INFO("validFrom=%s\n",sstr);
  4289. strcpy(tempvalidFromStr,sstr);
  4290. }
  4291. else
  4292. {
  4293. strcpy(tempvalidFromStr,"");
  4294. }
  4295. //**********startSchedule**********/
  4296. c = 0;
  4297. loc = strstr(sLineWord, "startSchedule");
  4298. //DEBUG_INFO("loc=%s\n",loc);
  4299. memset(sstr ,0, sizeof(sstr) );
  4300. while (loc[3+strlen("startSchedule")+c] != '\"')
  4301. {
  4302. sstr[c] = loc[3+strlen("startSchedule")+c];
  4303. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4304. c++;
  4305. }
  4306. sstr[c] = '\0';
  4307. strcpy(tempstartScheduleStr, sstr);
  4308. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4309. //**********chargingRateUnit**********/
  4310. c = 0;
  4311. loc = strstr(sLineWord, "chargingRateUnit");
  4312. memset(sstr ,0, sizeof(sstr) );
  4313. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4314. {
  4315. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4316. c++;
  4317. }
  4318. sstr[c] = '\0';
  4319. strcpy(tempchargingRateUnitStr, sstr);
  4320. //**********minChargingRate*******/
  4321. c = 0;
  4322. loc = strstr(sLineWord, "minChargingRate");
  4323. //printf("loc=%s\n",loc);
  4324. if(loc != NULL)
  4325. {
  4326. memset(sstr ,0, sizeof(sstr) );
  4327. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4328. {
  4329. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4330. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4331. c++;
  4332. }
  4333. sstr[c] = '\0';
  4334. tempminChargingRateFloat = atof(sstr);
  4335. }
  4336. else
  4337. {
  4338. tempminChargingRateFloat = 0.0;
  4339. }
  4340. //
  4341. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4342. tp.tm_isdst = -1;
  4343. time_t utc = mktime(&tp);
  4344. // current time
  4345. time_t t = time(NULL);
  4346. diff_t = difftime(t, utc);
  4347. //parsing strings to words
  4348. i = 0;
  4349. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4350. loc = loc+3+strlen("chargingSchedulePeriod");
  4351. pch = strtok(loc ,"{");
  4352. while (pch != NULL)
  4353. {
  4354. strcpy(SchedulePeriodList[i], pch);
  4355. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4356. //printf ("%s\n",pch);
  4357. pch = strtok (NULL, "{");
  4358. i = i + 1;
  4359. }
  4360. n_SchedulePeriods = i;
  4361. for(int i=0;i<n_SchedulePeriods;i++)
  4362. {
  4363. //*************startPeriod****************/
  4364. c = 0;
  4365. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4366. memset(sstr ,0, sizeof(sstr) );
  4367. while (loc[strlen("startPeriod")+2+c] != ',')
  4368. {
  4369. sstr[c] = loc[strlen("startPeriod")+2+c];
  4370. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4371. c++;
  4372. }
  4373. sstr[c] = '\0';
  4374. tempStartPeriodInt = atoi(sstr);
  4375. //*************limit****************/
  4376. c = 0;
  4377. loc = strstr(SchedulePeriodList[i], "limit");
  4378. memset(sstr ,0, sizeof(sstr) );
  4379. while (loc[strlen("limit")+2+c] != ',')
  4380. {
  4381. sstr[c] = loc[strlen("limit")+2+c];
  4382. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4383. c++;
  4384. }
  4385. sstr[c] = '\0';
  4386. tempLimitInt = atof(sstr);
  4387. //*************numberPhases****************/
  4388. c = 0;
  4389. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4390. memset(sstr ,0, sizeof(sstr) );
  4391. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4392. {
  4393. sstr[c] = loc[strlen("numberPhases")+2+c];
  4394. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4395. c++;
  4396. }
  4397. sstr[c] = '\0';
  4398. tempNumberPhasesInt = atoi(sstr);
  4399. ChargePointMaxProfile.Duration = durationInt;
  4400. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4401. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4402. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4403. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4404. }
  4405. if(MinChargingRate < tempminChargingRateFloat)
  4406. MinChargingRate = tempminChargingRateFloat;
  4407. }
  4408. }// End of file ChargingProfile
  4409. } //THE END OF ACCESS ChargePointMaxProfile
  4410. //******************************TxDefaultProfile***********************************************/
  4411. strcpy(fname, TxDefaultProfile_0_JSON);
  4412. memset(word, 0, 30);
  4413. memset(sLineWord, 0, 1060);
  4414. //char word[30]={0};
  4415. //char sLineWord[1060]={0};
  4416. n_chargingProfile=0;
  4417. TxDefaultProfileFileIsNull=TRUE;
  4418. if((access(fname,F_OK))!=-1)
  4419. {
  4420. fptr1 = fopen(fname, "r");
  4421. c = 0;
  4422. c = fgetc(fptr1);
  4423. //DEBUG_INFO("c:%d\n",c);
  4424. rewind(fptr1);
  4425. if(c == EOF)
  4426. {
  4427. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4428. TxDefaultProfileFileIsNull=TRUE;
  4429. fclose(fptr1);
  4430. }
  4431. else
  4432. {
  4433. TxDefaultProfileFileIsNull=FALSE;
  4434. while(fscanf(fptr1, "%s", word) != EOF)
  4435. {
  4436. if(strcmp(word, "chargingProfileId") == 0)
  4437. {
  4438. n_chargingProfile = n_chargingProfile + 1;
  4439. printf("Found\n");
  4440. }
  4441. }
  4442. rewind(fptr1);
  4443. //search Charging Profile Element
  4444. int i= 0;
  4445. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4446. #if 0
  4447. /***********connectorId****************/
  4448. c = 0;
  4449. loc = strstr(sLineWord, "connectorId");
  4450. // printf("loc=%s\n",loc);
  4451. memset(sstr ,0, sizeof(sstr) );
  4452. while (loc[strlen("connectorId")+2+c] != ',')
  4453. {
  4454. sstr[c] = loc[strlen("connectorId")+2+c];
  4455. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4456. c++;
  4457. }
  4458. sstr[c] = '\0';
  4459. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4460. tempconnectorIdInt = atoi(sstr);
  4461. #endif
  4462. //***********validFrom**************/
  4463. c = 0;
  4464. loc = strstr(sLineWord, "validFrom");
  4465. //DEBUG_INFO("loc=%s\n",loc);
  4466. memset(sstr ,0, sizeof(sstr) );
  4467. if(loc != NULL)
  4468. {
  4469. while (loc[3+strlen("validFrom")+c] != '\"')
  4470. {
  4471. sstr[c] = loc[3+strlen("validFrom")+c];
  4472. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4473. c++;
  4474. }
  4475. sstr[c] = '\0';
  4476. DEBUG_INFO("validFrom=%s\n",sstr);
  4477. strcpy(tempvalidFromStr,sstr);
  4478. }
  4479. else
  4480. {
  4481. strcpy(tempvalidFromStr,"");
  4482. }
  4483. //**********startSchedule**********/
  4484. c = 0;
  4485. loc = strstr(sLineWord, "startSchedule");
  4486. //DEBUG_INFO("loc=%s\n",loc);
  4487. memset(sstr ,0, sizeof(sstr) );
  4488. while (loc[3+strlen("startSchedule")+c] != '\"')
  4489. {
  4490. sstr[c] = loc[3+strlen("startSchedule")+c];
  4491. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4492. c++;
  4493. }
  4494. sstr[c] = '\0';
  4495. strcpy(tempstartScheduleStr, sstr);
  4496. strcpy(TxDefaultProfileScheduleStr, sstr);
  4497. DEBUG_INFO(" debug 3-1\n");
  4498. //**********chargingRateUnit**********/
  4499. c = 0;
  4500. loc = strstr(sLineWord, "chargingRateUnit");
  4501. memset(sstr ,0, sizeof(sstr) );
  4502. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4503. {
  4504. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4505. c++;
  4506. }
  4507. sstr[c] = '\0';
  4508. strcpy(tempchargingRateUnitStr, sstr);
  4509. //**********minChargingRate*******/
  4510. c = 0;
  4511. loc = strstr(sLineWord, "minChargingRate");
  4512. //printf("loc=%s\n",loc);
  4513. if(loc != NULL)
  4514. {
  4515. memset(sstr ,0, sizeof(sstr) );
  4516. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4517. {
  4518. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4519. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4520. c++;
  4521. }
  4522. sstr[c] = '\0';
  4523. tempminChargingRateFloat = atof(sstr);
  4524. }
  4525. else
  4526. {
  4527. tempminChargingRateFloat = 0.0;
  4528. }
  4529. //
  4530. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4531. tp.tm_isdst = -1;
  4532. time_t utc = mktime(&tp);
  4533. // current time
  4534. time_t t = time(NULL);
  4535. diff_t = difftime(t, utc);
  4536. //parsing strings to words
  4537. i = 0;
  4538. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4539. loc = loc+3+strlen("chargingSchedulePeriod");
  4540. pch = strtok(loc ,"{");
  4541. while (pch != NULL)
  4542. {
  4543. strcpy(SchedulePeriodList[i], pch);
  4544. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4545. //printf ("%s\n",pch);
  4546. pch = strtok (NULL, "{");
  4547. i = i + 1;
  4548. }
  4549. n_SchedulePeriods = i;
  4550. for(int i=0;i<n_SchedulePeriods;i++)
  4551. {
  4552. //*************startPeriod****************/
  4553. c = 0;
  4554. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4555. memset(sstr ,0, sizeof(sstr) );
  4556. while (loc[strlen("startPeriod")+2+c] != ',')
  4557. {
  4558. sstr[c] = loc[strlen("startPeriod")+2+c];
  4559. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4560. c++;
  4561. }
  4562. sstr[c] = '\0';
  4563. tempStartPeriodInt = atoi(sstr);
  4564. //*************limit****************/
  4565. c = 0;
  4566. loc = strstr(SchedulePeriodList[i], "limit");
  4567. memset(sstr ,0, sizeof(sstr) );
  4568. while (loc[strlen("limit")+2+c] != ',')
  4569. {
  4570. sstr[c] = loc[strlen("limit")+2+c];
  4571. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4572. c++;
  4573. }
  4574. sstr[c] = '\0';
  4575. tempLimitInt = atof(sstr);
  4576. //*************numberPhases****************/
  4577. c = 0;
  4578. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4579. memset(sstr ,0, sizeof(sstr) );
  4580. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4581. {
  4582. sstr[c] = loc[strlen("numberPhases")+2+c];
  4583. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4584. c++;
  4585. }
  4586. sstr[c] = '\0';
  4587. tempNumberPhasesInt = atoi(sstr);
  4588. TxDefaultProfile.Duration = durationInt;
  4589. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4590. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4591. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4592. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4593. }
  4594. if(MinChargingRate < tempminChargingRateFloat)
  4595. MinChargingRate = tempminChargingRateFloat;
  4596. }
  4597. }
  4598. }// the end of ACCESS TxDefaultProfile
  4599. // Composite Schedule
  4600. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4601. {
  4602. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4603. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4604. {
  4605. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4606. {
  4607. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4608. }
  4609. else
  4610. {
  4611. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4612. }
  4613. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4614. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4615. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4616. }
  4617. }
  4618. //* Define temporary variables */
  4619. struct tm *gtime;
  4620. time_t now;
  4621. char buf[28];
  4622. /* Read the current system time */
  4623. time(&now);
  4624. /* Convert the system time to GMT (now UTC) */
  4625. gtime = gmtime(&now);
  4626. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4627. // make .conf
  4628. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4629. //MaxChargingProfilesInstalled is 10
  4630. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4631. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4632. //nPeriod = 1;
  4633. if(chargingRateUnitStr[0] != 0)
  4634. {
  4635. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4636. }
  4637. else
  4638. {
  4639. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4640. }
  4641. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4642. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4643. confirmPeriods = 1;
  4644. }
  4645. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4646. {
  4647. //*****************************ChargePointMaxProfile******************************************/
  4648. strcpy(fname, ChargePointMaxProfile_JSON);
  4649. ChargePointMaxProfileIsNull=TRUE;
  4650. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4651. {
  4652. fptr1 = fopen(fname, "r");
  4653. int c;
  4654. c = fgetc(fptr1);
  4655. //DEBUG_INFO("c:%d\n",c);
  4656. rewind(fptr1);
  4657. if(c == EOF)
  4658. {
  4659. DEBUG_INFO("\n End of file reached.");
  4660. ChargePointMaxProfileIsNull=TRUE;
  4661. fclose(fptr1);
  4662. }
  4663. else
  4664. {
  4665. ChargePointMaxProfileIsNull=FALSE;
  4666. while(fscanf(fptr1, "%s", word) != EOF)
  4667. {
  4668. if(strcmp(word, "chargingProfileId") == 0)
  4669. {
  4670. n_chargingProfile = n_chargingProfile + 1;
  4671. }
  4672. }
  4673. rewind(fptr1);
  4674. //search Charging Profile Element
  4675. int i = 0;
  4676. int j = 0;
  4677. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4678. #if 0
  4679. /***********connectorId****************/
  4680. c = 0;
  4681. loc = strstr(sLineWord, "connectorId");
  4682. memset(sstr ,0, sizeof(sstr) );
  4683. while (loc[strlen("connectorId")+2+c] != ',')
  4684. {
  4685. sstr[c] = loc[strlen("connectorId")+2+c];
  4686. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4687. c++;
  4688. }
  4689. sstr[c] = '\0';
  4690. tempconnectorIdInt = atoi(sstr);
  4691. #endif
  4692. //***********validFrom**************/
  4693. c = 0;
  4694. loc = strstr(sLineWord, "validFrom");
  4695. if(loc != NULL)
  4696. {
  4697. memset(sstr ,0, sizeof(sstr) );
  4698. while (loc[3+strlen("validFrom")+c] != '\"')
  4699. {
  4700. sstr[c] = loc[3+strlen("validFrom")+c];
  4701. c++;
  4702. }
  4703. sstr[c] = '\0';
  4704. strcpy(tempvalidFromStr,sstr);
  4705. }
  4706. else
  4707. {
  4708. strcpy(tempvalidFromStr,"");
  4709. }
  4710. //***********validFrom**************/
  4711. c = 0;
  4712. loc = strstr(sLineWord, "duration");
  4713. if(loc != NULL)
  4714. {
  4715. memset(sstr ,0, sizeof(sstr) );
  4716. while (loc[2+strlen("duration")+c] != ',')
  4717. {
  4718. sstr[c] = loc[2+strlen("duration")+c];
  4719. c++;
  4720. }
  4721. sstr[c] = '\0';
  4722. tempdurationInt = atoi(sstr);
  4723. }
  4724. else
  4725. {
  4726. tempdurationInt = 0;
  4727. }
  4728. //**********startSchedule**********/
  4729. c = 0;
  4730. loc = strstr(sLineWord, "startSchedule");
  4731. memset(sstr ,0, sizeof(sstr) );
  4732. while (loc[3+strlen("startSchedule")+c] != '\"')
  4733. {
  4734. sstr[c] = loc[3+strlen("startSchedule")+c];
  4735. c++;
  4736. }
  4737. sstr[c] = '\0';
  4738. strcpy(tempstartScheduleStr, sstr);
  4739. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4740. //**********chargingRateUnit**********/
  4741. c = 0;
  4742. loc = strstr(sLineWord, "chargingRateUnit");
  4743. memset(sstr ,0, sizeof(sstr) );
  4744. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4745. {
  4746. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4747. c++;
  4748. }
  4749. sstr[c] = '\0';
  4750. strcpy(tempchargingRateUnitStr, sstr);
  4751. //**********minChargingRate*******/
  4752. c = 0;
  4753. loc = strstr(sLineWord, "minChargingRate");
  4754. if(loc != NULL)
  4755. {
  4756. memset(sstr ,0, sizeof(sstr) );
  4757. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4758. {
  4759. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4760. c++;
  4761. }
  4762. sstr[c] = '\0';
  4763. tempminChargingRateFloat = atof(sstr);
  4764. }
  4765. else
  4766. {
  4767. tempminChargingRateFloat = 0.0;
  4768. }
  4769. //
  4770. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4771. tp.tm_isdst = -1;
  4772. time_t utc = mktime(&tp);
  4773. time_t t = time(NULL);
  4774. diff_t = difftime(t, utc);
  4775. DEBUG_INFO("diff_t=%f\n",diff_t);
  4776. DEBUG_INFO(" debug 5 -1\n");
  4777. //parsing strings to words
  4778. i = 0;
  4779. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4780. loc = loc+3+strlen("chargingSchedulePeriod");
  4781. pch = strtok(loc ,"{");
  4782. while (pch != NULL)
  4783. {
  4784. strcpy(SchedulePeriodList[i], pch);
  4785. pch = strtok (NULL, "{");
  4786. i = i + 1;
  4787. }
  4788. n_SchedulePeriods = i;
  4789. for(int i=0;i<n_SchedulePeriods;i++)
  4790. {
  4791. //*************startPeriod****************/
  4792. c = 0;
  4793. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4794. memset(sstr ,0, sizeof(sstr) );
  4795. while (loc[strlen("startPeriod")+2+c] != ',')
  4796. {
  4797. sstr[c] = loc[strlen("startPeriod")+2+c];
  4798. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4799. c++;
  4800. }
  4801. sstr[c] = '\0';
  4802. tempStartPeriodInt = atoi(sstr);
  4803. //*************limit****************/
  4804. c = 0;
  4805. loc = strstr(SchedulePeriodList[i], "limit");
  4806. memset(sstr ,0, sizeof(sstr) );
  4807. while (loc[strlen("limit")+2+c] != ',')
  4808. {
  4809. sstr[c] = loc[strlen("limit")+2+c];
  4810. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4811. c++;
  4812. }
  4813. sstr[c] = '\0';
  4814. tempLimitInt = atof(sstr);
  4815. //*************numberPhases****************/
  4816. c = 0;
  4817. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4818. memset(sstr ,0, sizeof(sstr) );
  4819. while (loc[strlen("numberPhases")+2+c] != '}')
  4820. {
  4821. sstr[c] = loc[strlen("numberPhases")+2+c];
  4822. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4823. c++;
  4824. }
  4825. sstr[c] = '\0';
  4826. tempNumberPhasesInt = atoi(sstr);
  4827. if(j == 0)
  4828. {
  4829. ChargePointMaxProfile.Duration = tempdurationInt;
  4830. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4831. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4832. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4833. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4834. }
  4835. }
  4836. if(MinChargingRate < tempminChargingRateFloat)
  4837. {
  4838. MinChargingRate = tempminChargingRateFloat;
  4839. }
  4840. if(confirmPeriods < n_SchedulePeriods)
  4841. {
  4842. confirmPeriods = n_SchedulePeriods;
  4843. }
  4844. j = j + 1;
  4845. }
  4846. fclose(fptr1);
  4847. }
  4848. }// the end of access file ChargePointMaxProfile
  4849. //****************************TxDefaultProfile************************************************/
  4850. switch(connectorIdInt)
  4851. {
  4852. case 0:
  4853. break;
  4854. case 1:
  4855. strcpy(fname, TxDefaultProfile_1_JSON );
  4856. break;
  4857. case 2:
  4858. strcpy(fname, TxDefaultProfile_2_JSON );
  4859. break;
  4860. default:
  4861. strcpy(fname, TxDefaultProfile_1_JSON );
  4862. break;
  4863. }
  4864. TxDefaultProfileFileIsNull=TRUE;
  4865. if((access(fname,F_OK))!=-1)
  4866. {
  4867. fptr1 = fopen(fname, "r");
  4868. c = 0;
  4869. c = fgetc(fptr1);
  4870. //DEBUG_INFO("c:%d\n",c);
  4871. rewind(fptr1);
  4872. if(c == EOF)
  4873. {
  4874. DEBUG_INFO("\n End of file reached.");
  4875. TxDefaultProfileFileIsNull=TRUE;
  4876. fclose(fptr1);
  4877. }
  4878. else
  4879. {
  4880. TxDefaultProfileFileIsNull=FALSE;
  4881. while(fscanf(fptr1, "%s", word) != EOF)
  4882. {
  4883. if(strcmp(word, "chargingProfileId") == 0)
  4884. {
  4885. n_chargingProfile = n_chargingProfile + 1;
  4886. }
  4887. }
  4888. rewind(fptr1);
  4889. //search Charging Profile Element
  4890. int i = 0;
  4891. int j = 0;
  4892. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4893. DEBUG_INFO(" 1-1\n");
  4894. #if 0
  4895. /***********connectorId****************/
  4896. c = 0;
  4897. loc = strstr(sLineWord, "connectorId");
  4898. memset(sstr ,0, sizeof(sstr) );
  4899. while (loc[strlen("connectorId")+2+c] != ',')
  4900. {
  4901. sstr[c] = loc[strlen("connectorId")+2+c];
  4902. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4903. c++;
  4904. }
  4905. sstr[c] = '\0';
  4906. tempconnectorIdInt = atoi(sstr);
  4907. #endif
  4908. //***********validFrom**************/
  4909. c = 0;
  4910. loc = strstr(sLineWord, "validFrom");
  4911. if(loc != NULL)
  4912. {
  4913. memset(sstr ,0, sizeof(sstr) );
  4914. while (loc[3+strlen("validFrom")+c] != '\"')
  4915. {
  4916. sstr[c] = loc[3+strlen("validFrom")+c];
  4917. c++;
  4918. }
  4919. sstr[c] = '\0';
  4920. strcpy(tempvalidFromStr,sstr);
  4921. }
  4922. else
  4923. {
  4924. strcpy(tempvalidFromStr,"");
  4925. }
  4926. //***********validFrom**************/
  4927. c = 0;
  4928. loc = strstr(sLineWord, "duration");
  4929. if(loc != NULL)
  4930. {
  4931. memset(sstr ,0, sizeof(sstr) );
  4932. while (loc[2+strlen("duration")+c] != ',')
  4933. {
  4934. sstr[c] = loc[2+strlen("duration")+c];
  4935. c++;
  4936. }
  4937. sstr[c] = '\0';
  4938. tempdurationInt = atoi(sstr);
  4939. }
  4940. else
  4941. {
  4942. tempdurationInt = 0;
  4943. }
  4944. //**********startSchedule**********/
  4945. c = 0;
  4946. loc = strstr(sLineWord, "startSchedule");
  4947. memset(sstr ,0, sizeof(sstr) );
  4948. while (loc[3+strlen("startSchedule")+c] != '\"')
  4949. {
  4950. sstr[c] = loc[3+strlen("startSchedule")+c];
  4951. c++;
  4952. }
  4953. sstr[c] = '\0';
  4954. strcpy(tempstartScheduleStr, sstr);
  4955. strcpy(TxDefaultProfileScheduleStr, sstr);
  4956. //**********chargingRateUnit**********/
  4957. c = 0;
  4958. loc = strstr(sLineWord, "chargingRateUnit");
  4959. memset(sstr ,0, sizeof(sstr) );
  4960. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4961. {
  4962. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4963. c++;
  4964. }
  4965. sstr[c] = '\0';
  4966. strcpy(tempchargingRateUnitStr, sstr);
  4967. //**********minChargingRate*******/
  4968. c = 0;
  4969. loc = strstr(sLineWord, "minChargingRate");
  4970. if(loc != NULL)
  4971. {
  4972. memset(sstr ,0, sizeof(sstr) );
  4973. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4974. {
  4975. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4976. c++;
  4977. }
  4978. sstr[c] = '\0';
  4979. tempminChargingRateFloat = atof(sstr);
  4980. }
  4981. else
  4982. {
  4983. tempminChargingRateFloat = 0.0;
  4984. }
  4985. //
  4986. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4987. tp.tm_isdst = -1;
  4988. time_t utc = mktime(&tp);
  4989. time_t t = time(NULL);
  4990. diff_t = difftime(t, utc);
  4991. DEBUG_INFO("diff_t=%f\n",diff_t);
  4992. //parsing strings to words
  4993. i = 0;
  4994. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4995. loc = loc+3+strlen("chargingSchedulePeriod");
  4996. pch = strtok(loc ,"{");
  4997. while (pch != NULL)
  4998. {
  4999. strcpy(SchedulePeriodList[i], pch);
  5000. pch = strtok (NULL, "{");
  5001. i = i + 1;
  5002. }
  5003. n_SchedulePeriods = i;
  5004. for(int i=0;i<n_SchedulePeriods;i++)
  5005. {
  5006. //*************startPeriod****************/
  5007. c = 0;
  5008. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5009. memset(sstr ,0, sizeof(sstr) );
  5010. while (loc[strlen("startPeriod")+2+c] != ',')
  5011. {
  5012. sstr[c] = loc[strlen("startPeriod")+2+c];
  5013. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5014. c++;
  5015. }
  5016. sstr[c] = '\0';
  5017. tempStartPeriodInt = atoi(sstr);
  5018. //*************limit****************/
  5019. c = 0;
  5020. loc = strstr(SchedulePeriodList[i], "limit");
  5021. memset(sstr ,0, sizeof(sstr) );
  5022. while (loc[strlen("limit")+2+c] != ',')
  5023. {
  5024. sstr[c] = loc[strlen("limit")+2+c];
  5025. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5026. c++;
  5027. }
  5028. sstr[c] = '\0';
  5029. tempLimitInt = atof(sstr);
  5030. //*************numberPhases****************/
  5031. c = 0;
  5032. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5033. memset(sstr ,0, sizeof(sstr) );
  5034. while (loc[strlen("numberPhases")+2+c] != '}')
  5035. {
  5036. sstr[c] = loc[strlen("numberPhases")+2+c];
  5037. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5038. c++;
  5039. }
  5040. sstr[c] = '\0';
  5041. tempNumberPhasesInt = atoi(sstr);
  5042. if(j == 0)
  5043. {
  5044. TxDefaultProfile.Duration = tempdurationInt;
  5045. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5046. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5047. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5048. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5049. }
  5050. else
  5051. {
  5052. //other stack level charging Profile
  5053. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5054. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5055. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5056. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5057. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5058. }
  5059. }
  5060. if(MinChargingRate < tempminChargingRateFloat)
  5061. MinChargingRate = tempminChargingRateFloat;
  5062. if(confirmPeriods < n_SchedulePeriods)
  5063. confirmPeriods = n_SchedulePeriods;
  5064. j = j + 1;
  5065. DEBUG_INFO(" 1-2\n");
  5066. }
  5067. fclose(fptr1);
  5068. //Stacking Charging Profiles
  5069. for(int l=0; l <(j-1) ;l++)
  5070. {
  5071. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5072. {
  5073. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5074. {
  5075. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5076. {
  5077. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5078. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5079. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5080. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5081. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5082. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5083. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5084. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5085. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5086. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5087. }
  5088. else
  5089. {
  5090. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5091. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5092. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5093. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5094. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5095. }
  5096. }
  5097. }
  5098. }
  5099. //end of Stacking Charging Profiles
  5100. }
  5101. }// the end of ACCESS TxDefaultProfile
  5102. //****************************TxProfile************************************************/
  5103. switch(connectorIdInt)
  5104. {
  5105. case 0:
  5106. break;
  5107. case 1:
  5108. strcpy(fname, TxProfile_1_JSON );
  5109. break;
  5110. case 2:
  5111. strcpy(fname, TxProfile_2_JSON );
  5112. break;
  5113. default:
  5114. strcpy(fname, TxProfile_1_JSON );
  5115. break;
  5116. }
  5117. TxProfileIsNull=TRUE;
  5118. if((access(fname,F_OK))!=-1)
  5119. {
  5120. fptr1 = fopen(fname, "r");
  5121. c = 0;
  5122. c = fgetc(fptr1);
  5123. //DEBUG_INFO("c:%d\n",c);
  5124. rewind(fptr1);
  5125. if(c == EOF)
  5126. {
  5127. DEBUG_INFO("\n End of file reached.");
  5128. TxProfileIsNull=TRUE;
  5129. fclose(fptr1);
  5130. }
  5131. else
  5132. {
  5133. TxProfileIsNull=FALSE;
  5134. while(fscanf(fptr1, "%s", word) != EOF)
  5135. {
  5136. if(strcmp(word, "chargingProfileId") == 0)
  5137. {
  5138. n_chargingProfile = n_chargingProfile + 1;
  5139. }
  5140. }
  5141. rewind(fptr1);
  5142. //search Charging Profile Element
  5143. int i= 0;
  5144. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5145. #if 0
  5146. /***********connectorId****************/
  5147. c = 0;
  5148. loc = strstr(sLineWord, "connectorId");
  5149. memset(sstr ,0, sizeof(sstr) );
  5150. while (loc[strlen("connectorId")+2+c] != ',')
  5151. {
  5152. sstr[c] = loc[strlen("connectorId")+2+c];
  5153. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5154. c++;
  5155. }
  5156. sstr[c] = '\0';
  5157. tempconnectorIdInt = atoi(sstr);
  5158. #endif
  5159. //***********validFrom**************/
  5160. c = 0;
  5161. loc = strstr(sLineWord, "validFrom");
  5162. if(loc != NULL)
  5163. {
  5164. memset(sstr ,0, sizeof(sstr) );
  5165. while (loc[3+strlen("validFrom")+c] != '\"')
  5166. {
  5167. sstr[c] = loc[3+strlen("validFrom")+c];
  5168. c++;
  5169. }
  5170. sstr[c] = '\0';
  5171. strcpy(tempvalidFromStr,sstr);
  5172. }
  5173. else
  5174. {
  5175. strcpy(tempvalidFromStr,"");
  5176. }
  5177. //**********startSchedule**********/
  5178. c = 0;
  5179. loc = strstr(sLineWord, "startSchedule");
  5180. memset(sstr ,0, sizeof(sstr) );
  5181. while (loc[3+strlen("startSchedule")+c] != '\"')
  5182. {
  5183. sstr[c] = loc[3+strlen("startSchedule")+c];
  5184. c++;
  5185. }
  5186. sstr[c] = '\0';
  5187. strcpy(tempstartScheduleStr, sstr);
  5188. strcpy(TxProfileScheduleStr, sstr);
  5189. //**********chargingRateUnit**********/
  5190. c = 0;
  5191. loc = strstr(sLineWord, "chargingRateUnit");
  5192. memset(sstr ,0, sizeof(sstr) );
  5193. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5194. {
  5195. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5196. c++;
  5197. }
  5198. sstr[c] = '\0';
  5199. strcpy(tempchargingRateUnitStr, sstr);
  5200. //**********minChargingRate*******/
  5201. c = 0;
  5202. loc = strstr(sLineWord, "minChargingRate");
  5203. if(loc != NULL)
  5204. {
  5205. memset(sstr ,0, sizeof(sstr) );
  5206. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5207. {
  5208. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5209. c++;
  5210. }
  5211. sstr[c] = '\0';
  5212. tempminChargingRateFloat = atof(sstr);
  5213. }
  5214. else
  5215. {
  5216. tempminChargingRateFloat = 0.0;
  5217. }
  5218. //
  5219. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5220. tp.tm_isdst = -1;
  5221. time_t utc = mktime(&tp);
  5222. time_t t = time(NULL);
  5223. diff_t = difftime(t, utc);
  5224. DEBUG_INFO("diff_t=%f\n",diff_t);
  5225. //parsing strings to words
  5226. i = 0;
  5227. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5228. loc = loc+3+strlen("chargingSchedulePeriod");
  5229. pch = strtok(loc ,"{");
  5230. while (pch != NULL)
  5231. {
  5232. strcpy(SchedulePeriodList[i], pch);
  5233. pch = strtok (NULL, "{");
  5234. i = i + 1;
  5235. }
  5236. n_SchedulePeriods = i;
  5237. for(int i=0;i<n_SchedulePeriods;i++)
  5238. {
  5239. //*************startPeriod****************/
  5240. c = 0;
  5241. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5242. memset(sstr ,0, sizeof(sstr) );
  5243. while (loc[strlen("startPeriod")+2+c] != ',')
  5244. {
  5245. sstr[c] = loc[strlen("startPeriod")+2+c];
  5246. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5247. c++;
  5248. }
  5249. sstr[c] = '\0';
  5250. tempStartPeriodInt = atoi(sstr);
  5251. //*************limit****************/
  5252. c = 0;
  5253. loc = strstr(SchedulePeriodList[i], "limit");
  5254. memset(sstr ,0, sizeof(sstr) );
  5255. while (loc[strlen("limit")+2+c] != ',')
  5256. {
  5257. sstr[c] = loc[strlen("limit")+2+c];
  5258. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5259. c++;
  5260. }
  5261. sstr[c] = '\0';
  5262. tempLimitInt = atof(sstr);
  5263. //*************numberPhases****************/
  5264. c = 0;
  5265. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5266. memset(sstr ,0, sizeof(sstr) );
  5267. while (loc[strlen("numberPhases")+2+c] != '}')
  5268. {
  5269. sstr[c] = loc[strlen("numberPhases")+2+c];
  5270. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5271. c++;
  5272. }
  5273. sstr[c] = '\0';
  5274. tempNumberPhasesInt = atoi(sstr);
  5275. TxProfile.Duration = durationInt;
  5276. TxProfile.TotalPeriod = n_SchedulePeriods;
  5277. TxProfile.Period[i].Limit = tempLimitInt;
  5278. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5279. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5280. }
  5281. if(MinChargingRate < tempminChargingRateFloat)
  5282. MinChargingRate = tempminChargingRateFloat;
  5283. if(confirmPeriods < n_SchedulePeriods)
  5284. confirmPeriods = n_SchedulePeriods;
  5285. }
  5286. fclose(fptr1);
  5287. }
  5288. }// the end of ACCESS TxProfile
  5289. //CompositeSchedule
  5290. int period=0;
  5291. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5292. {
  5293. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5294. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5295. {
  5296. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5297. {
  5298. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5299. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5300. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5301. period = period + 1;
  5302. }
  5303. else
  5304. {
  5305. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5306. {
  5307. }
  5308. else
  5309. {
  5310. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5311. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5312. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5313. period = period + 1;
  5314. }
  5315. }
  5316. }
  5317. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5318. {
  5319. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5320. {
  5321. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5322. {
  5323. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5324. }
  5325. else
  5326. {
  5327. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5328. }
  5329. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5330. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5331. period = period + 1;
  5332. }
  5333. }
  5334. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5335. {
  5336. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5337. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5338. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5339. period = period + 1;
  5340. }
  5341. }
  5342. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5343. {
  5344. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5345. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5346. {
  5347. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5348. {
  5349. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5350. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5351. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5352. period = period + 1;
  5353. }
  5354. else
  5355. {
  5356. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5357. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5358. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5359. period = period + 1;
  5360. }
  5361. }
  5362. }
  5363. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5364. {
  5365. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5366. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5367. {
  5368. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5369. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5370. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5371. period = period + 1;
  5372. }
  5373. }
  5374. confirmPeriods = period;
  5375. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5376. //* Define temporary variables */
  5377. struct tm *gtime;
  5378. time_t now;
  5379. char buf[28];
  5380. //* Read the current system time */
  5381. time(&now);
  5382. //* Convert the system time to GMT (now UTC) */
  5383. gtime = gmtime(&now);
  5384. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5385. // make .conf
  5386. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5387. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5388. //DEBUG_INFO(" debug 11\n");
  5389. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5390. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5391. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5392. }
  5393. else
  5394. {
  5395. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5396. }
  5397. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5398. return result;
  5399. }
  5400. int handleGetConfigurationRequest(char *uuid, char *payload)
  5401. {
  5402. mtrace();
  5403. int result = FAIL;
  5404. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5405. //struct json_object *jsonitem;
  5406. int MaxKeySupported = 0;
  5407. int n_keys = 0;
  5408. char requestKey[43][50]={0};
  5409. char search[]="[";
  5410. char sstr[500]={ 0 };
  5411. //int pos;
  5412. int l, c = 0;
  5413. int i = 0;
  5414. char *delim = "\",\"";
  5415. char * pch;
  5416. char *loc = strstr(payload, search);
  5417. //********************* Parsing String ***********************************/
  5418. if(loc == NULL) {
  5419. DEBUG_INFO("no key match in Configuration \n");
  5420. }
  5421. else {
  5422. //pos = loc - payload;
  5423. l = strlen(loc)-4;
  5424. while (c < l)
  5425. {
  5426. sstr[c] = loc[c+2];
  5427. c++;
  5428. }
  5429. sstr[c] = '\0';
  5430. //parsing strings to words
  5431. pch = strtok(sstr,delim);
  5432. if(pch == NULL)
  5433. {
  5434. strcpy(requestKey[0], sstr);
  5435. }
  5436. else
  5437. {
  5438. while (pch != NULL)
  5439. {
  5440. strcpy(requestKey[i], pch);
  5441. pch = strtok (NULL, delim);
  5442. i = i + 1;
  5443. }
  5444. n_keys = i;
  5445. }
  5446. }
  5447. UnknownKeynum = 0;
  5448. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5449. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5450. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5451. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5452. if(n_keys != 0)
  5453. {
  5454. for(int i=0;i<n_keys;i++)
  5455. {
  5456. getKeyValue(requestKey[i]);
  5457. //json_object_put(jsonitem);
  5458. }
  5459. }
  5460. else
  5461. {
  5462. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5463. getKeyValue("");
  5464. }
  5465. processUnkownKey();
  5466. sendGetConfigurationConfirmation(uuid);
  5467. return result;
  5468. }
  5469. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5470. {
  5471. mtrace();
  5472. int result = FAIL;
  5473. //void *ret; //
  5474. char fnamePlusPath[50]="";
  5475. char fname[16]="";
  5476. pthread_t t; // pthread 變數
  5477. time_t rawtime;
  5478. struct tm * timeinfo;
  5479. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5480. system("exec /root/logPackTools 'log' 6");
  5481. //char buffer [128];
  5482. time (&rawtime);
  5483. //printf("%ld\n", rawtime);
  5484. timeinfo = localtime (&rawtime);
  5485. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5486. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5487. if((access(fnamePlusPath,F_OK))!=-1)
  5488. {
  5489. DEBUG_INFO("fnamePlusPath exist.\n");
  5490. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5491. }
  5492. else
  5493. {
  5494. DEBUG_INFO("fnamePlusPath not exist!\n");
  5495. }
  5496. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5497. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5498. pthread_join(t, NULL/*&ret*/);
  5499. return result;
  5500. }
  5501. void* GetDiagnosticsProcess(void* data)
  5502. {
  5503. mtrace();
  5504. int retriesInt=0, retryIntervalInt=0;
  5505. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5506. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5507. 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};
  5508. int port=0;
  5509. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5510. char fname[16]="";
  5511. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5512. int c = 0;
  5513. char *loc;
  5514. int isSuccess = FALSE;
  5515. char ftpbuf[200]={0};
  5516. //char temp[100]={0};
  5517. char * pch;
  5518. // [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"}]
  5519. char *str = (char*) data; // ? ?輸入資 ?
  5520. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5521. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5522. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5523. //****************location*******************/
  5524. c = 0;
  5525. memset(sstr ,0, sizeof(sstr) );
  5526. loc = strstr(str, "location");
  5527. while (loc[3+strlen("location")+c] != '\"')
  5528. {
  5529. sstr[c] = loc[3+strlen("location")+c];
  5530. c++;
  5531. }
  5532. sstr[c] = '\0';
  5533. strcpy(locationstr,sstr);
  5534. if(strcmp(locationstr,"")==0)
  5535. {
  5536. DEBUG_INFO("location is <Empty>!\n");
  5537. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5538. goto end;
  5539. }
  5540. //****************retries*******************/
  5541. c = 0;
  5542. loc = strstr(str, "retries");
  5543. if(loc == NULL)
  5544. {
  5545. retriesIsNULL = TRUE;
  5546. }
  5547. else
  5548. {
  5549. while (loc[strlen("retries")+2+c] != ',')
  5550. {
  5551. sstr[c] = loc[strlen("retries")+2+c];
  5552. c++;
  5553. }
  5554. sstr[c] = '\0';
  5555. retriesInt = atoi(sstr);
  5556. }
  5557. if(retriesIsNULL == TRUE)
  5558. {
  5559. retriesInt = 0;
  5560. }
  5561. //****************retryInterval*******************/
  5562. c = 0;
  5563. loc = strstr(str, "retryInterval");
  5564. if(loc == NULL)
  5565. {
  5566. retryIntervalIsNULL = TRUE;
  5567. }
  5568. else
  5569. {
  5570. while (loc[strlen("retryInterval")+2+c] != ',')
  5571. {
  5572. sstr[c] = loc[strlen("retryInterval")+2+c];
  5573. c++;
  5574. }
  5575. sstr[c] = '\0';
  5576. retryIntervalInt = atoi(sstr);
  5577. }
  5578. //****************startTime*******************/
  5579. c = 0;
  5580. memset(sstr ,0, sizeof(sstr) );
  5581. loc = strstr(str, "startTime");
  5582. if(loc == NULL)
  5583. {
  5584. startTimeIsNULL = TRUE;
  5585. }
  5586. else
  5587. {
  5588. while (loc[3+strlen("startTime")+c] != '\"')
  5589. {
  5590. sstr[c] = loc[3+strlen("startTime")+c];
  5591. c++;
  5592. }
  5593. sstr[c] = '\0';
  5594. strcpy(startTimestr,sstr);
  5595. }
  5596. //****************stopTime*******************/
  5597. c = 0;
  5598. memset(sstr ,0, sizeof(sstr) );
  5599. loc = strstr(str, "stopTime");
  5600. if(loc == NULL)
  5601. {
  5602. stopTimeIsNULL = TRUE;
  5603. }
  5604. else
  5605. {
  5606. while (loc[3+strlen("stopTime")+c] != '\"')
  5607. {
  5608. sstr[c] = loc[3+strlen("stopTime")+c];
  5609. c++;
  5610. }
  5611. sstr[c] = '\0';
  5612. strcpy(stopTimestr,sstr);
  5613. }
  5614. memset(protocol, 0, sizeof(protocol));
  5615. memset(user, 0, sizeof(user) );
  5616. memset(password, 0, sizeof(password));
  5617. memset(host, 0, sizeof(host));
  5618. memset(path, 0, sizeof(path));
  5619. memset(ftppath, 0, sizeof(ftppath));
  5620. memset(host1, 0, sizeof(host1));
  5621. memset(path1, 0, sizeof(path1));
  5622. /*location: ftp://user:password@host:port/path*/
  5623. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5624. // protocol, user, password, host, &port, path);
  5625. #if 0 // remove for temporally
  5626. //zip files in /Storage
  5627. system("exec /root/logPackTools 'log' 6");
  5628. #endif
  5629. // system("exec /root/Module_WebService 'log' 6");
  5630. time_t rawtime;
  5631. struct tm * timeinfo;
  5632. //char buffer [128];
  5633. time (&rawtime);
  5634. //printf("%ld\n", rawtime);
  5635. timeinfo = localtime (&rawtime);
  5636. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5637. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5638. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5639. if((access(fnamePlusPath,F_OK))!=-1)
  5640. {
  5641. DEBUG_INFO("fnamePlusPath exist.\n");
  5642. }
  5643. else
  5644. {
  5645. DEBUG_INFO("fnamePlusPath not exist!\n");
  5646. goto end;
  5647. }
  5648. pch=strchr(locationstr,'@');
  5649. if(pch==NULL)
  5650. {
  5651. sscanf(locationstr,
  5652. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5653. protocol, host, &port, path);
  5654. strcpy(user,"anonymous");
  5655. strcpy(password,"");
  5656. }
  5657. else
  5658. {
  5659. DEBUG_INFO("pch=%s\n", pch);
  5660. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5661. protocol, user, password, host, &port, path);
  5662. }
  5663. if(strcmp(protocol,"ftp")!=0)
  5664. {
  5665. DEBUG_INFO("protocol is not ftp!\n");
  5666. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5667. goto end;
  5668. }
  5669. sscanf(host,"%[^/]%s",host1, path1);
  5670. sprintf(ftppath,"%s", path1);
  5671. DEBUG_INFO("protocol =%s\n",protocol);
  5672. DEBUG_INFO("user =%s\n",user);
  5673. DEBUG_INFO("password =%s\n",password);
  5674. DEBUG_INFO("host1 =%s\n",host1);
  5675. DEBUG_INFO("port =%d\n",port);
  5676. DEBUG_INFO("path1 =%s\n",path1);
  5677. DEBUG_INFO("ftppath=%s\n",ftppath);
  5678. int ftppathlen=strlen(ftppath);
  5679. int i=1;
  5680. char filenametemp[50];
  5681. while(i < ftppathlen)
  5682. {
  5683. int len=ftppathlen-i;
  5684. if(ftppath[len]== 47) // '/' ascll code: 47
  5685. {
  5686. DEBUG_INFO("find '/' all right\n");
  5687. break;
  5688. }
  5689. i=i+1;
  5690. }
  5691. memset(filenametemp, 0, sizeof(filenametemp));
  5692. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5693. filenametemp[i+1] = 0;
  5694. //httpDownLoadFile(host, ftppath, fname);
  5695. memset(ftpbuf, 0, sizeof(ftpbuf));
  5696. if(port == 0)
  5697. port = 21;
  5698. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5699. do{
  5700. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5701. sleep(retryIntervalInt);
  5702. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5703. if(!isSuccess)
  5704. {
  5705. //BulldogUtil.sleepMs(interval*1000);
  5706. DEBUG_INFO("Diagnostics fail.\n");
  5707. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5708. }
  5709. else
  5710. {
  5711. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5712. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5713. //isUpdateRequest = TRUE;
  5714. }
  5715. end:
  5716. // json_object_put(obj);
  5717. DiagnosticsStatusNotificationStatus = 0; //Idle
  5718. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5719. }
  5720. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5721. {
  5722. mtrace();
  5723. int result = FAIL;
  5724. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5725. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5726. {
  5727. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5728. localversion = -1;
  5729. }
  5730. else
  5731. {
  5732. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5733. OCPP_getListVerion();
  5734. }
  5735. //from db.OCPP_getListVerion
  5736. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5737. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5738. sendGetLocalListVersionConfirmation(uuid,"");
  5739. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5740. return result;
  5741. }
  5742. int handleRemoteStartRequest(char *uuid, char *payload)
  5743. {
  5744. mtrace();
  5745. int result = FAIL;
  5746. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5747. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5748. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5749. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5750. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5751. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5752. int chargingSchedulePeriodCount = 0;
  5753. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5754. int c = 0;
  5755. char *loc;
  5756. char comfirmstr[20]={0};
  5757. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5758. if(server_pending == TRUE)
  5759. {
  5760. return 0;
  5761. }
  5762. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5763. //**********connectorId****************/
  5764. c = 0;
  5765. memset(sstr ,0, sizeof(sstr) );
  5766. loc = strstr(payload, "connectorId");
  5767. if(loc == NULL)
  5768. {
  5769. connectorIdIsNULL = TRUE;
  5770. }
  5771. else
  5772. {
  5773. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5774. {
  5775. sstr[c] = loc[strlen("connectorId")+2+c];
  5776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5777. c++;
  5778. }
  5779. sstr[c] = '\0';
  5780. connectorIdInt = atoi(sstr);
  5781. }
  5782. if(connectorIdIsNULL == TRUE) // need to discussion
  5783. {
  5784. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5785. goto end;
  5786. }
  5787. //****************idTag*******************/
  5788. c = 0;
  5789. memset(sstr ,0, sizeof(sstr) );
  5790. loc = strstr(payload, "idTag");
  5791. while (loc[3+strlen("idTag")+c] != '\"')
  5792. {
  5793. sstr[c] = loc[3+strlen("idTag")+c];
  5794. c++;
  5795. }
  5796. sstr[c] = '\0';
  5797. strcpy(idTagstr,sstr);
  5798. //****************chargingProfile*******************/
  5799. c = 0;
  5800. memset(sstr ,0, sizeof(sstr) );
  5801. loc = strstr(payload, "chargingProfile");
  5802. if(loc == NULL)
  5803. {
  5804. chargingProfileIsNULL = TRUE;
  5805. }
  5806. else
  5807. {
  5808. //****************chargingProfileId*******************/
  5809. c=0;
  5810. loc = strstr(payload, "chargingProfileId");
  5811. memset(sstr ,0, sizeof(sstr) );
  5812. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5813. {
  5814. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5815. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5816. c++;
  5817. }
  5818. sstr[c] = '\0';
  5819. chargingProfileIdInt = atoi(sstr);
  5820. //****************transactionId*******************/
  5821. loc = strstr(payload, "transactionId");
  5822. if(loc == NULL)
  5823. {
  5824. transactionIdIsNULL = TRUE;
  5825. }
  5826. else
  5827. {
  5828. c=0;
  5829. memset(sstr ,0, sizeof(sstr) );
  5830. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5831. {
  5832. sstr[c] = loc[strlen("transactionId")+2+c];
  5833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5834. c++;
  5835. }
  5836. sstr[c] = '\0';
  5837. transactionIdInt = atoi(sstr);
  5838. }
  5839. //****************stackLevel*******************/
  5840. c=0;
  5841. loc = strstr(payload, "stackLevel");
  5842. memset(sstr ,0, sizeof(sstr) );
  5843. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5844. {
  5845. sstr[c] = loc[strlen("stackLevel")+2+c];
  5846. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5847. c++;
  5848. }
  5849. sstr[c] = '\0';
  5850. stackLevelInt = atoi(sstr);
  5851. //****************chargingProfilePurpose*******************/
  5852. c = 0;
  5853. memset(sstr ,0, sizeof(sstr) );
  5854. loc = strstr(payload, "chargingProfilePurpose");
  5855. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5856. {
  5857. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5858. c++;
  5859. }
  5860. sstr[c] = '\0';
  5861. strcpy(chargingProfilePurposestr,sstr);
  5862. //****************chargingProfileKind*******************/
  5863. c = 0;
  5864. memset(sstr ,0, sizeof(sstr) );
  5865. loc = strstr(payload, "chargingProfileKind");
  5866. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5867. {
  5868. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5869. c++;
  5870. }
  5871. sstr[c] = '\0';
  5872. strcpy(chargingProfileKindstr,sstr);
  5873. //****************recurrencyKind*******************/
  5874. loc = strstr(payload, "recurrencyKind");
  5875. if(loc == NULL)
  5876. {
  5877. recurrencyKindIsNULL = TRUE;
  5878. }
  5879. else
  5880. {
  5881. c = 0;
  5882. memset(sstr ,0, sizeof(sstr) );
  5883. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5884. {
  5885. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5886. c++;
  5887. }
  5888. sstr[c] = '\0';
  5889. strcpy(recurrencyKindstr,sstr);
  5890. }
  5891. //****************validFrom*******************/
  5892. loc = strstr(payload, "validFrom");
  5893. if(loc == NULL)
  5894. {
  5895. validFromIsNULL = TRUE;
  5896. }
  5897. else
  5898. {
  5899. c = 0;
  5900. memset(sstr ,0, sizeof(sstr) );
  5901. while (loc[3+strlen("validFrom")+c] != '\"')
  5902. {
  5903. sstr[c] = loc[3+strlen("validFrom")+c];
  5904. c++;
  5905. }
  5906. sstr[c] = '\0';
  5907. strcpy(validFromstr,sstr);
  5908. }
  5909. //****************validTo*******************/
  5910. loc = strstr(payload, "validTo");
  5911. if(loc == NULL)
  5912. {
  5913. validToIsNULL = TRUE;
  5914. }
  5915. else
  5916. {
  5917. c = 0;
  5918. memset(sstr ,0, sizeof(sstr) );
  5919. while (loc[3+strlen("validTo")+c] != '\"')
  5920. {
  5921. sstr[c] = loc[3+strlen("validTo")+c];
  5922. c++;
  5923. }
  5924. sstr[c] = '\0';
  5925. strcpy(validTostr,sstr);
  5926. }
  5927. //****************chargingSchedule*******************/
  5928. loc = strstr(payload, "chargingSchedule");
  5929. if(loc != NULL)
  5930. {
  5931. //****************duration*******************/
  5932. loc = strstr(payload, "duration");
  5933. if(loc == NULL)
  5934. {
  5935. durationIsNULL = TRUE;
  5936. }
  5937. else
  5938. {
  5939. c=0;
  5940. memset(sstr ,0, sizeof(sstr) );
  5941. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5942. {
  5943. sstr[c] = loc[strlen("duration")+2+c];
  5944. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5945. c++;
  5946. }
  5947. sstr[c] = '\0';
  5948. durationInt = atoi(sstr);
  5949. }
  5950. //****************startSchedule******************/
  5951. loc = strstr(payload, "startSchedule");
  5952. if(loc == NULL)
  5953. {
  5954. startScheduleIsNULL = TRUE;
  5955. }
  5956. else
  5957. {
  5958. c = 0;
  5959. memset(sstr ,0, sizeof(sstr) );
  5960. while (loc[3+strlen("startSchedule")+c] != '\"')
  5961. {
  5962. sstr[c] = loc[3+strlen("startSchedule")+c];
  5963. c++;
  5964. }
  5965. sstr[c] = '\0';
  5966. strcpy(startSchedulestr,sstr);
  5967. }
  5968. //****************chargingRateUnit*******************/
  5969. c = 0;
  5970. memset(sstr ,0, sizeof(sstr) );
  5971. loc = strstr(payload, "chargingRateUnit");
  5972. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5973. {
  5974. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5975. c++;
  5976. }
  5977. sstr[c] = '\0';
  5978. strcpy(chargingRateUnitstr,sstr);
  5979. //****************minChargingRate*******************/
  5980. loc = strstr(payload, "minChargingRate");
  5981. if(loc == NULL)
  5982. {
  5983. minChargingRateIsNULL = TRUE;
  5984. }
  5985. else
  5986. {
  5987. c=0;
  5988. memset(sstr ,0, sizeof(sstr) );
  5989. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5990. {
  5991. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5992. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5993. c++;
  5994. }
  5995. sstr[c] = '\0';
  5996. minChargingRateflaot = atof(sstr);
  5997. }
  5998. //****************chargingSchedulePeriod count*******************/
  5999. int what_len = strlen("startPeriod");
  6000. char *where = payload;
  6001. while ((where = strstr(where, "startPeriod"))) {
  6002. where += what_len;
  6003. chargingSchedulePeriodCount++;
  6004. }
  6005. where = payload;
  6006. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6007. {
  6008. //****************startPeriod*******************/
  6009. c=0;
  6010. loc = strstr(where, "startPeriod");
  6011. memset(sstr ,0, sizeof(sstr) );
  6012. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6013. {
  6014. sstr[c] = loc[strlen("startPeriod")+2+c];
  6015. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6016. c++;
  6017. }
  6018. sstr[c] = '\0';
  6019. startPeriodInt[periodNums] = atoi(sstr);
  6020. //****************limit*******************/
  6021. c=0;
  6022. loc = strstr(where, "limit");
  6023. memset(sstr ,0, sizeof(sstr) );
  6024. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6025. {
  6026. sstr[c] = loc[strlen("limit")+2+c];
  6027. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6028. c++;
  6029. }
  6030. sstr[c] = '\0';
  6031. limitflaot[periodNums] = atof(sstr);
  6032. //****************numberPhases*******************/
  6033. loc = strstr(where, "numberPhases");
  6034. if(loc == NULL)
  6035. {
  6036. numberPhasesIsNULL = TRUE;
  6037. }
  6038. else
  6039. {
  6040. c=0;
  6041. memset(sstr ,0, sizeof(sstr) );
  6042. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6043. {
  6044. sstr[c] = loc[strlen("numberPhases")+2+c];
  6045. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6046. c++;
  6047. }
  6048. sstr[c] = '\0';
  6049. numberPhasesInt[periodNums] = atoi(sstr);
  6050. }
  6051. where = loc;
  6052. }
  6053. }
  6054. }
  6055. /*
  6056. enum _SYSTEM_STATUS
  6057. {
  6058. S_BOOTING = 0,
  6059. S_IDLE, = 1
  6060. S_AUTHORIZING, =2
  6061. S_REASSIGN_CHECK, =3
  6062. S_REASSIGN, =4
  6063. S_PRECHARGE, =5
  6064. S_PREPARING_FOR_EV, =6
  6065. S_PREPARING_FOR_EVSE, =7
  6066. S_CHARGING, =8
  6067. S_TERMINATING, =9
  6068. S_COMPLETE, =10
  6069. S_ALARM, =11
  6070. S_FAULT =12
  6071. }
  6072. */
  6073. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6074. {
  6075. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6076. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6077. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6078. //check Transaction active
  6079. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6080. {
  6081. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6082. {
  6083. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6084. {
  6085. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6086. {
  6087. //Reserved
  6088. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6089. }
  6090. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6091. {
  6092. //Reserved
  6093. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6094. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6095. goto end;
  6096. }
  6097. else
  6098. {
  6099. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6100. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6101. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6102. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6103. {
  6104. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6105. goto end;
  6106. }
  6107. }//END FOR ELSE
  6108. }
  6109. }// END FOR CHAdeMO_QUANTITY
  6110. for (int index = 0; index < CCS_QUANTITY; index++)
  6111. {
  6112. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6113. {
  6114. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6115. {
  6116. //Reserved
  6117. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6118. }
  6119. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6120. {
  6121. //Reserved
  6122. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6123. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6124. goto end;
  6125. }
  6126. else
  6127. {
  6128. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6129. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6130. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6131. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6132. {
  6133. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6134. goto end;
  6135. }
  6136. }// END FOR ELSE
  6137. }
  6138. }// END FOR CCS_QUANTITY
  6139. for (int index = 0; index < GB_QUANTITY; index++)
  6140. {
  6141. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6142. {
  6143. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6144. {
  6145. //Reserved
  6146. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6147. }
  6148. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6149. {
  6150. //Reserved
  6151. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6152. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6153. goto end;
  6154. }
  6155. else
  6156. {
  6157. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6158. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6159. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6160. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6161. {
  6162. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6163. goto end;
  6164. }
  6165. }// END FOR ELSE
  6166. }
  6167. } // END FOR GB_QUANTITY
  6168. }
  6169. else
  6170. {
  6171. for (int index = 0; index < AC_QUANTITY; index++)
  6172. {
  6173. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6174. {
  6175. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6176. {
  6177. //Reserved
  6178. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6179. }
  6180. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6181. {
  6182. //Reserved
  6183. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6184. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6185. goto end;
  6186. }
  6187. else
  6188. {
  6189. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6190. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6191. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6192. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6193. {
  6194. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6195. goto end;
  6196. }
  6197. }//END FOR ELSE
  6198. }
  6199. }// END FOR AC_QUANTITY
  6200. }
  6201. if(chargingProfileIsNULL == FALSE)
  6202. {
  6203. //ChargingProfile
  6204. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6205. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6206. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6207. if(recurrencyKindIsNULL == FALSE) //OPTION
  6208. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6209. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6210. if(transactionIdIsNULL == FALSE) // OPTION
  6211. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6212. if(validFromIsNULL == FALSE) // OPTION
  6213. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6214. if(validToIsNULL == FALSE) //OPTION
  6215. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6216. //ChargingSchedule
  6217. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6218. if(durationIsNULL == FALSE) //OPTION
  6219. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6220. if(minChargingRateIsNULL == FALSE) //OPTION
  6221. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6222. if(startScheduleIsNULL == FALSE) //OPTION
  6223. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6224. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6225. {
  6226. //ChargingSchedulePeriod
  6227. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6228. if(numberPhasesIsNULL == FALSE)
  6229. {
  6230. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6231. }
  6232. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6233. }
  6234. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6235. {
  6236. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6237. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6238. //memset idTag
  6239. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6240. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6241. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6242. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6243. }
  6244. else
  6245. {
  6246. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6247. }
  6248. }
  6249. else
  6250. {
  6251. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6252. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6253. //memset idTag
  6254. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6255. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6256. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6257. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6258. }
  6259. }
  6260. else
  6261. {
  6262. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6263. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6264. }
  6265. end:
  6266. if(connectorIdIsNULL == FALSE)
  6267. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6268. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6269. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6270. //OCPP send RemoteStartConfirmation by first.
  6271. sendRemoteStartConfirmation(uuid, comfirmstr);
  6272. return result;
  6273. }
  6274. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6275. {
  6276. mtrace();
  6277. int result = FAIL;
  6278. int match = FALSE;
  6279. int GunNO = 0;
  6280. int transactionIdInt=0;
  6281. int transactionIdIsNULL= FALSE;
  6282. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6283. int c = 0;
  6284. char *loc;
  6285. char comfirmstr[20];
  6286. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6287. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6288. if(server_pending == TRUE)
  6289. {
  6290. return 0;
  6291. }
  6292. c=0;
  6293. loc = strstr(payload, "transactionId");
  6294. if(loc == NULL)
  6295. {
  6296. transactionIdIsNULL= TRUE;
  6297. }
  6298. else
  6299. {
  6300. memset(sstr ,0, sizeof(sstr) );
  6301. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6302. {
  6303. sstr[c] = loc[strlen("transactionId")+2+c];
  6304. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6305. c++;
  6306. }
  6307. sstr[c] = '\0';
  6308. transactionIdInt = atoi(sstr);
  6309. }
  6310. if(transactionIdIsNULL == FALSE)
  6311. {
  6312. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6313. {
  6314. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6315. {
  6316. //check Transaction active
  6317. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6318. {
  6319. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6320. {
  6321. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6322. {
  6323. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6324. {
  6325. match = TRUE;
  6326. GunNO = gun_index;
  6327. }
  6328. }
  6329. }// END FOR CHAdeMO_QUANTITY
  6330. for (int index = 0; index < CCS_QUANTITY; index++)
  6331. {
  6332. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6333. {
  6334. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6335. {
  6336. match = TRUE;
  6337. GunNO = gun_index;
  6338. }
  6339. }
  6340. }// END FOR CCS_QUANTITY
  6341. for (int index = 0; index < GB_QUANTITY; index++)
  6342. {
  6343. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6344. {
  6345. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6346. {
  6347. match = TRUE;
  6348. GunNO = gun_index;
  6349. }
  6350. }
  6351. }// END FOR GB_QUANTITY
  6352. }
  6353. else
  6354. {
  6355. for (int index = 0; index < AC_QUANTITY; index++)
  6356. {
  6357. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6358. {
  6359. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6360. {
  6361. match = TRUE;
  6362. GunNO = gun_index;
  6363. }
  6364. }
  6365. }// END FOR CHAdeMO_QUANTITY
  6366. }// END FOR AC ELSE
  6367. }// CHECK IF ResponseTransactionId == transactionIdInt
  6368. }//END FOR
  6369. if( match == TRUE)
  6370. {
  6371. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6372. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6373. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6374. }
  6375. else
  6376. {
  6377. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6378. }
  6379. }
  6380. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6381. return result;
  6382. }
  6383. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6384. {
  6385. mtrace();
  6386. int result = FAIL;
  6387. int connectorIdInt=0, reservationIdInt=0;
  6388. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6389. char comfirmstr[20]={0};
  6390. char sstr[180]={ 0 };
  6391. int c = 0;
  6392. char *loc;
  6393. //char *ptr;
  6394. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6395. //***(1)connectorId ****/
  6396. c=0;
  6397. loc = strstr(payload, "connectorId");
  6398. memset(sstr ,0, sizeof(sstr) );
  6399. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6400. {
  6401. sstr[c] = loc[strlen("connectorId")+2+c];
  6402. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6403. c++;
  6404. }
  6405. sstr[c] = '\0';
  6406. connectorIdInt = atoi(sstr);
  6407. //***(2)expiryDate ****/
  6408. loc = strstr(payload, "expiryDate");
  6409. memset(sstr ,0, sizeof(sstr) );
  6410. c = 0;
  6411. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6412. {
  6413. sstr[c] = loc[3+strlen("expiryDate")+c];
  6414. c++;
  6415. }
  6416. sstr[c] = '\0';
  6417. strcpy(expiryDatestr, sstr);
  6418. //***(3)idTag ****/
  6419. loc = strstr(payload, "idTag");
  6420. memset(sstr ,0, sizeof(sstr) );
  6421. c = 0;
  6422. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6423. {
  6424. sstr[c] = loc[3+strlen("idTag")+c];
  6425. c++;
  6426. }
  6427. sstr[c] = '\0';
  6428. strcpy(idTagstr, sstr);
  6429. //***(4)parentIdTag ****/
  6430. loc = strstr(payload, "parentIdTag");
  6431. memset(sstr ,0, sizeof(sstr) );
  6432. c = 0;
  6433. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6434. {
  6435. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6436. c++;
  6437. }
  6438. sstr[c] = '\0';
  6439. strcpy(parentIdTagstr, sstr);
  6440. //***(5)reservationId ****/
  6441. c=0;
  6442. loc = strstr(payload, "reservationId");
  6443. memset(sstr ,0, sizeof(sstr) );
  6444. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6445. {
  6446. sstr[c] = loc[strlen("reservationId")+2+c];
  6447. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6448. c++;
  6449. }
  6450. sstr[c] = '\0';
  6451. reservationIdInt = atoi(sstr);
  6452. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6453. /*
  6454. enum _SYSTEM_STATUS
  6455. {
  6456. S_BOOTING = 0,
  6457. S_IDLE, = 1
  6458. S_AUTHORIZING, =2
  6459. S_REASSIGN_CHECK, =3
  6460. S_REASSIGN, =4
  6461. S_PRECHARGE, =5
  6462. S_PREPARING_FOR_EV, =6
  6463. S_PREPARING_FOR_EVSE, =7
  6464. S_CHARGING, =8
  6465. S_TERMINATING, =9
  6466. S_COMPLETE, =10
  6467. S_ALARM, =11
  6468. S_FAULT =12
  6469. }
  6470. */
  6471. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6472. {
  6473. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6474. goto end;
  6475. }
  6476. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6477. {
  6478. //check Transaction active
  6479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6480. {
  6481. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6482. {
  6483. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6484. {
  6485. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6486. {
  6487. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6488. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6489. {
  6490. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6491. {
  6492. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6493. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6494. }
  6495. 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'))
  6496. {
  6497. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6498. }
  6499. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6500. {
  6501. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6502. }
  6503. else
  6504. {
  6505. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6506. }
  6507. }
  6508. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6509. {
  6510. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6511. }
  6512. }
  6513. else
  6514. {
  6515. //replace reservation
  6516. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6517. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6518. }
  6519. }
  6520. } // END FOR CHAdeMO_QUANTITY
  6521. for (int index = 0; index < CCS_QUANTITY; index++)
  6522. {
  6523. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6524. {
  6525. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6526. {
  6527. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6528. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6529. {
  6530. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6531. {
  6532. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6533. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6534. }
  6535. 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'))
  6536. {
  6537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6538. }
  6539. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6540. {
  6541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6542. }
  6543. else
  6544. {
  6545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6546. }
  6547. }
  6548. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6549. {
  6550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6551. }
  6552. }
  6553. else
  6554. {
  6555. //replace reservation
  6556. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6557. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6558. }
  6559. }
  6560. } // END FOR CCS_QUANTITY
  6561. for (int index = 0; index < GB_QUANTITY; index++)
  6562. {
  6563. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6564. {
  6565. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6566. {
  6567. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6568. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6569. {
  6570. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6571. {
  6572. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6573. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6574. }
  6575. else if((ShmSysConfigAndInfo->SysInfo.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'))
  6576. {
  6577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6578. }
  6579. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6580. {
  6581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6582. }
  6583. else
  6584. {
  6585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6586. }
  6587. }
  6588. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6589. {
  6590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6591. }
  6592. }
  6593. else
  6594. {
  6595. //replace reservation
  6596. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6597. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6598. }
  6599. }
  6600. }// END FOR GB_QUANTITY
  6601. }
  6602. else
  6603. {
  6604. for (int index = 0; index < AC_QUANTITY; index++)
  6605. {
  6606. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6607. {
  6608. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6609. {
  6610. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6611. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6612. {
  6613. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6614. {
  6615. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6617. }
  6618. 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'))
  6619. {
  6620. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6621. }
  6622. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6623. {
  6624. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6625. }
  6626. else
  6627. {
  6628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6629. }
  6630. }
  6631. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6632. {
  6633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6634. }
  6635. }
  6636. else
  6637. {
  6638. //replace reservation
  6639. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6641. }
  6642. }
  6643. } // END FOR AC_QUANTITY
  6644. }//END FOR AC ELSE
  6645. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6646. }
  6647. else if(connectorIdInt == 0)
  6648. {
  6649. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6650. {
  6651. //check Transaction active
  6652. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6653. {
  6654. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6655. {
  6656. 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'))
  6657. {
  6658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6659. goto end;
  6660. }
  6661. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6662. {
  6663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6664. goto end;
  6665. }
  6666. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6667. {
  6668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6669. goto end;
  6670. }
  6671. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6672. {
  6673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6674. goto end;
  6675. }
  6676. }
  6677. }// END FOR CHAdeMO_QUANTITY
  6678. for (int index = 0; index < CCS_QUANTITY; index++)
  6679. {
  6680. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6681. {
  6682. 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'))
  6683. {
  6684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6685. }
  6686. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6687. {
  6688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6689. }
  6690. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6691. {
  6692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6693. }
  6694. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6695. {
  6696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6697. }
  6698. }
  6699. } // END FOR CCS_QUANTITY
  6700. for (int index = 0; index < GB_QUANTITY; index++)
  6701. {
  6702. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6703. {
  6704. 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'))
  6705. {
  6706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6707. }
  6708. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6709. {
  6710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6711. }
  6712. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6713. {
  6714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6715. }
  6716. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6717. {
  6718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6719. }
  6720. }
  6721. } // END FOR GB_QUANTITY
  6722. }
  6723. else
  6724. {
  6725. for (int index = 0; index < AC_QUANTITY; index++)
  6726. {
  6727. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6728. {
  6729. 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'))
  6730. {
  6731. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6732. goto end;
  6733. }
  6734. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6735. {
  6736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6737. goto end;
  6738. }
  6739. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6740. {
  6741. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6742. goto end;
  6743. }
  6744. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6745. {
  6746. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6747. goto end;
  6748. }
  6749. }
  6750. }// END FOR AC_QUANTITY
  6751. }
  6752. //The connectorId is 0
  6753. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6754. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6755. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6756. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6757. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6758. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6759. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6760. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6761. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6762. result = TRUE;
  6763. return result;
  6764. }
  6765. else
  6766. {
  6767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6768. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6769. }
  6770. if(strcmp(comfirmstr,"Accepted") == 0)
  6771. {
  6772. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6773. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6774. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6775. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6776. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6777. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6778. result = TRUE;
  6779. return result;
  6780. }
  6781. end:
  6782. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6783. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6784. return result;
  6785. }
  6786. int handleResetRequest(char *uuid, char *payload)
  6787. {
  6788. mtrace();
  6789. int result = FAIL;
  6790. char sstr[10]={0};
  6791. char typestr[10]={0};
  6792. char comfirmstr[20]={0};
  6793. int c = 0;
  6794. char *loc;
  6795. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6796. DEBUG_INFO("handleResetRequest ...\n");
  6797. loc = strstr(payload, "type");
  6798. memset(sstr ,0, sizeof(sstr) );
  6799. c = 0;
  6800. while (loc[3+strlen("type")+c] != '\"')
  6801. {
  6802. sstr[c] = loc[3+strlen("type")+c];
  6803. c++;
  6804. }
  6805. sstr[c] = '\0';
  6806. strcpy(typestr,sstr);
  6807. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6808. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6809. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6810. {
  6811. //check Transaction active
  6812. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6813. {
  6814. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6815. {
  6816. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6817. {
  6818. //0: unplug, 1: Plug-in
  6819. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6820. }
  6821. }
  6822. for (int index = 0; index < CCS_QUANTITY; index++)
  6823. {
  6824. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6825. {
  6826. //0: unplug, 1: Plug-in
  6827. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6828. }
  6829. }
  6830. for (int index = 0; index < GB_QUANTITY; index++)
  6831. {
  6832. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6833. {
  6834. //0: unplug, 1: Plug-in
  6835. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6836. }
  6837. }
  6838. }
  6839. else
  6840. {
  6841. for (int index = 0; index < AC_QUANTITY; index++)
  6842. {
  6843. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6844. {
  6845. //0: unplug, 1: Plug-in
  6846. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6847. }
  6848. }
  6849. }// END FOR AC ELSE
  6850. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6851. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6852. result = TRUE;
  6853. return result;
  6854. }
  6855. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6856. {
  6857. //check Transaction active
  6858. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6859. {
  6860. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6861. {
  6862. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6863. {
  6864. //0: unplug, 1: Plug-in
  6865. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6866. }
  6867. }
  6868. for (int index = 0; index < CCS_QUANTITY; index++)
  6869. {
  6870. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6871. {
  6872. //0: unplug, 1: Plug-in
  6873. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6874. }
  6875. }
  6876. for (int index = 0; index < GB_QUANTITY; index++)
  6877. {
  6878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6879. {
  6880. //0: unplug, 1: Plug-in
  6881. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6882. }
  6883. }
  6884. }
  6885. else
  6886. {
  6887. for (int index = 0; index < AC_QUANTITY; index++)
  6888. {
  6889. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6890. {
  6891. //0: unplug, 1: Plug-in
  6892. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6893. }
  6894. }
  6895. }// END FOR AC ELSE
  6896. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6897. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6898. result = TRUE;
  6899. return result;
  6900. }
  6901. else
  6902. {
  6903. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6904. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6905. goto errorend;
  6906. }
  6907. errorend:
  6908. sendResetConfirmation(uuid, comfirmstr);
  6909. return result;
  6910. }
  6911. int handleSendLocalListRequest(char *uuid, char *payload)
  6912. {
  6913. mtrace();
  6914. int result = FAIL;
  6915. int listVersionInt;
  6916. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6917. char listsearch[]="listVersion";
  6918. char updateTypesearch[]="updateType";
  6919. char localAuthorizationListsearch[]="localAuthorizationList";
  6920. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6921. char CardList[500][160]={0};
  6922. char updateTypestr[15]={0};
  6923. char idTagstr[20]={0};
  6924. char parentIdTag[20]={0};
  6925. char expiryDate[30]={0};
  6926. char idTagstatus[16]={0};
  6927. int c = 0;
  6928. int i = 0;
  6929. char *delim1 = "}";
  6930. char * pch;
  6931. char *loc;
  6932. //char *ptr;
  6933. char comfirmstr[20];
  6934. //int n_localAuthorizations = 0;
  6935. int checkState_Faulted = FALSE;
  6936. DEBUG_INFO("handleSendLocalListRequest\n");
  6937. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6938. {
  6939. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6940. goto end;
  6941. }
  6942. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6943. {
  6944. //check Charge Point state
  6945. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6946. {
  6947. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6948. {
  6949. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6950. }
  6951. }
  6952. for (int index = 0; index < CCS_QUANTITY; index++)
  6953. {
  6954. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6955. {
  6956. checkState_Faulted = TRUE; //OCPP Status
  6957. }
  6958. }
  6959. for (int index = 0; index < GB_QUANTITY; index++)
  6960. {
  6961. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6962. {
  6963. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6964. }
  6965. }
  6966. }
  6967. else
  6968. {
  6969. //check Charge Point state
  6970. for (int index = 0; index < AC_QUANTITY; index++)
  6971. {
  6972. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6973. {
  6974. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6975. }
  6976. }
  6977. }// END FOR AC ELSE
  6978. if(checkState_Faulted == TRUE)
  6979. {
  6980. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6981. goto end;
  6982. }
  6983. //listVersion
  6984. c = 0;
  6985. loc = strstr(payload, listsearch);
  6986. while (loc[strlen("listVersion")+2+c] != ',')
  6987. {
  6988. sstr[c] = loc[strlen("listVersion")+2+c];
  6989. c++;
  6990. }
  6991. sstr[c] = '\0';
  6992. listVersionInt = atoi(sstr);
  6993. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6994. //updateType
  6995. loc = strstr(payload, updateTypesearch);
  6996. c = 0;
  6997. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6998. {
  6999. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7000. c++;
  7001. }
  7002. sstr[c] = '\0';
  7003. strcpy(updateTypestr, sstr);
  7004. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7005. //localAuthorizationList
  7006. memset(sstr ,0, sizeof(sstr) );
  7007. loc = strstr(payload, localAuthorizationListsearch);
  7008. if(loc != NULL) // localAuthorizationList is not NULL
  7009. {
  7010. //Check UpdateType
  7011. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7012. {
  7013. //Local list full update
  7014. printf("Local list full update.\n");
  7015. OCPP_cleanLocalList();
  7016. }
  7017. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7018. {
  7019. //Local list different update
  7020. printf("Local list different update.\n");
  7021. OCPP_getListVerion();
  7022. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7023. {
  7024. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7025. goto end;
  7026. }
  7027. }
  7028. else
  7029. {
  7030. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7031. goto end;
  7032. }
  7033. c = 0;
  7034. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7035. {
  7036. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7037. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7038. c++;
  7039. }
  7040. sstr[c] = '\0';
  7041. //parsing strings to words
  7042. i = 0;
  7043. pch = strtok(sstr,delim1);
  7044. while (pch != NULL)
  7045. {
  7046. strcpy(CardList[i], pch);
  7047. pch = strtok (NULL, delim1);
  7048. i = i + 1;
  7049. }
  7050. //local Authorizations List Numbers
  7051. //n_localAuthorizations = i;
  7052. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7053. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7054. c= 0;
  7055. while(c < i)
  7056. {
  7057. //Search "IdToken"
  7058. memset(sstr ,0, sizeof(sstr) );
  7059. loc = strstr(CardList[c], "idTag");
  7060. int j = 0;
  7061. while (loc[3+strlen("idTag")+j] != '\"')
  7062. {
  7063. sstr[j] = loc[3+strlen("idTag")+j];
  7064. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7065. j++;
  7066. }
  7067. sstr[j] = '\0';
  7068. strcpy(idTagstr, sstr);
  7069. //Search "expiryDate"
  7070. memset(sstr ,0, sizeof(sstr) );
  7071. loc = strstr(CardList[c], "expiryDate");
  7072. j = 0;
  7073. while (loc[3+strlen("expiryDate")+j] != '\"')
  7074. {
  7075. sstr[j] = loc[3+strlen("expiryDate")+j];
  7076. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7077. j++;
  7078. }
  7079. sstr[j] = '\0';
  7080. strcpy(expiryDate, sstr);
  7081. //Search "parentIdTag"
  7082. memset(sstr ,0, sizeof(sstr) );
  7083. loc = strstr(CardList[c], "parentIdTag");
  7084. j = 0;
  7085. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7086. {
  7087. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7088. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7089. j++;
  7090. }
  7091. sstr[j] = '\0';
  7092. strcpy(parentIdTag, sstr);
  7093. //Search "status"
  7094. memset(sstr ,0, sizeof(sstr) );
  7095. loc = strstr(CardList[c], "status");
  7096. j = 0;
  7097. while (loc[3+strlen("status")+j] != '\"')
  7098. {
  7099. sstr[j] = loc[3+strlen("status")+j];
  7100. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7101. j++;
  7102. }
  7103. sstr[j] = '\0';
  7104. strcpy(idTagstatus, sstr);
  7105. OCPP_getIdTag(idTagstr);
  7106. //OCPP_getIdTag("test"); For Test
  7107. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7108. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7109. {
  7110. //Local list full update
  7111. DEBUG_INFO("Local list full update.\n");
  7112. // update list
  7113. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7114. OCPP_get_TableAuthlocalAllData();
  7115. }
  7116. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7117. {
  7118. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7119. {
  7120. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7121. }
  7122. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7123. {
  7124. OCPP_deleteIdTag(idTagstr);
  7125. }
  7126. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7127. {
  7128. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7129. }
  7130. }
  7131. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7132. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7133. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7134. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7135. c++;
  7136. }
  7137. }
  7138. else
  7139. {
  7140. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7141. {
  7142. //Local list different update
  7143. DEBUG_INFO("Local list different update.\n");
  7144. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7145. goto end;
  7146. }
  7147. }
  7148. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7149. end:
  7150. sendSendLocalListConfirmation(uuid, comfirmstr);
  7151. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7152. #if 0
  7153. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7154. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7155. #endif
  7156. return result;
  7157. }
  7158. /*
  7159. enum _SYSTEM_STATUS
  7160. {
  7161. S_BOOTING = 0,
  7162. S_IDLE, =1
  7163. S_AUTHORIZING, =2
  7164. S_REASSIGN_CHECK, =3
  7165. S_REASSIGN, =4
  7166. S_PRECHARGE, =5
  7167. S_PREPARING_FOR_EV, =6
  7168. S_PREPARING_FOR_EVSE, =7
  7169. S_CHARGING, =8
  7170. S_TERMINATING, =9
  7171. S_COMPLETE, =10
  7172. S_ALARM, =11
  7173. S_FAULT =12
  7174. };
  7175. */
  7176. #define MAX 200
  7177. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7178. {
  7179. mtrace();
  7180. int result = FAIL;
  7181. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7182. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7183. char chargingProfilePurposeStr[30]={0};
  7184. char chargingProfileKindStr[16]={0};
  7185. char recurrencyKindStr[10]={0};
  7186. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7187. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7188. int chargingSchedulePeriodCount = 0;
  7189. //int updateflag = FALSE;
  7190. char comfirmstr[20]={0};
  7191. int meet= FALSE;
  7192. char sstr[10]={0};
  7193. int c = 0;
  7194. char *loc;
  7195. FILE *fptr1;//, *fptr2;
  7196. //int lno=0;//, linectr = 0;
  7197. //int modifyflag = FALSE;
  7198. char filename[MAX]={0};
  7199. char tempfile[] = "../Storage/OCPP/temp.json";
  7200. int resultRename=0;
  7201. char rmFileCmd[50]={0};
  7202. char tempchargingProfilePurposeStr[30]={0};
  7203. //[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}}}]
  7204. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7205. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7206. //*********************connectorId***************************/
  7207. loc = strstr(payload, "connectorId");
  7208. c = 0;
  7209. memset(sstr ,0, sizeof(sstr) );
  7210. while (loc[strlen("connectorId")+2+c] != ',')
  7211. {
  7212. sstr[c] = loc[strlen("connectorId")+2+c];
  7213. c++;
  7214. }
  7215. sstr[c] = '\0';
  7216. connectorIdInt = atoi(sstr);
  7217. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7218. {
  7219. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7220. }
  7221. else
  7222. {
  7223. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7224. }
  7225. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7226. //*********************chargingProfileId***************************/
  7227. loc = strstr(payload, "chargingProfileId");
  7228. c = 0;
  7229. memset(sstr ,0, sizeof(sstr) );
  7230. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7231. {
  7232. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7233. c++;
  7234. }
  7235. sstr[c] = '\0';
  7236. chargingProfileIdInt = atoi(sstr);
  7237. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7238. {
  7239. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7240. }
  7241. else
  7242. {
  7243. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7244. }
  7245. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7246. //*********************transactionId***************************/
  7247. loc = strstr(payload, "transactionId");
  7248. if(loc != NULL)
  7249. {
  7250. c = 0;
  7251. memset(sstr ,0, sizeof(sstr) );
  7252. while (loc[strlen("transactionId")+2+c] != ',')
  7253. {
  7254. sstr[c] = loc[strlen("transactionId")+2+c];
  7255. c++;
  7256. }
  7257. sstr[c] = '\0';
  7258. transactionIdInt = atoi(sstr);
  7259. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7260. {
  7261. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7262. }
  7263. else
  7264. {
  7265. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7266. }
  7267. }
  7268. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7269. //*********************stackLevel***************************/
  7270. loc = strstr(payload, "stackLevel");
  7271. c = 0;
  7272. memset(sstr ,0, sizeof(sstr) );
  7273. while (loc[strlen("stackLevel")+2+c] != ',')
  7274. {
  7275. sstr[c] = loc[strlen("stackLevel")+2+c];
  7276. c++;
  7277. }
  7278. sstr[c] = '\0';
  7279. stackLevelInt = atoi(sstr);
  7280. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7281. {
  7282. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7283. }
  7284. else
  7285. {
  7286. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7287. }
  7288. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7289. //*********************chargingProfilePurpose***************************/
  7290. loc = strstr(payload, "chargingProfilePurpose");
  7291. c = 0;
  7292. memset(sstr ,0, sizeof(sstr) );
  7293. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7294. {
  7295. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7296. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7297. c++;
  7298. }
  7299. sstr[c] = '\0';
  7300. strcpy(chargingProfilePurposeStr,sstr);
  7301. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7302. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7303. {
  7304. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7305. }
  7306. else
  7307. {
  7308. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7309. }
  7310. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7311. //*********************chargingProfileKind***************************/
  7312. loc = strstr(payload, "chargingProfileKind");
  7313. c = 0;
  7314. memset(sstr ,0, sizeof(sstr) );
  7315. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7316. {
  7317. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7318. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7319. c++;
  7320. }
  7321. sstr[c] = '\0';
  7322. strcpy(chargingProfileKindStr,sstr);
  7323. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7324. {
  7325. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7326. }
  7327. else
  7328. {
  7329. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7330. }
  7331. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7332. //*********************recurrencyKind***************************/
  7333. loc = strstr(payload, "recurrencyKind");
  7334. if(loc != NULL)
  7335. {
  7336. c = 0;
  7337. memset(sstr ,0, sizeof(sstr) );
  7338. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7339. {
  7340. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7341. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7342. c++;
  7343. }
  7344. sstr[c] = '\0';
  7345. strcpy(recurrencyKindStr,sstr);
  7346. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7347. {
  7348. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7349. }
  7350. else
  7351. {
  7352. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7353. }
  7354. }
  7355. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7356. //*********************validFrom***************************/
  7357. loc = strstr(payload, "validFrom");
  7358. if(loc != NULL)
  7359. {
  7360. c = 0;
  7361. memset(sstr ,0, sizeof(sstr) );
  7362. while (loc[3+strlen("validFrom")+c] != '\"')
  7363. {
  7364. sstr[c] = loc[3+strlen("validFrom")+c];
  7365. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7366. c++;
  7367. }
  7368. sstr[c] = '\0';
  7369. strcpy(validFromStr,sstr);
  7370. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7371. {
  7372. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7373. }
  7374. else
  7375. {
  7376. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7377. }
  7378. }
  7379. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7380. //*********************validTo***************************/
  7381. loc = strstr(payload, "validTo");
  7382. if(loc != NULL)
  7383. {
  7384. c = 0;
  7385. memset(sstr ,0, sizeof(sstr) );
  7386. while (loc[3+strlen("validTo")+c] != '\"')
  7387. {
  7388. sstr[c] = loc[3+strlen("validTo")+c];
  7389. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7390. c++;
  7391. }
  7392. sstr[c] = '\0';
  7393. strcpy(validToStr,sstr);
  7394. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7395. {
  7396. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7397. }
  7398. else
  7399. {
  7400. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7401. }
  7402. }
  7403. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7404. //*********************duration***************************/
  7405. loc = strstr(payload, "duration");
  7406. if(loc != NULL)
  7407. {
  7408. c = 0;
  7409. memset(sstr ,0, sizeof(sstr) );
  7410. while (loc[strlen("duration")+2+c] != ',')
  7411. {
  7412. sstr[c] = loc[strlen("duration")+2+c];
  7413. c++;
  7414. }
  7415. sstr[c] = '\0';
  7416. durationInt = atoi(sstr);
  7417. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7418. {
  7419. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7420. }
  7421. else
  7422. {
  7423. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7424. }
  7425. }
  7426. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7427. //*********************startSchedule***************************/
  7428. loc = strstr(payload, "startSchedule");
  7429. if(loc != NULL)
  7430. {
  7431. c = 0;
  7432. memset(sstr ,0, sizeof(sstr) );
  7433. while (loc[3+strlen("startSchedule")+c] != '\"')
  7434. {
  7435. sstr[c] = loc[3+strlen("startSchedule")+c];
  7436. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7437. c++;
  7438. }
  7439. sstr[c] = '\0';
  7440. strcpy(startScheduleStr,sstr);
  7441. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7442. {
  7443. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7444. }
  7445. else
  7446. {
  7447. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7448. }
  7449. }
  7450. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7451. //*********************chargingRateUnit***************************/
  7452. loc = strstr(payload, "chargingRateUnit");
  7453. if(loc != NULL)
  7454. {
  7455. c = 0;
  7456. memset(sstr ,0, sizeof(sstr) );
  7457. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7458. {
  7459. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7460. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7461. c++;
  7462. }
  7463. sstr[c] = '\0';
  7464. strcpy(chargingRateUnitStr,sstr);
  7465. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7466. {
  7467. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7468. }
  7469. else
  7470. {
  7471. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7472. }
  7473. }
  7474. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7475. //****************chargingSchedulePeriod count start*******************/
  7476. int what_len = strlen("startPeriod");
  7477. char *where = payload;
  7478. if (what_len)
  7479. while ((where = strstr(where, "startPeriod"))) {
  7480. where += what_len;
  7481. chargingSchedulePeriodCount++;
  7482. }
  7483. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7484. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7485. where = payload;
  7486. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7487. {
  7488. //****************startPeriod*******************/
  7489. c=0;
  7490. loc = strstr(where, "startPeriod");
  7491. memset(sstr ,0, sizeof(sstr) );
  7492. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7493. {
  7494. sstr[c] = loc[strlen("startPeriod")+2+c];
  7495. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7496. c++;
  7497. }
  7498. sstr[c] = '\0';
  7499. startPeriodInt[periodNums] = atoi(sstr);
  7500. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7501. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7502. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7503. {
  7504. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7505. }
  7506. else
  7507. {
  7508. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7509. }
  7510. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7511. //****************limit*******************/
  7512. c=0;
  7513. loc = strstr(where, "limit");
  7514. memset(sstr ,0, sizeof(sstr) );
  7515. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7516. {
  7517. sstr[c] = loc[strlen("limit")+2+c];
  7518. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7519. c++;
  7520. }
  7521. sstr[c] = '\0';
  7522. limitflaot[periodNums] = atof(sstr);
  7523. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7524. {
  7525. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7526. }
  7527. else
  7528. {
  7529. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7530. }
  7531. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7532. //****************numberPhases*******************/
  7533. loc = strstr(where, "numberPhases");
  7534. if(loc != NULL)
  7535. {
  7536. c=0;
  7537. memset(sstr ,0, sizeof(sstr) );
  7538. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7539. {
  7540. sstr[c] = loc[strlen("numberPhases")+2+c];
  7541. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7542. c++;
  7543. }
  7544. sstr[c] = '\0';
  7545. numberPhasesInt[periodNums] = atoi(sstr);
  7546. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7547. {
  7548. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7549. }
  7550. else
  7551. {
  7552. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7553. }
  7554. }
  7555. where = loc;
  7556. }
  7557. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7558. //****************chargingSchedulePeriod count end*******************/
  7559. //*********************minChargingRate***************************/
  7560. loc = strstr(payload, "minChargingRate");
  7561. if(loc != NULL)
  7562. {
  7563. c = 0;
  7564. memset(sstr ,0, sizeof(sstr) );
  7565. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7566. {
  7567. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7568. c++;
  7569. }
  7570. sstr[c] = '\0';
  7571. minChargingRateFloat = atof(sstr);
  7572. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7573. {
  7574. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7575. }
  7576. else
  7577. {
  7578. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7579. }
  7580. }
  7581. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7582. {
  7583. //printf("set chargingProfile 1-2\n");
  7584. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7585. if(connectorIdInt != 0)
  7586. {
  7587. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7588. goto end;
  7589. }
  7590. strcpy(filename, ChargePointMaxProfile_JSON );
  7591. fptr1 = fopen(filename, "r");
  7592. if (!fptr1)
  7593. {
  7594. //file not exist
  7595. DEBUG_INFO("Unable to open the input file!!\n");
  7596. fptr1 = fopen(filename, "w+");
  7597. }
  7598. fclose(fptr1);
  7599. }
  7600. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7601. {
  7602. //printf("set chargingProfile 1-3\n");
  7603. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7604. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7605. {
  7606. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7607. goto end;
  7608. }
  7609. switch(connectorIdInt)
  7610. {
  7611. case 0:
  7612. strcpy(filename, TxDefaultProfile_0_JSON );
  7613. break;
  7614. case 1:
  7615. strcpy(filename, TxDefaultProfile_1_JSON );
  7616. break;
  7617. case 2:
  7618. strcpy(filename, TxDefaultProfile_2_JSON );
  7619. break;
  7620. default:
  7621. strcpy(filename, TxDefaultProfile_0_JSON );
  7622. break;
  7623. }
  7624. fptr1 = fopen(filename, "r");
  7625. if (!fptr1)
  7626. {
  7627. //file not exist
  7628. DEBUG_INFO("Unable to open the input file!!\n");
  7629. fptr1 = fopen(filename, "w+");
  7630. }
  7631. fclose(fptr1);
  7632. }
  7633. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7634. {
  7635. //printf("set chargingProfile 1-4\n");
  7636. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7637. //check Transaction active
  7638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7639. {
  7640. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7641. {
  7642. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7643. {
  7644. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7645. {
  7646. meet = TRUE;
  7647. break;
  7648. }
  7649. }
  7650. }
  7651. }
  7652. for (int index = 0; index < CCS_QUANTITY; index++)
  7653. {
  7654. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7655. {
  7656. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7657. {
  7658. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7659. {
  7660. meet = TRUE;
  7661. break;
  7662. }
  7663. }
  7664. }
  7665. }
  7666. for (int index = 0; index < GB_QUANTITY; index++)
  7667. {
  7668. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7669. {
  7670. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7671. {
  7672. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7673. {
  7674. meet = TRUE;
  7675. break;
  7676. }
  7677. }
  7678. }
  7679. }
  7680. if(meet == FALSE)
  7681. {
  7682. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7683. goto end;
  7684. }
  7685. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7686. {
  7687. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7688. goto end;
  7689. }
  7690. switch(connectorIdInt)
  7691. {
  7692. case 0:
  7693. break;
  7694. case 1:
  7695. strcpy(filename, TxProfile_1_JSON);
  7696. break;
  7697. case 2:
  7698. strcpy(filename, TxProfile_2_JSON);
  7699. break;
  7700. default:
  7701. strcpy(filename, TxProfile_1_JSON);
  7702. break;
  7703. }
  7704. fptr1 = fopen(filename, "r");
  7705. if (!fptr1)
  7706. {
  7707. //file not exist
  7708. DEBUG_INFO("Unable to open the input file!!\n");
  7709. fptr1 = fopen(filename, "w+");
  7710. }
  7711. fclose(fptr1);
  7712. }
  7713. //**********************************Write to File********************************************************/
  7714. FILE *infile;
  7715. FILE *outfile;
  7716. // open file for writing
  7717. infile = fopen (filename, "r");
  7718. outfile = fopen (tempfile, "w");
  7719. int d =0;
  7720. d = fgetc(infile);
  7721. //DEBUG_INFO("d:%d\n",d);
  7722. rewind(infile);
  7723. //*检测到文件结束标识返回1,否则返回0。*/
  7724. if(d == EOF)
  7725. {
  7726. DEBUG_INFO("ChargingProfile content is NULL\n");
  7727. fprintf(outfile,"[%s]\n",payload);
  7728. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7729. fclose(infile);
  7730. fclose(outfile);
  7731. sprintf(rmFileCmd,"rm -f %s",filename);
  7732. system(rmFileCmd);
  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. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7743. //system(rmFileCmd);
  7744. }
  7745. else
  7746. {
  7747. char buf[1000]={0};
  7748. int ChargingProfileAdded = FALSE;
  7749. while (fgets(buf, sizeof(buf), infile) != NULL)
  7750. {
  7751. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7752. //*************************tempconnectorIdInt*********************************/
  7753. loc = strstr(buf, "connectorId");
  7754. c = 0;
  7755. memset(sstr ,0, sizeof(sstr) );
  7756. while (loc[strlen("connectorId")+2+c] != ',')
  7757. {
  7758. sstr[c] = loc[strlen("connectorId")+2+c];
  7759. c++;
  7760. }
  7761. sstr[c] = '\0';
  7762. tempconnectorIdInt = atoi(sstr);
  7763. //*************************tempchargingProfileIdInt*********************************/
  7764. loc = strstr(buf, "chargingProfileId");
  7765. c = 0;
  7766. memset(sstr ,0, sizeof(sstr) );
  7767. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7768. {
  7769. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7770. c++;
  7771. }
  7772. sstr[c] = '\0';
  7773. tempchargingProfileIdInt = atoi(sstr);
  7774. //*************************tempstackLevelInt*********************************/
  7775. loc = strstr(buf, "stackLevel");
  7776. c = 0;
  7777. memset(sstr ,0, sizeof(sstr) );
  7778. while (loc[strlen("stackLevel")+2+c] != ',')
  7779. {
  7780. sstr[c] = loc[strlen("stackLevel")+2+c];
  7781. c++;
  7782. }
  7783. sstr[c] = '\0';
  7784. tempstackLevelInt = atoi(sstr);
  7785. //*************************tempchargingProfilePurposeStr*********************************/
  7786. loc = strstr(payload, "chargingProfilePurpose");
  7787. c = 0;
  7788. memset(sstr ,0, sizeof(sstr) );
  7789. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7790. {
  7791. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7792. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7793. c++;
  7794. }
  7795. sstr[c] = '\0';
  7796. strcpy(tempchargingProfilePurposeStr,sstr);
  7797. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7798. {
  7799. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7800. {
  7801. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7802. if(ChargingProfileAdded == FALSE)
  7803. {
  7804. fprintf(outfile,"%s\n",payload);
  7805. ChargingProfileAdded = TRUE;
  7806. }
  7807. }
  7808. else
  7809. {
  7810. if(tempstackLevelInt < stackLevelInt)
  7811. {
  7812. if(ChargingProfileAdded == FALSE)
  7813. {
  7814. fprintf(outfile,"%s\n",payload);
  7815. ChargingProfileAdded = TRUE;
  7816. fprintf(outfile,"%s\n",buf);
  7817. }
  7818. else
  7819. {
  7820. fprintf(outfile,"%s\n",buf);
  7821. }
  7822. }
  7823. else
  7824. {
  7825. if(ChargingProfileAdded == FALSE)
  7826. {
  7827. fprintf(outfile,"%s\n",buf);
  7828. fprintf(outfile,"%s\n",payload);
  7829. ChargingProfileAdded = TRUE;
  7830. }
  7831. else
  7832. {
  7833. fprintf(outfile,"%s\n",buf);
  7834. }
  7835. }
  7836. }
  7837. }
  7838. else
  7839. {
  7840. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7841. {
  7842. if(ChargingProfileAdded == FALSE)
  7843. {
  7844. fprintf(outfile,"%s\n",payload);
  7845. ChargingProfileAdded = TRUE;
  7846. fprintf(outfile,"%s\n",buf);
  7847. }
  7848. else
  7849. {
  7850. fprintf(outfile,"%s\n",buf);
  7851. }
  7852. }
  7853. else if(tempstackLevelInt < stackLevelInt)
  7854. {
  7855. if(ChargingProfileAdded == FALSE)
  7856. {
  7857. fprintf(outfile,"%s\n",payload);
  7858. ChargingProfileAdded = TRUE;
  7859. fprintf(outfile,"%s\n",buf);
  7860. }
  7861. else
  7862. {
  7863. fprintf(outfile,"%s\n",buf);
  7864. }
  7865. }
  7866. else
  7867. {
  7868. if(ChargingProfileAdded == FALSE)
  7869. {
  7870. fprintf(outfile,"%s\n",buf);
  7871. fprintf(outfile,"%s\n",payload);
  7872. ChargingProfileAdded = TRUE;
  7873. }
  7874. else
  7875. {
  7876. fprintf(outfile,"%s\n",buf);
  7877. }
  7878. }
  7879. }
  7880. } // end of while loop
  7881. fclose(infile);
  7882. fclose(outfile);
  7883. sprintf(rmFileCmd,"rm -f %s",filename);
  7884. system(rmFileCmd);
  7885. resultRename = rename(tempfile, filename);
  7886. if(resultRename == 0)
  7887. {
  7888. DEBUG_INFO("File chargingProfile renamed successfully");
  7889. }
  7890. else
  7891. {
  7892. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7893. }
  7894. result = TRUE;
  7895. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7896. }
  7897. end:
  7898. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7899. return result;
  7900. return result;
  7901. }
  7902. int handleTriggerMessageRequest(char *uuid, char *payload)
  7903. {
  7904. mtrace();
  7905. int result = FAIL;
  7906. int connectorIdIsNULL = FALSE;
  7907. int connectorIdInt =0;
  7908. char sstr[40]={0};
  7909. char requestedMessagestr[40]={0};
  7910. char comfirmstr[20]={0};
  7911. int c = 0;
  7912. char *loc;
  7913. DEBUG_INFO("handleTriggerMessageRequest\n");
  7914. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7915. c = 0;
  7916. loc = strstr(payload, "requestedMessage");
  7917. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7918. {
  7919. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7920. c++;
  7921. }
  7922. sstr[c] = '\0';
  7923. strcpy(requestedMessagestr, sstr);
  7924. c = 0;
  7925. loc = strstr(payload, "connectorId");
  7926. if(loc == NULL)
  7927. {
  7928. connectorIdIsNULL = TRUE;
  7929. }
  7930. else
  7931. {
  7932. memset(sstr ,0, sizeof(sstr) );
  7933. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7934. {
  7935. sstr[c] = loc[strlen("connectorId")+2+c];
  7936. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7937. c++;
  7938. }
  7939. sstr[c] = '\0';
  7940. connectorIdInt = atoi(sstr);
  7941. }
  7942. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7943. {
  7944. //connectorIdInt = json_object_get_int(connectorId);
  7945. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7946. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7947. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7948. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7949. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7950. }
  7951. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7952. {
  7953. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7954. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7955. return TRUE;
  7956. }
  7957. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7958. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7959. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7960. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7961. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7962. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7963. {
  7964. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7965. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7966. return TRUE;
  7967. }
  7968. else
  7969. {
  7970. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7971. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7972. }
  7973. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7974. {
  7975. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  7976. {
  7977. FirmwareStatusNotificationStatus = 3;
  7978. }
  7979. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7980. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7981. }
  7982. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7983. {
  7984. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7985. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7986. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7987. }
  7988. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7989. {
  7990. sendBootNotificationRequest();
  7991. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7992. }
  7993. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7994. {
  7995. sendHeartbeatRequest(connectorIdInt);
  7996. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7997. }
  7998. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7999. {
  8000. if(connectorIdIsNULL == FALSE)
  8001. {
  8002. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8003. {
  8004. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8005. sendMeterValuesRequest(connectorIdInt -1);
  8006. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8007. }
  8008. }
  8009. else
  8010. {
  8011. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8012. {
  8013. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8014. sendMeterValuesRequest(idx);
  8015. }
  8016. }
  8017. }
  8018. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8019. {
  8020. if(connectorIdIsNULL == FALSE)
  8021. {
  8022. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8023. {
  8024. sendStatusNotificationRequest(connectorIdInt -1);
  8025. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8026. }
  8027. }
  8028. else
  8029. {
  8030. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8031. sendStatusNotificationRequest(idx);
  8032. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8033. }
  8034. }
  8035. return result;
  8036. }
  8037. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8038. {
  8039. mtrace();
  8040. int result = FAIL;
  8041. char sstr[6]={0};
  8042. int connectorIdInt =0;
  8043. char comfirmstr[20]={0};
  8044. int c = 0;
  8045. char *loc;
  8046. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8047. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8048. c = 0;
  8049. loc = strstr(payload, "connectorId");
  8050. memset(sstr ,0, sizeof(sstr) );
  8051. while (loc[strlen("connectorId")+2+c] != '}')
  8052. {
  8053. sstr[c] = loc[strlen("connectorId")+2+c];
  8054. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8055. c++;
  8056. }
  8057. sstr[c] = '\0';
  8058. connectorIdInt = atoi(sstr);
  8059. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8060. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8061. {
  8062. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8063. goto end;
  8064. }
  8065. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8066. {
  8067. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8068. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8069. goto end;
  8070. }
  8071. else
  8072. {
  8073. //check Transaction active
  8074. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8075. {
  8076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8077. {
  8078. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8079. {
  8080. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8081. }
  8082. }
  8083. for (int index = 0; index < CCS_QUANTITY; index++)
  8084. {
  8085. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8086. {
  8087. //stop Transaction
  8088. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8089. }
  8090. }
  8091. for (int index = 0; index < GB_QUANTITY; index++)
  8092. {
  8093. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8094. {
  8095. //stop Transaction
  8096. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8097. }
  8098. }
  8099. }
  8100. else
  8101. {
  8102. for (int index = 0; index < AC_QUANTITY; index++)
  8103. {
  8104. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8105. {
  8106. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8107. }
  8108. }
  8109. }// END FOR AC ELSE
  8110. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8111. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8112. result = TRUE;
  8113. return result;
  8114. }
  8115. end:
  8116. //json_object_put(obj); --- remove temporally
  8117. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8118. return result;
  8119. }
  8120. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8121. {
  8122. mtrace();
  8123. int result = FAIL;
  8124. pthread_t t;
  8125. sendUpdateFirmwareConfirmation(uuid);
  8126. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8127. ////pthread_join(t, NULL); //
  8128. pthread_detach(t);
  8129. //sendUpdateFirmwareConfirmation(uuid);
  8130. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8131. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8132. return result;
  8133. }
  8134. void *UpdateFirmwareProcess(void *data)
  8135. {
  8136. mtrace();
  8137. int retriesInt =0, retryIntervalInt=0;
  8138. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8139. int port=0;
  8140. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8141. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8142. //char comfirmstr[20];
  8143. int isSuccess = 0;
  8144. char ftpbuf[200];
  8145. char temp[100];
  8146. char * pch;
  8147. int retriesISNULL=FALSE;
  8148. int retryInterval=FALSE;
  8149. int c = 0;
  8150. //int i = 0;
  8151. char *loc;
  8152. char sstr[300]={ 0 };
  8153. char *str = (char*) data; // ? ?輸入資 ?
  8154. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8155. //***************location **************/
  8156. loc = strstr(str, "location");
  8157. memset(sstr ,0, sizeof(sstr) );
  8158. c = 0;
  8159. while (loc[3+strlen("location")+c] != '\"')
  8160. {
  8161. sstr[c] = loc[3+strlen("location")+c];
  8162. c++;
  8163. }
  8164. sstr[c] = '\0';
  8165. strcpy(locationstr, sstr);
  8166. //***************retries**************/
  8167. c = 0;
  8168. loc = strstr(str, "retries");
  8169. if(loc == NULL)
  8170. {
  8171. retriesISNULL=TRUE;
  8172. }
  8173. else
  8174. {
  8175. memset(sstr ,0, sizeof(sstr) );
  8176. while (loc[strlen("retries")+2+c] != ',')
  8177. {
  8178. sstr[c] = loc[strlen("retries")+2+c];
  8179. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8180. c++;
  8181. }
  8182. sstr[c] = '\0';
  8183. }
  8184. if(retriesISNULL == FALSE)
  8185. {
  8186. retriesInt = atoi(sstr);
  8187. }
  8188. //***************retrieveDate **************/
  8189. loc = strstr(str, "retrieveDate");
  8190. memset(sstr ,0, sizeof(sstr) );
  8191. c = 0;
  8192. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8193. {
  8194. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8195. c++;
  8196. }
  8197. sstr[c] = '\0';
  8198. strcpy(retrieveDatestr, sstr);
  8199. //***************retryInterval **************/
  8200. c = 0;
  8201. loc = strstr(str, "retryInterval");
  8202. memset(sstr ,0, sizeof(sstr) );
  8203. if(loc == NULL)
  8204. {
  8205. retryInterval=TRUE;
  8206. }
  8207. else
  8208. {
  8209. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8210. {
  8211. sstr[c] = loc[strlen("retryInterval")+2+c];
  8212. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8213. c++;
  8214. }
  8215. sstr[c] = '\0';
  8216. }
  8217. if(retryInterval==FALSE)
  8218. {
  8219. retryIntervalInt = atoi(sstr);
  8220. }
  8221. memset(ftppath, 0, sizeof(ftppath));
  8222. memset(path, 0, sizeof(path));
  8223. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8224. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8225. if(strncmp(locationstr,"http", 4) == 0)
  8226. {
  8227. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8228. protocol, host, path);
  8229. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8230. // protocol, user, password, host, path);
  8231. sprintf(ftppath,"/%s", path);
  8232. DEBUG_INFO("protocol =%s\n",protocol);
  8233. DEBUG_INFO("host =%s\n",host);
  8234. DEBUG_INFO("path =%s\n",path);
  8235. DEBUG_INFO("ftppath=%s\n",ftppath);
  8236. int ftppathlen=strlen(ftppath);
  8237. int i=1;
  8238. char filenametemp[50];
  8239. while(i < ftppathlen)
  8240. {
  8241. int len=ftppathlen-i;
  8242. if(ftppath[len]== 47) // '/' ascll code: 47
  8243. {
  8244. DEBUG_INFO("compare '/' all right\n");
  8245. break;
  8246. }
  8247. i=i+1;
  8248. }
  8249. memset(filenametemp, 0, sizeof(filenametemp));
  8250. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8251. filenametemp[i+1] = 0;
  8252. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8253. do{
  8254. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8255. sleep(retryIntervalInt);
  8256. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8257. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8258. if(!isSuccess)
  8259. {
  8260. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8261. }
  8262. else
  8263. {
  8264. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8265. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8266. isUpdateRequest = TRUE;
  8267. }
  8268. }
  8269. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8270. {
  8271. memset(ftpbuf, 0, sizeof(ftpbuf));
  8272. memset(temp, 0, sizeof(temp));
  8273. DEBUG_INFO("locationstr=%s\n",locationstr);
  8274. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8275. int ftppathlen=strlen(ftpbuf);
  8276. int i=1;
  8277. char filenametemp[50];
  8278. while(i < ftppathlen)
  8279. {
  8280. int len=ftppathlen-i;
  8281. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8282. {
  8283. DEBUG_INFO(" compare '/' all right\n");
  8284. break;
  8285. }
  8286. i=i+1;
  8287. }
  8288. memset(filenametemp, 0, sizeof(filenametemp));
  8289. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8290. filenametemp[i+1] = 0;
  8291. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8292. pch=strchr(temp,'@');
  8293. if(pch==NULL)
  8294. {
  8295. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8296. protocol, host, &port, path);
  8297. strcpy(user,"anonymous");
  8298. strcpy(password,"");
  8299. }
  8300. else
  8301. {
  8302. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8303. protocol, user, password, host, &port, path);
  8304. }
  8305. sscanf(host,"%[^/]%s",host1, path1);
  8306. sprintf(ftppath,"%s", path1);
  8307. DEBUG_INFO("protocol =%s\n",protocol);
  8308. DEBUG_INFO("user =%s\n",user);
  8309. DEBUG_INFO("password =%s\n",password);
  8310. DEBUG_INFO("host1 =%s\n",host1);
  8311. DEBUG_INFO("port =%d\n",port);
  8312. DEBUG_INFO("path1 =%s\n",path1);
  8313. DEBUG_INFO("ftppath=%s\n",ftppath);
  8314. //ftpFile(host, user, password, port, ftppath, fname);
  8315. //download firmware pthred
  8316. if(port == 0)
  8317. {
  8318. port = 21;
  8319. }
  8320. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8321. do{
  8322. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8323. sleep(retryIntervalInt);
  8324. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8325. if(!isSuccess)
  8326. {
  8327. //BulldogUtil.sleepMs(interval*1000);
  8328. DEBUG_INFO("Update firmware request and download file fail.\n");
  8329. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8330. }
  8331. else
  8332. {
  8333. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8334. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8335. isUpdateRequest = TRUE;
  8336. }
  8337. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8338. }
  8339. else
  8340. {
  8341. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8342. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8343. }
  8344. pthread_exit(NULL);
  8345. }
  8346. //==========================================
  8347. // Handle server response routine
  8348. //==========================================
  8349. void handleAuthorizeResponse(char *payload, int gun_index)
  8350. {
  8351. mtrace();
  8352. char expiryDatestr[30]={0};
  8353. char parentIdTagstr[20]={0};
  8354. char statusstr[20]={0};
  8355. char expiryDatestrtemp[30]={0};
  8356. char parentIdTagstrtemp[20]={0};
  8357. char IdTagstrtemp[20]={0};
  8358. char statusstrtemp[20]={0};
  8359. int expiryDateISNULL=FALSE;
  8360. int parentIdTagISNULL=FALSE;
  8361. char sstr[160]={ 0 };
  8362. char* filename = AuthorizationCache_JSON;
  8363. char tempfile[] = "../Storage/OCPP/temp.json";
  8364. int c = 0;
  8365. char *loc;
  8366. int resultRename=0;
  8367. int responseIdTagInfoAsZero= 0;
  8368. char rmFileCmd[50]={0};
  8369. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8370. //***********expiryDate*************/
  8371. loc = strstr(payload, "expiryDate");
  8372. memset(sstr ,0, sizeof(sstr) );
  8373. c = 0;
  8374. if(loc == NULL)
  8375. {
  8376. expiryDateISNULL = TRUE;
  8377. }
  8378. else
  8379. {
  8380. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8381. {
  8382. sstr[c] = loc[3+strlen("expiryDate")+c];
  8383. c++;
  8384. }
  8385. sstr[c] = '\0';
  8386. strcpy(expiryDatestr, sstr);
  8387. }
  8388. //***********parentIdTag*************/
  8389. loc = strstr(payload, "parentIdTag");
  8390. memset(sstr ,0, sizeof(sstr) );
  8391. c = 0;
  8392. if(loc == NULL)
  8393. {
  8394. parentIdTagISNULL = TRUE;
  8395. }
  8396. else
  8397. {
  8398. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8399. {
  8400. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8401. c++;
  8402. }
  8403. sstr[c] = '\0';
  8404. strcpy(parentIdTagstr, sstr);
  8405. }
  8406. //***********status*************/
  8407. loc = strstr(payload, "status");
  8408. memset(sstr ,0, sizeof(sstr) );
  8409. c = 0;
  8410. while (loc[3+strlen("status")+c] != '\"')
  8411. {
  8412. sstr[c] = loc[3+strlen("status")+c];
  8413. c++;
  8414. }
  8415. sstr[c] = '\0';
  8416. strcpy(statusstr, sstr);
  8417. //#ifdef SystemLogMessage
  8418. // if(expiryDateISNULL == FALSE)
  8419. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8420. // if(parentIdTagISNULL == FALSE)
  8421. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8422. // DEBUG_INFO("status: %s\n", statusstr);
  8423. //#endif
  8424. if(expiryDateISNULL == FALSE)
  8425. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8426. if(parentIdTagISNULL == FALSE)
  8427. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8428. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8429. //Update idTag information to authorization cache if supproted
  8430. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8431. {
  8432. if((access(filename,F_OK))!=-1)
  8433. {
  8434. DEBUG_INFO("AuthorizationCache exist.\n");
  8435. }
  8436. else
  8437. {
  8438. DEBUG_INFO("AuthorizationCache not exist\n");
  8439. FILE *log = fopen(filename, "w+");
  8440. if(log == NULL)
  8441. {
  8442. DEBUG_INFO("log is NULL\n");
  8443. goto out;
  8444. }
  8445. else
  8446. {
  8447. fclose(log);
  8448. }
  8449. }
  8450. FILE *infile;
  8451. FILE *outfile;
  8452. // open file for writing
  8453. infile = fopen (filename, "r");
  8454. outfile = fopen (tempfile, "w");
  8455. //*检测到文件结束标识返回1,否则返回0。*/
  8456. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8457. int c;
  8458. c = fgetc(infile);
  8459. //DEBUG_INFO("c:%d\n",c);
  8460. rewind(infile);
  8461. if(c == EOF)
  8462. {
  8463. DEBUG_INFO("Orignal File is NULL\n");
  8464. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8465. {
  8466. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8467. }
  8468. else
  8469. {
  8470. strcpy(expiryDatestrtemp, "");
  8471. }
  8472. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8473. {
  8474. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8475. }
  8476. else
  8477. {
  8478. //write Authorize IdTag
  8479. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8480. }
  8481. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8482. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8483. fclose(infile);
  8484. fclose(outfile);
  8485. sprintf(rmFileCmd,"rm -f %s",filename);
  8486. system(rmFileCmd);
  8487. resultRename = rename(tempfile, filename);
  8488. if(resultRename == 0)
  8489. {
  8490. DEBUG_INFO("File renamed successfully");
  8491. }
  8492. else
  8493. {
  8494. DEBUG_INFO("Error: unable to rename the file");
  8495. }
  8496. }
  8497. else
  8498. {
  8499. char buf[160]={0};
  8500. //DEBUG_INFO("Orignal File is not NULL\n");
  8501. while (fgets(buf, sizeof(buf), infile) != NULL)
  8502. {
  8503. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8504. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8505. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8506. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8507. memset(statusstr, 0, sizeof(statusstrtemp));
  8508. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8509. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8510. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8511. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8512. //------------------IdTag-----------------------
  8513. loc = strstr(buf, "idTag");
  8514. memset(sstr ,0, sizeof(sstr) );
  8515. c = 0;
  8516. while (loc[3+strlen("idTag")+c] != '\"')
  8517. {
  8518. sstr[c] = loc[3+strlen("idTag")+c];
  8519. c++;
  8520. }
  8521. sstr[c] = '\0';
  8522. strcpy(IdTagstrtemp,sstr);
  8523. //*********************expiryDate***************/
  8524. loc = strstr(buf, "expiryDate");
  8525. memset(sstr ,0, sizeof(sstr) );
  8526. c = 0;
  8527. while (loc[3+strlen("expiryDate")+c] != '\"')
  8528. {
  8529. sstr[c] = loc[3+strlen("expiryDate")+c];
  8530. c++;
  8531. }
  8532. sstr[c] = '\0';
  8533. strcpy(expiryDatestr,sstr);
  8534. //*********************parentIdTag***************/
  8535. loc = strstr(buf, "parentIdTag");
  8536. memset(sstr ,0, sizeof(sstr) );
  8537. c = 0;
  8538. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8539. {
  8540. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8541. c++;
  8542. }
  8543. sstr[c] = '\0';
  8544. strcpy(parentIdTagstr,sstr);
  8545. //*********************status***************/
  8546. loc = strstr(buf, "status");
  8547. memset(sstr ,0, sizeof(sstr) );
  8548. c = 0;
  8549. while (loc[3+strlen("status")+c] != '\"')
  8550. {
  8551. sstr[c] = loc[3+strlen("status")+c];
  8552. c++;
  8553. }
  8554. sstr[c] = '\0';
  8555. strcpy(statusstr,sstr);
  8556. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8557. {
  8558. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8559. responseIdTagInfoAsZero = 1;
  8560. }
  8561. else
  8562. {
  8563. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8564. }
  8565. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8566. {
  8567. //modify item
  8568. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8569. {
  8570. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8571. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8572. }
  8573. else
  8574. {
  8575. strcpy(expiryDatestrtemp, "");
  8576. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8577. }
  8578. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8579. {
  8580. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8581. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8582. }
  8583. else
  8584. {
  8585. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8586. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8587. }
  8588. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8589. }
  8590. else
  8591. {
  8592. //wrie original item
  8593. strcpy(expiryDatestrtemp, expiryDatestr);
  8594. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8595. strcpy(statusstrtemp, statusstr);
  8596. }
  8597. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8598. }
  8599. fclose(infile);
  8600. fclose(outfile);
  8601. sprintf(rmFileCmd,"rm -f %s",filename);
  8602. system(rmFileCmd);
  8603. resultRename = rename(tempfile, filename);
  8604. if(resultRename == 0)
  8605. {
  8606. DEBUG_INFO("File renamed successfully");
  8607. }
  8608. else
  8609. {
  8610. DEBUG_INFO("Error: unable to rename the file");
  8611. }
  8612. }
  8613. }
  8614. out:
  8615. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8616. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8617. authorizeRetryTimes = 0;
  8618. }
  8619. void handleBootNotificationResponse(char *payload, int gun_index)
  8620. {
  8621. mtrace();
  8622. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8623. char statusStr[12]={0};
  8624. char currentTimeStr[30]={0};
  8625. char *loc;
  8626. int intervalInt = 0;
  8627. int c = 0;
  8628. //double diff_t;
  8629. struct tm tp;
  8630. char buf[28]={0};
  8631. char timebuf[50]={0};
  8632. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8633. //*** interval ****/
  8634. c = 0;
  8635. loc = strstr(payload, "interval");
  8636. //printf("loc=%s\n",loc);
  8637. memset(sstr ,0, sizeof(sstr) );
  8638. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8639. {
  8640. sstr[c] = loc[strlen("interval")+2+c];
  8641. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8642. c++;
  8643. }
  8644. sstr[c] = '\0';
  8645. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8646. intervalInt = atoi(sstr);
  8647. //***status ****/
  8648. loc = strstr(payload, "status");
  8649. memset(sstr ,0, sizeof(sstr) );
  8650. c = 0;
  8651. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8652. {
  8653. sstr[c] = loc[3+strlen("status")+c];
  8654. c++;
  8655. }
  8656. sstr[c] = '\0';
  8657. strcpy(statusStr, sstr);
  8658. //***currentTime ****/
  8659. loc = strstr(payload, "currentTime");
  8660. //printf("loc=%s\n",loc);
  8661. memset(sstr ,0, sizeof(sstr) );
  8662. c = 0;
  8663. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8664. {
  8665. sstr[c] = loc[3+strlen("currentTime")+c];
  8666. c++;
  8667. }
  8668. sstr[c] = '\0';
  8669. strcpy(currentTimeStr, sstr);
  8670. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8671. HeartBeatWaitTime = BootNotificationInterval;
  8672. //#ifdef SystemLogMessage
  8673. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8674. // DEBUG_INFO("interval: %d\n", intervalInt);
  8675. // DEBUG_INFO("status: %s\n", statusStr);
  8676. //#endif
  8677. //write back to ShmOCPP16Data->BootNotification
  8678. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8679. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8680. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8681. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8682. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8683. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8684. {
  8685. server_sign = TRUE;
  8686. server_pending =FALSE;
  8687. }
  8688. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8689. {
  8690. server_pending = TRUE;
  8691. }
  8692. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8693. tp.tm_isdst = -1;
  8694. //time_t utc = mktime(&tp);
  8695. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8696. memset(timebuf, 0, sizeof timebuf);
  8697. sprintf(timebuf,"date -s '%s'",buf);
  8698. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8699. system(timebuf);
  8700. //==============================================
  8701. // RTC sync
  8702. //==============================================
  8703. system("/sbin/hwclock -w --systohc");
  8704. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8705. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8706. }
  8707. void handleDataTransferResponse(char *payload, int gun_index)
  8708. {
  8709. char sstr[160]={0};//sstr[200]={ 0 };
  8710. int c = 0;
  8711. char *loc;
  8712. DEBUG_INFO("handleDataTransferResponse ...\n");
  8713. loc = strstr(payload, "status");
  8714. printf("loc=%s\n",loc);
  8715. c = 0;
  8716. while (loc[3+strlen("status")+c] != '\"')
  8717. {
  8718. sstr[c] = loc[3+strlen("status")+c];
  8719. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8720. c++;
  8721. }
  8722. sstr[c] = '\0';
  8723. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8724. //#ifdef SystemLogMessage
  8725. //DEBUG_INFO("data: %s\n", payload);
  8726. //#endif
  8727. }
  8728. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8729. {
  8730. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8731. //struct json_object *obj;
  8732. // obj = json_tokener_parse(payload);
  8733. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8734. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8735. //No fields are defined.
  8736. }
  8737. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8738. {
  8739. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8740. //struct json_object *obj;
  8741. // obj = json_tokener_parse(payload);
  8742. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8743. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8744. //No fields are defined.
  8745. }
  8746. void handleHeartbeatResponse(char *payload, int gun_index)
  8747. {
  8748. mtrace();
  8749. //double diff_t;
  8750. struct tm tp;
  8751. char buf[28]={0};
  8752. char timebuf[50]={0};
  8753. char sstr[30]={ 0 };
  8754. int c = 0;
  8755. char *loc;
  8756. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8757. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8758. c = 0;
  8759. loc = strstr(payload, "currentTime");
  8760. memset(sstr ,0, sizeof(sstr) );
  8761. while (loc[3+strlen("currentTime")+c] != '\"')
  8762. {
  8763. sstr[c] = loc[3+strlen("currentTime")+c];
  8764. c++;
  8765. }
  8766. sstr[c] = '\0';
  8767. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8768. // #ifdef SystemLogMessage
  8769. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8770. // #endif
  8771. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8772. tp.tm_isdst = -1;
  8773. //time_t utc = mktime(&tp);
  8774. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8775. memset(timebuf, 0, sizeof timebuf);
  8776. sprintf(timebuf,"date -s '%s'",buf);
  8777. system(timebuf);
  8778. //==============================================
  8779. // RTC sync
  8780. //==============================================
  8781. system("/sbin/hwclock -w --systohc");
  8782. if(FirstHeartBeat == 0)
  8783. {
  8784. FirstHeartBeat = 1;
  8785. }
  8786. HeartBeatWithNOResponse = 0;
  8787. }
  8788. void handleMeterValuesResponse(char *payload, int gun_index)
  8789. {
  8790. mtrace();
  8791. //struct json_object *obj;
  8792. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8793. //No fields are defined.
  8794. }
  8795. void handleStartTransactionResponse(char *payload, int gun_index)
  8796. {
  8797. mtrace();
  8798. char sstr[28]={ 0 };
  8799. int c = 0;
  8800. char *loc;
  8801. int transactionIdInt = 0;
  8802. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8803. DEBUG_INFO("handleStartTransactionResponse\n");
  8804. //****************expiryDate********************/
  8805. loc = strstr(payload, "expiryDate");
  8806. if(loc == NULL)
  8807. {
  8808. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8809. }
  8810. else
  8811. {
  8812. c = 0;
  8813. memset(sstr ,0, sizeof(sstr) );
  8814. while (loc[3+strlen("expiryDate")+c] != '\"')
  8815. {
  8816. sstr[c] = loc[3+strlen("expiryDate")+c];
  8817. c++;
  8818. }
  8819. sstr[c] = '\0';
  8820. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8821. }
  8822. //****************parentIdTag********************/
  8823. loc = strstr(payload, "parentIdTag");
  8824. if(loc == NULL)
  8825. {
  8826. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8827. }
  8828. else
  8829. {
  8830. c = 0;
  8831. memset(sstr ,0, sizeof(sstr) );
  8832. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8833. {
  8834. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8835. c++;
  8836. }
  8837. sstr[c] = '\0';
  8838. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8839. }
  8840. //****************status********************/
  8841. loc = strstr(payload, "status");
  8842. if(loc == NULL)
  8843. {
  8844. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8845. }
  8846. else
  8847. {
  8848. c = 0;
  8849. memset(sstr ,0, sizeof(sstr) );
  8850. while (loc[3+strlen("status")+c] != '\"')
  8851. {
  8852. sstr[c] = loc[3+strlen("status")+c];
  8853. c++;
  8854. }
  8855. sstr[c] = '\0';
  8856. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8857. }
  8858. //****************transactionId********************/
  8859. c=0;
  8860. loc = strstr(payload, "transactionId");
  8861. memset(sstr ,0, sizeof(sstr) );
  8862. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8863. {
  8864. sstr[c] = loc[strlen("transactionId")+2+c];
  8865. c++;
  8866. }
  8867. sstr[c] = '\0';
  8868. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8869. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8870. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8871. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8872. #ifdef SystemLogMessage
  8873. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8874. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8875. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8876. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8877. #endif
  8878. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8879. {
  8880. //add Charging Record
  8881. SettingChargingRecord(gun_index, transactionIdInt);
  8882. }
  8883. DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8884. }
  8885. void handleStatusNotificationResponse(char *payload, int gun_index)
  8886. {
  8887. mtrace();
  8888. printf("handleStatusNotificationResponse\n");
  8889. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8890. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8891. }
  8892. void handleStopTransactionnResponse(char *payload, int gun_index)
  8893. {
  8894. mtrace();
  8895. char sstr[30]={ 0 };
  8896. int c = 0;
  8897. char *loc;
  8898. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8899. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8900. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8901. loc = strstr(payload, "idTagInfo");
  8902. //***********************idTagInfo************************/
  8903. if(loc != NULL)
  8904. {
  8905. //***********************expiryDate************************/
  8906. loc = strstr(payload, "expiryDate");
  8907. if(loc != NULL)
  8908. {
  8909. memset(sstr ,0, sizeof(sstr) );
  8910. c = 0;
  8911. while (loc[3+strlen("expiryDate")+c] != '\"')
  8912. {
  8913. sstr[c] = loc[3+strlen("expiryDate")+c];
  8914. c++;
  8915. }
  8916. sstr[c] = '\0';
  8917. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8918. }
  8919. //***********************parentIdTag************************/
  8920. loc = strstr(payload, "parentIdTag");
  8921. if(loc != NULL)
  8922. {
  8923. memset(sstr ,0, sizeof(sstr) );
  8924. c = 0;
  8925. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8926. {
  8927. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8928. c++;
  8929. }
  8930. sstr[c] = '\0';
  8931. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8932. }
  8933. //***********************status************************/
  8934. loc = strstr(payload, "status");
  8935. memset(sstr ,0, sizeof(sstr) );
  8936. c = 0;
  8937. while (loc[3+strlen("status")+c] != '\"')
  8938. {
  8939. sstr[c] = loc[3+strlen("status")+c];
  8940. c++;
  8941. }
  8942. sstr[c] = '\0';
  8943. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8944. }
  8945. #ifdef SystemLogMessage
  8946. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8947. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8948. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8949. #endif
  8950. }
  8951. //==========================================
  8952. // Handle Error routine
  8953. //==========================================
  8954. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8955. {
  8956. mtrace();
  8957. #ifdef SystemLogMessage
  8958. DEBUG_INFO("errorCode: %s\n", errorCode);
  8959. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8960. DEBUG_INFO("errorDetails: %s\n", payload);
  8961. #endif
  8962. }
  8963. //===============================================
  8964. // Common routine
  8965. //===============================================
  8966. int initialConfigurationTable(void)
  8967. {
  8968. printf("initialConfigurationTable \n");
  8969. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8970. /*Core Profile*/
  8971. //AllowOfflineTxForUnknownId
  8972. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8973. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8976. //AuthorizationCacheEnabled
  8977. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8980. //AuthorizeRemoteTxRequests
  8981. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8984. //BlinkRepeat
  8985. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8988. //ClockAlignedDataInterval
  8989. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8992. //ConnectionTimeOut
  8993. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8996. //GetConfigurationMaxKeys
  8997. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9000. // HeartbeatInterval
  9001. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9004. // LightIntensity
  9005. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9008. // LocalAuthorizeOffline
  9009. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9012. // LocalPreAuthorize
  9013. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9016. // MaxEnergyOnInvalidId
  9017. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9020. // MeterValuesAlignedData
  9021. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9024. // MeterValuesAlignedDataMaxLength
  9025. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9028. // MeterValuesSampledData
  9029. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9032. // MeterValuesSampledDataMaxLength
  9033. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9036. // MeterValueSampleInterval
  9037. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9040. // MinimumStatusDuration
  9041. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9044. // NumberOfConnectors
  9045. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  9048. // ResetRetries
  9049. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9052. // ConnectorPhaseRotation
  9053. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  9056. // ConnectorPhaseRotationMaxLength
  9057. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9060. // StopTransactionOnEVSideDisconnect
  9061. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9064. // StopTransactionOnInvalidId
  9065. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9068. // StopTxnAlignedData
  9069. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9072. // StopTxnAlignedDataMaxLength
  9073. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9076. // StopTxnSampledData
  9077. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9080. // StopTxnSampledDataMaxLength
  9081. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9084. // SupportedFeatureProfiles
  9085. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9088. // SupportedFeatureProfilesMaxLength
  9089. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9092. // TransactionMessageAttempts
  9093. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9096. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9097. // TransactionMessageRetryInterval
  9098. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9101. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9102. // UnlockConnectorOnEVSideDisconnect
  9103. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9106. // WebSocketPingInterval
  9107. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9110. //* Local Auth List Management Profile*/
  9111. #if 0
  9112. //For OCTT Test Case
  9113. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9116. #endif
  9117. #if 1
  9118. //LocalAuthListEnabled
  9119. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9122. #endif
  9123. //LocalAuthListMaxLength
  9124. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9127. //SendLocalListMaxLength
  9128. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9131. //ReserveConnectorZeroSupported
  9132. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9135. //* Smart Charging Profile */
  9136. //ChargeProfileMaxStackLevel
  9137. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9140. // ChargingScheduleAllowedChargingRateUnit
  9141. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9144. // ChargingScheduleMaxPeriods
  9145. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9148. // ConnectorSwitch3to1PhaseSupported
  9149. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9152. // MaxChargingProfilesInstalled
  9153. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9156. return 0;
  9157. }
  9158. void getKeyValue(char *keyReq)
  9159. {
  9160. int isEmpty = FALSE;
  9161. int isKnowKey = FALSE;
  9162. //int unKnowIndex = 0;
  9163. DEBUG_INFO("getKeyValue \n");
  9164. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9165. isEmpty = TRUE;
  9166. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9167. {
  9168. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9171. {
  9172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9173. }
  9174. else
  9175. {
  9176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9177. }
  9178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9179. isKnowKey = TRUE;
  9180. }
  9181. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9182. {
  9183. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9186. {
  9187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9188. }
  9189. else
  9190. {
  9191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9192. }
  9193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9194. isKnowKey = TRUE;
  9195. }
  9196. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9197. {
  9198. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9200. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9201. {
  9202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9203. }
  9204. else
  9205. {
  9206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9207. }
  9208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9209. isKnowKey = TRUE;
  9210. }
  9211. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9212. {
  9213. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9216. {
  9217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9218. }
  9219. else
  9220. {
  9221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9222. }
  9223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9224. isKnowKey = TRUE;
  9225. }
  9226. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9227. {
  9228. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9231. {
  9232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9233. }
  9234. else
  9235. {
  9236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9237. }
  9238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9239. isKnowKey = TRUE;
  9240. }
  9241. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9242. {
  9243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9246. {
  9247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9248. }
  9249. else
  9250. {
  9251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9252. }
  9253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9254. isKnowKey = TRUE;
  9255. }
  9256. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9257. {
  9258. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9260. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9261. {
  9262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9263. }
  9264. else
  9265. {
  9266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9267. }
  9268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9269. isKnowKey = TRUE;
  9270. }
  9271. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9272. {
  9273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9276. {
  9277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9278. }
  9279. else
  9280. {
  9281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9282. }
  9283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9284. isKnowKey = TRUE;
  9285. }
  9286. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9287. {
  9288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9291. {
  9292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9293. }
  9294. else
  9295. {
  9296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9297. }
  9298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9299. isKnowKey = TRUE;
  9300. }
  9301. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9302. {
  9303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9306. {
  9307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9308. }
  9309. else
  9310. {
  9311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9312. }
  9313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9314. isKnowKey = TRUE;
  9315. }
  9316. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9317. {
  9318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9321. {
  9322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9323. }
  9324. else
  9325. {
  9326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9327. }
  9328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9329. isKnowKey = TRUE;
  9330. }
  9331. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9332. {
  9333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9335. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9336. {
  9337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9338. }
  9339. else
  9340. {
  9341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9342. }
  9343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9344. isKnowKey = TRUE;
  9345. }
  9346. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9347. {
  9348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9351. {
  9352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9353. }
  9354. else
  9355. {
  9356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9357. }
  9358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9359. isKnowKey = TRUE;
  9360. }
  9361. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9362. {
  9363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9365. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9366. {
  9367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9368. }
  9369. else
  9370. {
  9371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9372. }
  9373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9374. isKnowKey = TRUE;
  9375. }
  9376. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9377. {
  9378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9380. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9381. {
  9382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9383. }
  9384. else
  9385. {
  9386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9387. }
  9388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9389. isKnowKey = TRUE;
  9390. }
  9391. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9392. {
  9393. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9395. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9396. {
  9397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9398. }
  9399. else
  9400. {
  9401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9402. }
  9403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9404. isKnowKey = TRUE;
  9405. }
  9406. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9407. {
  9408. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9410. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9411. {
  9412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9413. }
  9414. else
  9415. {
  9416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9417. }
  9418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9419. isKnowKey = TRUE;
  9420. }
  9421. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9422. {
  9423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9426. {
  9427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9428. }
  9429. else
  9430. {
  9431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9432. }
  9433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9434. isKnowKey = TRUE;
  9435. }
  9436. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9437. {
  9438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9441. {
  9442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9443. }
  9444. else
  9445. {
  9446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9447. }
  9448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9449. isKnowKey = TRUE;
  9450. }
  9451. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9452. {
  9453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9456. {
  9457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9458. }
  9459. else
  9460. {
  9461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9462. }
  9463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9464. isKnowKey = TRUE;
  9465. }
  9466. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9467. {
  9468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9471. {
  9472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9473. }
  9474. else
  9475. {
  9476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9477. }
  9478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9479. isKnowKey = TRUE;
  9480. }
  9481. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9482. {
  9483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9486. {
  9487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9488. }
  9489. else
  9490. {
  9491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9492. }
  9493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9494. isKnowKey = TRUE;
  9495. }
  9496. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9497. {
  9498. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9501. {
  9502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9503. }
  9504. else
  9505. {
  9506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9507. }
  9508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9509. isKnowKey = TRUE;
  9510. }
  9511. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9512. {
  9513. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9516. {
  9517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9518. }
  9519. else
  9520. {
  9521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9522. }
  9523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9524. isKnowKey = TRUE;
  9525. }
  9526. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9527. {
  9528. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9531. {
  9532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9533. }
  9534. else
  9535. {
  9536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9537. }
  9538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9539. isKnowKey = TRUE;
  9540. }
  9541. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9542. {
  9543. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9546. {
  9547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9548. }
  9549. else
  9550. {
  9551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9552. }
  9553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9554. isKnowKey = TRUE;
  9555. }
  9556. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9557. {
  9558. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9561. {
  9562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9563. }
  9564. else
  9565. {
  9566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9567. }
  9568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9569. isKnowKey = TRUE;
  9570. }
  9571. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9572. {
  9573. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9575. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9576. {
  9577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9578. }
  9579. else
  9580. {
  9581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9582. }
  9583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9584. isKnowKey = TRUE;
  9585. }
  9586. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9587. {
  9588. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9591. {
  9592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9593. }
  9594. else
  9595. {
  9596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9597. }
  9598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9599. isKnowKey = TRUE;
  9600. }
  9601. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9602. {
  9603. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9606. {
  9607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9608. }
  9609. else
  9610. {
  9611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9612. }
  9613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9614. isKnowKey = TRUE;
  9615. }
  9616. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9617. {
  9618. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9621. {
  9622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9623. }
  9624. else
  9625. {
  9626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9627. }
  9628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9629. isKnowKey = TRUE;
  9630. }
  9631. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9632. {
  9633. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9636. {
  9637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9638. }
  9639. else
  9640. {
  9641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9642. }
  9643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9644. isKnowKey = TRUE;
  9645. }
  9646. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9647. {
  9648. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9651. {
  9652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9653. }
  9654. else
  9655. {
  9656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9657. }
  9658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9659. isKnowKey = TRUE;
  9660. }
  9661. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9662. {
  9663. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9666. {
  9667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9668. }
  9669. else
  9670. {
  9671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9672. }
  9673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9674. isKnowKey = TRUE;
  9675. }
  9676. #if 0
  9677. //For OCTT Test Case
  9678. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9679. {
  9680. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9682. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9683. {
  9684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9685. }
  9686. else
  9687. {
  9688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9689. }
  9690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9691. isKnowKey = TRUE;
  9692. }
  9693. #endif
  9694. #if 1
  9695. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9696. {
  9697. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9699. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9700. {
  9701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9702. }
  9703. else
  9704. {
  9705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9706. }
  9707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9708. isKnowKey = TRUE;
  9709. }
  9710. #endif
  9711. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9712. {
  9713. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9715. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9716. {
  9717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9718. }
  9719. else
  9720. {
  9721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9722. }
  9723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9724. isKnowKey = TRUE;
  9725. }
  9726. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9727. {
  9728. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9730. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9731. {
  9732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9733. }
  9734. else
  9735. {
  9736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9737. }
  9738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9739. isKnowKey = TRUE;
  9740. }
  9741. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9742. {
  9743. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9745. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9746. {
  9747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9748. }
  9749. else
  9750. {
  9751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9752. }
  9753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9754. isKnowKey = TRUE;
  9755. }
  9756. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9757. {
  9758. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9760. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9761. {
  9762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9763. }
  9764. else
  9765. {
  9766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9767. }
  9768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9769. isKnowKey = TRUE;
  9770. }
  9771. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9772. {
  9773. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9775. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9776. {
  9777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9778. }
  9779. else
  9780. {
  9781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9782. }
  9783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9784. isKnowKey = TRUE;
  9785. }
  9786. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9787. {
  9788. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9790. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9791. {
  9792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9793. }
  9794. else
  9795. {
  9796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9797. }
  9798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9799. isKnowKey = TRUE;
  9800. }
  9801. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9802. {
  9803. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9805. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9806. {
  9807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9808. }
  9809. else
  9810. {
  9811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9812. }
  9813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9814. isKnowKey = TRUE;
  9815. }
  9816. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9817. {
  9818. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9820. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9821. {
  9822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9823. }
  9824. else
  9825. {
  9826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9827. }
  9828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9829. isKnowKey = TRUE;
  9830. }
  9831. //=========================================================
  9832. if(!isEmpty && !isKnowKey)
  9833. {
  9834. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9835. strcpy(unknownkey[UnknownKeynum], keyReq);
  9836. UnknownKeynum = UnknownKeynum + 1;
  9837. }
  9838. }
  9839. void processUnkownKey(void)
  9840. {
  9841. DEBUG_INFO("processUnkownKey\n");
  9842. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9843. for(int index=0; index < UnknownKeynum; index++)
  9844. {
  9845. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9846. {
  9847. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9848. }
  9849. }
  9850. }
  9851. int setKeyValue(char *key, char *value)
  9852. {
  9853. int isSuccess = NotSupported;
  9854. int check_ascii=0;
  9855. #ifdef Debug
  9856. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9857. #endif
  9858. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9859. {
  9860. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9862. {
  9863. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9864. isSuccess = ConfigurationStatus_Accepted;
  9865. }
  9866. else
  9867. {
  9868. isSuccess = ConfigurationStatus_Rejected;
  9869. }
  9870. }
  9871. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9872. {
  9873. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9875. {
  9876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9877. isSuccess = ConfigurationStatus_Accepted;
  9878. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9879. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9880. }
  9881. else
  9882. {
  9883. isSuccess = ConfigurationStatus_Rejected;
  9884. }
  9885. }
  9886. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9887. {
  9888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9889. {
  9890. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9891. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9892. isSuccess = ConfigurationStatus_Accepted;
  9893. }
  9894. else
  9895. {
  9896. isSuccess = ConfigurationStatus_Rejected;
  9897. }
  9898. }
  9899. if(strcmp(key, "BlinkRepeat") == 0)
  9900. {
  9901. //Charger.BlinkRepeat = Integer.parseInt(value);
  9902. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9903. {
  9904. check_ascii = value[0];
  9905. if( (check_ascii < 48) || (check_ascii > 57) )
  9906. {
  9907. isSuccess = ConfigurationStatus_Rejected;
  9908. }
  9909. else
  9910. {
  9911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9912. isSuccess = ConfigurationStatus_Accepted;
  9913. }
  9914. }
  9915. else
  9916. {
  9917. isSuccess = ConfigurationStatus_Rejected;
  9918. }
  9919. }
  9920. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9921. {
  9922. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9923. {
  9924. check_ascii = value[0];
  9925. if( (check_ascii < 48) || (check_ascii > 57) )
  9926. {
  9927. isSuccess = ConfigurationStatus_Rejected;
  9928. }
  9929. else
  9930. {
  9931. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9932. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9933. isSuccess = ConfigurationStatus_Accepted;
  9934. }
  9935. }
  9936. else
  9937. {
  9938. isSuccess = ConfigurationStatus_Rejected;
  9939. }
  9940. }
  9941. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9942. {
  9943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9944. {
  9945. check_ascii = value[0];
  9946. if( (check_ascii < 48) || (check_ascii > 57) )
  9947. {
  9948. isSuccess = ConfigurationStatus_Rejected;
  9949. }
  9950. else
  9951. {
  9952. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9954. isSuccess = ConfigurationStatus_Accepted;
  9955. }
  9956. }
  9957. else
  9958. {
  9959. isSuccess = ConfigurationStatus_Rejected;
  9960. }
  9961. }
  9962. if(strcmp(key, "HeartbeatInterval") == 0)
  9963. {
  9964. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9965. {
  9966. check_ascii = value[0];
  9967. if( (check_ascii < 48) || (check_ascii > 57) )
  9968. {
  9969. isSuccess = ConfigurationStatus_Rejected;
  9970. }
  9971. else
  9972. {
  9973. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9975. HeartBeatWaitTime = atoi(value);
  9976. isSuccess = ConfigurationStatus_Accepted;
  9977. }
  9978. }
  9979. else
  9980. {
  9981. isSuccess = ConfigurationStatus_Rejected;
  9982. }
  9983. }
  9984. if(strcmp(key, "LightIntensity") == 0)
  9985. {
  9986. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9987. {
  9988. check_ascii = value[0];
  9989. if( (check_ascii < 48) || (check_ascii > 57) )
  9990. {
  9991. isSuccess = ConfigurationStatus_Rejected;
  9992. }
  9993. else
  9994. {
  9995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9996. isSuccess = ConfigurationStatus_Accepted;
  9997. }
  9998. }
  9999. else
  10000. {
  10001. isSuccess = ConfigurationStatus_Rejected;
  10002. }
  10003. }
  10004. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10005. {
  10006. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10007. {
  10008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10009. isSuccess = ConfigurationStatus_Accepted;
  10010. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10011. }
  10012. else
  10013. {
  10014. isSuccess = ConfigurationStatus_Rejected;
  10015. }
  10016. }
  10017. if(strcmp(key, "LocalPreAuthorize") == 0)
  10018. {
  10019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10020. {
  10021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10022. isSuccess = ConfigurationStatus_Accepted;
  10023. }
  10024. else
  10025. {
  10026. isSuccess = ConfigurationStatus_Rejected;
  10027. }
  10028. }
  10029. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10030. {
  10031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10032. {
  10033. check_ascii = value[0];
  10034. if( (check_ascii < 48) || (check_ascii > 57) )
  10035. {
  10036. isSuccess = ConfigurationStatus_Rejected;
  10037. }
  10038. else
  10039. {
  10040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10041. isSuccess = ConfigurationStatus_Accepted;
  10042. }
  10043. }
  10044. else
  10045. {
  10046. isSuccess = ConfigurationStatus_Rejected;
  10047. }
  10048. }
  10049. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10050. {
  10051. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10052. {
  10053. //int valueLength = strlen(value);
  10054. for(int i = 0; value[i]; i++){
  10055. value[i] = tolower(value[i]);
  10056. }
  10057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10058. isSuccess = ConfigurationStatus_Accepted;
  10059. }
  10060. else
  10061. {
  10062. isSuccess = ConfigurationStatus_Rejected;
  10063. }
  10064. }
  10065. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10066. {
  10067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10068. {
  10069. //int valueLength = strlen(value);
  10070. for(int i = 0; value[i]; i++){
  10071. value[i] = tolower(value[i]);
  10072. }
  10073. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10074. isSuccess = ConfigurationStatus_Accepted;
  10075. }
  10076. else
  10077. {
  10078. isSuccess = ConfigurationStatus_Rejected;
  10079. }
  10080. }
  10081. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10082. {
  10083. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10084. {
  10085. check_ascii = value[0];
  10086. if( (check_ascii < 48) || (check_ascii > 57) )
  10087. {
  10088. isSuccess = ConfigurationStatus_Rejected;
  10089. }
  10090. else
  10091. {
  10092. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10094. isSuccess = ConfigurationStatus_Accepted;
  10095. }
  10096. #ifdef Debug
  10097. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10098. #endif
  10099. }
  10100. else
  10101. {
  10102. isSuccess = ConfigurationStatus_Rejected;
  10103. #ifdef Debug
  10104. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10105. #endif
  10106. }
  10107. }
  10108. if(strcmp(key, "MinimumStatusDuration") == 0)
  10109. {
  10110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10111. {
  10112. check_ascii = value[0];
  10113. if( (check_ascii < 48) || (check_ascii > 57) )
  10114. {
  10115. isSuccess = ConfigurationStatus_Rejected;
  10116. }
  10117. else
  10118. {
  10119. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10120. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10121. isSuccess = ConfigurationStatus_Accepted;
  10122. }
  10123. }
  10124. else
  10125. {
  10126. isSuccess = ConfigurationStatus_Rejected;
  10127. }
  10128. }
  10129. if(strcmp(key, "ResetRetries") == 0)
  10130. {
  10131. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10132. {
  10133. check_ascii = value[0];
  10134. if( (check_ascii < 48) || (check_ascii > 57) )
  10135. {
  10136. isSuccess = ConfigurationStatus_Rejected;
  10137. }
  10138. else
  10139. {
  10140. //Charger.ResetRetries = Integer.parseInt(value);
  10141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10142. isSuccess = ConfigurationStatus_Accepted;
  10143. }
  10144. }
  10145. else
  10146. {
  10147. isSuccess = ConfigurationStatus_Rejected;
  10148. }
  10149. }
  10150. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10151. {
  10152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10153. {
  10154. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10155. //int valueLength = strlen(value);
  10156. for(int i = 0; value[i]; i++){
  10157. value[i] = tolower(value[i]);
  10158. }
  10159. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10160. isSuccess = ConfigurationStatus_Accepted;
  10161. }
  10162. else
  10163. {
  10164. isSuccess = ConfigurationStatus_Rejected;
  10165. }
  10166. }
  10167. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10168. {
  10169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10170. {
  10171. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10173. isSuccess = ConfigurationStatus_Accepted;
  10174. }
  10175. else
  10176. {
  10177. isSuccess = ConfigurationStatus_Rejected;
  10178. }
  10179. }
  10180. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10181. {
  10182. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10183. {
  10184. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10186. isSuccess = ConfigurationStatus_Accepted;
  10187. }
  10188. else
  10189. {
  10190. isSuccess = ConfigurationStatus_Rejected;
  10191. }
  10192. }
  10193. if(strcmp(key, "StopTxnAlignedData") == 0)
  10194. {
  10195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10196. {
  10197. //Charger.StopTxnAlignedData = value.toLowerCase();
  10198. //int valueLength = strlen(value);
  10199. for(int i = 0; value[i]; i++){
  10200. value[i] = tolower(value[i]);
  10201. }
  10202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10203. isSuccess = ConfigurationStatus_Accepted;
  10204. }
  10205. else
  10206. {
  10207. isSuccess = ConfigurationStatus_Rejected;
  10208. }
  10209. }
  10210. if(strcmp(key, "StopTxnSampledData") == 0)
  10211. {
  10212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10213. {
  10214. //Charger.StopTxnSampledData = value.toLowerCase();
  10215. //int valueLength = strlen(value);
  10216. for(int i = 0; value[i]; i++){
  10217. value[i] = tolower(value[i]);
  10218. }
  10219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10220. isSuccess = ConfigurationStatus_Accepted;
  10221. }
  10222. else
  10223. {
  10224. isSuccess = ConfigurationStatus_Rejected;
  10225. }
  10226. }
  10227. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10228. {
  10229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10230. {
  10231. check_ascii = value[0];
  10232. if( (check_ascii < 48) || (check_ascii > 57) )
  10233. {
  10234. isSuccess = ConfigurationStatus_Rejected;
  10235. }
  10236. else
  10237. {
  10238. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10240. TransactionMessageAttemptsValue = atoi(value);
  10241. isSuccess = ConfigurationStatus_Accepted;
  10242. }
  10243. }
  10244. else
  10245. {
  10246. isSuccess = ConfigurationStatus_Rejected;
  10247. }
  10248. }
  10249. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10250. {
  10251. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10252. {
  10253. check_ascii = value[0];
  10254. if( (check_ascii < 48) || (check_ascii > 57) )
  10255. {
  10256. isSuccess = ConfigurationStatus_Rejected;
  10257. }
  10258. else
  10259. {
  10260. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10262. TransactionMessageRetryIntervalValue = atoi(value);
  10263. isSuccess = ConfigurationStatus_Accepted;
  10264. }
  10265. }
  10266. else
  10267. {
  10268. isSuccess = ConfigurationStatus_Rejected;
  10269. }
  10270. }
  10271. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10272. {
  10273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10274. {
  10275. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10277. isSuccess = ConfigurationStatus_Accepted;
  10278. }
  10279. else
  10280. {
  10281. isSuccess = ConfigurationStatus_Rejected;
  10282. }
  10283. }
  10284. if(strcmp(key, "WebSocketPingInterval") == 0)
  10285. {
  10286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10287. {
  10288. check_ascii = value[0];
  10289. if( (check_ascii < 48) || (check_ascii > 57) )
  10290. {
  10291. isSuccess = ConfigurationStatus_Rejected;
  10292. }
  10293. else
  10294. {
  10295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10296. isSuccess = ConfigurationStatus_Accepted;
  10297. }
  10298. }
  10299. else
  10300. {
  10301. isSuccess = ConfigurationStatus_Rejected;
  10302. }
  10303. }
  10304. #if 0
  10305. //For OCPP Test Case
  10306. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10307. {
  10308. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10309. {
  10310. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10311. isSuccess = ConfigurationStatus_Accepted;
  10312. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10313. }
  10314. else
  10315. {
  10316. isSuccess = ConfigurationStatus_Rejected;
  10317. }
  10318. }
  10319. #endif
  10320. #if 1
  10321. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10322. {
  10323. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10324. {
  10325. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10326. isSuccess = ConfigurationStatus_Accepted;
  10327. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10328. }
  10329. else
  10330. {
  10331. isSuccess = ConfigurationStatus_Rejected;
  10332. }
  10333. }
  10334. #endif
  10335. return isSuccess;
  10336. }
  10337. int updateSetting(char *key, char *value)
  10338. {
  10339. mtrace();
  10340. int isSuccess = FALSE;
  10341. char string[1000]={0}, buffer[1000]={0};
  10342. char strtemp[50]={0};
  10343. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10344. int pos, c = 0;
  10345. char *loc;
  10346. int pos1=0;
  10347. FILE *f = fopen("/var/www/settings1", "r");
  10348. if(f == NULL)
  10349. {
  10350. #ifdef Debug
  10351. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10352. #endif
  10353. return isSuccess;
  10354. }
  10355. fseek(f, 0, SEEK_END);
  10356. long fsize = ftell(f);
  10357. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10358. fread(string, 1, fsize, f);
  10359. fclose(f);
  10360. string[fsize] = 0;
  10361. loc = strstr(string, key);
  10362. if(loc != NULL)
  10363. {
  10364. DEBUG_INFO("key exist!\n");
  10365. pos = loc - string-1;
  10366. f = fopen("/var/www/settings1", "w");
  10367. strncpy(buffer, string, pos);
  10368. fprintf(f, "%s", buffer);
  10369. memset(sstr ,0, sizeof(sstr) );
  10370. c = 0;
  10371. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10372. {
  10373. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10374. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10375. c++;
  10376. }
  10377. sstr[c] = '\0';
  10378. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10379. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10380. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10381. memset(buffer ,0, sizeof(buffer) );
  10382. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10383. //printf("buffer=%s",buffer);
  10384. fprintf(f, "%s", buffer);
  10385. fclose(f);
  10386. }
  10387. else
  10388. {
  10389. printf("key not exist!\n");
  10390. f = fopen("/var/www/settings1", "w+");
  10391. fputs(string, f);
  10392. fseek(f, -1, SEEK_CUR);
  10393. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10394. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10395. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10396. fclose(f);
  10397. }
  10398. isSuccess = TRUE;
  10399. return isSuccess;
  10400. }
  10401. int TransactionMessageAttemptsGet(void)
  10402. {
  10403. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10404. }
  10405. int FirstHeartBeatResponse(void)
  10406. {
  10407. return FirstHeartBeat;
  10408. }
  10409. int TransactionMessageRetryIntervalGet(void)
  10410. {
  10411. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10412. }
  10413. #define SA struct sockaddr
  10414. #define MAXBUF 1024
  10415. //static int m_socket_data;
  10416. //static int sockfd;
  10417. int ReadHttpStatus(int sock){
  10418. //char c;
  10419. char buff[1024]="",*ptr=buff+1;
  10420. int bytes_received, status;
  10421. DEBUG_INFO("Begin Response ..\n");
  10422. while((bytes_received = recv(sock, ptr, 1, 0))){
  10423. if(bytes_received==-1){
  10424. perror("ReadHttpStatus");
  10425. exit(1);
  10426. }
  10427. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10428. ptr++;
  10429. }
  10430. *ptr=0;
  10431. ptr=buff+1;
  10432. sscanf(ptr,"%*s %d ", &status);
  10433. DEBUG_INFO("%s\n",ptr);
  10434. DEBUG_INFO("status=%d\n",status);
  10435. DEBUG_INFO("End Response ..\n");
  10436. return (bytes_received>0)?status:0;
  10437. }
  10438. //the only filed that it parsed is 'Content-Length'
  10439. int ParseHeader(int sock){
  10440. //char c;
  10441. char buff[1024]="",*ptr=buff+4;
  10442. int bytes_received;
  10443. DEBUG_INFO("Begin HEADER ..\n");
  10444. while((bytes_received = recv(sock, ptr, 1, 0))){
  10445. if(bytes_received==-1){
  10446. perror("Parse Header");
  10447. exit(1);
  10448. }
  10449. if(
  10450. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10451. (ptr[-1]=='\r') && (*ptr=='\n' )
  10452. ) break;
  10453. ptr++;
  10454. }
  10455. *ptr=0;
  10456. ptr=buff+4;
  10457. //printf("%s",ptr);
  10458. if(bytes_received){
  10459. ptr=strstr(ptr,"Content-Length:");
  10460. if(ptr){
  10461. sscanf(ptr,"%*s %d",&bytes_received);
  10462. }else
  10463. bytes_received=-1; //unknown size
  10464. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10465. }
  10466. DEBUG_INFO("End HEADER ..\n");
  10467. return bytes_received ;
  10468. }
  10469. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10470. {
  10471. char rmFileCmd[100]={0};
  10472. char FilePath[100]={0};
  10473. char ftpbuf[200];
  10474. int systemresult;
  10475. DEBUG_INFO("filename=%s\n",filename);
  10476. DEBUG_INFO("url=%s\n",url);
  10477. sprintf(FilePath,"../mnt/%s",filename);
  10478. if((access(FilePath,F_OK))!=-1)
  10479. {
  10480. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10481. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10482. system(rmFileCmd);
  10483. }
  10484. memset(ftpbuf, 0, sizeof(ftpbuf));
  10485. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10486. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10487. systemresult = system(ftpbuf);
  10488. DEBUG_INFO("systemresult=%d\n",systemresult);
  10489. if(systemresult != 0)
  10490. {
  10491. DEBUG_INFO("http DownLoad error!\n");
  10492. return FALSE;
  10493. }
  10494. return TRUE;
  10495. }
  10496. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10497. {
  10498. char rmFileCmd[100]={0};
  10499. char FilePath[100]={0};
  10500. char ftpbuf[200];
  10501. int systemresult;
  10502. //char temp[100];
  10503. #if 0
  10504. struct hostent* server;
  10505. char *IPbuffer;
  10506. server = gethostbyname(location);
  10507. // To convert an Internet network
  10508. // address into ASCII string
  10509. IPbuffer = inet_ntoa(*((struct in_addr*)
  10510. server->h_addr_list[0]));
  10511. #endif
  10512. sprintf(FilePath,"../mnt/%s",filename);
  10513. if((access(FilePath,F_OK))!=-1)
  10514. {
  10515. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10516. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10517. system(rmFileCmd);
  10518. }
  10519. memset(ftpbuf, 0, sizeof(ftpbuf));
  10520. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10521. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10522. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10523. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10524. systemresult = system(ftpbuf);
  10525. DEBUG_INFO("systemresult=%d\n",systemresult);
  10526. if(systemresult != 0)
  10527. {
  10528. printf("ftpget error!\n");
  10529. return FALSE;
  10530. }
  10531. return TRUE;
  10532. }
  10533. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10534. {
  10535. struct hostent* server;
  10536. char *IPbuffer;
  10537. char ftpbuf[200];
  10538. int systemresult;
  10539. // To retrieve host information
  10540. server = gethostbyname(location);
  10541. // To convert an Internet network
  10542. // address into ASCII string
  10543. IPbuffer = inet_ntoa(*((struct in_addr*)
  10544. server->h_addr_list[0]));
  10545. memset(ftpbuf, 0, sizeof(ftpbuf));
  10546. /* format : ftpput -u username -p passwd IP target source*/
  10547. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10548. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10549. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10550. systemresult = system(ftpbuf);
  10551. DEBUG_INFO("systemresult=%d\n",systemresult);
  10552. if(systemresult != 0)
  10553. {
  10554. DEBUG_INFO("ftpput error!\n");
  10555. return FALSE;
  10556. }
  10557. return TRUE;
  10558. }
  10559. int SettingChargingRecord(int target, int transactionId)
  10560. {
  10561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10562. {
  10563. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10564. {
  10565. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10566. {
  10567. addBuff(target, transactionId, 0);
  10568. return TRUE;
  10569. }
  10570. }
  10571. for (int index = 0; index < CCS_QUANTITY; index++)
  10572. {
  10573. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10574. {
  10575. addBuff(target, transactionId, 0);
  10576. return TRUE;
  10577. }
  10578. }
  10579. for (int index = 0; index < GB_QUANTITY; index++)
  10580. {
  10581. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10582. {
  10583. addBuff(target, transactionId, 0);
  10584. return TRUE;
  10585. }
  10586. }
  10587. }
  10588. else
  10589. {
  10590. for (int index = 0; index < AC_QUANTITY; index++)
  10591. {
  10592. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10593. {
  10594. addBuff(target, transactionId, 0);
  10595. return TRUE;
  10596. }
  10597. }
  10598. }
  10599. return FALSE;
  10600. }
  10601. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10602. {
  10603. int isSuccess = FALSE;
  10604. //char *query = NULL;
  10605. sqlite3_stmt *stmt;
  10606. int rc; // return code
  10607. char str[20];
  10608. sprintf(str,"%d",user_id);
  10609. 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 */
  10610. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10611. rc = sqlite3_step(stmt); /* 3 */
  10612. if (rc != SQLITE_DONE) {
  10613. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10614. goto out;
  10615. }
  10616. sqlite3_finalize(stmt);
  10617. // free(query);
  10618. out:
  10619. //----------------------
  10620. // close SQLite database
  10621. //----------------------
  10622. sqlite3_close(db);
  10623. printf("database closed.\n");
  10624. return isSuccess;
  10625. }
  10626. /**
  10627. * Place the contents of the specified file into a memory buffer
  10628. *
  10629. * @param[in] filename The path and name of the file to read
  10630. * @param[out] filebuffer A pointer to the contents in memory
  10631. * @return status 0 success, 1 on failure
  10632. */
  10633. int get_file_contents(const char* filename, char** outbuffer) {
  10634. FILE* file = NULL;
  10635. long filesize;
  10636. const int blocksize = 1;
  10637. size_t readsize;
  10638. char* filebuffer;
  10639. // Open the file
  10640. file = fopen(filename, "r");
  10641. if (NULL == file)
  10642. {
  10643. printf("'%s' not opened\n", filename);
  10644. exit(EXIT_FAILURE);
  10645. }
  10646. // Determine the file size
  10647. fseek(file, 0, SEEK_END);
  10648. filesize = ftell(file);
  10649. rewind (file);
  10650. // Allocate memory for the file contents
  10651. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10652. *outbuffer = filebuffer;
  10653. if (filebuffer == NULL)
  10654. {
  10655. fputs ("malloc out-of-memory", stderr);
  10656. exit(EXIT_FAILURE);
  10657. }
  10658. // Read in the file
  10659. readsize = fread(filebuffer, blocksize, filesize, file);
  10660. if (readsize != filesize)
  10661. {
  10662. fputs ("didn't read file completely",stderr);
  10663. exit(EXIT_FAILURE);
  10664. }
  10665. // Clean exit
  10666. fclose(file);
  10667. return EXIT_SUCCESS;
  10668. }
  10669. static int selectSqlCount = 0;
  10670. static int callback(void *data, int argc, char **argv, char **azColName){
  10671. int i;
  10672. printf("%s: ", (const char*)data);
  10673. selectSqlCount = argc;
  10674. for(i = 0; i<argc; i++){
  10675. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10676. }
  10677. printf("\n");
  10678. return 0;
  10679. }
  10680. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10681. //int i;
  10682. //printf("%s:\n", (const char*)data);
  10683. localversion = argv[5] ? atoi(argv[5]) : 0;
  10684. printf("localversion=%d\n", localversion);
  10685. return 0;
  10686. }
  10687. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10688. //int i;
  10689. //printf("%s:\n", (const char*)data);
  10690. //idTag
  10691. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10692. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10693. //parentIdTag
  10694. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10695. //expir_date
  10696. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10697. //status
  10698. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10699. //version
  10700. idTagQuery.listVersionInt = atoi(argv[5]);
  10701. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10702. return 0;
  10703. }
  10704. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10705. int i;
  10706. //printf("%s:\n", (const char*)data);
  10707. #if 1
  10708. for(i=0; i<argc; i++){
  10709. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10710. }
  10711. //printf("");
  10712. #endif
  10713. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10714. // printf("localversion=%d\n", localversion);
  10715. return 0;
  10716. }
  10717. /** sqlite3_exec的回调。
  10718. *
  10719. * 向控制台打印查询的结果。
  10720. *
  10721. * @param in data 传递给回调函数的数据。
  10722. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10723. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10724. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10725. * @return 状态码。
  10726. */
  10727. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10728. {
  10729. for (int i = 0; i < n_columns; i++)
  10730. {
  10731. DEBUG_INFO("%s/t", col_values[i]);
  10732. }
  10733. DEBUG_INFO("/n");
  10734. return 0;
  10735. }
  10736. void OCPP_getListVerion()
  10737. {
  10738. int rc = 0;
  10739. // const char* data = "Callback function called";
  10740. char sql[100];
  10741. char zErrMsg[100];
  10742. memset(sql, 0, 100);
  10743. memset(zErrMsg, 0, 100);
  10744. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10745. /* Execute SQL statement */
  10746. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10747. DEBUG_INFO("rc=%d\n",rc);
  10748. if( rc != SQLITE_OK ){
  10749. DEBUG_INFO("SQL error: %s", zErrMsg);
  10750. //sqlite3_free(zErrMsg);
  10751. }else{
  10752. DEBUG_INFO("Operation done successfully");
  10753. }
  10754. }
  10755. void OCPP_getIdTag(char *idTag)
  10756. {
  10757. int rc = 0;
  10758. // const char* data = "Callback function called";
  10759. char sql[100];
  10760. char zErrMsg[100];
  10761. memset(sql, 0, 100);
  10762. memset(zErrMsg, 0, 100);
  10763. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10764. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10765. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10766. /* Execute SQL statement */
  10767. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10768. if( rc != SQLITE_OK ){
  10769. DEBUG_INFO("SQL error: %s", zErrMsg);
  10770. //sqlite3_free(zErrMsg);
  10771. }else{
  10772. printf("Operation done successfully");
  10773. }
  10774. //return ver;
  10775. }
  10776. void OCPP_get_TableAuthlocalAllData(void)
  10777. {
  10778. int rc = 0;
  10779. // const char* data = "Callback function called";
  10780. char sql[100];
  10781. char zErrMsg[100];
  10782. memset(sql, 0, 100);
  10783. memset(zErrMsg, 0, 100);
  10784. sprintf(sql,"select * from ocpp_auth_local ");
  10785. /* Execute SQL statement */
  10786. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10787. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10788. if( rc != SQLITE_OK ){
  10789. DEBUG_INFO("SQL error: %s", zErrMsg);
  10790. //sqlite3_free(zErrMsg);
  10791. }else{
  10792. DEBUG_INFO("Operation done successfully");
  10793. }
  10794. //return ver;
  10795. }
  10796. int OCPP_cleanLocalList()
  10797. {
  10798. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10799. char *errMsg = 0;
  10800. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10801. if (SQLITE_OK != rc)
  10802. {
  10803. DEBUG_INFO("%s\n",errMsg);
  10804. return FALSE;
  10805. }
  10806. else
  10807. {
  10808. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10809. }
  10810. return TRUE;
  10811. }
  10812. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10813. {
  10814. int isSuccess = FALSE;
  10815. int ret = 0;
  10816. //const char* data = "Callback function called";
  10817. char sql[200];
  10818. char zErrMsg[100];
  10819. memset(sql, 0, 200);
  10820. memset(zErrMsg, 0, 100);
  10821. 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);
  10822. //* Execute SQL statement */
  10823. //zErrMsg = 0;
  10824. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10825. if( ret != SQLITE_OK ){
  10826. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10827. // free(zErrMsg);
  10828. // free(sql);
  10829. return isSuccess;
  10830. }
  10831. DEBUG_INFO("successfully Insert records created\n");
  10832. isSuccess = TRUE;
  10833. return isSuccess;
  10834. }
  10835. void OCPP_deleteIdTag(char *idTag)
  10836. {
  10837. //int ver = 0;
  10838. //int isSuccess = FALSE;
  10839. int rc = 0;
  10840. char sql[100];
  10841. char zErrMsg[100];
  10842. memset(sql, 0, 100);
  10843. memset(zErrMsg, 0, 100);
  10844. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10845. //* Execute SQL statement */
  10846. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10847. if( rc != SQLITE_OK ){
  10848. DEBUG_INFO("SQL error: %s", zErrMsg);
  10849. //sqlite3_free(zErrMsg);
  10850. }else{
  10851. DEBUG_INFO("Operation done successfully");
  10852. }
  10853. }
  10854. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10855. {
  10856. int isSuccess = FALSE;
  10857. int ret = 0;
  10858. const char* data = "Callback function called";
  10859. char sql[200];
  10860. char zErrMsg[100];
  10861. memset(sql, 0, 200);
  10862. memset(zErrMsg, 0, 100);
  10863. //* selectFromTable */
  10864. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10865. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10866. //* Execute SQL statement */
  10867. selectSqlCount = 0;
  10868. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10869. if( ret != SQLITE_OK ){
  10870. printf("Error SQL: %s\n", zErrMsg);
  10871. }
  10872. printf("successfully select operation done\n");
  10873. memset(sql, 0, 200);
  10874. memset(zErrMsg, 0, 100);
  10875. if(selectSqlCount == 0)
  10876. {
  10877. //Insert
  10878. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  10879. 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);
  10880. DEBUG_INFO("sql:%s\n", sql);
  10881. //* Execute SQL statement */
  10882. //zErrMsg = 0;
  10883. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10884. if( ret != SQLITE_OK ){
  10885. printf("SQL error: %s\n", zErrMsg);
  10886. return isSuccess;
  10887. }
  10888. DEBUG_INFO("successfully Insert records created\n");
  10889. isSuccess = TRUE;
  10890. }
  10891. else
  10892. {
  10893. //Update
  10894. //* Create merged SQL statement */
  10895. 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);
  10896. /* Execute SQL statement */
  10897. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10898. if( ret != SQLITE_OK ){
  10899. printf("SQL error: %s\n", zErrMsg);
  10900. //sqlite3_free(zErrMsg);
  10901. //sqlite3_free(sql);
  10902. return isSuccess;
  10903. }
  10904. DEBUG_INFO("Successfully operation done \n");
  10905. isSuccess = TRUE;
  10906. }
  10907. return isSuccess;
  10908. }
  10909. char *GetOcppServerURL()
  10910. {
  10911. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10912. memset(OcppHost, 0, sizeof(OcppHost));
  10913. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10914. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  10915. {
  10916. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  10917. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  10918. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10919. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10920. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10921. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10922. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10923. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10924. goto End;
  10925. }
  10926. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  10927. {
  10928. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  10929. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10930. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10931. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10932. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10933. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10934. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10935. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10936. goto End;
  10937. }
  10938. else
  10939. {
  10940. strcpy(OcppHost,"");
  10941. }
  10942. End:
  10943. return OcppHost;
  10944. }
  10945. char *GetOcppPath()
  10946. {
  10947. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  10948. {
  10949. if(OcppTempPath == NULL)
  10950. {
  10951. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10952. }
  10953. else
  10954. {
  10955. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10956. }
  10957. goto End;
  10958. }
  10959. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  10960. {
  10961. if(OcppTempPath == NULL)
  10962. {
  10963. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10964. }
  10965. else
  10966. {
  10967. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10968. }
  10969. goto End;
  10970. }
  10971. else
  10972. {
  10973. strcpy(OcppHost,"");
  10974. }
  10975. End:
  10976. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10977. return OcppPath;
  10978. }
  10979. int GetOcppPort()
  10980. {
  10981. return OcppPort;
  10982. }
  10983. int GetOcppConnStatus(void)
  10984. {
  10985. return ShmOCPP16Data->OcppConnStatus;
  10986. }
  10987. void SetOcppConnStatus(uint8_t status)
  10988. {
  10989. ShmOCPP16Data->OcppConnStatus = status;
  10990. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  10991. if(status == FALSE)
  10992. {
  10993. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10994. {
  10995. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  10996. }
  10997. else
  10998. {
  10999. SystemInitial = AC_QUANTITY;
  11000. }
  11001. }
  11002. }
  11003. int GetHeartBeatWithNOResponse(void)
  11004. {
  11005. return HeartBeatWithNOResponse;
  11006. }
  11007. void SetHeartBeatWithNOResponse(void)
  11008. {
  11009. HeartBeatWithNOResponse = 0;
  11010. }
  11011. int InternetDisconnect(void)
  11012. {
  11013. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  11014. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  11015. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  11016. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  11017. }
  11018. void GetChargingProfileRequest(int gunindex)
  11019. {
  11020. mtrace();
  11021. //int connectorIdInt, durationInt;
  11022. //char chargingRateUnitStr[4]={0};
  11023. int tempdurationInt = 0;
  11024. int tempchargingProfileId = 0;
  11025. int tempstackLevel = 0;
  11026. int temptransactionId = 0;
  11027. float tempminChargingRateFloat = 0.0;
  11028. char tempchargingProfilePurposeStr[24]={0};
  11029. char tempchargingProfileKindStr[12]={0};
  11030. char temprecurrencyKindStr[8]={0};
  11031. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  11032. char tempvalidToStr[28]={0};
  11033. int tempStartPeriodInt = 0;
  11034. float tempLimitInt = 0.0;//0.1;
  11035. int tempNumberPhasesInt=0;
  11036. char fname[200];
  11037. //char comfirmstr[20];
  11038. float MinChargingRate =0.0;
  11039. double diff_t;
  11040. struct tm tp;
  11041. FILE *fptr1;//, *fptr2;
  11042. int c = 0;
  11043. char * pch;
  11044. char *loc;
  11045. char sstr[200]={ 0 };
  11046. int n_chargingProfile = 0;
  11047. int n_SchedulePeriods = 0;
  11048. char SchedulePeriodList[10][200]={0};
  11049. char sLineWord[800]={0};
  11050. char word[1000]={0};
  11051. int confirmPeriods = 0;
  11052. struct StructProfile ChargePointMaxProfile;
  11053. struct StructProfile TxDefaultProfile;
  11054. struct StructProfile TxProfile;
  11055. struct StructProfile TxDefaultProfiletemp[2]={0};
  11056. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  11057. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  11058. struct StructChargingProfile TxProfile_TEMP={0};
  11059. int TxDefaultProfileFileIsNull=FALSE;
  11060. int ChargePointMaxProfileIsNull=FALSE;
  11061. int TxProfileIsNull=FALSE;
  11062. // int CompositeSceduleIndex = 0;
  11063. char ChargePointMaxProfileScheduleStr[30]={0};
  11064. char TxDefaultProfileScheduleStr[30]={0};
  11065. char TxProfileScheduleStr[30]={0};
  11066. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  11067. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  11068. memset(&TxProfile,0,sizeof(struct StructProfile));
  11069. DEBUG_INFO("GetChargingProfileRequest\n");
  11070. //*****************************ChargePointMaxProfile******************************************/
  11071. strcpy(fname, ChargePointMaxProfile_JSON);
  11072. ChargePointMaxProfileIsNull=TRUE;
  11073. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  11074. {
  11075. fptr1 = fopen(fname, "r");
  11076. int c;
  11077. c = fgetc(fptr1);
  11078. //DEBUG_INFO("c:%d\n",c);
  11079. rewind(fptr1);
  11080. if(c == EOF)
  11081. {
  11082. DEBUG_INFO("\n End of file reached.");
  11083. ChargePointMaxProfileIsNull=TRUE;
  11084. fclose(fptr1);
  11085. }
  11086. else
  11087. {
  11088. ChargePointMaxProfileIsNull=FALSE;
  11089. while(fscanf(fptr1, "%s", word) != EOF)
  11090. {
  11091. if(strcmp(word, "chargingProfileId") == 0)
  11092. {
  11093. n_chargingProfile = n_chargingProfile + 1;
  11094. }
  11095. }
  11096. rewind(fptr1);
  11097. //search Charging Profile Element
  11098. int i = 0;
  11099. int j = 0;
  11100. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11101. //***********chargingProfileId**************/
  11102. c = 0;
  11103. loc = strstr(sLineWord, "chargingProfileId");
  11104. //DEBUG_INFO("loc=%s\n",loc);
  11105. memset(sstr ,0, sizeof(sstr) );
  11106. if(loc != NULL)
  11107. {
  11108. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11109. {
  11110. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11111. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11112. c++;
  11113. }
  11114. sstr[c] = '\0';
  11115. tempchargingProfileId = atoi(sstr);
  11116. }
  11117. else
  11118. {
  11119. tempchargingProfileId = 0;
  11120. }
  11121. //***********stackLevel**************/
  11122. c = 0;
  11123. loc = strstr(sLineWord, "stackLevel");
  11124. //DEBUG_INFO("loc=%s\n",loc);
  11125. memset(sstr ,0, sizeof(sstr) );
  11126. if(loc != NULL)
  11127. {
  11128. while (loc[2+strlen("stackLevel")+c] != '\"')
  11129. {
  11130. sstr[c] = loc[2+strlen("stackLevel")+c];
  11131. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11132. c++;
  11133. }
  11134. sstr[c] = '\0';
  11135. tempstackLevel = atoi(sstr);
  11136. }
  11137. else
  11138. {
  11139. tempstackLevel = 0;
  11140. }
  11141. //***********chargingProfilePurpose **************/
  11142. c = 0;
  11143. loc = strstr(sLineWord, "chargingProfilePurpose");
  11144. //DEBUG_INFO("loc=%s\n",loc);
  11145. memset(sstr ,0, sizeof(sstr) );
  11146. if(loc != NULL)
  11147. {
  11148. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11149. {
  11150. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11151. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11152. c++;
  11153. }
  11154. sstr[c] = '\0';
  11155. strcpy(tempchargingProfilePurposeStr,sstr);
  11156. }
  11157. else
  11158. {
  11159. strcpy(tempchargingProfilePurposeStr,"");
  11160. }
  11161. //***********chargingProfileKind **************/
  11162. c = 0;
  11163. loc = strstr(sLineWord, "chargingProfileKind");
  11164. //DEBUG_INFO("loc=%s\n",loc);
  11165. memset(sstr ,0, sizeof(sstr) );
  11166. if(loc != NULL)
  11167. {
  11168. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11169. {
  11170. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11171. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11172. c++;
  11173. }
  11174. sstr[c] = '\0';
  11175. strcpy(tempchargingProfileKindStr,sstr);
  11176. }
  11177. else
  11178. {
  11179. strcpy(tempchargingProfileKindStr,"");
  11180. }
  11181. //***********recurrencyKind **************/
  11182. c = 0;
  11183. loc = strstr(sLineWord, "recurrencyKind");
  11184. //DEBUG_INFO("loc=%s\n",loc);
  11185. memset(sstr ,0, sizeof(sstr) );
  11186. if(loc != NULL)
  11187. {
  11188. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11189. {
  11190. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11191. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11192. c++;
  11193. }
  11194. sstr[c] = '\0';
  11195. strcpy(temprecurrencyKindStr,sstr);
  11196. }
  11197. else
  11198. {
  11199. strcpy(temprecurrencyKindStr,"");
  11200. }
  11201. //***********validFrom**************/
  11202. c = 0;
  11203. loc = strstr(sLineWord, "validFrom");
  11204. //DEBUG_INFO("loc=%s\n",loc);
  11205. memset(sstr ,0, sizeof(sstr) );
  11206. if(loc != NULL)
  11207. {
  11208. while (loc[3+strlen("validFrom")+c] != '\"')
  11209. {
  11210. sstr[c] = loc[3+strlen("validFrom")+c];
  11211. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11212. c++;
  11213. }
  11214. sstr[c] = '\0';
  11215. strcpy(tempvalidFromStr,sstr);
  11216. }
  11217. else
  11218. {
  11219. strcpy(tempvalidFromStr,"");
  11220. }
  11221. //***********validTo **************/
  11222. c = 0;
  11223. loc = strstr(sLineWord, "validTo");
  11224. //DEBUG_INFO("loc=%s\n",loc);
  11225. memset(sstr ,0, sizeof(sstr) );
  11226. if(loc != NULL)
  11227. {
  11228. while (loc[3+strlen("validTo")+c] != '\"')
  11229. {
  11230. sstr[c] = loc[3+strlen("validTo")+c];
  11231. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11232. c++;
  11233. }
  11234. sstr[c] = '\0';
  11235. strcpy(tempvalidToStr,sstr);
  11236. }
  11237. else
  11238. {
  11239. strcpy(tempvalidToStr,"");
  11240. }
  11241. //***********validFrom**************/
  11242. c = 0;
  11243. loc = strstr(sLineWord, "validFrom");
  11244. if(loc != NULL)
  11245. {
  11246. memset(sstr ,0, sizeof(sstr) );
  11247. while (loc[3+strlen("validFrom")+c] != '\"')
  11248. {
  11249. sstr[c] = loc[3+strlen("validFrom")+c];
  11250. c++;
  11251. }
  11252. sstr[c] = '\0';
  11253. strcpy(tempvalidFromStr,sstr);
  11254. }
  11255. else
  11256. {
  11257. strcpy(tempvalidFromStr,"");
  11258. }
  11259. //***********duration**************/
  11260. c = 0;
  11261. loc = strstr(sLineWord, "duration");
  11262. if(loc != NULL)
  11263. {
  11264. memset(sstr ,0, sizeof(sstr) );
  11265. while (loc[2+strlen("duration")+c] != ',')
  11266. {
  11267. sstr[c] = loc[2+strlen("duration")+c];
  11268. c++;
  11269. }
  11270. sstr[c] = '\0';
  11271. tempdurationInt = atoi(sstr);
  11272. }
  11273. else
  11274. {
  11275. tempdurationInt = 0;
  11276. }
  11277. //**********startSchedule**********/
  11278. c = 0;
  11279. loc = strstr(sLineWord, "startSchedule");
  11280. memset(sstr ,0, sizeof(sstr) );
  11281. while (loc[3+strlen("startSchedule")+c] != '\"')
  11282. {
  11283. sstr[c] = loc[3+strlen("startSchedule")+c];
  11284. c++;
  11285. }
  11286. sstr[c] = '\0';
  11287. strcpy(tempstartScheduleStr, sstr);
  11288. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  11289. //**********chargingRateUnit**********/
  11290. c = 0;
  11291. loc = strstr(sLineWord, "chargingRateUnit");
  11292. memset(sstr ,0, sizeof(sstr) );
  11293. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  11294. {
  11295. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  11296. c++;
  11297. }
  11298. sstr[c] = '\0';
  11299. strcpy(tempchargingRateUnitStr, sstr);
  11300. //**********minChargingRate*******/
  11301. c = 0;
  11302. loc = strstr(sLineWord, "minChargingRate");
  11303. if(loc != NULL)
  11304. {
  11305. memset(sstr ,0, sizeof(sstr) );
  11306. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  11307. {
  11308. sstr[c] = loc[2+strlen("minChargingRate")+c];
  11309. c++;
  11310. }
  11311. sstr[c] = '\0';
  11312. tempminChargingRateFloat = atof(sstr);
  11313. }
  11314. else
  11315. {
  11316. tempminChargingRateFloat = 0.0;
  11317. }
  11318. //
  11319. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  11320. tp.tm_isdst = -1;
  11321. time_t utc = mktime(&tp);
  11322. time_t t = time(NULL);
  11323. diff_t = difftime(t, utc);
  11324. //DEBUG_INFO("diff_t=%f\n",diff_t);
  11325. //parsing strings to words
  11326. i = 0;
  11327. loc = strstr(sLineWord, "chargingSchedulePeriod");
  11328. loc = loc+3+strlen("chargingSchedulePeriod");
  11329. pch = strtok(loc ,"{");
  11330. while (pch != NULL)
  11331. {
  11332. strcpy(SchedulePeriodList[i], pch);
  11333. pch = strtok (NULL, "{");
  11334. i = i + 1;
  11335. }
  11336. n_SchedulePeriods = i;
  11337. for(int i=0;i<n_SchedulePeriods;i++)
  11338. {
  11339. //*************startPeriod****************/
  11340. c = 0;
  11341. loc = strstr(SchedulePeriodList[i], "startPeriod");
  11342. memset(sstr ,0, sizeof(sstr) );
  11343. while (loc[strlen("startPeriod")+2+c] != ',')
  11344. {
  11345. sstr[c] = loc[strlen("startPeriod")+2+c];
  11346. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11347. c++;
  11348. }
  11349. sstr[c] = '\0';
  11350. tempStartPeriodInt = atoi(sstr);
  11351. //*************limit****************/
  11352. c = 0;
  11353. loc = strstr(SchedulePeriodList[i], "limit");
  11354. memset(sstr ,0, sizeof(sstr) );
  11355. while (loc[strlen("limit")+2+c] != ',')
  11356. {
  11357. sstr[c] = loc[strlen("limit")+2+c];
  11358. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11359. c++;
  11360. }
  11361. sstr[c] = '\0';
  11362. tempLimitInt = atof(sstr);
  11363. //*************numberPhases****************/
  11364. c = 0;
  11365. loc = strstr(SchedulePeriodList[i], "numberPhases");
  11366. memset(sstr ,0, sizeof(sstr) );
  11367. while (loc[strlen("numberPhases")+2+c] != '}')
  11368. {
  11369. sstr[c] = loc[strlen("numberPhases")+2+c];
  11370. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11371. c++;
  11372. }
  11373. sstr[c] = '\0';
  11374. tempNumberPhasesInt = atoi(sstr);
  11375. if(j == 0)
  11376. {
  11377. ChargePointMaxProfile.Duration = tempdurationInt;
  11378. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  11379. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  11380. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  11381. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  11382. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  11383. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  11384. ChargePointMaxProfile_TEMP.TransactionId = 0;
  11385. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  11386. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  11387. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  11388. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  11389. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  11390. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  11391. }
  11392. }
  11393. if(MinChargingRate < tempminChargingRateFloat)
  11394. {
  11395. MinChargingRate = tempminChargingRateFloat;
  11396. }
  11397. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  11398. if(confirmPeriods < n_SchedulePeriods)
  11399. {
  11400. confirmPeriods = n_SchedulePeriods;
  11401. }
  11402. j = j + 1;
  11403. }
  11404. fclose(fptr1);
  11405. }
  11406. }// the end of access file ChargePointMaxProfile
  11407. //****************************TxDefaultProfile************************************************/
  11408. switch(gunindex + 1)
  11409. {
  11410. case 0:
  11411. break;
  11412. case 1:
  11413. strcpy(fname, TxDefaultProfile_1_JSON );
  11414. break;
  11415. case 2:
  11416. strcpy(fname, TxDefaultProfile_2_JSON );
  11417. break;
  11418. default:
  11419. strcpy(fname, TxDefaultProfile_1_JSON );
  11420. break;
  11421. }
  11422. TxDefaultProfileFileIsNull=TRUE;
  11423. if((access(fname,F_OK))!=-1)
  11424. {
  11425. fptr1 = fopen(fname, "r");
  11426. c = 0;
  11427. c = fgetc(fptr1);
  11428. //DEBUG_INFO("c:%d\n",c);
  11429. rewind(fptr1);
  11430. if(c == EOF)
  11431. {
  11432. DEBUG_INFO("\n End of file reached.");
  11433. TxDefaultProfileFileIsNull=TRUE;
  11434. fclose(fptr1);
  11435. }
  11436. else
  11437. {
  11438. TxDefaultProfileFileIsNull=FALSE;
  11439. while(fscanf(fptr1, "%s", word) != EOF)
  11440. {
  11441. if(strcmp(word, "chargingProfileId") == 0)
  11442. {
  11443. n_chargingProfile = n_chargingProfile + 1;
  11444. }
  11445. }
  11446. rewind(fptr1);
  11447. //search Charging Profile Element
  11448. int i = 0;
  11449. int j = 0;
  11450. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11451. #if 0
  11452. /***********connectorId****************/
  11453. c = 0;
  11454. loc = strstr(sLineWord, "connectorId");
  11455. memset(sstr ,0, sizeof(sstr) );
  11456. while (loc[strlen("connectorId")+2+c] != ',')
  11457. {
  11458. sstr[c] = loc[strlen("connectorId")+2+c];
  11459. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11460. c++;
  11461. }
  11462. sstr[c] = '\0';
  11463. tempconnectorIdInt = atoi(sstr);
  11464. #endif
  11465. //***********chargingProfileId**************/
  11466. c = 0;
  11467. loc = strstr(sLineWord, "chargingProfileId");
  11468. //DEBUG_INFO("loc=%s\n",loc);
  11469. memset(sstr ,0, sizeof(sstr) );
  11470. if(loc != NULL)
  11471. {
  11472. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11473. {
  11474. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11475. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11476. c++;
  11477. }
  11478. sstr[c] = '\0';
  11479. tempchargingProfileId = atoi(sstr);
  11480. }
  11481. else
  11482. {
  11483. tempchargingProfileId = 0;
  11484. }
  11485. //***********stackLevel**************/
  11486. c = 0;
  11487. loc = strstr(sLineWord, "stackLevel");
  11488. //DEBUG_INFO("loc=%s\n",loc);
  11489. memset(sstr ,0, sizeof(sstr) );
  11490. if(loc != NULL)
  11491. {
  11492. while (loc[2+strlen("stackLevel")+c] != '\"')
  11493. {
  11494. sstr[c] = loc[2+strlen("stackLevel")+c];
  11495. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11496. c++;
  11497. }
  11498. sstr[c] = '\0';
  11499. tempstackLevel = atoi(sstr);
  11500. }
  11501. else
  11502. {
  11503. tempstackLevel = 0;
  11504. }
  11505. //***********chargingProfilePurpose **************/
  11506. c = 0;
  11507. loc = strstr(sLineWord, "chargingProfilePurpose");
  11508. //DEBUG_INFO("loc=%s\n",loc);
  11509. memset(sstr ,0, sizeof(sstr) );
  11510. if(loc != NULL)
  11511. {
  11512. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11513. {
  11514. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11515. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11516. c++;
  11517. }
  11518. sstr[c] = '\0';
  11519. strcpy(tempchargingProfilePurposeStr,sstr);
  11520. }
  11521. else
  11522. {
  11523. strcpy(tempchargingProfilePurposeStr,"");
  11524. }
  11525. //***********chargingProfileKind **************/
  11526. c = 0;
  11527. loc = strstr(sLineWord, "chargingProfileKind");
  11528. //DEBUG_INFO("loc=%s\n",loc);
  11529. memset(sstr ,0, sizeof(sstr) );
  11530. if(loc != NULL)
  11531. {
  11532. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11533. {
  11534. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11535. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11536. c++;
  11537. }
  11538. sstr[c] = '\0';
  11539. strcpy(tempchargingProfileKindStr,sstr);
  11540. }
  11541. else
  11542. {
  11543. strcpy(tempchargingProfileKindStr,"");
  11544. }
  11545. //***********recurrencyKind **************/
  11546. c = 0;
  11547. loc = strstr(sLineWord, "recurrencyKind");
  11548. //DEBUG_INFO("loc=%s\n",loc);
  11549. memset(sstr ,0, sizeof(sstr) );
  11550. if(loc != NULL)
  11551. {
  11552. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11553. {
  11554. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11555. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11556. c++;
  11557. }
  11558. sstr[c] = '\0';
  11559. strcpy(temprecurrencyKindStr,sstr);
  11560. }
  11561. else
  11562. {
  11563. strcpy(temprecurrencyKindStr,"");
  11564. }
  11565. //***********validFrom**************/
  11566. c = 0;
  11567. loc = strstr(sLineWord, "validFrom");
  11568. if(loc != NULL)
  11569. {
  11570. memset(sstr ,0, sizeof(sstr) );
  11571. while (loc[3+strlen("validFrom")+c] != '\"')
  11572. {
  11573. sstr[c] = loc[3+strlen("validFrom")+c];
  11574. c++;
  11575. }
  11576. sstr[c] = '\0';
  11577. strcpy(tempvalidFromStr,sstr);
  11578. }
  11579. else
  11580. {
  11581. strcpy(tempvalidFromStr,"");
  11582. }
  11583. //***********validFrom**************/
  11584. c = 0;
  11585. loc = strstr(sLineWord, "duration");
  11586. if(loc != NULL)
  11587. {
  11588. memset(sstr ,0, sizeof(sstr) );
  11589. while (loc[2+strlen("duration")+c] != ',')
  11590. {
  11591. sstr[c] = loc[2+strlen("duration")+c];
  11592. c++;
  11593. }
  11594. sstr[c] = '\0';
  11595. tempdurationInt = atoi(sstr);
  11596. }
  11597. else
  11598. {
  11599. tempdurationInt = 0;
  11600. }
  11601. //**********startSchedule**********/
  11602. c = 0;
  11603. loc = strstr(sLineWord, "startSchedule");
  11604. memset(sstr ,0, sizeof(sstr) );
  11605. while (loc[3+strlen("startSchedule")+c] != '\"')
  11606. {
  11607. sstr[c] = loc[3+strlen("startSchedule")+c];
  11608. c++;
  11609. }
  11610. sstr[c] = '\0';
  11611. strcpy(tempstartScheduleStr, sstr);
  11612. strcpy(TxDefaultProfileScheduleStr, sstr);
  11613. //**********chargingRateUnit**********/
  11614. c = 0;
  11615. loc = strstr(sLineWord, "chargingRateUnit");
  11616. memset(sstr ,0, sizeof(sstr) );
  11617. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  11618. {
  11619. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  11620. c++;
  11621. }
  11622. sstr[c] = '\0';
  11623. strcpy(tempchargingRateUnitStr, sstr);
  11624. //**********minChargingRate*******/
  11625. c = 0;
  11626. loc = strstr(sLineWord, "minChargingRate");
  11627. if(loc != NULL)
  11628. {
  11629. memset(sstr ,0, sizeof(sstr) );
  11630. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  11631. {
  11632. sstr[c] = loc[2+strlen("minChargingRate")+c];
  11633. c++;
  11634. }
  11635. sstr[c] = '\0';
  11636. tempminChargingRateFloat = atof(sstr);
  11637. }
  11638. else
  11639. {
  11640. tempminChargingRateFloat = 0.0;
  11641. }
  11642. //
  11643. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  11644. tp.tm_isdst = -1;
  11645. time_t utc = mktime(&tp);
  11646. time_t t = time(NULL);
  11647. diff_t = difftime(t, utc);
  11648. printf("diff between startScheduleStr and now =%f\n",diff_t);
  11649. //parsing strings to words
  11650. i = 0;
  11651. loc = strstr(sLineWord, "chargingSchedulePeriod");
  11652. loc = loc+3+strlen("chargingSchedulePeriod");
  11653. pch = strtok(loc ,"{");
  11654. while (pch != NULL)
  11655. {
  11656. strcpy(SchedulePeriodList[i], pch);
  11657. pch = strtok (NULL, "{");
  11658. i = i + 1;
  11659. }
  11660. n_SchedulePeriods = i;
  11661. for(int i=0;i<n_SchedulePeriods;i++)
  11662. {
  11663. //*************startPeriod****************/
  11664. c = 0;
  11665. loc = strstr(SchedulePeriodList[i], "startPeriod");
  11666. memset(sstr ,0, sizeof(sstr) );
  11667. while (loc[strlen("startPeriod")+2+c] != ',')
  11668. {
  11669. sstr[c] = loc[strlen("startPeriod")+2+c];
  11670. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11671. c++;
  11672. }
  11673. sstr[c] = '\0';
  11674. tempStartPeriodInt = atoi(sstr);
  11675. //*************limit****************/
  11676. c = 0;
  11677. loc = strstr(SchedulePeriodList[i], "limit");
  11678. memset(sstr ,0, sizeof(sstr) );
  11679. while (loc[strlen("limit")+2+c] != ',')
  11680. {
  11681. sstr[c] = loc[strlen("limit")+2+c];
  11682. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11683. c++;
  11684. }
  11685. sstr[c] = '\0';
  11686. tempLimitInt = atof(sstr);
  11687. //*************numberPhases****************/
  11688. c = 0;
  11689. loc = strstr(SchedulePeriodList[i], "numberPhases");
  11690. memset(sstr ,0, sizeof(sstr) );
  11691. while (loc[strlen("numberPhases")+2+c] != '}')
  11692. {
  11693. sstr[c] = loc[strlen("numberPhases")+2+c];
  11694. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11695. c++;
  11696. }
  11697. sstr[c] = '\0';
  11698. tempNumberPhasesInt = atoi(sstr);
  11699. if(j == 0)
  11700. {
  11701. TxDefaultProfile.Duration = tempdurationInt;
  11702. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  11703. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  11704. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  11705. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  11706. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  11707. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  11708. TxDefaultProfile_TEMP.TransactionId = 0;
  11709. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  11710. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  11711. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  11712. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  11713. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  11714. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  11715. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  11716. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  11717. }
  11718. else
  11719. {
  11720. //other stack level charging Profile
  11721. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  11722. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  11723. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  11724. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  11725. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  11726. }
  11727. }
  11728. if(MinChargingRate < tempminChargingRateFloat)
  11729. {
  11730. MinChargingRate = tempminChargingRateFloat;
  11731. }
  11732. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  11733. if(confirmPeriods < n_SchedulePeriods)
  11734. confirmPeriods = n_SchedulePeriods;
  11735. j = j + 1;
  11736. }
  11737. fclose(fptr1);
  11738. //Stacking Charging Profiles
  11739. for(int l=0; l <(j-1) ;l++)
  11740. {
  11741. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  11742. {
  11743. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  11744. {
  11745. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  11746. {
  11747. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  11748. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  11749. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  11750. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11751. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11752. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  11753. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  11754. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  11755. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11756. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11757. }
  11758. else
  11759. {
  11760. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  11761. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  11762. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  11763. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  11764. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  11765. }
  11766. }
  11767. }
  11768. }
  11769. //end of Stacking Charging Profiles
  11770. }
  11771. }// the end of ACCESS TxDefaultProfile
  11772. //****************************TxProfile************************************************/
  11773. switch(gunindex + 1)
  11774. {
  11775. case 0:
  11776. break;
  11777. case 1:
  11778. strcpy(fname, TxProfile_1_JSON );
  11779. break;
  11780. case 2:
  11781. strcpy(fname, TxProfile_2_JSON );
  11782. break;
  11783. default:
  11784. strcpy(fname, TxProfile_1_JSON );
  11785. break;
  11786. }
  11787. TxProfileIsNull=TRUE;
  11788. if((access(fname,F_OK))!=-1)
  11789. {
  11790. fptr1 = fopen(fname, "r");
  11791. c = 0;
  11792. c = fgetc(fptr1);
  11793. //DEBUG_INFO("c:%d\n",c);
  11794. rewind(fptr1);
  11795. if(c == EOF)
  11796. {
  11797. DEBUG_INFO("\n End of file reached.");
  11798. TxProfileIsNull=TRUE;
  11799. fclose(fptr1);
  11800. }
  11801. else
  11802. {
  11803. TxProfileIsNull=FALSE;
  11804. while(fscanf(fptr1, "%s", word) != EOF)
  11805. {
  11806. if(strcmp(word, "chargingProfileId") == 0)
  11807. {
  11808. n_chargingProfile = n_chargingProfile + 1;
  11809. }
  11810. }
  11811. rewind(fptr1);
  11812. //search Charging Profile Element
  11813. int i= 0;
  11814. int j= 0;
  11815. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  11816. #if 0
  11817. /***********connectorId****************/
  11818. c = 0;
  11819. loc = strstr(sLineWord, "connectorId");
  11820. memset(sstr ,0, sizeof(sstr) );
  11821. while (loc[strlen("connectorId")+2+c] != ',')
  11822. {
  11823. sstr[c] = loc[strlen("connectorId")+2+c];
  11824. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11825. c++;
  11826. }
  11827. sstr[c] = '\0';
  11828. tempconnectorIdInt = atoi(sstr);
  11829. #endif
  11830. //***********chargingProfileId**************/
  11831. c = 0;
  11832. loc = strstr(sLineWord, "chargingProfileId");
  11833. memset(sstr ,0, sizeof(sstr) );
  11834. if(loc != NULL)
  11835. {
  11836. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  11837. {
  11838. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  11839. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11840. c++;
  11841. }
  11842. sstr[c] = '\0';
  11843. tempchargingProfileId = atoi(sstr);
  11844. }
  11845. else
  11846. {
  11847. tempchargingProfileId = 0;
  11848. }
  11849. //***********transactionId **************/
  11850. c = 0;
  11851. loc = strstr(sLineWord, "transactionId");
  11852. //DEBUG_INFO("loc=%s\n",loc);
  11853. memset(sstr ,0, sizeof(sstr) );
  11854. if(loc != NULL)
  11855. {
  11856. while (loc[2+strlen("transactionId")+c] != '\"')
  11857. {
  11858. sstr[c] = loc[2+strlen("transactionId")+c];
  11859. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11860. c++;
  11861. }
  11862. sstr[c] = '\0';
  11863. temptransactionId = atoi(sstr);
  11864. }
  11865. else
  11866. {
  11867. temptransactionId = 0;
  11868. }
  11869. //***********stackLevel**************/
  11870. c = 0;
  11871. loc = strstr(sLineWord, "stackLevel");
  11872. //DEBUG_INFO("loc=%s\n",loc);
  11873. memset(sstr ,0, sizeof(sstr) );
  11874. if(loc != NULL)
  11875. {
  11876. while (loc[2+strlen("stackLevel")+c] != '\"')
  11877. {
  11878. sstr[c] = loc[2+strlen("stackLevel")+c];
  11879. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11880. c++;
  11881. }
  11882. sstr[c] = '\0';
  11883. tempstackLevel = atoi(sstr);
  11884. }
  11885. else
  11886. {
  11887. tempstackLevel = 0;
  11888. }
  11889. //***********chargingProfilePurpose **************/
  11890. c = 0;
  11891. loc = strstr(sLineWord, "chargingProfilePurpose");
  11892. //DEBUG_INFO("loc=%s\n",loc);
  11893. memset(sstr ,0, sizeof(sstr) );
  11894. if(loc != NULL)
  11895. {
  11896. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11897. {
  11898. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11899. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11900. c++;
  11901. }
  11902. sstr[c] = '\0';
  11903. strcpy(tempchargingProfilePurposeStr,sstr);
  11904. }
  11905. else
  11906. {
  11907. strcpy(tempchargingProfilePurposeStr,"");
  11908. }
  11909. //***********chargingProfileKind **************/
  11910. c = 0;
  11911. loc = strstr(sLineWord, "chargingProfileKind");
  11912. //DEBUG_INFO("loc=%s\n",loc);
  11913. memset(sstr ,0, sizeof(sstr) );
  11914. if(loc != NULL)
  11915. {
  11916. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  11917. {
  11918. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  11919. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11920. c++;
  11921. }
  11922. sstr[c] = '\0';
  11923. strcpy(tempchargingProfileKindStr,sstr);
  11924. }
  11925. else
  11926. {
  11927. strcpy(tempchargingProfileKindStr,"");
  11928. }
  11929. //***********recurrencyKind **************/
  11930. c = 0;
  11931. loc = strstr(sLineWord, "recurrencyKind");
  11932. //DEBUG_INFO("loc=%s\n",loc);
  11933. memset(sstr ,0, sizeof(sstr) );
  11934. if(loc != NULL)
  11935. {
  11936. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  11937. {
  11938. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  11939. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11940. c++;
  11941. }
  11942. sstr[c] = '\0';
  11943. strcpy(temprecurrencyKindStr,sstr);
  11944. }
  11945. else
  11946. {
  11947. strcpy(temprecurrencyKindStr,"");
  11948. }
  11949. //***********validFrom**************/
  11950. c = 0;
  11951. loc = strstr(sLineWord, "validFrom");
  11952. if(loc != NULL)
  11953. {
  11954. memset(sstr ,0, sizeof(sstr) );
  11955. while (loc[3+strlen("validFrom")+c] != '\"')
  11956. {
  11957. sstr[c] = loc[3+strlen("validFrom")+c];
  11958. c++;
  11959. }
  11960. sstr[c] = '\0';
  11961. strcpy(tempvalidFromStr,sstr);
  11962. }
  11963. else
  11964. {
  11965. strcpy(tempvalidFromStr,"");
  11966. }
  11967. //***********duration**************/
  11968. c = 0;
  11969. loc = strstr(sLineWord, "duration");
  11970. //DEBUG_INFO("loc=%s\n",loc);
  11971. memset(sstr ,0, sizeof(sstr) );
  11972. if(loc != NULL)
  11973. {
  11974. while (loc[2+strlen("duration")+c] != '\"')
  11975. {
  11976. sstr[c] = loc[2+strlen("duration")+c];
  11977. c++;
  11978. }
  11979. sstr[c] = '\0';
  11980. tempdurationInt = atoi(sstr);
  11981. }
  11982. else
  11983. {
  11984. tempdurationInt = 0;
  11985. }
  11986. //**********startSchedule**********/
  11987. c = 0;
  11988. loc = strstr(sLineWord, "startSchedule");
  11989. memset(sstr ,0, sizeof(sstr) );
  11990. while (loc[3+strlen("startSchedule")+c] != '\"')
  11991. {
  11992. sstr[c] = loc[3+strlen("startSchedule")+c];
  11993. c++;
  11994. }
  11995. sstr[c] = '\0';
  11996. strcpy(tempstartScheduleStr, sstr);
  11997. strcpy(TxProfileScheduleStr, sstr);
  11998. //**********chargingRateUnit**********/
  11999. c = 0;
  12000. loc = strstr(sLineWord, "chargingRateUnit");
  12001. memset(sstr ,0, sizeof(sstr) );
  12002. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12003. {
  12004. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12005. c++;
  12006. }
  12007. sstr[c] = '\0';
  12008. strcpy(tempchargingRateUnitStr, sstr);
  12009. //**********minChargingRate*******/
  12010. c = 0;
  12011. loc = strstr(sLineWord, "minChargingRate");
  12012. if(loc != NULL)
  12013. {
  12014. memset(sstr ,0, sizeof(sstr) );
  12015. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12016. {
  12017. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12018. c++;
  12019. }
  12020. sstr[c] = '\0';
  12021. tempminChargingRateFloat = atof(sstr);
  12022. }
  12023. else
  12024. {
  12025. tempminChargingRateFloat = 0.0;
  12026. }
  12027. //
  12028. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12029. tp.tm_isdst = -1;
  12030. time_t utc = mktime(&tp);
  12031. time_t t = time(NULL);
  12032. diff_t = difftime(t, utc);
  12033. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12034. //parsing strings to words
  12035. i = 0;
  12036. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12037. loc = loc+3+strlen("chargingSchedulePeriod");
  12038. pch = strtok(loc ,"{");
  12039. while (pch != NULL)
  12040. {
  12041. strcpy(SchedulePeriodList[i], pch);
  12042. pch = strtok (NULL, "{");
  12043. i = i + 1;
  12044. }
  12045. n_SchedulePeriods = i;
  12046. for(int i=0;i<n_SchedulePeriods;i++)
  12047. {
  12048. //*************startPeriod****************/
  12049. c = 0;
  12050. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12051. memset(sstr ,0, sizeof(sstr) );
  12052. while (loc[strlen("startPeriod")+2+c] != ',')
  12053. {
  12054. sstr[c] = loc[strlen("startPeriod")+2+c];
  12055. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12056. c++;
  12057. }
  12058. sstr[c] = '\0';
  12059. tempStartPeriodInt = atoi(sstr);
  12060. //*************limit****************/
  12061. c = 0;
  12062. loc = strstr(SchedulePeriodList[i], "limit");
  12063. memset(sstr ,0, sizeof(sstr) );
  12064. while (loc[strlen("limit")+2+c] != ',')
  12065. {
  12066. sstr[c] = loc[strlen("limit")+2+c];
  12067. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12068. c++;
  12069. }
  12070. sstr[c] = '\0';
  12071. tempLimitInt = atof(sstr);
  12072. //*************numberPhases****************/
  12073. c = 0;
  12074. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12075. memset(sstr ,0, sizeof(sstr) );
  12076. while (loc[strlen("numberPhases")+2+c] != '}')
  12077. {
  12078. sstr[c] = loc[strlen("numberPhases")+2+c];
  12079. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12080. c++;
  12081. }
  12082. sstr[c] = '\0';
  12083. tempNumberPhasesInt = atoi(sstr);
  12084. //TxProfile.Duration = durationInt;
  12085. TxProfile.TotalPeriod = n_SchedulePeriods;
  12086. TxProfile.Period[i].Limit = tempLimitInt;
  12087. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12088. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12089. }
  12090. if(MinChargingRate < tempminChargingRateFloat)
  12091. {
  12092. MinChargingRate = tempminChargingRateFloat;
  12093. }
  12094. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12095. if(confirmPeriods < n_SchedulePeriods)
  12096. confirmPeriods = n_SchedulePeriods;
  12097. if(j == 0)
  12098. {
  12099. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12100. TxProfile_TEMP.StackLevel = tempstackLevel;
  12101. TxProfile_TEMP.TransactionId = 0;
  12102. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  12103. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12104. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12105. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12106. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12107. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12108. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12109. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12110. }
  12111. }
  12112. fclose(fptr1);
  12113. }
  12114. }// the end of ACCESS TxProfile
  12115. //CompositeSchedule
  12116. int period=0;
  12117. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  12118. {
  12119. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  12120. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  12121. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  12122. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  12123. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  12124. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  12125. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  12126. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  12127. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  12128. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  12129. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  12130. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  12131. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  12132. for(int k=0; k < TxProfile.TotalPeriod;k++)
  12133. {
  12134. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  12135. {
  12136. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  12137. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12138. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12139. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  12140. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12141. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12142. period = period + 1;
  12143. }
  12144. else
  12145. {
  12146. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  12147. {
  12148. }
  12149. else
  12150. {
  12151. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12152. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12153. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12154. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12155. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  12156. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  12157. period = period + 1;
  12158. }
  12159. }
  12160. }
  12161. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12162. {
  12163. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  12164. {
  12165. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  12166. {
  12167. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  12168. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  12169. }
  12170. else
  12171. {
  12172. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12173. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  12174. }
  12175. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12176. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12177. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12178. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12179. period = period + 1;
  12180. }
  12181. }
  12182. }
  12183. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  12184. {
  12185. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  12186. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  12187. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12188. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  12189. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  12190. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  12191. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  12192. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  12193. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  12194. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  12195. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  12196. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  12197. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  12198. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12199. {
  12200. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  12201. {
  12202. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12203. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12204. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12205. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12206. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12207. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12208. period = period + 1;
  12209. }
  12210. else
  12211. {
  12212. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  12213. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12214. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12215. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  12216. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12217. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12218. period = period + 1;
  12219. }
  12220. }
  12221. }
  12222. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  12223. {
  12224. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  12225. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  12226. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  12227. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  12228. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  12229. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  12230. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  12231. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  12232. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  12233. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  12234. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  12235. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  12236. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  12237. {
  12238. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12239. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12240. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12241. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  12242. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  12243. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  12244. period = period + 1;
  12245. }
  12246. }
  12247. confirmPeriods = period;
  12248. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  12249. 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,"
  12250. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  12251. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  12252. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  12253. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  12254. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  12255. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  12256. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  12257. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  12258. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  12259. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  12260. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  12261. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  12262. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  12263. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  12264. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  12265. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  12266. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  12267. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  12268. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  12269. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  12270. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  12271. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  12272. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  12273. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  12274. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  12275. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  12276. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  12277. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  12278. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  12279. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  12280. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  12281. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  12282. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  12283. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  12284. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  12285. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  12286. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  12287. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  12288. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  12289. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  12290. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  12291. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  12292. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  12293. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  12294. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  12295. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  12296. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  12297. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  12298. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  12299. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  12300. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  12301. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  12302. }
  12303. void LWS_Send(char * str)
  12304. {
  12305. //=====================================================
  12306. // Check InternetConn 0: disconnected, 1: connected
  12307. //====================================================
  12308. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  12309. {
  12310. DEBUG_INFO("\n offline now !!!\n");
  12311. return;
  12312. }
  12313. pthread_mutex_lock(&lock);
  12314. memset(SendBuffer,0,SendBufLen);
  12315. sprintf((char *)SendBuffer, "%s", str);
  12316. pthread_mutex_unlock(&lock);
  12317. lws_callback_on_writable(wsi_client);
  12318. lws_service(context, 10000);//timeout_ms
  12319. //usleep(10000); // 等 ?? ?微 ?
  12320. //DEBUG_INFO("Send message end\n");
  12321. }