MessageHandler.c 455 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977
  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 /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY )*/ ;gun_index++)
  1080. {
  1081. //===============================
  1082. // CSU Trigger Reset Conf
  1083. //===============================
  1084. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1085. {
  1086. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1087. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1088. {
  1089. server_sign = FALSE;
  1090. }
  1091. }
  1092. //===============================
  1093. // CSU Trigger Authorize Request
  1094. //===============================
  1095. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1096. {
  1097. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1098. {
  1099. sendAuthorizeRequest(0);
  1100. authorizeRetryTimes = authorizeRetryTimes + 1;
  1101. // authenrequest = TRUE
  1102. if(authorizeRetryTimes < 3)
  1103. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1104. }
  1105. }
  1106. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1107. {
  1108. authorizeRetryTimes = 0;
  1109. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1110. server_sign = FALSE;
  1111. }
  1112. //==============================================
  1113. // Charger start transaction
  1114. //==============================================
  1115. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1116. {
  1117. sendStartTransactionRequest(gun_index);
  1118. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1119. clientTime.StartTransaction = time((time_t*)NULL);
  1120. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1121. }
  1122. //==============================================
  1123. // Charger stop transaction
  1124. //==============================================
  1125. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1126. {
  1127. sendStopTransactionRequest(gun_index);
  1128. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1129. clientTime.StopTransaction = time((time_t*)NULL);
  1130. }
  1131. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1132. //==============================================
  1133. // Charger status report
  1134. //==============================================
  1135. /* Check Mode Change */
  1136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1137. {
  1138. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1139. {
  1140. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1141. {
  1142. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1143. {
  1144. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1145. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1146. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1147. statusModeChage[gun_index] = TRUE;
  1148. }
  1149. }
  1150. }
  1151. for (int index = 0; index < CCS_QUANTITY; index++)
  1152. {
  1153. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1154. {
  1155. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1156. {
  1157. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1158. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1159. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1160. statusModeChage[gun_index] = TRUE;
  1161. }
  1162. }
  1163. }
  1164. for (int index = 0; index < GB_QUANTITY; index++)
  1165. {
  1166. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1167. {
  1168. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1169. {
  1170. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1171. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1172. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1173. statusModeChage[gun_index] = TRUE;
  1174. }
  1175. }
  1176. }
  1177. }
  1178. else //AC
  1179. {
  1180. for (int index = 0; index < AC_QUANTITY; index++)
  1181. {
  1182. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1183. {
  1184. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1185. {
  1186. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1187. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1188. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1189. statusModeChage[gun_index] = TRUE;
  1190. }
  1191. }
  1192. }// END OF FOR
  1193. }// END OF ELSE
  1194. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1195. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1196. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1197. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1198. {
  1199. if(SystemInitial != 0)
  1200. SystemInitial = SystemInitial -1;
  1201. //GunStatusInterval= GunStatusInterval* gun_index;
  1202. sendStatusNotificationRequest(gun_index);
  1203. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1204. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1205. statusModeChage[gun_index] = FALSE;
  1206. //sleep(30); // sleep for 30 seconds
  1207. }
  1208. //==============================================
  1209. // Meter report
  1210. //==============================================
  1211. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1212. {
  1213. //check Transaction active
  1214. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1215. {
  1216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1217. {
  1218. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1219. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1220. {
  1221. meterValueSend[gun_index] =1;
  1222. }
  1223. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1224. {
  1225. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1226. if((access(filenmae,F_OK))!=-1)
  1227. {
  1228. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1229. sprintf(str,"rm -f %s",filenmae);
  1230. system(str);
  1231. }
  1232. }
  1233. }// End for CHAdeMO
  1234. for (int index = 0; index < CCS_QUANTITY; index++)
  1235. {
  1236. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1237. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1238. {
  1239. meterValueSend[gun_index] =1;
  1240. }
  1241. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1242. {
  1243. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1244. if((access(filenmae,F_OK))!=-1)
  1245. {
  1246. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1247. sprintf(str,"rm -f %s",filenmae);
  1248. system(str);
  1249. }
  1250. }
  1251. } // End for CCS
  1252. for (int index = 0; index < GB_QUANTITY; index++)
  1253. {
  1254. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1255. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1256. {
  1257. meterValueSend[gun_index] =1;
  1258. }
  1259. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1260. {
  1261. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1262. if((access(filenmae,F_OK))!=-1)
  1263. {
  1264. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1265. sprintf(str,"rm -f %s",filenmae);
  1266. system(str);
  1267. }
  1268. }
  1269. }// End for GB
  1270. }
  1271. else
  1272. {
  1273. for (int index = 0; index < AC_QUANTITY; index++)
  1274. {
  1275. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1276. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1277. {
  1278. meterValueSend[gun_index] =1;
  1279. }
  1280. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1281. {
  1282. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1283. if((access(filenmae,F_OK))!=-1)
  1284. {
  1285. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1286. sprintf(str,"rm -f %s",filenmae);
  1287. system(str);
  1288. }
  1289. }
  1290. }//End for AC
  1291. }//END OF ELSE
  1292. // sleep(1);
  1293. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1294. if(meterValueSend[gun_index] == 1)
  1295. sendMeterValuesRequest(gun_index);
  1296. }
  1297. //==============================================
  1298. // Check Connector reserved
  1299. //==============================================
  1300. //===============================
  1301. // Check if Reserve is expired
  1302. //===============================
  1303. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1304. {
  1305. double diff_t;
  1306. struct tm tp;
  1307. // current time
  1308. time_t t = time(NULL);
  1309. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1310. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1311. tp.tm_isdst = -1;
  1312. time_t utc = mktime(&tp);
  1313. diff_t = difftime(utc, t);
  1314. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1315. if(diff_t <= 0)
  1316. {
  1317. DEBUG_INFO("reserve expired !!! \n");
  1318. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1319. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1320. }
  1321. #if 0
  1322. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1323. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1324. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1325. {
  1326. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1327. }
  1328. else
  1329. {
  1330. //check Transaction active
  1331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1332. {
  1333. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1334. {
  1335. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1336. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1337. {
  1338. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1339. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1340. {
  1341. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1342. }
  1343. }
  1344. }
  1345. for (int index = 0; index < CCS_QUANTITY; index++)
  1346. {
  1347. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1348. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1349. {
  1350. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1351. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1352. {
  1353. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1354. }
  1355. }
  1356. }
  1357. for (int index = 0; index < GB_QUANTITY; index++)
  1358. {
  1359. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1360. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1361. {
  1362. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1363. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1364. {
  1365. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1366. }
  1367. }
  1368. }
  1369. }
  1370. else //AC
  1371. {
  1372. for (int index = 0; index < AC_QUANTITY; index++)
  1373. {
  1374. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1375. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1376. {
  1377. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1378. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1379. {
  1380. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1381. }
  1382. }
  1383. }
  1384. }// END OF ELSE
  1385. }// END OF check Transaction active
  1386. #endif
  1387. }//END OF Check if Reserve is expired
  1388. //==========================================
  1389. // csu trigger FirmwareStatusNotificationReq
  1390. //==========================================
  1391. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1392. {
  1393. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1394. }
  1395. //==========================================
  1396. // csu trigger CancelReservationConf
  1397. //==========================================
  1398. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1399. {
  1400. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1401. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1402. }
  1403. //==========================================
  1404. // csu trigger ChangeAvailabilityConf
  1405. //==========================================
  1406. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1407. {
  1408. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1409. }
  1410. //==========================================
  1411. // csu trigger UnlockConnectorConf
  1412. //==========================================
  1413. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1414. {
  1415. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1416. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1417. }
  1418. //==========================================
  1419. // csu trigger ReserveNowConf
  1420. //==========================================
  1421. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1422. {
  1423. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1424. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1425. }
  1426. //==========================================
  1427. // csu trigger DataTransferReq
  1428. //==========================================
  1429. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1430. {
  1431. sendDataTransferRequest(gun_index);
  1432. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1433. }
  1434. }
  1435. }
  1436. //==========================================
  1437. // send request routine
  1438. //==========================================
  1439. int sendAuthorizeRequest(int gun_index)
  1440. {
  1441. mtrace();
  1442. int result = FAIL;
  1443. char message[100]={0};
  1444. char guid[37];
  1445. char tempdata[65]={0};
  1446. DEBUG_INFO("sendAuthorizeRequest \n");
  1447. //Local Authorize
  1448. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1449. {
  1450. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1451. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1452. {
  1453. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1454. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1455. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1456. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1457. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1458. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1459. authorizeRetryTimes = 0;
  1460. return result;
  1461. }
  1462. else
  1463. {
  1464. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1465. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1466. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1467. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1468. result = PASS;
  1469. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1470. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1471. authorizeRetryTimes = 0;
  1472. return result;
  1473. }
  1474. }
  1475. //initailize struct Authorize
  1476. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1477. //get data from shared memory
  1478. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1479. random_uuid(guid);
  1480. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1481. LWS_Send(message);
  1482. sprintf(tempdata, "Authorize,%d", gun_index);
  1483. if(hashmap_operation(0, guid, tempdata) == 1)
  1484. {
  1485. result = PASS;
  1486. DEBUG_ERROR("Authorize mapItem pass\n");
  1487. }
  1488. //#ifdef SystemLogMessage
  1489. //DEBUG_INFO(">>>>>Authorize request\n");
  1490. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1491. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1492. //#endif
  1493. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1494. return result;
  1495. }
  1496. int sendBootNotificationRequest(void)
  1497. {
  1498. mtrace();
  1499. int result = FAIL;
  1500. char message[500]={0}, payload[700]={0};
  1501. char guid[37]={0};
  1502. char tempdata[65]={0};
  1503. int IsGunCharging = FALSE;
  1504. //check Transaction active
  1505. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1506. {
  1507. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1508. {
  1509. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1510. {
  1511. IsGunCharging = TRUE;
  1512. }
  1513. }
  1514. for (int index = 0; index < CCS_QUANTITY; index++)
  1515. {
  1516. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1517. {
  1518. IsGunCharging = TRUE;
  1519. }
  1520. }
  1521. for (int index = 0; index < GB_QUANTITY; index++)
  1522. {
  1523. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1524. {
  1525. IsGunCharging = TRUE;
  1526. }
  1527. }
  1528. }
  1529. else
  1530. {
  1531. for (int index = 0; index < AC_QUANTITY; index++)
  1532. {
  1533. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1534. {
  1535. IsGunCharging = TRUE;
  1536. }
  1537. }
  1538. }
  1539. if(IsGunCharging == TRUE)
  1540. {
  1541. server_sign = TRUE;
  1542. return result;
  1543. }
  1544. // Fill BootNotification fields
  1545. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1546. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1547. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1548. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1549. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1550. ShmOCPP16Data->ChargeBoxId
  1551. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1552. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1553. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1554. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1555. ,ShmOCPP16Data->BootNotification.CpIccid
  1556. ,ShmOCPP16Data->BootNotification.CpImsi
  1557. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1558. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1559. random_uuid(guid);
  1560. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1561. LWS_Send(message);
  1562. sprintf(tempdata, "BootNotification,0");
  1563. 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*/)
  1564. {
  1565. result = PASS;
  1566. }
  1567. memset(queuedata, 0, sizeof(queuedata));
  1568. strcpy(queuedata,message);
  1569. //#ifdef SystemLogMessage
  1570. //DEBUG_INFO(">>>>>BootNotification request\n");
  1571. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1572. //#endif
  1573. return result;
  1574. }
  1575. int sendDataTransferRequest(int gun_index)
  1576. {
  1577. mtrace();
  1578. char message[1000]={0};
  1579. char guid[37]={0};
  1580. char tempdata[65]={0};
  1581. int result = FAIL;
  1582. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1583. random_uuid(guid);
  1584. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1585. MESSAGE_TYPE_CALL,
  1586. guid,
  1587. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1588. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1589. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1590. LWS_Send(message);
  1591. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1592. 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*/)
  1593. {
  1594. result = PASS;
  1595. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1596. }
  1597. //#ifdef SystemLogMessage
  1598. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1599. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1600. //#endif
  1601. return result;
  1602. }
  1603. int sendDiagnosticsStatusNotificationRequest(char *status)
  1604. {
  1605. mtrace();
  1606. int result = FAIL;
  1607. char message[110]={0};
  1608. char guid[37]={0};
  1609. char tempdata[65]={0};
  1610. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1611. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1612. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1613. random_uuid(guid);
  1614. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1615. LWS_Send(message);
  1616. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1617. if(hashmap_operation(0, guid, tempdata) == 1)
  1618. {
  1619. result = PASS;
  1620. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1621. }
  1622. //#ifdef SystemLogMessage
  1623. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1624. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1625. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1626. //#endif
  1627. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1628. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1629. //record status
  1630. if(strcmp(status,"Idle")==0)
  1631. {
  1632. DiagnosticsStatusNotificationStatus = 0;
  1633. }
  1634. else if(strcmp(status,"Uploaded")==0)
  1635. {
  1636. DiagnosticsStatusNotificationStatus = 1;
  1637. }
  1638. else if(strcmp(status,"UploadFailed")==0)
  1639. {
  1640. DiagnosticsStatusNotificationStatus = 2;
  1641. }
  1642. else if(strcmp(status,"Uploading")==0)
  1643. {
  1644. DiagnosticsStatusNotificationStatus = 3;
  1645. }
  1646. return result;
  1647. }
  1648. int sendFirmwareStatusNotificationRequest(char *status)
  1649. {
  1650. mtrace();
  1651. int result = FAIL;
  1652. char message[110]={0};
  1653. char guid[37]={0};
  1654. char tempdata[65]={0};
  1655. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1656. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1657. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1658. random_uuid(guid);
  1659. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1660. LWS_Send(message);
  1661. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1662. 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*/)
  1663. {
  1664. result = PASS;
  1665. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1666. }
  1667. //#ifdef SystemLogMessage
  1668. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1669. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1670. //#endif
  1671. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1672. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1673. //record status
  1674. if(strcmp(status,"Downloaded")==0)
  1675. {
  1676. FirmwareStatusNotificationStatus = 0;
  1677. }
  1678. else if(strcmp(status,"DownloadFailed")==0)
  1679. {
  1680. FirmwareStatusNotificationStatus = 1;
  1681. }
  1682. else if(strcmp(status,"Downloading")==0)
  1683. {
  1684. FirmwareStatusNotificationStatus = 2;
  1685. }
  1686. else if(strcmp(status,"Idle")==0)
  1687. {
  1688. FirmwareStatusNotificationStatus = 3;
  1689. }
  1690. else if(strcmp(status,"InstallationFailed")==0)
  1691. {
  1692. FirmwareStatusNotificationStatus = 4;
  1693. }
  1694. else if(strcmp(status,"Installing")==0)
  1695. {
  1696. FirmwareStatusNotificationStatus = 5;
  1697. }
  1698. else if(strcmp(status,"Installed")==0)
  1699. {
  1700. FirmwareStatusNotificationStatus = 6;
  1701. }
  1702. return result;
  1703. }
  1704. int sendHeartbeatRequest(int gun_index)
  1705. {
  1706. mtrace();
  1707. int result = FAIL;
  1708. char message[80]={0};
  1709. char guid[37]={0};
  1710. char tempdata[65]={0};
  1711. random_uuid(guid);
  1712. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1713. , MESSAGE_TYPE_CALL
  1714. , guid );
  1715. LWS_Send(message);
  1716. sprintf(tempdata, "Heartbeat,%d", 0);
  1717. 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*/)
  1718. {
  1719. result = PASS;
  1720. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1721. }
  1722. //#ifdef SystemLogMessage
  1723. //DEBUG_INFO(">>>>>Heartbeat request\n");
  1724. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1725. //#endif
  1726. return result;
  1727. }
  1728. int sendStartTransactionRequest(int gun_index)
  1729. {
  1730. mtrace();
  1731. int result = FAIL;
  1732. char message[250]={0};
  1733. char guid[37]={0};
  1734. struct timeval tmnow;
  1735. struct tm *tm;
  1736. char buf[28];//, usec_buf[6];
  1737. char tempdata[65]={0};
  1738. DEBUG_INFO("sendStartTransactionRequest...");
  1739. gettimeofday(&tmnow, NULL);
  1740. time_t t;
  1741. t = time(NULL);
  1742. /*UTC time and date*/
  1743. tm = gmtime(&t);
  1744. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1745. #if 0 // remove temporally
  1746. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1747. strcat(buf,".");
  1748. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1749. strcat(buf,usec_buf);
  1750. #endif
  1751. //printf("Start Charging Time :%s",buf);
  1752. // set value
  1753. //if(ShmOCPP16Data->OcppConnStatus == 1 )
  1754. //{
  1755. //memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1756. //}
  1757. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1758. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1759. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1760. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1761. {
  1762. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1763. {
  1764. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1765. {
  1766. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1767. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1768. }
  1769. }
  1770. for (int index = 0; index < CCS_QUANTITY; index++)
  1771. {
  1772. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1773. {
  1774. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1775. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1776. }
  1777. }
  1778. for (int index = 0; index < GB_QUANTITY; index++)
  1779. {
  1780. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1781. {
  1782. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1783. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1784. }
  1785. }
  1786. }
  1787. else
  1788. {
  1789. for (int index = 0; index < AC_QUANTITY; index++)
  1790. {
  1791. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1792. {
  1793. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1794. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1795. }
  1796. }
  1797. }//END OF ELSE
  1798. random_uuid(guid);
  1799. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1800. , MESSAGE_TYPE_CALL
  1801. , guid
  1802. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1803. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1804. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1805. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1806. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1807. LWS_Send(message);
  1808. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1809. 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*/)
  1810. {
  1811. result = PASS;
  1812. }
  1813. strcpy(queuedata, message);
  1814. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1815. //#ifdef SystemLogMessage
  1816. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1817. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1818. //#endif
  1819. return result;
  1820. }
  1821. int sendStatusNotificationRequest(int gun_index)
  1822. {
  1823. mtrace();
  1824. int result = FAIL;
  1825. char message[600]={0};
  1826. char guid[37];
  1827. int currentStatus = 0;
  1828. struct timeval tmnow;
  1829. struct tm *tm;
  1830. char buf[28];//, usec_buf[6];
  1831. char tempdata[65]={0};
  1832. gettimeofday(&tmnow, NULL);
  1833. time_t t;
  1834. t = time(NULL);
  1835. /*UTC time and date*/
  1836. tm = gmtime(&t);
  1837. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1838. #if 0 // remove temporally
  1839. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1840. strcat(buf,".");
  1841. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1842. strcat(buf,usec_buf);
  1843. #endif
  1844. printf("%s",buf);
  1845. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1846. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1847. // it's option
  1848. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1849. /*
  1850. enum _SYSTEM_STATUS
  1851. {
  1852. S_BOOTING = 0,
  1853. S_IDLE, = 1
  1854. S_AUTHORIZING, =2
  1855. S_REASSIGN_CHECK, =3
  1856. S_REASSIGN, =4
  1857. S_PRECHARGE, =5
  1858. S_PREPARING_FOR_EV, =6
  1859. S_PREPARING_FOR_EVSE, =7
  1860. S_CHARGING, =8
  1861. S_TERMINATING, =9
  1862. S_COMPLETE, =10
  1863. S_ALARM, =11
  1864. S_FAULT =12
  1865. }
  1866. */
  1867. //check Transaction active
  1868. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1869. {
  1870. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1871. {
  1872. //printf("gun_index=%d\n",gun_index);
  1873. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1874. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1875. {
  1876. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1877. currentStatus = 0; //OCPP Status
  1878. }
  1879. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1880. {
  1881. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1882. currentStatus = 1; //OCPP Status
  1883. }
  1884. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1885. {
  1886. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1887. currentStatus = 2; //OCPP Status
  1888. }
  1889. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1890. {
  1891. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1892. currentStatus = 5; //OCPP Status
  1893. }
  1894. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1895. {
  1896. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1897. currentStatus = 4; //OCPP Status
  1898. }
  1899. 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
  1900. {
  1901. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1902. currentStatus = 7; //OCPP Status: Unavailable
  1903. }
  1904. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1905. {
  1906. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1907. currentStatus = 8; //OCPP Status: Faulted
  1908. }
  1909. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1910. {
  1911. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1912. currentStatus = 6; //OCPP Status: Reserved
  1913. }
  1914. }//end of for CHAdeMO_QUANTITY
  1915. for (int index = 0; index < CCS_QUANTITY; index++)
  1916. {
  1917. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1918. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1919. {
  1920. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1921. currentStatus = 0; //OCPP Status
  1922. }
  1923. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1924. {
  1925. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1926. currentStatus = 1; //OCPP Status
  1927. }
  1928. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1929. {
  1930. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1931. currentStatus = 2; //OCPP Status
  1932. }
  1933. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1934. {
  1935. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1936. currentStatus = 5; //OCPP Status
  1937. }
  1938. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1939. {
  1940. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1941. currentStatus = 4; //OCPP Status
  1942. }
  1943. 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
  1944. {
  1945. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1946. currentStatus = 7; //OCPP Status
  1947. }
  1948. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1949. {
  1950. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1951. currentStatus = 8; //OCPP Status
  1952. }
  1953. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1954. {
  1955. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1956. currentStatus = 6; //OCPP Status
  1957. }
  1958. }
  1959. for (int index = 0; index < GB_QUANTITY; index++)
  1960. {
  1961. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1962. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1963. {
  1964. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1965. currentStatus = 0; //OCPP Status
  1966. }
  1967. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1968. {
  1969. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1970. currentStatus = 1; //OCPP Status
  1971. }
  1972. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1973. {
  1974. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1975. currentStatus = 2; //OCPP Status
  1976. }
  1977. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1978. {
  1979. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1980. currentStatus = 5; //OCPP Status
  1981. }
  1982. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1983. {
  1984. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1985. currentStatus = 4; //OCPP Status
  1986. }
  1987. 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
  1988. {
  1989. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1990. currentStatus = 7; //OCPP Status: Unavailable
  1991. }
  1992. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1993. {
  1994. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1995. currentStatus = 8; //OCPP Status: Faulted
  1996. }
  1997. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1998. {
  1999. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2000. currentStatus = 6; //OCPP Status: Faulted
  2001. }
  2002. }
  2003. }
  2004. else
  2005. {
  2006. for (int index = 0; index < AC_QUANTITY; index++)
  2007. {
  2008. //printf("gun_index=%d\n",gun_index);
  2009. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2010. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2011. {
  2012. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2013. currentStatus = 0; //OCPP Status
  2014. }
  2015. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2016. {
  2017. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2018. currentStatus = 1; //OCPP Status
  2019. }
  2020. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2021. {
  2022. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2023. currentStatus = 2; //OCPP Status
  2024. }
  2025. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2026. {
  2027. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2028. currentStatus = 5; //OCPP Status
  2029. }
  2030. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2031. {
  2032. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2033. currentStatus = 4; //OCPP Status
  2034. }
  2035. 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
  2036. {
  2037. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2038. currentStatus = 7; //OCPP Status: Unavailable
  2039. }
  2040. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2041. {
  2042. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2043. currentStatus = 8; //OCPP Status: Faulted
  2044. }
  2045. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2046. {
  2047. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2048. currentStatus = 6; //OCPP Status: Reserved
  2049. }
  2050. }//end of for AC_QUANTITY
  2051. }//END OF ELSE
  2052. //it's option
  2053. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2054. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2055. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2056. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2057. random_uuid(guid);
  2058. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2059. , MESSAGE_TYPE_CALL
  2060. , guid
  2061. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2062. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2063. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2064. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2065. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2066. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2067. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2068. LWS_Send(message);
  2069. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2070. 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*/)
  2071. {
  2072. //DEBUG_ERROR("statusNotification mapitem pass");
  2073. result = PASS;
  2074. }
  2075. //#ifdef SystemLogMessage
  2076. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2077. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2078. //#endif
  2079. return result;
  2080. }
  2081. int sendStopTransactionRequest(int gun_index)
  2082. {
  2083. mtrace();
  2084. int result = FAIL;
  2085. //char message[1500]={0};
  2086. char guid[37]={0};
  2087. char tempdata[65]={0};
  2088. //int idx_sample=0;
  2089. DEBUG_ERROR("sendStopTransactionRequest \n");
  2090. memset(queuedata, 0, sizeof(queuedata));
  2091. //ENERGY_ACTIVE_IMPORT_REGISTER
  2092. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2093. {
  2094. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2095. {
  2096. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2097. {
  2098. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2099. //Check Status
  2100. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2101. {
  2102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2103. }
  2104. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2105. }
  2106. }// END OF CHAdeMO_QUANTITY
  2107. for (int index = 0; index < CCS_QUANTITY; index++)
  2108. {
  2109. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2110. {
  2111. //for test
  2112. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2113. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2114. //Check Status
  2115. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2116. {
  2117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2118. }
  2119. else
  2120. {
  2121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2122. }
  2123. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2124. }
  2125. }// END OF CCS_QUANTITY
  2126. for (int index = 0; index < GB_QUANTITY; index++)
  2127. {
  2128. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2129. {
  2130. // for test
  2131. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2132. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2133. //Check Status
  2134. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2135. {
  2136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2137. }
  2138. else
  2139. {
  2140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2141. }
  2142. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2143. }
  2144. }// END OF GB_QUANTITY
  2145. }
  2146. else
  2147. {
  2148. for (int index = 0; index < AC_QUANTITY; index++)
  2149. {
  2150. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2151. {
  2152. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2153. //Check Status
  2154. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2155. {
  2156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2157. }
  2158. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2159. }
  2160. }// END OF AC_QUANTITY
  2161. }//END OF ELSE
  2162. //Stop Transaction Time
  2163. struct timeval tmnow;
  2164. struct tm *tm;
  2165. char buf[28];//, usec_buf[6];
  2166. gettimeofday(&tmnow, NULL);
  2167. time_t t;
  2168. t = time(NULL);
  2169. /*UTC time and date*/
  2170. tm = gmtime(&t);
  2171. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2172. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2174. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2175. random_uuid(guid);
  2176. /***********************************transactionData******************************************************/
  2177. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2178. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2179. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2181. //=================================
  2182. // Transaction_Begin
  2183. //=================================
  2184. // Energy.Active.Export.Interval
  2185. //idx_sample=0;
  2186. 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
  2187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2189. 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*/]);
  2190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2193. //=================================
  2194. // Transaction_End
  2195. //=================================
  2196. //Current.Export
  2197. //idx_sample=1;
  2198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2199. {
  2200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2201. {
  2202. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2203. {
  2204. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2205. }
  2206. }
  2207. for (int index = 0; index < CCS_QUANTITY; index++)
  2208. {
  2209. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2210. {
  2211. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2212. }
  2213. }
  2214. for (int index = 0; index < GB_QUANTITY; index++)
  2215. {
  2216. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2217. {
  2218. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2219. }
  2220. }
  2221. }
  2222. else
  2223. {
  2224. for (int index = 0; index < AC_QUANTITY; index++)
  2225. {
  2226. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2227. {
  2228. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2229. }
  2230. }
  2231. }// END FOR AC ELSE
  2232. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2235. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2236. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2238. //Energy.Active.Export.Interval
  2239. //idx_sample=2;
  2240. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2241. {
  2242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2243. {
  2244. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2245. {
  2246. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2247. }
  2248. }
  2249. for (int index = 0; index < CCS_QUANTITY; index++)
  2250. {
  2251. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2252. {
  2253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2254. }
  2255. }
  2256. for (int index = 0; index < GB_QUANTITY; index++)
  2257. {
  2258. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2259. {
  2260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2261. }
  2262. }
  2263. }
  2264. else
  2265. {
  2266. for (int index = 0; index < AC_QUANTITY; index++)
  2267. {
  2268. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2269. {
  2270. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2271. }
  2272. }
  2273. }// END FOR AC ELSE
  2274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2280. //Power.Active.Export
  2281. //idx_sample=3;
  2282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2283. {
  2284. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2285. {
  2286. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2287. {
  2288. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2289. }
  2290. }
  2291. for (int index = 0; index < CCS_QUANTITY; index++)
  2292. {
  2293. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2294. {
  2295. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2296. }
  2297. }
  2298. for (int index = 0; index < GB_QUANTITY; index++)
  2299. {
  2300. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2301. {
  2302. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2303. }
  2304. }
  2305. }
  2306. else
  2307. {
  2308. for (int index = 0; index < AC_QUANTITY; index++)
  2309. {
  2310. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2311. {
  2312. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2313. }
  2314. }
  2315. }// END FOR AC ELSE
  2316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2318. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2319. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2320. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2322. //Voltage
  2323. //idx_sample=4;
  2324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2325. {
  2326. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2327. {
  2328. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2329. {
  2330. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2331. }
  2332. }
  2333. for (int index = 0; index < CCS_QUANTITY; index++)
  2334. {
  2335. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2336. {
  2337. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2338. }
  2339. }
  2340. for (int index = 0; index < GB_QUANTITY; index++)
  2341. {
  2342. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2343. {
  2344. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2345. }
  2346. }
  2347. }
  2348. else
  2349. {
  2350. for (int index = 0; index < AC_QUANTITY; index++)
  2351. {
  2352. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2353. {
  2354. 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
  2355. }
  2356. }
  2357. }// END FOR AC ELSE
  2358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2364. //SoC
  2365. //idx_sample=5;
  2366. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2367. {
  2368. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2369. {
  2370. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2371. {
  2372. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2373. }
  2374. }
  2375. for (int index = 0; index < CCS_QUANTITY; index++)
  2376. {
  2377. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2378. {
  2379. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2380. }
  2381. }
  2382. for (int index = 0; index < GB_QUANTITY; index++)
  2383. {
  2384. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2385. {
  2386. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2387. }
  2388. }
  2389. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2391. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L1_N]);
  2393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2395. } // END FOR DC CASE
  2396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2397. {
  2398. 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\" } ] } ] } ]"
  2399. ,MESSAGE_TYPE_CALL
  2400. ,guid
  2401. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2402. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2403. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2404. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2405. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2406. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2407. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2408. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2409. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2410. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2411. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2412. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2413. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2414. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2415. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2416. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2417. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2418. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2419. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2420. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2421. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2422. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2423. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2424. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2425. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2426. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2427. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2428. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2429. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2430. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2431. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2432. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2433. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2434. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2435. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2436. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2437. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2438. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2439. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2440. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2441. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2442. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2443. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2444. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2445. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2446. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2447. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2448. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2449. );
  2450. }
  2451. else
  2452. {
  2453. 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\" } ] } ] } ]"
  2454. ,MESSAGE_TYPE_CALL
  2455. ,guid
  2456. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2457. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2458. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2459. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2460. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2461. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2462. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2463. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2464. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2465. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2466. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2467. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2468. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2469. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2470. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2471. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2472. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2473. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2474. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2475. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2476. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2477. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2478. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2479. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2480. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2481. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2482. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2483. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2484. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2485. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2486. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2487. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2488. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2489. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2490. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2491. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2492. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2493. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2494. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2495. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2496. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2497. );
  2498. }
  2499. LWS_Send(queuedata);
  2500. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2501. if(hashmap_operation(0, guid, tempdata) == 1)
  2502. {
  2503. result = PASS;
  2504. DEBUG_INFO("StopTransaction mapitem pass\n");
  2505. }
  2506. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2507. //for test
  2508. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2509. return result;
  2510. }
  2511. int sendMeterValuesRequest(int gun_index)
  2512. {
  2513. mtrace();
  2514. int result = FAIL;
  2515. // char message[1500]={0};
  2516. char guid[37]={0};
  2517. //int idx_sample=0;
  2518. //int length = 0;
  2519. char tempdata[65]={0};
  2520. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2521. DEBUG_ERROR("gun_index =%d\n",gun_index);
  2522. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2523. {
  2524. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2525. DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2526. DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2527. return result;
  2528. }
  2529. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2530. {
  2531. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2532. }
  2533. memset(queuedata, 0, sizeof(queuedata));
  2534. //set value
  2535. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2536. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2537. random_uuid(guid);
  2538. //UTC Date time
  2539. struct timeval tmnow;
  2540. struct tm *tm;
  2541. char buf[28];//, usec_buf[6];
  2542. gettimeofday(&tmnow, NULL);
  2543. time_t t;
  2544. t = time(NULL);
  2545. /*UTC time and date*/
  2546. tm = gmtime(&t);
  2547. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2549. //idx_sample=0;
  2550. //********************************(1)Current.Export************************************************/
  2551. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2552. {
  2553. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2554. {
  2555. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2556. {
  2557. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2558. }
  2559. }
  2560. for (int index = 0; index < CCS_QUANTITY; index++)
  2561. {
  2562. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2563. {
  2564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2565. }
  2566. }
  2567. for (int index = 0; index < GB_QUANTITY; index++)
  2568. {
  2569. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2570. {
  2571. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2572. }
  2573. }
  2574. }
  2575. else
  2576. {
  2577. for (int index = 0; index < AC_QUANTITY; index++)
  2578. {
  2579. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2580. {
  2581. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2582. }
  2583. }
  2584. }// END FOR AC ELSE
  2585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2587. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2588. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2589. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2590. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2591. //idx_sample=1;
  2592. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2593. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2594. {
  2595. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2596. {
  2597. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2598. {
  2599. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2600. }
  2601. }
  2602. for (int index = 0; index < CCS_QUANTITY; index++)
  2603. {
  2604. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2605. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2606. {
  2607. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2608. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2609. }
  2610. }
  2611. for (int index = 0; index < GB_QUANTITY; index++)
  2612. {
  2613. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2614. {
  2615. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2616. }
  2617. }
  2618. }
  2619. else
  2620. {
  2621. for (int index = 0; index < AC_QUANTITY; index++)
  2622. {
  2623. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2624. {
  2625. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2626. }
  2627. }
  2628. }//END FOR AC ELSE
  2629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2630. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2632. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1]);
  2633. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2634. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2635. //idx_sample=2;
  2636. //********************************(4)Power.Active.Export************************************************/
  2637. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2638. {
  2639. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2640. {
  2641. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2642. {
  2643. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2644. }
  2645. }
  2646. for (int index = 0; index < CCS_QUANTITY; index++)
  2647. {
  2648. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2649. {
  2650. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2651. }
  2652. }
  2653. for (int index = 0; index < GB_QUANTITY; index++)
  2654. {
  2655. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2656. {
  2657. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2658. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2659. }
  2660. }
  2661. }
  2662. else
  2663. {
  2664. for (int index = 0; index < AC_QUANTITY; index++)
  2665. {
  2666. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2667. {
  2668. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2669. }
  2670. }
  2671. }// END FOR AC ELSE
  2672. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2673. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2674. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2676. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2677. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2678. //idx_sample=3;
  2679. //***********************************************(5)VOLTAGE******************************************************/
  2680. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2681. {
  2682. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2683. {
  2684. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2685. {
  2686. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2687. }
  2688. }
  2689. for (int index = 0; index < CCS_QUANTITY; index++)
  2690. {
  2691. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2692. {
  2693. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2694. }
  2695. }
  2696. for (int index = 0; index < GB_QUANTITY; index++)
  2697. {
  2698. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2699. {
  2700. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2701. }
  2702. }
  2703. }
  2704. else
  2705. {
  2706. for (int index = 0; index < AC_QUANTITY; index++)
  2707. {
  2708. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2709. {
  2710. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2711. }
  2712. }
  2713. }//END FOR AC ELSE
  2714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2715. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2716. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2718. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2719. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2720. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2721. {
  2722. //idx_sample=4;
  2723. //sampledValue = NULL;
  2724. //***********************************************(6)SOC******************************************************/
  2725. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2726. {
  2727. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2728. {
  2729. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2730. }
  2731. }
  2732. for (int index = 0; index < CCS_QUANTITY; index++)
  2733. {
  2734. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2735. {
  2736. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2737. }
  2738. }
  2739. for (int index = 0; index < GB_QUANTITY; index++)
  2740. {
  2741. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2742. {
  2743. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2744. }
  2745. }
  2746. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2747. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2748. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2749. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  2750. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2751. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2752. }
  2753. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2754. {
  2755. 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\"}]}]}]"
  2756. ,MESSAGE_TYPE_CALL
  2757. ,guid
  2758. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2759. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2760. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2796. );
  2797. }
  2798. else
  2799. {
  2800. 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\"}]}]}]"
  2801. ,MESSAGE_TYPE_CALL
  2802. ,guid
  2803. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2804. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2805. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2832. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2833. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2834. );
  2835. }
  2836. LWS_Send(queuedata);
  2837. // Put request guid to hash map
  2838. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2839. 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*/)
  2840. {
  2841. result = PASS;
  2842. DEBUG_INFO("MeterValues mapitem pass\n");
  2843. }
  2844. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2845. return result;
  2846. }
  2847. //==========================================
  2848. // send confirm routine
  2849. //==========================================
  2850. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2851. {
  2852. mtrace();
  2853. int result = FAIL;
  2854. char message[100]={0};
  2855. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2856. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2857. LWS_Send(message);
  2858. result = TRUE;
  2859. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2860. return result;
  2861. }
  2862. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2863. {
  2864. mtrace();
  2865. int result = FAIL;
  2866. char message[100]={0};
  2867. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2868. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2869. LWS_Send(message);
  2870. result = TRUE;
  2871. return result;
  2872. }
  2873. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2874. {
  2875. mtrace();
  2876. int result = FAIL;
  2877. char message[100]={0};
  2878. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2879. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2880. LWS_Send(message);
  2881. result = TRUE;
  2882. return result;
  2883. }
  2884. int sendClearCacheConfirmation(char *uuid,char *payload)
  2885. {
  2886. mtrace();
  2887. int result = FAIL;
  2888. char message[500]={0};
  2889. // int count = 0;
  2890. // int gun_index = 0;
  2891. // char guid[37];
  2892. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2893. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2894. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2895. LWS_Send(message);
  2896. return result;
  2897. }
  2898. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2899. {
  2900. mtrace();
  2901. int result = FAIL;
  2902. char message[500]={0};
  2903. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2904. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2905. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2906. LWS_Send(message);
  2907. return result;
  2908. }
  2909. int sendDataTransferConfirmation(char *uuid,char *payload)
  2910. {
  2911. mtrace();
  2912. char statusStr[20]={0};
  2913. char dataStr[10]={0};
  2914. char sstr[20]={0};
  2915. int c = 0;
  2916. char *loc;
  2917. int result = FAIL;
  2918. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2919. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2920. /**********************status**************************/
  2921. loc = strstr(payload, "status");
  2922. memset(sstr ,0, sizeof(sstr) );
  2923. c = 0;
  2924. while (loc[3+strlen("status")+c] != '\"')
  2925. {
  2926. sstr[c] = loc[3+strlen("status")+c];
  2927. c++;
  2928. }
  2929. sstr[c] = '\0';
  2930. strcpy(statusStr, sstr);
  2931. /**********************data**************************/
  2932. loc = strstr(payload, "data");
  2933. memset(sstr ,0, sizeof(sstr) );
  2934. c = 0;
  2935. while (loc[3+strlen("data")+c] != '\"')
  2936. {
  2937. sstr[c] = loc[3+strlen("data")+c];
  2938. c++;
  2939. }
  2940. sstr[c] = '\0';
  2941. strcpy(dataStr, sstr);
  2942. return result;
  2943. }
  2944. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2945. {
  2946. mtrace();
  2947. int result = FAIL;
  2948. char message[1000]={0};
  2949. double diff_f = 0.0;
  2950. int diff_i = 0;
  2951. int diffSeconds = 0;
  2952. struct tm tp;
  2953. int TimeZero = FALSE;
  2954. int CompositeScheduleIndex = 0;
  2955. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2956. #if 0
  2957. if(connectorIdInt > 0)
  2958. {
  2959. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2960. {
  2961. TimeZero = TRUE;
  2962. }
  2963. else
  2964. {
  2965. strptime((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2966. }
  2967. }
  2968. else
  2969. {
  2970. if((ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule == NULL)||(strcmp((const char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"")==0))
  2971. {
  2972. TimeZero = TRUE;
  2973. }
  2974. else
  2975. {
  2976. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  2977. }
  2978. }
  2979. DEBUG_INFO("ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule=%s\n",ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule);
  2980. #endif
  2981. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2982. {
  2983. TimeZero = TRUE;
  2984. }
  2985. else
  2986. {
  2987. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2988. }
  2989. if(TimeZero == FALSE)
  2990. {
  2991. tp.tm_isdst = -1;
  2992. time_t utc = mktime(&tp);
  2993. time_t t = time(NULL);
  2994. diff_f = difftime(t, utc);
  2995. diff_i = (int)diff_f;
  2996. diffSeconds = diff_i % 86400;//86400 seconds/day
  2997. }
  2998. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2999. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3000. #if 0 //remove temporally
  3001. 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}"
  3002. ,MESSAGE_TYPE_CALLRESULT
  3003. ,uuid
  3004. ,payload
  3005. ,connectorIdInt
  3006. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3007. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3008. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3009. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3010. #endif
  3011. if(nPeriod == 0)
  3012. {
  3013. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3014. ,MESSAGE_TYPE_CALLRESULT
  3015. ,uuid
  3016. ,payload
  3017. ,connectorIdInt
  3018. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3019. }
  3020. else
  3021. {
  3022. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3023. ,MESSAGE_TYPE_CALLRESULT
  3024. ,uuid
  3025. ,payload
  3026. ,connectorIdInt
  3027. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3028. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3029. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3030. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3031. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3032. #if 1 // remove temporally
  3033. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3034. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  3035. {
  3036. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3037. , 0
  3038. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3039. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3040. }
  3041. else
  3042. {
  3043. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3044. {
  3045. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) || (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  3046. {
  3047. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3048. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3049. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3050. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3051. }
  3052. else
  3053. {
  3054. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3055. , (((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*/))
  3056. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3057. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3058. }
  3059. }
  3060. }
  3061. #endif
  3062. sprintf(message + strlen(message), "]}}]");
  3063. }
  3064. LWS_Send(message);
  3065. result = TRUE;
  3066. return result;
  3067. }
  3068. int sendGetConfigurationConfirmation(char *uuid)
  3069. {
  3070. mtrace();
  3071. int result = FAIL;
  3072. int MaxKeySupported = 0;
  3073. int sentConfigurationNumber= 0;
  3074. int sentunConfigurationNumber= 0;
  3075. char message[4000]={0};
  3076. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3077. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3078. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3079. ,MESSAGE_TYPE_CALLRESULT
  3080. ,uuid );
  3081. //configuration key
  3082. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3083. {
  3084. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3085. {
  3086. if (sentConfigurationNumber == 0)
  3087. {
  3088. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3089. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3090. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3091. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3092. }
  3093. else
  3094. {
  3095. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3096. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3097. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3098. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3099. }
  3100. sentConfigurationNumber = sentConfigurationNumber + 1;
  3101. }
  3102. }
  3103. sprintf(message + strlen(message), "]");
  3104. if(UnknownKeynum != 0)
  3105. {
  3106. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3107. //unkown key
  3108. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3109. {
  3110. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3111. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3112. if(sentunConfigurationNumber == 0)
  3113. {
  3114. sprintf(message + strlen(message), "\"%s\""
  3115. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3116. }
  3117. else
  3118. {
  3119. sprintf(message + strlen(message), ",\"%s\""
  3120. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3121. }
  3122. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3123. }
  3124. sprintf(message + strlen(message), "]");
  3125. }
  3126. sprintf(message + strlen(message), "} ]");
  3127. LWS_Send(message);
  3128. #if 0
  3129. printf("error 1-0\n");
  3130. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3131. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3132. #endif
  3133. return result;
  3134. }
  3135. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3136. {
  3137. mtrace();
  3138. int result = FAIL;
  3139. char message[400]={0};
  3140. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3141. if(strcmp(payload,"")==0)
  3142. {
  3143. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3144. }
  3145. else
  3146. {
  3147. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3148. }
  3149. LWS_Send(message);
  3150. result = TRUE;
  3151. return result;
  3152. }
  3153. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3154. {
  3155. mtrace();
  3156. int result = FAIL;
  3157. char message[80]={0};
  3158. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3159. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3160. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3161. LWS_Send(message);
  3162. result = TRUE;
  3163. return result;
  3164. }
  3165. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3166. {
  3167. mtrace();
  3168. int result = FAIL;
  3169. char message[80]={0};
  3170. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3171. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3172. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3173. LWS_Send(message);
  3174. result = TRUE;
  3175. return result;
  3176. }
  3177. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3178. {
  3179. mtrace();
  3180. int result = FAIL;
  3181. char message[80]={0};
  3182. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3183. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3184. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3185. LWS_Send(message);
  3186. result = TRUE;
  3187. return result;
  3188. }
  3189. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3190. {
  3191. mtrace();
  3192. int result = FAIL;
  3193. char message[80]={0};
  3194. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3195. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3196. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3197. LWS_Send(message);
  3198. result = TRUE;
  3199. return result;
  3200. }
  3201. int sendResetConfirmation(char *uuid,char *payload)
  3202. {
  3203. mtrace();
  3204. int result = FAIL;
  3205. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3206. char message[80]={0};
  3207. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3208. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3209. LWS_Send(message);
  3210. result = TRUE;
  3211. return result;
  3212. }
  3213. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3214. {
  3215. mtrace();
  3216. int result = FAIL;
  3217. char message[500]={0};
  3218. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3219. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3220. LWS_Send(message);
  3221. result = TRUE;
  3222. return result;
  3223. }
  3224. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3225. {
  3226. mtrace();
  3227. int result = FAIL;
  3228. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3229. char message[80]={0};
  3230. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  3231. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3232. LWS_Send(message);
  3233. result = TRUE;
  3234. return result;
  3235. }
  3236. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3237. {
  3238. mtrace();
  3239. int result = FAIL;
  3240. char message[80]={0};
  3241. DEBUG_ERROR("sendTriggerMessageConfirmation\n");
  3242. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3243. LWS_Send(message);
  3244. result = TRUE;
  3245. return result;
  3246. }
  3247. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3248. {
  3249. mtrace();
  3250. int result = FAIL;
  3251. char message[80]={0};
  3252. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3253. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  3254. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3255. LWS_Send(message);
  3256. result = TRUE;
  3257. return result;
  3258. }
  3259. int sendUpdateFirmwareConfirmation(char *uuid)
  3260. {
  3261. mtrace();
  3262. int result = FAIL;
  3263. char message[60]={0};
  3264. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3265. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3266. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3267. LWS_Send(message);
  3268. result = TRUE;
  3269. return result;
  3270. }
  3271. //==========================================
  3272. // send CallError routine
  3273. //==========================================
  3274. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3275. {
  3276. mtrace();
  3277. //int result = FAIL;
  3278. char message[220]={0};
  3279. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3280. #ifdef SystemLogMessage
  3281. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3282. uniqueId, action, errorCode, errorDescription);
  3283. #endif
  3284. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3285. LWS_Send(message);
  3286. //result = TRUE;
  3287. }
  3288. //==========================================
  3289. // Handle server request routine Start
  3290. //==========================================
  3291. #define GUN_NUM 1
  3292. int handleCancelReservationRequest(char *uuid, char *payload)
  3293. {
  3294. mtrace();
  3295. int result = FAIL;
  3296. int gunNO = 0;
  3297. int reservationIdInt =0;
  3298. char comfirmstr[20];
  3299. int c = 0;
  3300. char *loc;
  3301. char sstr[100]={0};
  3302. DEBUG_INFO("handle CancelReservationRequest\n");
  3303. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3304. c = 0;
  3305. loc = strstr(payload, "reservationId");
  3306. memset(sstr ,0, sizeof(sstr) );
  3307. while (loc[strlen("reservationId")+2+c] != '}')
  3308. {
  3309. sstr[c] = loc[strlen("reservationId")+2+c];
  3310. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3311. c++;
  3312. }
  3313. sstr[c] = '\0';
  3314. reservationIdInt = atoi(sstr);
  3315. memset(comfirmstr, 0, sizeof comfirmstr);
  3316. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3317. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3318. //check Transaction active
  3319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3320. {
  3321. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3322. {
  3323. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3324. {
  3325. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3326. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3327. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3328. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3329. goto end;
  3330. }
  3331. }
  3332. for (int index = 0; index < CCS_QUANTITY; index++)
  3333. {
  3334. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3335. {
  3336. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3337. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3338. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3339. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3340. goto end;
  3341. }
  3342. }
  3343. for (int index = 0; index < GB_QUANTITY; index++)
  3344. {
  3345. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3346. {
  3347. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3348. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3349. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3350. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3351. goto end;
  3352. }
  3353. }
  3354. }
  3355. else
  3356. {
  3357. for (int index = 0; index < AC_QUANTITY; index++)
  3358. {
  3359. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3360. {
  3361. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3362. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3363. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3364. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3365. goto end;
  3366. }
  3367. }
  3368. }// END FOR AC ELSE
  3369. //The reservationId does NOT match the reservationId
  3370. sendCancelReservationConfirmation(uuid, comfirmstr);
  3371. end:
  3372. // Fill in ocpp packet uuid
  3373. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3374. return result;
  3375. }
  3376. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3377. {
  3378. mtrace();
  3379. int result = FAIL;
  3380. int gunIndex = 0;
  3381. char sstr[90]={0};
  3382. char typeStr[16]={0};
  3383. char comfirmstr[20];
  3384. int specificId = FALSE;
  3385. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3386. char *loc;
  3387. //int intervalInt = 0;
  3388. int c = 0;
  3389. /*** connectorId ****/
  3390. c = 0;
  3391. loc = strstr(payload, "connectorId");
  3392. memset(sstr ,0, sizeof(sstr) );
  3393. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3394. {
  3395. sstr[c] = loc[strlen("connectorId")+2+c];
  3396. c++;
  3397. }
  3398. sstr[c] = '\0';
  3399. gunIndex = atoi(sstr);
  3400. /***type ****/
  3401. loc = strstr(payload, "type");
  3402. memset(sstr ,0, sizeof(sstr) );
  3403. c = 0;
  3404. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3405. {
  3406. sstr[c] = loc[3+strlen("type")+c];
  3407. c++;
  3408. }
  3409. sstr[c] = '\0';
  3410. strcpy(typeStr, sstr);
  3411. if(gunIndex != 0)
  3412. {
  3413. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3414. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3415. }
  3416. else
  3417. {
  3418. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3419. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3420. }
  3421. memset(comfirmstr, 0, sizeof comfirmstr);
  3422. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3423. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3424. {
  3425. specificId = TRUE;
  3426. }
  3427. if(specificId == FALSE)
  3428. goto end;
  3429. if(gunIndex != 0)
  3430. {
  3431. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3432. }
  3433. else
  3434. {
  3435. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3436. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3437. }
  3438. /*
  3439. enum _SYSTEM_STATUS
  3440. {
  3441. S_BOOTING = 0,
  3442. S_IDLE, = 1
  3443. S_AUTHORIZING, =2
  3444. S_REASSIGN_CHECK, =3
  3445. S_REASSIGN, =4
  3446. S_PRECHARGE, =5
  3447. S_PREPARING_FOR_EV, =6
  3448. S_PREPARING_FOR_EVSE, =7
  3449. S_CHARGING, =8
  3450. S_TERMINATING, =9
  3451. S_COMPLETE, =10
  3452. S_ALARM, =11
  3453. S_FAULT =12
  3454. }
  3455. */
  3456. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3457. {
  3458. //check Transaction active
  3459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3460. {
  3461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3462. {
  3463. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3464. {
  3465. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3466. {
  3467. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3468. }
  3469. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3470. {
  3471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3472. }
  3473. else
  3474. {
  3475. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3476. }
  3477. goto end;
  3478. }
  3479. }//END FOR CHAdeMO_QUANTITY
  3480. for (int index = 0; index < CCS_QUANTITY; index++)
  3481. {
  3482. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3483. {
  3484. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3485. {
  3486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3487. }
  3488. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3489. {
  3490. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3491. }
  3492. else
  3493. {
  3494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3495. }
  3496. goto end;
  3497. }
  3498. }//END FOR CCS_QUANTITY
  3499. for (int index = 0; index < GB_QUANTITY; index++)
  3500. {
  3501. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3502. {
  3503. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3504. {
  3505. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3506. }
  3507. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3508. {
  3509. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3510. }
  3511. else
  3512. {
  3513. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3514. }
  3515. goto end;
  3516. }
  3517. }// END FOR GB_QUANTITY
  3518. }
  3519. else
  3520. {
  3521. for (int index = 0; index < AC_QUANTITY; index++)
  3522. {
  3523. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3524. {
  3525. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3526. {
  3527. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3528. }
  3529. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3530. {
  3531. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3532. }
  3533. else
  3534. {
  3535. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3536. }
  3537. goto end;
  3538. }
  3539. }//END FOR AC_QUANTITY
  3540. }// END FOR AC ELSE
  3541. }//END FOR AvailabilityTypeStr[Inoperative]
  3542. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3543. {
  3544. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3545. //check Transaction active
  3546. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3547. {
  3548. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3549. {
  3550. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3551. {
  3552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3553. goto end;
  3554. }
  3555. }//END FOR CHAdeMO_QUANTITY
  3556. for (int index = 0; index < CCS_QUANTITY; index++)
  3557. {
  3558. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3559. {
  3560. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3561. goto end;
  3562. }
  3563. }//END FOR CCS_QUANTITY
  3564. for (int index = 0; index < GB_QUANTITY; index++)
  3565. {
  3566. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3567. {
  3568. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3569. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3570. goto end;
  3571. }
  3572. }// END FOR GB_QUANTITY
  3573. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3574. }
  3575. else
  3576. {
  3577. for (int index = 0; index < AC_QUANTITY; index++)
  3578. {
  3579. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3580. {
  3581. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3582. goto end;
  3583. }
  3584. }//END FOR CHAdeMO_QUANTITY
  3585. }//END FOR AC ELSE
  3586. }//END FOR AvailabilityTypeStr[Operative]
  3587. end:
  3588. if(gunIndex != 0)
  3589. {
  3590. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3591. }
  3592. else
  3593. {
  3594. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3595. }
  3596. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3597. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3598. return result;
  3599. }
  3600. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3601. {
  3602. mtrace();
  3603. int result = FAIL;
  3604. char sstr[100]={0};
  3605. char keystr[40]={0};
  3606. char valuestr[16]={0};
  3607. char *loc;
  3608. int c = 0;
  3609. char comfirmstr[20];
  3610. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3611. /***key ****/
  3612. loc = strstr(payload, "key");
  3613. memset(sstr ,0, sizeof(sstr) );
  3614. c = 0;
  3615. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3616. {
  3617. sstr[c] = loc[3+strlen("key")+c];
  3618. c++;
  3619. }
  3620. sstr[c] = '\0';
  3621. strcpy(keystr, sstr);
  3622. /***value ****/
  3623. loc = strstr(payload, "value");
  3624. memset(sstr ,0, sizeof(sstr) );
  3625. c = 0;
  3626. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3627. {
  3628. sstr[c] = loc[3+strlen("value")+c];
  3629. c++;
  3630. }
  3631. sstr[c] = '\0';
  3632. strcpy(valuestr, sstr);
  3633. if((uuid==NULL) || (payload ==NULL) )
  3634. {
  3635. #ifdef Debug
  3636. DEBUG_INFO("payload is null\n");
  3637. #endif
  3638. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3639. }
  3640. else
  3641. {
  3642. int status = setKeyValue(keystr, valuestr);
  3643. switch(status)
  3644. {
  3645. case ConfigurationStatus_Accepted:
  3646. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3647. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3648. break;
  3649. case ConfigurationStatus_Rejected:
  3650. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3651. break;
  3652. case RebootRequired:
  3653. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3654. break;
  3655. case NotSupported:
  3656. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3657. break;
  3658. default:
  3659. break;
  3660. }
  3661. }
  3662. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3663. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3664. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3665. return result;
  3666. }
  3667. int handleClearCacheRequest(char *uuid, char *payload)
  3668. {
  3669. mtrace();
  3670. int result = FAIL;
  3671. char comfirmstr[20];
  3672. int fd;
  3673. char rmFileCmd[100]={0};
  3674. struct stat stats;
  3675. DEBUG_ERROR("handle ClearCacheRequest\n");
  3676. stat("../Storage/OCPP", &stats);
  3677. // Check for directory existence
  3678. if (S_ISDIR(stats.st_mode) == 1)
  3679. {
  3680. //DEBUG_ERROR("\n OCPP directory exist \n");
  3681. }
  3682. else
  3683. {
  3684. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3685. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3686. system(rmFileCmd);
  3687. }
  3688. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3689. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3690. {
  3691. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3692. }
  3693. else
  3694. {
  3695. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3696. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3697. if(log == NULL)
  3698. {
  3699. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3700. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3701. goto end;
  3702. }
  3703. else
  3704. {
  3705. fclose(log);
  3706. }
  3707. }
  3708. fd = open(AuthorizationCache_JSON,O_RDWR);
  3709. if(fd < 0)
  3710. {
  3711. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3712. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3713. }
  3714. else
  3715. {
  3716. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3717. //* 清空? 件 */
  3718. ftruncate(fd,0);
  3719. //* ? 新设置? 件? 移??*/
  3720. lseek(fd,0,SEEK_SET);
  3721. close(fd);
  3722. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3723. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3724. }
  3725. end:
  3726. sendClearCacheConfirmation(uuid, comfirmstr);
  3727. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3728. return result;
  3729. }
  3730. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3731. {
  3732. mtrace();
  3733. int result = FAIL;
  3734. int resultRename;
  3735. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3736. char chargingProfilePurposeStr[26]={0};
  3737. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3738. char tempchargingProfilePurposeStr[26]={0};
  3739. char sstr[160]={0};//sstr[200]={ 0 };
  3740. char str[100]={0};
  3741. int c = 0;
  3742. //int i = 0;
  3743. //char * pch;
  3744. char *loc;
  3745. char fname[200];
  3746. char comfirmstr[20]={0};
  3747. char word[1000]={0};
  3748. int clearflag = FALSE;
  3749. int chargingProfileIdIsNULL = FALSE;
  3750. int connectorIsNULL = FALSE;
  3751. int chargingProfilePurposeIsNULL = FALSE;
  3752. int stackLevelIsNULL = FALSE;
  3753. FILE *fptr1, *fptr2;
  3754. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3755. int n_chargingProfile=0;
  3756. char sLineWord[1060]={0};
  3757. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3758. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3759. //***id ****/
  3760. c = 0;
  3761. loc = strstr(payload, "id");
  3762. memset(sstr ,0, sizeof(sstr) );
  3763. if(loc == NULL)
  3764. {
  3765. chargingProfileIdIsNULL = TRUE;
  3766. }
  3767. else
  3768. {
  3769. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3770. {
  3771. sstr[c] = loc[strlen("id")+2+c];
  3772. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3773. c++;
  3774. }
  3775. sstr[c] = '\0';
  3776. chargingProfileIdInt = atoi(sstr);
  3777. }
  3778. //***connectorId ****/
  3779. c=0;
  3780. loc = strstr(payload, "connectorId");
  3781. memset(sstr ,0, sizeof(sstr) );
  3782. if(loc == NULL)
  3783. {
  3784. connectorIsNULL = TRUE;
  3785. }
  3786. else
  3787. {
  3788. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3789. {
  3790. sstr[c] = loc[strlen("connectorId")+2+c];
  3791. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3792. c++;
  3793. }
  3794. sstr[c] = '\0';
  3795. connectorIdInt = atoi(sstr);
  3796. }
  3797. //***chargingProfilePurpose ****/
  3798. loc = strstr(payload, "chargingProfilePurpose");
  3799. memset(sstr ,0, sizeof(sstr) );
  3800. c = 0;
  3801. if(loc == NULL)
  3802. {
  3803. chargingProfilePurposeIsNULL = TRUE;
  3804. }
  3805. else
  3806. {
  3807. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3808. {
  3809. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3810. c++;
  3811. }
  3812. sstr[c] = '\0';
  3813. strcpy(chargingProfilePurposeStr, sstr);
  3814. }
  3815. //***stackLevel ****/
  3816. c=0;
  3817. loc = strstr(payload, "stackLevel");
  3818. memset(sstr ,0, sizeof(sstr) );
  3819. if(loc == NULL)
  3820. {
  3821. stackLevelIsNULL = TRUE;
  3822. }
  3823. else
  3824. {
  3825. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3826. {
  3827. sstr[c] = loc[strlen("stackLevel")+2+c];
  3828. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3829. c++;
  3830. }
  3831. sstr[c] = '\0';
  3832. stackLevelInt = atoi(sstr);
  3833. }
  3834. if(connectorIsNULL == FALSE)
  3835. {
  3836. switch(connectorIdInt)
  3837. {
  3838. case 0:
  3839. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3840. {
  3841. strcpy(fname, ChargePointMaxProfile_JSON);
  3842. }
  3843. // else
  3844. // {
  3845. // strcpy(fname, TxDefaultProfile_0_JSON);
  3846. // }
  3847. break;
  3848. case 1:
  3849. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3850. {
  3851. strcpy(fname, TxDefaultProfile_1_JSON);
  3852. }
  3853. // else
  3854. // {
  3855. // strcpy(fname, TxProfile_1_JSON);
  3856. // }
  3857. break;
  3858. case 2:
  3859. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3860. {
  3861. strcpy(fname, TxDefaultProfile_2_JSON);
  3862. }
  3863. // else
  3864. // {
  3865. // strcpy(fname, TxProfile_2_JSON);
  3866. // }
  3867. break;
  3868. default:
  3869. strcpy(fname, ChargePointMaxProfile_JSON );
  3870. break;
  3871. }
  3872. }
  3873. else
  3874. {
  3875. strcpy(fname, ChargePointMaxProfile_JSON );
  3876. }
  3877. fptr1 = fopen(fname, "r");
  3878. if (!fptr1)
  3879. {
  3880. //file not exist
  3881. DEBUG_ERROR("Unable to open the input file!!\n");
  3882. fptr1 = fopen(fname, "w+");
  3883. }
  3884. fclose(fptr1);
  3885. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3886. {
  3887. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3888. goto end;
  3889. }
  3890. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3891. {
  3892. //clear the whole contents of a file in C
  3893. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3894. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3895. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3896. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3897. fclose(fopen(TxProfile_1_JSON, "w"));
  3898. fclose(fopen(TxProfile_2_JSON, "w"));
  3899. #if 0
  3900. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3901. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3902. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3903. #endif
  3904. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3905. }
  3906. else
  3907. {
  3908. fptr1 = fopen(fname, "r");
  3909. fptr2 = fopen(temp, "w+");
  3910. while(fscanf(fptr1, "%s", word) != EOF)
  3911. {
  3912. //DEBUG_INFO("word=%s\n",word);
  3913. if(strcmp(word, "chargingProfileId") == 0)
  3914. {
  3915. n_chargingProfile = n_chargingProfile + 1;
  3916. DEBUG_INFO("chargingProfileId Found\n");
  3917. }
  3918. }
  3919. rewind(fptr1);
  3920. //search Charging Profile Element
  3921. //int i= 0;
  3922. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3923. {
  3924. //*************************tempconnectorIdInt*********************************/
  3925. loc = strstr(sLineWord, "connectorId");
  3926. c = 0;
  3927. memset(sstr ,0, sizeof(sstr) );
  3928. while (loc[strlen("connectorId")+2+c] != ',')
  3929. {
  3930. sstr[c] = loc[strlen("connectorId")+2+c];
  3931. c++;
  3932. }
  3933. sstr[c] = '\0';
  3934. tempconnectorIdInt = atoi(sstr);
  3935. //chargingProfileId
  3936. c = 0;
  3937. loc = strstr(sLineWord, "chargingProfileId");
  3938. memset(sstr ,0, sizeof(sstr) );
  3939. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3940. {
  3941. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3942. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3943. c++;
  3944. }
  3945. sstr[c] = '\0';
  3946. tempchargingProfileIdInt = atoi(sstr);
  3947. //stackLevel
  3948. c = 0;
  3949. loc = strstr(sLineWord, "stackLevel");
  3950. memset(sstr ,0, sizeof(sstr) );
  3951. while (loc[strlen("stackLevel")+2+c] != ',')
  3952. {
  3953. sstr[c] = loc[strlen("stackLevel")+2+c];
  3954. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3955. c++;
  3956. }
  3957. sstr[c] = '\0';
  3958. tempstackLevelInt = atoi(sstr);
  3959. c = 0;
  3960. loc = strstr(sLineWord, "chargingProfilePurpose");
  3961. memset(sstr ,0, sizeof(sstr) );
  3962. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3963. {
  3964. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3965. c++;
  3966. }
  3967. sstr[c] = '\0';
  3968. strcpy(tempchargingProfilePurposeStr, sstr);
  3969. if(chargingProfileIdIsNULL == FALSE)
  3970. {
  3971. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3972. {
  3973. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3974. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3975. clearflag = TRUE;
  3976. continue;
  3977. }
  3978. else
  3979. {
  3980. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3981. //json_object_array_add(newHeatMap, jsonitem);
  3982. fprintf(fptr2, sLineWord);//writing data into file
  3983. }
  3984. }
  3985. else
  3986. {
  3987. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3988. {
  3989. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3990. {
  3991. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3992. clearflag = TRUE;
  3993. continue;
  3994. }
  3995. }
  3996. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3997. {
  3998. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3999. {
  4000. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  4001. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  4002. {
  4003. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4004. clearflag = TRUE;
  4005. continue;
  4006. }
  4007. }
  4008. }
  4009. else
  4010. {
  4011. //json_object_array_add(newHeatMap, jsonitem);
  4012. fprintf(fptr2, sLineWord);//writing data into file
  4013. }
  4014. }
  4015. memset(sLineWord, 0, sizeof sLineWord);
  4016. }
  4017. if(clearflag == FALSE)
  4018. {
  4019. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4020. goto end;
  4021. }
  4022. fclose(fptr1);
  4023. fclose(fptr2);
  4024. sprintf(str,"rm -f %s",fname);
  4025. system(str);
  4026. resultRename = rename(temp, fname);
  4027. if(resultRename == 0)
  4028. {
  4029. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4030. }
  4031. else
  4032. {
  4033. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4034. }
  4035. }
  4036. end:
  4037. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4038. return result;
  4039. }
  4040. int handleDataTransferRequest(char *uuid, char *payload)
  4041. {
  4042. mtrace();
  4043. int result = FAIL;
  4044. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4045. char tempvendorId[255]={0};
  4046. char tempmessageId[50]={0};
  4047. char tempdata[50]={0};
  4048. char sstr[160]={0};//sstr[200]={ 0 };
  4049. char message[80]={0};
  4050. int c = 0;
  4051. char *loc;
  4052. DEBUG_INFO("handle DataTransferRequest\n");
  4053. if((uuid != NULL) && (payload != NULL))
  4054. {
  4055. //===============================
  4056. // vendorId
  4057. //===============================
  4058. c = 0;
  4059. loc = strstr(payload, "vendorId");
  4060. while (loc[strlen("vendorId")+3+c] != '\"')
  4061. {
  4062. sstr[c] = loc[strlen("vendorId")+3+c];
  4063. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4064. c++;
  4065. }
  4066. sstr[c] = '\0';
  4067. strcpy(tempvendorId,sstr);
  4068. //===============================
  4069. // messageId
  4070. //===============================
  4071. memset(sstr ,0, sizeof(sstr) );
  4072. c = 0;
  4073. loc = strstr(payload, "messageId");
  4074. while (loc[strlen("messageId")+3+c] != '\"')
  4075. {
  4076. sstr[c] = loc[strlen("messageId")+3+c];
  4077. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4078. c++;
  4079. }
  4080. sstr[c] = '\0';
  4081. strcpy(tempmessageId,sstr);
  4082. //===============================
  4083. // data
  4084. //===============================
  4085. memset(sstr ,0, sizeof(sstr) );
  4086. c = 0;
  4087. loc = strstr(payload, "data");
  4088. printf("loc=%s\n",loc);
  4089. while (loc[strlen("data")+3+c] != '\"')
  4090. {
  4091. sstr[c] = loc[strlen("data")+3+c];
  4092. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4093. c++;
  4094. }
  4095. sstr[c] = '\0';
  4096. strcpy(tempdata,sstr);
  4097. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4098. }
  4099. else
  4100. {
  4101. char guid[37]={0};
  4102. random_uuid(guid);
  4103. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4104. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4105. }
  4106. LWS_Send(message);
  4107. return result;
  4108. }
  4109. #if 0
  4110. long long diff_tm(struct tm *a, struct tm *b) {
  4111. return a->tm_sec - b->tm_sec
  4112. + 60LL * (a->tm_min - b->tm_min)
  4113. + 3600LL * (a->tm_hour - b->tm_hour)
  4114. + 86400LL * (a->tm_yday - b->tm_yday)
  4115. + (a->tm_year - 70) * 31536000LL
  4116. - (a->tm_year - 69) / 4 * 86400LL
  4117. + (a->tm_year - 1) / 100 * 86400LL
  4118. - (a->tm_year + 299) / 400 * 86400LL
  4119. - (b->tm_year - 70) * 31536000LL
  4120. + (b->tm_year - 69) / 4 * 86400LL
  4121. - (b->tm_year - 1) / 100 * 86400LL
  4122. + (b->tm_year + 299) /400 * 86400LL;
  4123. }
  4124. #endif
  4125. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4126. {
  4127. mtrace();
  4128. int result = FAIL;
  4129. int connectorIdInt, durationInt;
  4130. char chargingRateUnitStr[4]={0};
  4131. //int tempconnectorIdInt,
  4132. int tempdurationInt;
  4133. float tempminChargingRateFloat = 0.0;
  4134. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4135. int tempStartPeriodInt=0;
  4136. float tempLimitInt=0.0;//0.1;
  4137. int tempNumberPhasesInt=0;
  4138. char fname[200];
  4139. char comfirmstr[20];
  4140. //float totallimit =0.0;
  4141. float MinChargingRate =0.0;
  4142. double diff_t;
  4143. struct tm tp;
  4144. //int clearflag = FALSE;
  4145. FILE *fptr1;//, *fptr2;
  4146. //char temp[] = "../Storage/OCPP/temp.json";
  4147. int c = 0;
  4148. //int i = 0;
  4149. char * pch;
  4150. char *loc;
  4151. char sstr[200]={ 0 };
  4152. int n_chargingProfile = 0;
  4153. int n_SchedulePeriods = 0;
  4154. char SchedulePeriodList[10][200]={0};
  4155. char sLineWord[800]={0};
  4156. //int n_periods = 0;
  4157. char word[1000]={0};
  4158. int confirmPeriods = 0;
  4159. struct StructProfile ChargePointMaxProfile;
  4160. struct StructProfile TxDefaultProfile;
  4161. struct StructProfile TxProfile;
  4162. struct StructProfile TxDefaultProfiletemp[2]={0};
  4163. int TxDefaultProfileFileIsNull=FALSE;
  4164. int ChargePointMaxProfileIsNull=FALSE;
  4165. int TxProfileIsNull=FALSE;
  4166. int CompositeSceduleIndex = 0;
  4167. char ChargePointMaxProfileScheduleStr[30]={0};
  4168. char TxDefaultProfileScheduleStr[30]={0};
  4169. char TxProfileScheduleStr[30]={0};
  4170. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4171. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4172. memset(&TxProfile,0,sizeof(struct StructProfile));
  4173. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4174. c=0;
  4175. loc = strstr(payload, "connectorId");
  4176. memset(sstr ,0, sizeof(sstr) );
  4177. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4178. {
  4179. sstr[c] = loc[strlen("connectorId")+2+c];
  4180. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4181. c++;
  4182. }
  4183. sstr[c] = '\0';
  4184. connectorIdInt = atoi(sstr);
  4185. c=0;
  4186. loc = strstr(payload, "duration");
  4187. memset(sstr ,0, sizeof(sstr) );
  4188. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4189. {
  4190. sstr[c] = loc[strlen("duration")+2+c];
  4191. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4192. c++;
  4193. }
  4194. sstr[c] = '\0';
  4195. durationInt = atoi(sstr);
  4196. c = 0;
  4197. loc = strstr(payload, "chargingRateUnit");
  4198. memset(sstr ,0, sizeof(sstr) );
  4199. if(loc == NULL)
  4200. {
  4201. }
  4202. else
  4203. {
  4204. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4205. {
  4206. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4207. c++;
  4208. }
  4209. sstr[c] = '\0';
  4210. strcpy(chargingRateUnitStr, sstr);
  4211. }
  4212. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4213. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4214. if(connectorIdInt==0) // connectorId is 0
  4215. {
  4216. //******************************ChargePointMaxProfile*****************************************************/
  4217. strcpy(fname, ChargePointMaxProfile_JSON );
  4218. char word[30]={0};
  4219. char sLineWord[1060]={0};
  4220. int n_chargingProfile=0;
  4221. ChargePointMaxProfileIsNull=TRUE;
  4222. if((access(fname,F_OK))!=-1)
  4223. {
  4224. fptr1 = fopen(fname, "r");
  4225. int c;
  4226. c = fgetc(fptr1);
  4227. //DEBUG_INFO("c:%d\n",c);
  4228. rewind(fptr1);
  4229. if(c == EOF)
  4230. {
  4231. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4232. ChargePointMaxProfileIsNull=TRUE;
  4233. fclose(fptr1);
  4234. }
  4235. else
  4236. {
  4237. ChargePointMaxProfileIsNull=FALSE;
  4238. while(fscanf(fptr1, "%s", word) != EOF)
  4239. {
  4240. if(strcmp(word, "chargingProfileId") == 0)
  4241. {
  4242. n_chargingProfile = n_chargingProfile + 1;
  4243. printf("Found\n");
  4244. }
  4245. }
  4246. rewind(fptr1);
  4247. //search Charging Profile Element
  4248. int i= 0;
  4249. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4250. #if 0
  4251. /***********connectorId****************/
  4252. c = 0;
  4253. loc = strstr(sLineWord, "connectorId");
  4254. // printf("loc=%s\n",loc);
  4255. memset(sstr ,0, sizeof(sstr) );
  4256. while (loc[strlen("connectorId")+2+c] != ',')
  4257. {
  4258. sstr[c] = loc[strlen("connectorId")+2+c];
  4259. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4260. c++;
  4261. }
  4262. sstr[c] = '\0';
  4263. tempconnectorIdInt = atoi(sstr);
  4264. #endif
  4265. //***********validFrom**************/
  4266. c = 0;
  4267. loc = strstr(sLineWord, "validFrom");
  4268. //DEBUG_INFO("loc=%s\n",loc);
  4269. memset(sstr ,0, sizeof(sstr) );
  4270. if(loc != NULL)
  4271. {
  4272. while (loc[3+strlen("validFrom")+c] != '\"')
  4273. {
  4274. sstr[c] = loc[3+strlen("validFrom")+c];
  4275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4276. c++;
  4277. }
  4278. sstr[c] = '\0';
  4279. DEBUG_INFO("validFrom=%s\n",sstr);
  4280. strcpy(tempvalidFromStr,sstr);
  4281. }
  4282. else
  4283. {
  4284. strcpy(tempvalidFromStr,"");
  4285. }
  4286. //**********startSchedule**********/
  4287. c = 0;
  4288. loc = strstr(sLineWord, "startSchedule");
  4289. //DEBUG_INFO("loc=%s\n",loc);
  4290. memset(sstr ,0, sizeof(sstr) );
  4291. while (loc[3+strlen("startSchedule")+c] != '\"')
  4292. {
  4293. sstr[c] = loc[3+strlen("startSchedule")+c];
  4294. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4295. c++;
  4296. }
  4297. sstr[c] = '\0';
  4298. strcpy(tempstartScheduleStr, sstr);
  4299. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4300. //**********chargingRateUnit**********/
  4301. c = 0;
  4302. loc = strstr(sLineWord, "chargingRateUnit");
  4303. memset(sstr ,0, sizeof(sstr) );
  4304. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4305. {
  4306. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4307. c++;
  4308. }
  4309. sstr[c] = '\0';
  4310. strcpy(tempchargingRateUnitStr, sstr);
  4311. //**********minChargingRate*******/
  4312. c = 0;
  4313. loc = strstr(sLineWord, "minChargingRate");
  4314. //printf("loc=%s\n",loc);
  4315. if(loc != NULL)
  4316. {
  4317. memset(sstr ,0, sizeof(sstr) );
  4318. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4319. {
  4320. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4321. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4322. c++;
  4323. }
  4324. sstr[c] = '\0';
  4325. tempminChargingRateFloat = atof(sstr);
  4326. }
  4327. else
  4328. {
  4329. tempminChargingRateFloat = 0.0;
  4330. }
  4331. //
  4332. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4333. tp.tm_isdst = -1;
  4334. time_t utc = mktime(&tp);
  4335. // current time
  4336. time_t t = time(NULL);
  4337. diff_t = difftime(t, utc);
  4338. //parsing strings to words
  4339. i = 0;
  4340. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4341. loc = loc+3+strlen("chargingSchedulePeriod");
  4342. pch = strtok(loc ,"{");
  4343. while (pch != NULL)
  4344. {
  4345. strcpy(SchedulePeriodList[i], pch);
  4346. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4347. //printf ("%s\n",pch);
  4348. pch = strtok (NULL, "{");
  4349. i = i + 1;
  4350. }
  4351. n_SchedulePeriods = i;
  4352. for(int i=0;i<n_SchedulePeriods;i++)
  4353. {
  4354. //*************startPeriod****************/
  4355. c = 0;
  4356. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4357. memset(sstr ,0, sizeof(sstr) );
  4358. while (loc[strlen("startPeriod")+2+c] != ',')
  4359. {
  4360. sstr[c] = loc[strlen("startPeriod")+2+c];
  4361. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4362. c++;
  4363. }
  4364. sstr[c] = '\0';
  4365. tempStartPeriodInt = atoi(sstr);
  4366. //*************limit****************/
  4367. c = 0;
  4368. loc = strstr(SchedulePeriodList[i], "limit");
  4369. memset(sstr ,0, sizeof(sstr) );
  4370. while (loc[strlen("limit")+2+c] != ',')
  4371. {
  4372. sstr[c] = loc[strlen("limit")+2+c];
  4373. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4374. c++;
  4375. }
  4376. sstr[c] = '\0';
  4377. tempLimitInt = atof(sstr);
  4378. //*************numberPhases****************/
  4379. c = 0;
  4380. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4381. memset(sstr ,0, sizeof(sstr) );
  4382. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4383. {
  4384. sstr[c] = loc[strlen("numberPhases")+2+c];
  4385. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4386. c++;
  4387. }
  4388. sstr[c] = '\0';
  4389. tempNumberPhasesInt = atoi(sstr);
  4390. ChargePointMaxProfile.Duration = durationInt;
  4391. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4392. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4393. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4394. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4395. }
  4396. if(MinChargingRate < tempminChargingRateFloat)
  4397. MinChargingRate = tempminChargingRateFloat;
  4398. }
  4399. }// End of file ChargingProfile
  4400. } //THE END OF ACCESS ChargePointMaxProfile
  4401. //******************************TxDefaultProfile***********************************************/
  4402. strcpy(fname, TxDefaultProfile_0_JSON);
  4403. memset(word, 0, 30);
  4404. memset(sLineWord, 0, 1060);
  4405. //char word[30]={0};
  4406. //char sLineWord[1060]={0};
  4407. n_chargingProfile=0;
  4408. TxDefaultProfileFileIsNull=TRUE;
  4409. if((access(fname,F_OK))!=-1)
  4410. {
  4411. fptr1 = fopen(fname, "r");
  4412. c = 0;
  4413. c = fgetc(fptr1);
  4414. //DEBUG_INFO("c:%d\n",c);
  4415. rewind(fptr1);
  4416. if(c == EOF)
  4417. {
  4418. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4419. TxDefaultProfileFileIsNull=TRUE;
  4420. fclose(fptr1);
  4421. }
  4422. else
  4423. {
  4424. TxDefaultProfileFileIsNull=FALSE;
  4425. while(fscanf(fptr1, "%s", word) != EOF)
  4426. {
  4427. if(strcmp(word, "chargingProfileId") == 0)
  4428. {
  4429. n_chargingProfile = n_chargingProfile + 1;
  4430. printf("Found\n");
  4431. }
  4432. }
  4433. rewind(fptr1);
  4434. //search Charging Profile Element
  4435. int i= 0;
  4436. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4437. #if 0
  4438. /***********connectorId****************/
  4439. c = 0;
  4440. loc = strstr(sLineWord, "connectorId");
  4441. // printf("loc=%s\n",loc);
  4442. memset(sstr ,0, sizeof(sstr) );
  4443. while (loc[strlen("connectorId")+2+c] != ',')
  4444. {
  4445. sstr[c] = loc[strlen("connectorId")+2+c];
  4446. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4447. c++;
  4448. }
  4449. sstr[c] = '\0';
  4450. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4451. tempconnectorIdInt = atoi(sstr);
  4452. #endif
  4453. //***********validFrom**************/
  4454. c = 0;
  4455. loc = strstr(sLineWord, "validFrom");
  4456. //DEBUG_INFO("loc=%s\n",loc);
  4457. memset(sstr ,0, sizeof(sstr) );
  4458. if(loc != NULL)
  4459. {
  4460. while (loc[3+strlen("validFrom")+c] != '\"')
  4461. {
  4462. sstr[c] = loc[3+strlen("validFrom")+c];
  4463. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4464. c++;
  4465. }
  4466. sstr[c] = '\0';
  4467. DEBUG_INFO("validFrom=%s\n",sstr);
  4468. strcpy(tempvalidFromStr,sstr);
  4469. }
  4470. else
  4471. {
  4472. strcpy(tempvalidFromStr,"");
  4473. }
  4474. //**********startSchedule**********/
  4475. c = 0;
  4476. loc = strstr(sLineWord, "startSchedule");
  4477. //DEBUG_INFO("loc=%s\n",loc);
  4478. memset(sstr ,0, sizeof(sstr) );
  4479. while (loc[3+strlen("startSchedule")+c] != '\"')
  4480. {
  4481. sstr[c] = loc[3+strlen("startSchedule")+c];
  4482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4483. c++;
  4484. }
  4485. sstr[c] = '\0';
  4486. strcpy(tempstartScheduleStr, sstr);
  4487. strcpy(TxDefaultProfileScheduleStr, sstr);
  4488. DEBUG_INFO(" debug 3-1\n");
  4489. //**********chargingRateUnit**********/
  4490. c = 0;
  4491. loc = strstr(sLineWord, "chargingRateUnit");
  4492. memset(sstr ,0, sizeof(sstr) );
  4493. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4494. {
  4495. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4496. c++;
  4497. }
  4498. sstr[c] = '\0';
  4499. strcpy(tempchargingRateUnitStr, sstr);
  4500. //**********minChargingRate*******/
  4501. c = 0;
  4502. loc = strstr(sLineWord, "minChargingRate");
  4503. //printf("loc=%s\n",loc);
  4504. if(loc != NULL)
  4505. {
  4506. memset(sstr ,0, sizeof(sstr) );
  4507. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4508. {
  4509. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4510. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4511. c++;
  4512. }
  4513. sstr[c] = '\0';
  4514. tempminChargingRateFloat = atof(sstr);
  4515. }
  4516. else
  4517. {
  4518. tempminChargingRateFloat = 0.0;
  4519. }
  4520. //
  4521. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4522. tp.tm_isdst = -1;
  4523. time_t utc = mktime(&tp);
  4524. // current time
  4525. time_t t = time(NULL);
  4526. diff_t = difftime(t, utc);
  4527. //parsing strings to words
  4528. i = 0;
  4529. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4530. loc = loc+3+strlen("chargingSchedulePeriod");
  4531. pch = strtok(loc ,"{");
  4532. while (pch != NULL)
  4533. {
  4534. strcpy(SchedulePeriodList[i], pch);
  4535. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4536. //printf ("%s\n",pch);
  4537. pch = strtok (NULL, "{");
  4538. i = i + 1;
  4539. }
  4540. n_SchedulePeriods = i;
  4541. for(int i=0;i<n_SchedulePeriods;i++)
  4542. {
  4543. //*************startPeriod****************/
  4544. c = 0;
  4545. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4546. memset(sstr ,0, sizeof(sstr) );
  4547. while (loc[strlen("startPeriod")+2+c] != ',')
  4548. {
  4549. sstr[c] = loc[strlen("startPeriod")+2+c];
  4550. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4551. c++;
  4552. }
  4553. sstr[c] = '\0';
  4554. tempStartPeriodInt = atoi(sstr);
  4555. //*************limit****************/
  4556. c = 0;
  4557. loc = strstr(SchedulePeriodList[i], "limit");
  4558. memset(sstr ,0, sizeof(sstr) );
  4559. while (loc[strlen("limit")+2+c] != ',')
  4560. {
  4561. sstr[c] = loc[strlen("limit")+2+c];
  4562. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4563. c++;
  4564. }
  4565. sstr[c] = '\0';
  4566. tempLimitInt = atof(sstr);
  4567. //*************numberPhases****************/
  4568. c = 0;
  4569. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4570. memset(sstr ,0, sizeof(sstr) );
  4571. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4572. {
  4573. sstr[c] = loc[strlen("numberPhases")+2+c];
  4574. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4575. c++;
  4576. }
  4577. sstr[c] = '\0';
  4578. tempNumberPhasesInt = atoi(sstr);
  4579. TxDefaultProfile.Duration = durationInt;
  4580. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4581. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4582. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4583. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4584. }
  4585. if(MinChargingRate < tempminChargingRateFloat)
  4586. MinChargingRate = tempminChargingRateFloat;
  4587. }
  4588. }
  4589. }// the end of ACCESS TxDefaultProfile
  4590. // Composite Schedule
  4591. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4592. {
  4593. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4594. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4595. {
  4596. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4597. {
  4598. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4599. }
  4600. else
  4601. {
  4602. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4603. }
  4604. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4605. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4606. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4607. }
  4608. }
  4609. //* Define temporary variables */
  4610. struct tm *gtime;
  4611. time_t now;
  4612. char buf[28];
  4613. /* Read the current system time */
  4614. time(&now);
  4615. /* Convert the system time to GMT (now UTC) */
  4616. gtime = gmtime(&now);
  4617. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4618. // make .conf
  4619. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4620. //MaxChargingProfilesInstalled is 10
  4621. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4622. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4623. //nPeriod = 1;
  4624. if(chargingRateUnitStr[0] != 0)
  4625. {
  4626. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4627. }
  4628. else
  4629. {
  4630. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4631. }
  4632. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4633. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4634. confirmPeriods = 1;
  4635. }
  4636. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4637. {
  4638. //*****************************ChargePointMaxProfile******************************************/
  4639. strcpy(fname, ChargePointMaxProfile_JSON);
  4640. ChargePointMaxProfileIsNull=TRUE;
  4641. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4642. {
  4643. fptr1 = fopen(fname, "r");
  4644. int c;
  4645. c = fgetc(fptr1);
  4646. //DEBUG_INFO("c:%d\n",c);
  4647. rewind(fptr1);
  4648. if(c == EOF)
  4649. {
  4650. DEBUG_INFO("\n End of file reached.");
  4651. ChargePointMaxProfileIsNull=TRUE;
  4652. fclose(fptr1);
  4653. }
  4654. else
  4655. {
  4656. ChargePointMaxProfileIsNull=FALSE;
  4657. while(fscanf(fptr1, "%s", word) != EOF)
  4658. {
  4659. if(strcmp(word, "chargingProfileId") == 0)
  4660. {
  4661. n_chargingProfile = n_chargingProfile + 1;
  4662. }
  4663. }
  4664. rewind(fptr1);
  4665. //search Charging Profile Element
  4666. int i = 0;
  4667. int j = 0;
  4668. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4669. #if 0
  4670. /***********connectorId****************/
  4671. c = 0;
  4672. loc = strstr(sLineWord, "connectorId");
  4673. memset(sstr ,0, sizeof(sstr) );
  4674. while (loc[strlen("connectorId")+2+c] != ',')
  4675. {
  4676. sstr[c] = loc[strlen("connectorId")+2+c];
  4677. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4678. c++;
  4679. }
  4680. sstr[c] = '\0';
  4681. tempconnectorIdInt = atoi(sstr);
  4682. #endif
  4683. //***********validFrom**************/
  4684. c = 0;
  4685. loc = strstr(sLineWord, "validFrom");
  4686. if(loc != NULL)
  4687. {
  4688. memset(sstr ,0, sizeof(sstr) );
  4689. while (loc[3+strlen("validFrom")+c] != '\"')
  4690. {
  4691. sstr[c] = loc[3+strlen("validFrom")+c];
  4692. c++;
  4693. }
  4694. sstr[c] = '\0';
  4695. strcpy(tempvalidFromStr,sstr);
  4696. }
  4697. else
  4698. {
  4699. strcpy(tempvalidFromStr,"");
  4700. }
  4701. //***********validFrom**************/
  4702. c = 0;
  4703. loc = strstr(sLineWord, "duration");
  4704. if(loc != NULL)
  4705. {
  4706. memset(sstr ,0, sizeof(sstr) );
  4707. while (loc[2+strlen("duration")+c] != ',')
  4708. {
  4709. sstr[c] = loc[2+strlen("duration")+c];
  4710. c++;
  4711. }
  4712. sstr[c] = '\0';
  4713. tempdurationInt = atoi(sstr);
  4714. }
  4715. else
  4716. {
  4717. tempdurationInt = 0;
  4718. }
  4719. //**********startSchedule**********/
  4720. c = 0;
  4721. loc = strstr(sLineWord, "startSchedule");
  4722. memset(sstr ,0, sizeof(sstr) );
  4723. while (loc[3+strlen("startSchedule")+c] != '\"')
  4724. {
  4725. sstr[c] = loc[3+strlen("startSchedule")+c];
  4726. c++;
  4727. }
  4728. sstr[c] = '\0';
  4729. strcpy(tempstartScheduleStr, sstr);
  4730. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4731. //**********chargingRateUnit**********/
  4732. c = 0;
  4733. loc = strstr(sLineWord, "chargingRateUnit");
  4734. memset(sstr ,0, sizeof(sstr) );
  4735. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4736. {
  4737. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4738. c++;
  4739. }
  4740. sstr[c] = '\0';
  4741. strcpy(tempchargingRateUnitStr, sstr);
  4742. //**********minChargingRate*******/
  4743. c = 0;
  4744. loc = strstr(sLineWord, "minChargingRate");
  4745. if(loc != NULL)
  4746. {
  4747. memset(sstr ,0, sizeof(sstr) );
  4748. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4749. {
  4750. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4751. c++;
  4752. }
  4753. sstr[c] = '\0';
  4754. tempminChargingRateFloat = atof(sstr);
  4755. }
  4756. else
  4757. {
  4758. tempminChargingRateFloat = 0.0;
  4759. }
  4760. //
  4761. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4762. tp.tm_isdst = -1;
  4763. time_t utc = mktime(&tp);
  4764. time_t t = time(NULL);
  4765. diff_t = difftime(t, utc);
  4766. DEBUG_INFO("diff_t=%f\n",diff_t);
  4767. DEBUG_INFO(" debug 5 -1\n");
  4768. //parsing strings to words
  4769. i = 0;
  4770. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4771. loc = loc+3+strlen("chargingSchedulePeriod");
  4772. pch = strtok(loc ,"{");
  4773. while (pch != NULL)
  4774. {
  4775. strcpy(SchedulePeriodList[i], pch);
  4776. pch = strtok (NULL, "{");
  4777. i = i + 1;
  4778. }
  4779. n_SchedulePeriods = i;
  4780. for(int i=0;i<n_SchedulePeriods;i++)
  4781. {
  4782. //*************startPeriod****************/
  4783. c = 0;
  4784. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4785. memset(sstr ,0, sizeof(sstr) );
  4786. while (loc[strlen("startPeriod")+2+c] != ',')
  4787. {
  4788. sstr[c] = loc[strlen("startPeriod")+2+c];
  4789. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4790. c++;
  4791. }
  4792. sstr[c] = '\0';
  4793. tempStartPeriodInt = atoi(sstr);
  4794. //*************limit****************/
  4795. c = 0;
  4796. loc = strstr(SchedulePeriodList[i], "limit");
  4797. memset(sstr ,0, sizeof(sstr) );
  4798. while (loc[strlen("limit")+2+c] != ',')
  4799. {
  4800. sstr[c] = loc[strlen("limit")+2+c];
  4801. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4802. c++;
  4803. }
  4804. sstr[c] = '\0';
  4805. tempLimitInt = atof(sstr);
  4806. //*************numberPhases****************/
  4807. c = 0;
  4808. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4809. memset(sstr ,0, sizeof(sstr) );
  4810. while (loc[strlen("numberPhases")+2+c] != '}')
  4811. {
  4812. sstr[c] = loc[strlen("numberPhases")+2+c];
  4813. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4814. c++;
  4815. }
  4816. sstr[c] = '\0';
  4817. tempNumberPhasesInt = atoi(sstr);
  4818. if(j == 0)
  4819. {
  4820. ChargePointMaxProfile.Duration = tempdurationInt;
  4821. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4822. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4823. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4824. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4825. }
  4826. }
  4827. if(MinChargingRate < tempminChargingRateFloat)
  4828. {
  4829. MinChargingRate = tempminChargingRateFloat;
  4830. }
  4831. if(confirmPeriods < n_SchedulePeriods)
  4832. {
  4833. confirmPeriods = n_SchedulePeriods;
  4834. }
  4835. j = j + 1;
  4836. }
  4837. fclose(fptr1);
  4838. }
  4839. }// the end of access file ChargePointMaxProfile
  4840. //****************************TxDefaultProfile************************************************/
  4841. switch(connectorIdInt)
  4842. {
  4843. case 0:
  4844. break;
  4845. case 1:
  4846. strcpy(fname, TxDefaultProfile_1_JSON );
  4847. break;
  4848. case 2:
  4849. strcpy(fname, TxDefaultProfile_2_JSON );
  4850. break;
  4851. default:
  4852. strcpy(fname, TxDefaultProfile_1_JSON );
  4853. break;
  4854. }
  4855. TxDefaultProfileFileIsNull=TRUE;
  4856. if((access(fname,F_OK))!=-1)
  4857. {
  4858. fptr1 = fopen(fname, "r");
  4859. c = 0;
  4860. c = fgetc(fptr1);
  4861. //DEBUG_INFO("c:%d\n",c);
  4862. rewind(fptr1);
  4863. if(c == EOF)
  4864. {
  4865. DEBUG_INFO("\n End of file reached.");
  4866. TxDefaultProfileFileIsNull=TRUE;
  4867. fclose(fptr1);
  4868. }
  4869. else
  4870. {
  4871. TxDefaultProfileFileIsNull=FALSE;
  4872. while(fscanf(fptr1, "%s", word) != EOF)
  4873. {
  4874. if(strcmp(word, "chargingProfileId") == 0)
  4875. {
  4876. n_chargingProfile = n_chargingProfile + 1;
  4877. }
  4878. }
  4879. rewind(fptr1);
  4880. //search Charging Profile Element
  4881. int i = 0;
  4882. int j = 0;
  4883. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4884. #if 0
  4885. /***********connectorId****************/
  4886. c = 0;
  4887. loc = strstr(sLineWord, "connectorId");
  4888. memset(sstr ,0, sizeof(sstr) );
  4889. while (loc[strlen("connectorId")+2+c] != ',')
  4890. {
  4891. sstr[c] = loc[strlen("connectorId")+2+c];
  4892. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4893. c++;
  4894. }
  4895. sstr[c] = '\0';
  4896. tempconnectorIdInt = atoi(sstr);
  4897. #endif
  4898. //***********validFrom**************/
  4899. c = 0;
  4900. loc = strstr(sLineWord, "validFrom");
  4901. if(loc != NULL)
  4902. {
  4903. memset(sstr ,0, sizeof(sstr) );
  4904. while (loc[3+strlen("validFrom")+c] != '\"')
  4905. {
  4906. sstr[c] = loc[3+strlen("validFrom")+c];
  4907. c++;
  4908. }
  4909. sstr[c] = '\0';
  4910. strcpy(tempvalidFromStr,sstr);
  4911. }
  4912. else
  4913. {
  4914. strcpy(tempvalidFromStr,"");
  4915. }
  4916. //***********validFrom**************/
  4917. c = 0;
  4918. loc = strstr(sLineWord, "duration");
  4919. if(loc != NULL)
  4920. {
  4921. memset(sstr ,0, sizeof(sstr) );
  4922. while (loc[2+strlen("duration")+c] != ',')
  4923. {
  4924. sstr[c] = loc[2+strlen("duration")+c];
  4925. c++;
  4926. }
  4927. sstr[c] = '\0';
  4928. tempdurationInt = atoi(sstr);
  4929. }
  4930. else
  4931. {
  4932. tempdurationInt = 0;
  4933. }
  4934. //**********startSchedule**********/
  4935. c = 0;
  4936. loc = strstr(sLineWord, "startSchedule");
  4937. memset(sstr ,0, sizeof(sstr) );
  4938. while (loc[3+strlen("startSchedule")+c] != '\"')
  4939. {
  4940. sstr[c] = loc[3+strlen("startSchedule")+c];
  4941. c++;
  4942. }
  4943. sstr[c] = '\0';
  4944. strcpy(tempstartScheduleStr, sstr);
  4945. strcpy(TxDefaultProfileScheduleStr, sstr);
  4946. //**********chargingRateUnit**********/
  4947. c = 0;
  4948. loc = strstr(sLineWord, "chargingRateUnit");
  4949. memset(sstr ,0, sizeof(sstr) );
  4950. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4951. {
  4952. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4953. c++;
  4954. }
  4955. sstr[c] = '\0';
  4956. strcpy(tempchargingRateUnitStr, sstr);
  4957. //**********minChargingRate*******/
  4958. c = 0;
  4959. loc = strstr(sLineWord, "minChargingRate");
  4960. if(loc != NULL)
  4961. {
  4962. memset(sstr ,0, sizeof(sstr) );
  4963. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4964. {
  4965. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4966. c++;
  4967. }
  4968. sstr[c] = '\0';
  4969. tempminChargingRateFloat = atof(sstr);
  4970. }
  4971. else
  4972. {
  4973. tempminChargingRateFloat = 0.0;
  4974. }
  4975. //
  4976. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4977. tp.tm_isdst = -1;
  4978. time_t utc = mktime(&tp);
  4979. time_t t = time(NULL);
  4980. diff_t = difftime(t, utc);
  4981. DEBUG_INFO("diff_t=%f\n",diff_t);
  4982. //parsing strings to words
  4983. i = 0;
  4984. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4985. loc = loc+3+strlen("chargingSchedulePeriod");
  4986. pch = strtok(loc ,"{");
  4987. while (pch != NULL)
  4988. {
  4989. strcpy(SchedulePeriodList[i], pch);
  4990. pch = strtok (NULL, "{");
  4991. i = i + 1;
  4992. }
  4993. n_SchedulePeriods = i;
  4994. for(int i=0;i<n_SchedulePeriods;i++)
  4995. {
  4996. //*************startPeriod****************/
  4997. c = 0;
  4998. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4999. memset(sstr ,0, sizeof(sstr) );
  5000. while (loc[strlen("startPeriod")+2+c] != ',')
  5001. {
  5002. sstr[c] = loc[strlen("startPeriod")+2+c];
  5003. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5004. c++;
  5005. }
  5006. sstr[c] = '\0';
  5007. tempStartPeriodInt = atoi(sstr);
  5008. //*************limit****************/
  5009. c = 0;
  5010. loc = strstr(SchedulePeriodList[i], "limit");
  5011. memset(sstr ,0, sizeof(sstr) );
  5012. while (loc[strlen("limit")+2+c] != ',')
  5013. {
  5014. sstr[c] = loc[strlen("limit")+2+c];
  5015. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5016. c++;
  5017. }
  5018. sstr[c] = '\0';
  5019. tempLimitInt = atof(sstr);
  5020. //*************numberPhases****************/
  5021. c = 0;
  5022. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5023. memset(sstr ,0, sizeof(sstr) );
  5024. while (loc[strlen("numberPhases")+2+c] != '}')
  5025. {
  5026. sstr[c] = loc[strlen("numberPhases")+2+c];
  5027. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5028. c++;
  5029. }
  5030. sstr[c] = '\0';
  5031. tempNumberPhasesInt = atoi(sstr);
  5032. if(j == 0)
  5033. {
  5034. TxDefaultProfile.Duration = tempdurationInt;
  5035. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5036. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5037. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5038. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5039. }
  5040. else
  5041. {
  5042. //other stack level charging Profile
  5043. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5044. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5045. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5046. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5047. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5048. }
  5049. }
  5050. if(MinChargingRate < tempminChargingRateFloat)
  5051. MinChargingRate = tempminChargingRateFloat;
  5052. if(confirmPeriods < n_SchedulePeriods)
  5053. confirmPeriods = n_SchedulePeriods;
  5054. j = j + 1;
  5055. }
  5056. fclose(fptr1);
  5057. //Stacking Charging Profiles
  5058. for(int l=0; l <(j-1) ;l++)
  5059. {
  5060. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5061. {
  5062. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5063. {
  5064. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5065. {
  5066. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5067. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5068. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5069. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5070. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5071. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5072. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5073. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5074. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5075. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5076. }
  5077. else
  5078. {
  5079. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5080. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5081. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5082. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5083. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5084. }
  5085. }
  5086. }
  5087. }
  5088. //end of Stacking Charging Profiles
  5089. }
  5090. }// the end of ACCESS TxDefaultProfile
  5091. //****************************TxProfile************************************************/
  5092. switch(connectorIdInt)
  5093. {
  5094. case 0:
  5095. break;
  5096. case 1:
  5097. strcpy(fname, TxProfile_1_JSON );
  5098. break;
  5099. case 2:
  5100. strcpy(fname, TxProfile_2_JSON );
  5101. break;
  5102. default:
  5103. strcpy(fname, TxProfile_1_JSON );
  5104. break;
  5105. }
  5106. TxProfileIsNull=TRUE;
  5107. if((access(fname,F_OK))!=-1)
  5108. {
  5109. fptr1 = fopen(fname, "r");
  5110. c = 0;
  5111. c = fgetc(fptr1);
  5112. //DEBUG_INFO("c:%d\n",c);
  5113. rewind(fptr1);
  5114. if(c == EOF)
  5115. {
  5116. DEBUG_INFO("\n End of file reached.");
  5117. TxProfileIsNull=TRUE;
  5118. fclose(fptr1);
  5119. }
  5120. else
  5121. {
  5122. TxProfileIsNull=FALSE;
  5123. while(fscanf(fptr1, "%s", word) != EOF)
  5124. {
  5125. if(strcmp(word, "chargingProfileId") == 0)
  5126. {
  5127. n_chargingProfile = n_chargingProfile + 1;
  5128. }
  5129. }
  5130. rewind(fptr1);
  5131. //search Charging Profile Element
  5132. int i= 0;
  5133. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5134. #if 0
  5135. /***********connectorId****************/
  5136. c = 0;
  5137. loc = strstr(sLineWord, "connectorId");
  5138. memset(sstr ,0, sizeof(sstr) );
  5139. while (loc[strlen("connectorId")+2+c] != ',')
  5140. {
  5141. sstr[c] = loc[strlen("connectorId")+2+c];
  5142. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5143. c++;
  5144. }
  5145. sstr[c] = '\0';
  5146. tempconnectorIdInt = atoi(sstr);
  5147. #endif
  5148. //***********validFrom**************/
  5149. c = 0;
  5150. loc = strstr(sLineWord, "validFrom");
  5151. if(loc != NULL)
  5152. {
  5153. memset(sstr ,0, sizeof(sstr) );
  5154. while (loc[3+strlen("validFrom")+c] != '\"')
  5155. {
  5156. sstr[c] = loc[3+strlen("validFrom")+c];
  5157. c++;
  5158. }
  5159. sstr[c] = '\0';
  5160. strcpy(tempvalidFromStr,sstr);
  5161. }
  5162. else
  5163. {
  5164. strcpy(tempvalidFromStr,"");
  5165. }
  5166. //**********startSchedule**********/
  5167. c = 0;
  5168. loc = strstr(sLineWord, "startSchedule");
  5169. memset(sstr ,0, sizeof(sstr) );
  5170. while (loc[3+strlen("startSchedule")+c] != '\"')
  5171. {
  5172. sstr[c] = loc[3+strlen("startSchedule")+c];
  5173. c++;
  5174. }
  5175. sstr[c] = '\0';
  5176. strcpy(tempstartScheduleStr, sstr);
  5177. strcpy(TxProfileScheduleStr, sstr);
  5178. //**********chargingRateUnit**********/
  5179. c = 0;
  5180. loc = strstr(sLineWord, "chargingRateUnit");
  5181. memset(sstr ,0, sizeof(sstr) );
  5182. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5183. {
  5184. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5185. c++;
  5186. }
  5187. sstr[c] = '\0';
  5188. strcpy(tempchargingRateUnitStr, sstr);
  5189. //**********minChargingRate*******/
  5190. c = 0;
  5191. loc = strstr(sLineWord, "minChargingRate");
  5192. if(loc != NULL)
  5193. {
  5194. memset(sstr ,0, sizeof(sstr) );
  5195. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5196. {
  5197. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5198. c++;
  5199. }
  5200. sstr[c] = '\0';
  5201. tempminChargingRateFloat = atof(sstr);
  5202. }
  5203. else
  5204. {
  5205. tempminChargingRateFloat = 0.0;
  5206. }
  5207. //
  5208. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5209. tp.tm_isdst = -1;
  5210. time_t utc = mktime(&tp);
  5211. time_t t = time(NULL);
  5212. diff_t = difftime(t, utc);
  5213. DEBUG_INFO("diff_t=%f\n",diff_t);
  5214. //parsing strings to words
  5215. i = 0;
  5216. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5217. loc = loc+3+strlen("chargingSchedulePeriod");
  5218. pch = strtok(loc ,"{");
  5219. while (pch != NULL)
  5220. {
  5221. strcpy(SchedulePeriodList[i], pch);
  5222. pch = strtok (NULL, "{");
  5223. i = i + 1;
  5224. }
  5225. n_SchedulePeriods = i;
  5226. for(int i=0;i<n_SchedulePeriods;i++)
  5227. {
  5228. //*************startPeriod****************/
  5229. c = 0;
  5230. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5231. memset(sstr ,0, sizeof(sstr) );
  5232. while (loc[strlen("startPeriod")+2+c] != ',')
  5233. {
  5234. sstr[c] = loc[strlen("startPeriod")+2+c];
  5235. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5236. c++;
  5237. }
  5238. sstr[c] = '\0';
  5239. tempStartPeriodInt = atoi(sstr);
  5240. //*************limit****************/
  5241. c = 0;
  5242. loc = strstr(SchedulePeriodList[i], "limit");
  5243. memset(sstr ,0, sizeof(sstr) );
  5244. while (loc[strlen("limit")+2+c] != ',')
  5245. {
  5246. sstr[c] = loc[strlen("limit")+2+c];
  5247. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5248. c++;
  5249. }
  5250. sstr[c] = '\0';
  5251. tempLimitInt = atof(sstr);
  5252. //*************numberPhases****************/
  5253. c = 0;
  5254. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5255. memset(sstr ,0, sizeof(sstr) );
  5256. while (loc[strlen("numberPhases")+2+c] != '}')
  5257. {
  5258. sstr[c] = loc[strlen("numberPhases")+2+c];
  5259. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5260. c++;
  5261. }
  5262. sstr[c] = '\0';
  5263. tempNumberPhasesInt = atoi(sstr);
  5264. TxProfile.Duration = durationInt;
  5265. TxProfile.TotalPeriod = n_SchedulePeriods;
  5266. TxProfile.Period[i].Limit = tempLimitInt;
  5267. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5268. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5269. }
  5270. if(MinChargingRate < tempminChargingRateFloat)
  5271. MinChargingRate = tempminChargingRateFloat;
  5272. if(confirmPeriods < n_SchedulePeriods)
  5273. confirmPeriods = n_SchedulePeriods;
  5274. }
  5275. fclose(fptr1);
  5276. }
  5277. }// the end of ACCESS TxProfile
  5278. //CompositeSchedule
  5279. int period=0;
  5280. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5281. {
  5282. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5283. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5284. {
  5285. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5286. {
  5287. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5288. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5289. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5290. period = period + 1;
  5291. }
  5292. else
  5293. {
  5294. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5295. {
  5296. }
  5297. else
  5298. {
  5299. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5300. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5301. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5302. period = period + 1;
  5303. }
  5304. }
  5305. }
  5306. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5307. {
  5308. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5309. {
  5310. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5311. {
  5312. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5313. }
  5314. else
  5315. {
  5316. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5317. }
  5318. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5319. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5320. period = period + 1;
  5321. }
  5322. }
  5323. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5324. {
  5325. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5326. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5327. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5328. period = period + 1;
  5329. }
  5330. }
  5331. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5332. {
  5333. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5334. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5335. {
  5336. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5337. {
  5338. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5339. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5340. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5341. period = period + 1;
  5342. }
  5343. else
  5344. {
  5345. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5346. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5347. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5348. period = period + 1;
  5349. }
  5350. }
  5351. }
  5352. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5353. {
  5354. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5355. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5356. {
  5357. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5358. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5359. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5360. period = period + 1;
  5361. }
  5362. }
  5363. confirmPeriods = period;
  5364. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5365. //* Define temporary variables */
  5366. struct tm *gtime;
  5367. time_t now;
  5368. char buf[28];
  5369. //* Read the current system time */
  5370. time(&now);
  5371. //* Convert the system time to GMT (now UTC) */
  5372. gtime = gmtime(&now);
  5373. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5374. // make .conf
  5375. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5376. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5377. //DEBUG_INFO(" debug 11\n");
  5378. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5379. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5380. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5381. }
  5382. else
  5383. {
  5384. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5385. }
  5386. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5387. return result;
  5388. }
  5389. int handleGetConfigurationRequest(char *uuid, char *payload)
  5390. {
  5391. mtrace();
  5392. int result = FAIL;
  5393. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5394. //struct json_object *jsonitem;
  5395. int MaxKeySupported = 0;
  5396. int n_keys = 0;
  5397. char requestKey[43][50]={0};
  5398. char search[]="[";
  5399. char sstr[500]={ 0 };
  5400. //int pos;
  5401. int l, c = 0;
  5402. int i = 0;
  5403. char *delim = "\",\"";
  5404. char * pch;
  5405. char *loc = strstr(payload, search);
  5406. //********************* Parsing String ***********************************/
  5407. if(loc == NULL) {
  5408. DEBUG_INFO("no key match in Configuration \n");
  5409. }
  5410. else {
  5411. //pos = loc - payload;
  5412. l = strlen(loc)-4;
  5413. while (c < l)
  5414. {
  5415. sstr[c] = loc[c+2];
  5416. c++;
  5417. }
  5418. sstr[c] = '\0';
  5419. //parsing strings to words
  5420. pch = strtok(sstr,delim);
  5421. if(pch == NULL)
  5422. {
  5423. strcpy(requestKey[0], sstr);
  5424. }
  5425. else
  5426. {
  5427. while (pch != NULL)
  5428. {
  5429. strcpy(requestKey[i], pch);
  5430. pch = strtok (NULL, delim);
  5431. i = i + 1;
  5432. }
  5433. n_keys = i;
  5434. }
  5435. }
  5436. UnknownKeynum = 0;
  5437. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5438. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5439. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5440. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5441. if(n_keys != 0)
  5442. {
  5443. for(int i=0;i<n_keys;i++)
  5444. {
  5445. getKeyValue(requestKey[i]);
  5446. //json_object_put(jsonitem);
  5447. }
  5448. }
  5449. else
  5450. {
  5451. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5452. getKeyValue("");
  5453. }
  5454. processUnkownKey();
  5455. sendGetConfigurationConfirmation(uuid);
  5456. return result;
  5457. }
  5458. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5459. {
  5460. mtrace();
  5461. int result = FAIL;
  5462. //void *ret; //
  5463. char fnamePlusPath[50]="";
  5464. char fname[16]="";
  5465. pthread_t t; // pthread 變數
  5466. time_t rawtime;
  5467. struct tm * timeinfo;
  5468. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5469. system("exec /root/logPackTools 'log' 6");
  5470. //char buffer [128];
  5471. time (&rawtime);
  5472. //printf("%ld\n", rawtime);
  5473. timeinfo = localtime (&rawtime);
  5474. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5475. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5476. if((access(fnamePlusPath,F_OK))!=-1)
  5477. {
  5478. DEBUG_INFO("fnamePlusPath exist.\n");
  5479. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5480. }
  5481. else
  5482. {
  5483. DEBUG_INFO("fnamePlusPath not exist!\n");
  5484. }
  5485. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5486. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5487. pthread_join(t, NULL/*&ret*/);
  5488. return result;
  5489. }
  5490. void* GetDiagnosticsProcess(void* data)
  5491. {
  5492. mtrace();
  5493. int retriesInt=0, retryIntervalInt=0;
  5494. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5495. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5496. 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};
  5497. int port=0;
  5498. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5499. char fname[16]="";
  5500. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5501. int c = 0;
  5502. char *loc;
  5503. int isSuccess = FALSE;
  5504. char ftpbuf[200]={0};
  5505. //char temp[100]={0};
  5506. char * pch;
  5507. // [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"}]
  5508. char *str = (char*) data; // ? ?輸入資 ?
  5509. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5510. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5511. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5512. //****************location*******************/
  5513. c = 0;
  5514. memset(sstr ,0, sizeof(sstr) );
  5515. loc = strstr(str, "location");
  5516. while (loc[3+strlen("location")+c] != '\"')
  5517. {
  5518. sstr[c] = loc[3+strlen("location")+c];
  5519. c++;
  5520. }
  5521. sstr[c] = '\0';
  5522. strcpy(locationstr,sstr);
  5523. if(strcmp(locationstr,"")==0)
  5524. {
  5525. DEBUG_INFO("location is <Empty>!\n");
  5526. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5527. goto end;
  5528. }
  5529. //****************retries*******************/
  5530. c = 0;
  5531. loc = strstr(str, "retries");
  5532. if(loc == NULL)
  5533. {
  5534. retriesIsNULL = TRUE;
  5535. }
  5536. else
  5537. {
  5538. while (loc[strlen("retries")+2+c] != ',')
  5539. {
  5540. sstr[c] = loc[strlen("retries")+2+c];
  5541. c++;
  5542. }
  5543. sstr[c] = '\0';
  5544. retriesInt = atoi(sstr);
  5545. }
  5546. if(retriesIsNULL == TRUE)
  5547. {
  5548. retriesInt = 0;
  5549. }
  5550. //****************retryInterval*******************/
  5551. c = 0;
  5552. loc = strstr(str, "retryInterval");
  5553. if(loc == NULL)
  5554. {
  5555. retryIntervalIsNULL = TRUE;
  5556. }
  5557. else
  5558. {
  5559. while (loc[strlen("retryInterval")+2+c] != ',')
  5560. {
  5561. sstr[c] = loc[strlen("retryInterval")+2+c];
  5562. c++;
  5563. }
  5564. sstr[c] = '\0';
  5565. retryIntervalInt = atoi(sstr);
  5566. }
  5567. //****************startTime*******************/
  5568. c = 0;
  5569. memset(sstr ,0, sizeof(sstr) );
  5570. loc = strstr(str, "startTime");
  5571. if(loc == NULL)
  5572. {
  5573. startTimeIsNULL = TRUE;
  5574. }
  5575. else
  5576. {
  5577. while (loc[3+strlen("startTime")+c] != '\"')
  5578. {
  5579. sstr[c] = loc[3+strlen("startTime")+c];
  5580. c++;
  5581. }
  5582. sstr[c] = '\0';
  5583. strcpy(startTimestr,sstr);
  5584. }
  5585. //****************stopTime*******************/
  5586. c = 0;
  5587. memset(sstr ,0, sizeof(sstr) );
  5588. loc = strstr(str, "stopTime");
  5589. if(loc == NULL)
  5590. {
  5591. stopTimeIsNULL = TRUE;
  5592. }
  5593. else
  5594. {
  5595. while (loc[3+strlen("stopTime")+c] != '\"')
  5596. {
  5597. sstr[c] = loc[3+strlen("stopTime")+c];
  5598. c++;
  5599. }
  5600. sstr[c] = '\0';
  5601. strcpy(stopTimestr,sstr);
  5602. }
  5603. memset(protocol, 0, sizeof(protocol));
  5604. memset(user, 0, sizeof(user) );
  5605. memset(password, 0, sizeof(password));
  5606. memset(host, 0, sizeof(host));
  5607. memset(path, 0, sizeof(path));
  5608. memset(ftppath, 0, sizeof(ftppath));
  5609. memset(host1, 0, sizeof(host1));
  5610. memset(path1, 0, sizeof(path1));
  5611. /*location: ftp://user:password@host:port/path*/
  5612. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5613. // protocol, user, password, host, &port, path);
  5614. #if 0 // remove for temporally
  5615. //zip files in /Storage
  5616. system("exec /root/logPackTools 'log' 6");
  5617. #endif
  5618. // system("exec /root/Module_WebService 'log' 6");
  5619. time_t rawtime;
  5620. struct tm * timeinfo;
  5621. //char buffer [128];
  5622. time (&rawtime);
  5623. //printf("%ld\n", rawtime);
  5624. timeinfo = localtime (&rawtime);
  5625. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5626. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5627. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5628. if((access(fnamePlusPath,F_OK))!=-1)
  5629. {
  5630. DEBUG_INFO("fnamePlusPath exist.\n");
  5631. }
  5632. else
  5633. {
  5634. DEBUG_INFO("fnamePlusPath not exist!\n");
  5635. goto end;
  5636. }
  5637. pch=strchr(locationstr,'@');
  5638. if(pch==NULL)
  5639. {
  5640. sscanf(locationstr,
  5641. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5642. protocol, host, &port, path);
  5643. strcpy(user,"anonymous");
  5644. strcpy(password,"");
  5645. }
  5646. else
  5647. {
  5648. DEBUG_INFO("pch=%s\n", pch);
  5649. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5650. protocol, user, password, host, &port, path);
  5651. }
  5652. if(strcmp(protocol,"ftp")!=0)
  5653. {
  5654. DEBUG_INFO("protocol is not ftp!\n");
  5655. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5656. goto end;
  5657. }
  5658. sscanf(host,"%[^/]%s",host1, path1);
  5659. sprintf(ftppath,"%s", path1);
  5660. DEBUG_INFO("protocol =%s\n",protocol);
  5661. DEBUG_INFO("user =%s\n",user);
  5662. DEBUG_INFO("password =%s\n",password);
  5663. DEBUG_INFO("host1 =%s\n",host1);
  5664. DEBUG_INFO("port =%d\n",port);
  5665. DEBUG_INFO("path1 =%s\n",path1);
  5666. DEBUG_INFO("ftppath=%s\n",ftppath);
  5667. int ftppathlen=strlen(ftppath);
  5668. int i=1;
  5669. char filenametemp[50];
  5670. while(i < ftppathlen)
  5671. {
  5672. int len=ftppathlen-i;
  5673. if(ftppath[len]== 47) // '/' ascll code: 47
  5674. {
  5675. DEBUG_INFO("find '/' all right\n");
  5676. break;
  5677. }
  5678. i=i+1;
  5679. }
  5680. memset(filenametemp, 0, sizeof(filenametemp));
  5681. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5682. filenametemp[i+1] = 0;
  5683. //httpDownLoadFile(host, ftppath, fname);
  5684. memset(ftpbuf, 0, sizeof(ftpbuf));
  5685. if(port == 0)
  5686. port = 21;
  5687. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5688. do{
  5689. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5690. sleep(retryIntervalInt);
  5691. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5692. if(!isSuccess)
  5693. {
  5694. //BulldogUtil.sleepMs(interval*1000);
  5695. DEBUG_INFO("Diagnostics fail.\n");
  5696. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5697. }
  5698. else
  5699. {
  5700. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5701. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5702. //isUpdateRequest = TRUE;
  5703. }
  5704. end:
  5705. // json_object_put(obj);
  5706. DiagnosticsStatusNotificationStatus = 0; //Idle
  5707. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5708. }
  5709. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5710. {
  5711. mtrace();
  5712. int result = FAIL;
  5713. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5714. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5715. {
  5716. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5717. localversion = -1;
  5718. }
  5719. else
  5720. {
  5721. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5722. OCPP_getListVerion();
  5723. }
  5724. //from db.OCPP_getListVerion
  5725. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5726. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5727. sendGetLocalListVersionConfirmation(uuid,"");
  5728. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5729. return result;
  5730. }
  5731. int handleRemoteStartRequest(char *uuid, char *payload)
  5732. {
  5733. mtrace();
  5734. int result = FAIL;
  5735. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5736. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5737. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5738. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5739. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5740. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5741. int chargingSchedulePeriodCount = 0;
  5742. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5743. int c = 0;
  5744. char *loc;
  5745. char comfirmstr[20]={0};
  5746. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5747. if(server_pending == TRUE)
  5748. {
  5749. return 0;
  5750. }
  5751. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5752. //**********connectorId****************/
  5753. c = 0;
  5754. memset(sstr ,0, sizeof(sstr) );
  5755. loc = strstr(payload, "connectorId");
  5756. if(loc == NULL)
  5757. {
  5758. connectorIdIsNULL = TRUE;
  5759. }
  5760. else
  5761. {
  5762. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5763. {
  5764. sstr[c] = loc[strlen("connectorId")+2+c];
  5765. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5766. c++;
  5767. }
  5768. sstr[c] = '\0';
  5769. connectorIdInt = atoi(sstr);
  5770. }
  5771. if(connectorIdIsNULL == TRUE) // need to discussion
  5772. {
  5773. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5774. goto end;
  5775. }
  5776. //****************idTag*******************/
  5777. c = 0;
  5778. memset(sstr ,0, sizeof(sstr) );
  5779. loc = strstr(payload, "idTag");
  5780. while (loc[3+strlen("idTag")+c] != '\"')
  5781. {
  5782. sstr[c] = loc[3+strlen("idTag")+c];
  5783. c++;
  5784. }
  5785. sstr[c] = '\0';
  5786. strcpy(idTagstr,sstr);
  5787. //****************chargingProfile*******************/
  5788. c = 0;
  5789. memset(sstr ,0, sizeof(sstr) );
  5790. loc = strstr(payload, "chargingProfile");
  5791. if(loc == NULL)
  5792. {
  5793. chargingProfileIsNULL = TRUE;
  5794. }
  5795. else
  5796. {
  5797. //****************chargingProfileId*******************/
  5798. c=0;
  5799. loc = strstr(payload, "chargingProfileId");
  5800. memset(sstr ,0, sizeof(sstr) );
  5801. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5802. {
  5803. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5804. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5805. c++;
  5806. }
  5807. sstr[c] = '\0';
  5808. chargingProfileIdInt = atoi(sstr);
  5809. //****************transactionId*******************/
  5810. loc = strstr(payload, "transactionId");
  5811. if(loc == NULL)
  5812. {
  5813. transactionIdIsNULL = TRUE;
  5814. }
  5815. else
  5816. {
  5817. c=0;
  5818. memset(sstr ,0, sizeof(sstr) );
  5819. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5820. {
  5821. sstr[c] = loc[strlen("transactionId")+2+c];
  5822. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5823. c++;
  5824. }
  5825. sstr[c] = '\0';
  5826. transactionIdInt = atoi(sstr);
  5827. }
  5828. //****************stackLevel*******************/
  5829. c=0;
  5830. loc = strstr(payload, "stackLevel");
  5831. memset(sstr ,0, sizeof(sstr) );
  5832. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5833. {
  5834. sstr[c] = loc[strlen("stackLevel")+2+c];
  5835. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5836. c++;
  5837. }
  5838. sstr[c] = '\0';
  5839. stackLevelInt = atoi(sstr);
  5840. //****************chargingProfilePurpose*******************/
  5841. c = 0;
  5842. memset(sstr ,0, sizeof(sstr) );
  5843. loc = strstr(payload, "chargingProfilePurpose");
  5844. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5845. {
  5846. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5847. c++;
  5848. }
  5849. sstr[c] = '\0';
  5850. strcpy(chargingProfilePurposestr,sstr);
  5851. //****************chargingProfileKind*******************/
  5852. c = 0;
  5853. memset(sstr ,0, sizeof(sstr) );
  5854. loc = strstr(payload, "chargingProfileKind");
  5855. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5856. {
  5857. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5858. c++;
  5859. }
  5860. sstr[c] = '\0';
  5861. strcpy(chargingProfileKindstr,sstr);
  5862. //****************recurrencyKind*******************/
  5863. loc = strstr(payload, "recurrencyKind");
  5864. if(loc == NULL)
  5865. {
  5866. recurrencyKindIsNULL = TRUE;
  5867. }
  5868. else
  5869. {
  5870. c = 0;
  5871. memset(sstr ,0, sizeof(sstr) );
  5872. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5873. {
  5874. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5875. c++;
  5876. }
  5877. sstr[c] = '\0';
  5878. strcpy(recurrencyKindstr,sstr);
  5879. }
  5880. //****************validFrom*******************/
  5881. loc = strstr(payload, "validFrom");
  5882. if(loc == NULL)
  5883. {
  5884. validFromIsNULL = TRUE;
  5885. }
  5886. else
  5887. {
  5888. c = 0;
  5889. memset(sstr ,0, sizeof(sstr) );
  5890. while (loc[3+strlen("validFrom")+c] != '\"')
  5891. {
  5892. sstr[c] = loc[3+strlen("validFrom")+c];
  5893. c++;
  5894. }
  5895. sstr[c] = '\0';
  5896. strcpy(validFromstr,sstr);
  5897. }
  5898. //****************validTo*******************/
  5899. loc = strstr(payload, "validTo");
  5900. if(loc == NULL)
  5901. {
  5902. validToIsNULL = TRUE;
  5903. }
  5904. else
  5905. {
  5906. c = 0;
  5907. memset(sstr ,0, sizeof(sstr) );
  5908. while (loc[3+strlen("validTo")+c] != '\"')
  5909. {
  5910. sstr[c] = loc[3+strlen("validTo")+c];
  5911. c++;
  5912. }
  5913. sstr[c] = '\0';
  5914. strcpy(validTostr,sstr);
  5915. }
  5916. //****************chargingSchedule*******************/
  5917. loc = strstr(payload, "chargingSchedule");
  5918. if(loc != NULL)
  5919. {
  5920. //****************duration*******************/
  5921. loc = strstr(payload, "duration");
  5922. if(loc == NULL)
  5923. {
  5924. durationIsNULL = TRUE;
  5925. }
  5926. else
  5927. {
  5928. c=0;
  5929. memset(sstr ,0, sizeof(sstr) );
  5930. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5931. {
  5932. sstr[c] = loc[strlen("duration")+2+c];
  5933. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5934. c++;
  5935. }
  5936. sstr[c] = '\0';
  5937. durationInt = atoi(sstr);
  5938. }
  5939. //****************startSchedule******************/
  5940. loc = strstr(payload, "startSchedule");
  5941. if(loc == NULL)
  5942. {
  5943. startScheduleIsNULL = TRUE;
  5944. }
  5945. else
  5946. {
  5947. c = 0;
  5948. memset(sstr ,0, sizeof(sstr) );
  5949. while (loc[3+strlen("startSchedule")+c] != '\"')
  5950. {
  5951. sstr[c] = loc[3+strlen("startSchedule")+c];
  5952. c++;
  5953. }
  5954. sstr[c] = '\0';
  5955. strcpy(startSchedulestr,sstr);
  5956. }
  5957. //****************chargingRateUnit*******************/
  5958. c = 0;
  5959. memset(sstr ,0, sizeof(sstr) );
  5960. loc = strstr(payload, "chargingRateUnit");
  5961. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5962. {
  5963. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5964. c++;
  5965. }
  5966. sstr[c] = '\0';
  5967. strcpy(chargingRateUnitstr,sstr);
  5968. //****************minChargingRate*******************/
  5969. loc = strstr(payload, "minChargingRate");
  5970. if(loc == NULL)
  5971. {
  5972. minChargingRateIsNULL = TRUE;
  5973. }
  5974. else
  5975. {
  5976. c=0;
  5977. memset(sstr ,0, sizeof(sstr) );
  5978. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5979. {
  5980. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5981. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5982. c++;
  5983. }
  5984. sstr[c] = '\0';
  5985. minChargingRateflaot = atof(sstr);
  5986. }
  5987. //****************chargingSchedulePeriod count*******************/
  5988. int what_len = strlen("startPeriod");
  5989. char *where = payload;
  5990. while ((where = strstr(where, "startPeriod"))) {
  5991. where += what_len;
  5992. chargingSchedulePeriodCount++;
  5993. }
  5994. where = payload;
  5995. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5996. {
  5997. //****************startPeriod*******************/
  5998. c=0;
  5999. loc = strstr(where, "startPeriod");
  6000. memset(sstr ,0, sizeof(sstr) );
  6001. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6002. {
  6003. sstr[c] = loc[strlen("startPeriod")+2+c];
  6004. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6005. c++;
  6006. }
  6007. sstr[c] = '\0';
  6008. startPeriodInt[periodNums] = atoi(sstr);
  6009. //****************limit*******************/
  6010. c=0;
  6011. loc = strstr(where, "limit");
  6012. memset(sstr ,0, sizeof(sstr) );
  6013. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6014. {
  6015. sstr[c] = loc[strlen("limit")+2+c];
  6016. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6017. c++;
  6018. }
  6019. sstr[c] = '\0';
  6020. limitflaot[periodNums] = atof(sstr);
  6021. //****************numberPhases*******************/
  6022. loc = strstr(where, "numberPhases");
  6023. if(loc == NULL)
  6024. {
  6025. numberPhasesIsNULL = TRUE;
  6026. }
  6027. else
  6028. {
  6029. c=0;
  6030. memset(sstr ,0, sizeof(sstr) );
  6031. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6032. {
  6033. sstr[c] = loc[strlen("numberPhases")+2+c];
  6034. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6035. c++;
  6036. }
  6037. sstr[c] = '\0';
  6038. numberPhasesInt[periodNums] = atoi(sstr);
  6039. }
  6040. where = loc;
  6041. }
  6042. }
  6043. }
  6044. /*
  6045. enum _SYSTEM_STATUS
  6046. {
  6047. S_BOOTING = 0,
  6048. S_IDLE, = 1
  6049. S_AUTHORIZING, =2
  6050. S_REASSIGN_CHECK, =3
  6051. S_REASSIGN, =4
  6052. S_PRECHARGE, =5
  6053. S_PREPARING_FOR_EV, =6
  6054. S_PREPARING_FOR_EVSE, =7
  6055. S_CHARGING, =8
  6056. S_TERMINATING, =9
  6057. S_COMPLETE, =10
  6058. S_ALARM, =11
  6059. S_FAULT =12
  6060. }
  6061. */
  6062. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6063. {
  6064. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6065. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6066. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6067. //check Transaction active
  6068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6069. {
  6070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6071. {
  6072. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6073. {
  6074. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6075. {
  6076. //Reserved
  6077. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6078. }
  6079. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6080. {
  6081. //Reserved
  6082. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6083. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6084. goto end;
  6085. }
  6086. else
  6087. {
  6088. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6089. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6090. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6091. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6092. {
  6093. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6094. goto end;
  6095. }
  6096. }//END FOR ELSE
  6097. }
  6098. }// END FOR CHAdeMO_QUANTITY
  6099. for (int index = 0; index < CCS_QUANTITY; index++)
  6100. {
  6101. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6102. {
  6103. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6104. {
  6105. //Reserved
  6106. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6107. }
  6108. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6109. {
  6110. //Reserved
  6111. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6112. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6113. goto end;
  6114. }
  6115. else
  6116. {
  6117. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6118. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6119. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6120. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6121. {
  6122. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6123. goto end;
  6124. }
  6125. }// END FOR ELSE
  6126. }
  6127. }// END FOR CCS_QUANTITY
  6128. for (int index = 0; index < GB_QUANTITY; index++)
  6129. {
  6130. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6131. {
  6132. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6133. {
  6134. //Reserved
  6135. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6136. }
  6137. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6138. {
  6139. //Reserved
  6140. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6141. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6142. goto end;
  6143. }
  6144. else
  6145. {
  6146. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6147. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6148. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6149. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6150. {
  6151. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6152. goto end;
  6153. }
  6154. }// END FOR ELSE
  6155. }
  6156. } // END FOR GB_QUANTITY
  6157. }
  6158. else
  6159. {
  6160. for (int index = 0; index < AC_QUANTITY; index++)
  6161. {
  6162. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6163. {
  6164. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6165. {
  6166. //Reserved
  6167. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6168. }
  6169. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6170. {
  6171. //Reserved
  6172. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6173. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6174. goto end;
  6175. }
  6176. else
  6177. {
  6178. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6179. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6180. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6181. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6182. {
  6183. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6184. goto end;
  6185. }
  6186. }//END FOR ELSE
  6187. }
  6188. }// END FOR AC_QUANTITY
  6189. }
  6190. if(chargingProfileIsNULL == FALSE)
  6191. {
  6192. //ChargingProfile
  6193. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6194. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6195. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6196. if(recurrencyKindIsNULL == FALSE) //OPTION
  6197. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6198. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6199. if(transactionIdIsNULL == FALSE) // OPTION
  6200. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6201. if(validFromIsNULL == FALSE) // OPTION
  6202. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6203. if(validToIsNULL == FALSE) //OPTION
  6204. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6205. //ChargingSchedule
  6206. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6207. if(durationIsNULL == FALSE) //OPTION
  6208. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6209. if(minChargingRateIsNULL == FALSE) //OPTION
  6210. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6211. if(startScheduleIsNULL == FALSE) //OPTION
  6212. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6213. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6214. {
  6215. //ChargingSchedulePeriod
  6216. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6217. if(numberPhasesIsNULL == FALSE)
  6218. {
  6219. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6220. }
  6221. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6222. }
  6223. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6224. {
  6225. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6226. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6227. //memset idTag
  6228. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6229. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6230. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6231. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6232. }
  6233. else
  6234. {
  6235. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6236. }
  6237. }
  6238. else
  6239. {
  6240. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6241. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6242. //memset idTag
  6243. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6244. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6245. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6246. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6247. }
  6248. }
  6249. else
  6250. {
  6251. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6252. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6253. }
  6254. end:
  6255. if(connectorIdIsNULL == FALSE)
  6256. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6257. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6258. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6259. //OCPP send RemoteStartConfirmation by first.
  6260. sendRemoteStartConfirmation(uuid, comfirmstr);
  6261. return result;
  6262. }
  6263. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6264. {
  6265. mtrace();
  6266. int result = FAIL;
  6267. int match = FALSE;
  6268. int GunNO = 0;
  6269. int transactionIdInt=0;
  6270. int transactionIdIsNULL= FALSE;
  6271. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6272. int c = 0;
  6273. char *loc;
  6274. char comfirmstr[20];
  6275. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6276. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6277. if(server_pending == TRUE)
  6278. {
  6279. return 0;
  6280. }
  6281. c=0;
  6282. loc = strstr(payload, "transactionId");
  6283. if(loc == NULL)
  6284. {
  6285. transactionIdIsNULL= TRUE;
  6286. }
  6287. else
  6288. {
  6289. memset(sstr ,0, sizeof(sstr) );
  6290. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6291. {
  6292. sstr[c] = loc[strlen("transactionId")+2+c];
  6293. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6294. c++;
  6295. }
  6296. sstr[c] = '\0';
  6297. transactionIdInt = atoi(sstr);
  6298. }
  6299. if(transactionIdIsNULL == FALSE)
  6300. {
  6301. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6302. {
  6303. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6304. {
  6305. //check Transaction active
  6306. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6307. {
  6308. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6309. {
  6310. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6311. {
  6312. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6313. {
  6314. match = TRUE;
  6315. GunNO = gun_index;
  6316. }
  6317. }
  6318. }// END FOR CHAdeMO_QUANTITY
  6319. for (int index = 0; index < CCS_QUANTITY; index++)
  6320. {
  6321. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6322. {
  6323. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6324. {
  6325. match = TRUE;
  6326. GunNO = gun_index;
  6327. }
  6328. }
  6329. }// END FOR CCS_QUANTITY
  6330. for (int index = 0; index < GB_QUANTITY; index++)
  6331. {
  6332. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6333. {
  6334. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6335. {
  6336. match = TRUE;
  6337. GunNO = gun_index;
  6338. }
  6339. }
  6340. }// END FOR GB_QUANTITY
  6341. }
  6342. else
  6343. {
  6344. for (int index = 0; index < AC_QUANTITY; index++)
  6345. {
  6346. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6347. {
  6348. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6349. {
  6350. match = TRUE;
  6351. GunNO = gun_index;
  6352. }
  6353. }
  6354. }// END FOR CHAdeMO_QUANTITY
  6355. }// END FOR AC ELSE
  6356. }// CHECK IF ResponseTransactionId == transactionIdInt
  6357. }//END FOR
  6358. if( match == TRUE)
  6359. {
  6360. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6361. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6362. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6363. }
  6364. else
  6365. {
  6366. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6367. }
  6368. }
  6369. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6370. return result;
  6371. }
  6372. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6373. {
  6374. mtrace();
  6375. int result = FAIL;
  6376. int connectorIdInt=0, reservationIdInt=0;
  6377. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6378. char comfirmstr[20]={0};
  6379. char sstr[180]={ 0 };
  6380. int c = 0;
  6381. char *loc;
  6382. //char *ptr;
  6383. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6384. //***(1)connectorId ****/
  6385. c=0;
  6386. loc = strstr(payload, "connectorId");
  6387. memset(sstr ,0, sizeof(sstr) );
  6388. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6389. {
  6390. sstr[c] = loc[strlen("connectorId")+2+c];
  6391. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6392. c++;
  6393. }
  6394. sstr[c] = '\0';
  6395. connectorIdInt = atoi(sstr);
  6396. //***(2)expiryDate ****/
  6397. loc = strstr(payload, "expiryDate");
  6398. memset(sstr ,0, sizeof(sstr) );
  6399. c = 0;
  6400. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6401. {
  6402. sstr[c] = loc[3+strlen("expiryDate")+c];
  6403. c++;
  6404. }
  6405. sstr[c] = '\0';
  6406. strcpy(expiryDatestr, sstr);
  6407. //***(3)idTag ****/
  6408. loc = strstr(payload, "idTag");
  6409. memset(sstr ,0, sizeof(sstr) );
  6410. c = 0;
  6411. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6412. {
  6413. sstr[c] = loc[3+strlen("idTag")+c];
  6414. c++;
  6415. }
  6416. sstr[c] = '\0';
  6417. strcpy(idTagstr, sstr);
  6418. //***(4)parentIdTag ****/
  6419. loc = strstr(payload, "parentIdTag");
  6420. memset(sstr ,0, sizeof(sstr) );
  6421. c = 0;
  6422. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6423. {
  6424. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6425. c++;
  6426. }
  6427. sstr[c] = '\0';
  6428. strcpy(parentIdTagstr, sstr);
  6429. //***(5)reservationId ****/
  6430. c=0;
  6431. loc = strstr(payload, "reservationId");
  6432. memset(sstr ,0, sizeof(sstr) );
  6433. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6434. {
  6435. sstr[c] = loc[strlen("reservationId")+2+c];
  6436. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6437. c++;
  6438. }
  6439. sstr[c] = '\0';
  6440. reservationIdInt = atoi(sstr);
  6441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6442. /*
  6443. enum _SYSTEM_STATUS
  6444. {
  6445. S_BOOTING = 0,
  6446. S_IDLE, = 1
  6447. S_AUTHORIZING, =2
  6448. S_REASSIGN_CHECK, =3
  6449. S_REASSIGN, =4
  6450. S_PRECHARGE, =5
  6451. S_PREPARING_FOR_EV, =6
  6452. S_PREPARING_FOR_EVSE, =7
  6453. S_CHARGING, =8
  6454. S_TERMINATING, =9
  6455. S_COMPLETE, =10
  6456. S_ALARM, =11
  6457. S_FAULT =12
  6458. }
  6459. */
  6460. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6461. {
  6462. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6463. goto end;
  6464. }
  6465. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6466. {
  6467. //check Transaction active
  6468. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6469. {
  6470. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6471. {
  6472. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6473. {
  6474. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6475. {
  6476. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6477. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6478. {
  6479. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6480. {
  6481. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6483. }
  6484. 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'))
  6485. {
  6486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6487. }
  6488. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6489. {
  6490. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6491. }
  6492. else
  6493. {
  6494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6495. }
  6496. }
  6497. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6498. {
  6499. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6500. }
  6501. }
  6502. else
  6503. {
  6504. //replace reservation
  6505. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6506. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6507. }
  6508. }
  6509. } // END FOR CHAdeMO_QUANTITY
  6510. for (int index = 0; index < CCS_QUANTITY; index++)
  6511. {
  6512. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6513. {
  6514. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6515. {
  6516. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6517. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6518. {
  6519. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6520. {
  6521. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6522. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6523. }
  6524. 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'))
  6525. {
  6526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6527. }
  6528. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6529. {
  6530. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6531. }
  6532. else
  6533. {
  6534. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6535. }
  6536. }
  6537. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6538. {
  6539. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6540. }
  6541. }
  6542. else
  6543. {
  6544. //replace reservation
  6545. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6547. }
  6548. }
  6549. } // END FOR CCS_QUANTITY
  6550. for (int index = 0; index < GB_QUANTITY; index++)
  6551. {
  6552. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6553. {
  6554. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6555. {
  6556. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6557. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6558. {
  6559. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6560. {
  6561. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6562. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6563. }
  6564. 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'))
  6565. {
  6566. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6567. }
  6568. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6569. {
  6570. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6571. }
  6572. else
  6573. {
  6574. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6575. }
  6576. }
  6577. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6578. {
  6579. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6580. }
  6581. }
  6582. else
  6583. {
  6584. //replace reservation
  6585. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6587. }
  6588. }
  6589. }// END FOR GB_QUANTITY
  6590. }
  6591. else
  6592. {
  6593. for (int index = 0; index < AC_QUANTITY; index++)
  6594. {
  6595. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6596. {
  6597. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6598. {
  6599. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6600. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6601. {
  6602. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6603. {
  6604. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6606. }
  6607. 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'))
  6608. {
  6609. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6610. }
  6611. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6612. {
  6613. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6614. }
  6615. else
  6616. {
  6617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6618. }
  6619. }
  6620. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6621. {
  6622. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6623. }
  6624. }
  6625. else
  6626. {
  6627. //replace reservation
  6628. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6629. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6630. }
  6631. }
  6632. } // END FOR AC_QUANTITY
  6633. }//END FOR AC ELSE
  6634. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6635. }
  6636. else if(connectorIdInt == 0)
  6637. {
  6638. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6639. {
  6640. //check Transaction active
  6641. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6642. {
  6643. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6644. {
  6645. 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'))
  6646. {
  6647. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6648. goto end;
  6649. }
  6650. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6651. {
  6652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6653. goto end;
  6654. }
  6655. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6656. {
  6657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6658. goto end;
  6659. }
  6660. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6661. {
  6662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6663. goto end;
  6664. }
  6665. }
  6666. }// END FOR CHAdeMO_QUANTITY
  6667. for (int index = 0; index < CCS_QUANTITY; index++)
  6668. {
  6669. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6670. {
  6671. 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'))
  6672. {
  6673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6674. }
  6675. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6676. {
  6677. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6678. }
  6679. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6680. {
  6681. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6682. }
  6683. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6684. {
  6685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6686. }
  6687. }
  6688. } // END FOR CCS_QUANTITY
  6689. for (int index = 0; index < GB_QUANTITY; index++)
  6690. {
  6691. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6692. {
  6693. 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'))
  6694. {
  6695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6696. }
  6697. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6698. {
  6699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6700. }
  6701. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6702. {
  6703. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6704. }
  6705. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6706. {
  6707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6708. }
  6709. }
  6710. } // END FOR GB_QUANTITY
  6711. }
  6712. else
  6713. {
  6714. for (int index = 0; index < AC_QUANTITY; index++)
  6715. {
  6716. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6717. {
  6718. 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'))
  6719. {
  6720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6721. goto end;
  6722. }
  6723. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6724. {
  6725. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6726. goto end;
  6727. }
  6728. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6729. {
  6730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6731. goto end;
  6732. }
  6733. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6734. {
  6735. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6736. goto end;
  6737. }
  6738. }
  6739. }// END FOR AC_QUANTITY
  6740. }
  6741. //The connectorId is 0
  6742. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6744. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6745. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6746. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6747. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6748. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6749. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6750. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6751. result = TRUE;
  6752. return result;
  6753. }
  6754. else
  6755. {
  6756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6757. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6758. }
  6759. if(strcmp(comfirmstr,"Accepted") == 0)
  6760. {
  6761. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6762. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6763. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6764. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6765. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6766. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6767. result = TRUE;
  6768. return result;
  6769. }
  6770. end:
  6771. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6772. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6773. return result;
  6774. }
  6775. int handleResetRequest(char *uuid, char *payload)
  6776. {
  6777. mtrace();
  6778. int result = FAIL;
  6779. char sstr[10]={0};
  6780. char typestr[10]={0};
  6781. char comfirmstr[20]={0};
  6782. int c = 0;
  6783. char *loc;
  6784. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6785. DEBUG_INFO("handleResetRequest ...\n");
  6786. loc = strstr(payload, "type");
  6787. memset(sstr ,0, sizeof(sstr) );
  6788. c = 0;
  6789. while (loc[3+strlen("type")+c] != '\"')
  6790. {
  6791. sstr[c] = loc[3+strlen("type")+c];
  6792. c++;
  6793. }
  6794. sstr[c] = '\0';
  6795. strcpy(typestr,sstr);
  6796. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6797. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6798. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6799. {
  6800. //check Transaction active
  6801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6802. {
  6803. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6804. {
  6805. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6806. {
  6807. //0: unplug, 1: Plug-in
  6808. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6809. }
  6810. }
  6811. for (int index = 0; index < CCS_QUANTITY; index++)
  6812. {
  6813. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6814. {
  6815. //0: unplug, 1: Plug-in
  6816. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6817. }
  6818. }
  6819. for (int index = 0; index < GB_QUANTITY; index++)
  6820. {
  6821. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6822. {
  6823. //0: unplug, 1: Plug-in
  6824. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6825. }
  6826. }
  6827. }
  6828. else
  6829. {
  6830. for (int index = 0; index < AC_QUANTITY; index++)
  6831. {
  6832. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6833. {
  6834. //0: unplug, 1: Plug-in
  6835. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6836. }
  6837. }
  6838. }// END FOR AC ELSE
  6839. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6840. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6841. result = TRUE;
  6842. return result;
  6843. }
  6844. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6845. {
  6846. //check Transaction active
  6847. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6848. {
  6849. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6850. {
  6851. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6852. {
  6853. //0: unplug, 1: Plug-in
  6854. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6855. }
  6856. }
  6857. for (int index = 0; index < CCS_QUANTITY; index++)
  6858. {
  6859. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6860. {
  6861. //0: unplug, 1: Plug-in
  6862. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6863. }
  6864. }
  6865. for (int index = 0; index < GB_QUANTITY; index++)
  6866. {
  6867. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6868. {
  6869. //0: unplug, 1: Plug-in
  6870. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6871. }
  6872. }
  6873. }
  6874. else
  6875. {
  6876. for (int index = 0; index < AC_QUANTITY; index++)
  6877. {
  6878. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6879. {
  6880. //0: unplug, 1: Plug-in
  6881. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6882. }
  6883. }
  6884. }// END FOR AC ELSE
  6885. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6886. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6887. result = TRUE;
  6888. return result;
  6889. }
  6890. else
  6891. {
  6892. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6893. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6894. goto errorend;
  6895. }
  6896. errorend:
  6897. sendResetConfirmation(uuid, comfirmstr);
  6898. return result;
  6899. }
  6900. int handleSendLocalListRequest(char *uuid, char *payload)
  6901. {
  6902. mtrace();
  6903. int result = FAIL;
  6904. int listVersionInt;
  6905. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6906. char listsearch[]="listVersion";
  6907. char updateTypesearch[]="updateType";
  6908. char localAuthorizationListsearch[]="localAuthorizationList";
  6909. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6910. char CardList[500][160]={0};
  6911. char updateTypestr[15]={0};
  6912. char idTagstr[20]={0};
  6913. char parentIdTag[20]={0};
  6914. char expiryDate[30]={0};
  6915. char idTagstatus[16]={0};
  6916. int c = 0;
  6917. int i = 0;
  6918. char *delim1 = "}";
  6919. char * pch;
  6920. char *loc;
  6921. //char *ptr;
  6922. char comfirmstr[20];
  6923. //int n_localAuthorizations = 0;
  6924. int checkState_Faulted = FALSE;
  6925. DEBUG_INFO("handleSendLocalListRequest\n");
  6926. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6927. {
  6928. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6929. goto end;
  6930. }
  6931. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6932. {
  6933. //check Charge Point state
  6934. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6935. {
  6936. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6937. {
  6938. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6939. }
  6940. }
  6941. for (int index = 0; index < CCS_QUANTITY; index++)
  6942. {
  6943. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6944. {
  6945. checkState_Faulted = TRUE; //OCPP Status
  6946. }
  6947. }
  6948. for (int index = 0; index < GB_QUANTITY; index++)
  6949. {
  6950. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6951. {
  6952. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6953. }
  6954. }
  6955. }
  6956. else
  6957. {
  6958. //check Charge Point state
  6959. for (int index = 0; index < AC_QUANTITY; index++)
  6960. {
  6961. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6962. {
  6963. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6964. }
  6965. }
  6966. }// END FOR AC ELSE
  6967. if(checkState_Faulted == TRUE)
  6968. {
  6969. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6970. goto end;
  6971. }
  6972. //listVersion
  6973. c = 0;
  6974. loc = strstr(payload, listsearch);
  6975. while (loc[strlen("listVersion")+2+c] != ',')
  6976. {
  6977. sstr[c] = loc[strlen("listVersion")+2+c];
  6978. c++;
  6979. }
  6980. sstr[c] = '\0';
  6981. listVersionInt = atoi(sstr);
  6982. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6983. //updateType
  6984. loc = strstr(payload, updateTypesearch);
  6985. c = 0;
  6986. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6987. {
  6988. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6989. c++;
  6990. }
  6991. sstr[c] = '\0';
  6992. strcpy(updateTypestr, sstr);
  6993. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6994. //localAuthorizationList
  6995. memset(sstr ,0, sizeof(sstr) );
  6996. loc = strstr(payload, localAuthorizationListsearch);
  6997. if(loc != NULL) // localAuthorizationList is not NULL
  6998. {
  6999. //Check UpdateType
  7000. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7001. {
  7002. //Local list full update
  7003. printf("Local list full update.\n");
  7004. OCPP_cleanLocalList();
  7005. }
  7006. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7007. {
  7008. //Local list different update
  7009. printf("Local list different update.\n");
  7010. OCPP_getListVerion();
  7011. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7012. {
  7013. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7014. goto end;
  7015. }
  7016. }
  7017. else
  7018. {
  7019. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7020. goto end;
  7021. }
  7022. c = 0;
  7023. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7024. {
  7025. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7026. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7027. c++;
  7028. }
  7029. sstr[c] = '\0';
  7030. //parsing strings to words
  7031. i = 0;
  7032. pch = strtok(sstr,delim1);
  7033. while (pch != NULL)
  7034. {
  7035. strcpy(CardList[i], pch);
  7036. pch = strtok (NULL, delim1);
  7037. i = i + 1;
  7038. }
  7039. //local Authorizations List Numbers
  7040. //n_localAuthorizations = i;
  7041. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7042. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7043. c= 0;
  7044. while(c < i)
  7045. {
  7046. //Search "IdToken"
  7047. memset(sstr ,0, sizeof(sstr) );
  7048. loc = strstr(CardList[c], "idTag");
  7049. int j = 0;
  7050. while (loc[3+strlen("idTag")+j] != '\"')
  7051. {
  7052. sstr[j] = loc[3+strlen("idTag")+j];
  7053. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7054. j++;
  7055. }
  7056. sstr[j] = '\0';
  7057. strcpy(idTagstr, sstr);
  7058. //Search "expiryDate"
  7059. memset(sstr ,0, sizeof(sstr) );
  7060. loc = strstr(CardList[c], "expiryDate");
  7061. j = 0;
  7062. while (loc[3+strlen("expiryDate")+j] != '\"')
  7063. {
  7064. sstr[j] = loc[3+strlen("expiryDate")+j];
  7065. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7066. j++;
  7067. }
  7068. sstr[j] = '\0';
  7069. strcpy(expiryDate, sstr);
  7070. //Search "parentIdTag"
  7071. memset(sstr ,0, sizeof(sstr) );
  7072. loc = strstr(CardList[c], "parentIdTag");
  7073. j = 0;
  7074. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7075. {
  7076. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7077. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7078. j++;
  7079. }
  7080. sstr[j] = '\0';
  7081. strcpy(parentIdTag, sstr);
  7082. //Search "status"
  7083. memset(sstr ,0, sizeof(sstr) );
  7084. loc = strstr(CardList[c], "status");
  7085. j = 0;
  7086. while (loc[3+strlen("status")+j] != '\"')
  7087. {
  7088. sstr[j] = loc[3+strlen("status")+j];
  7089. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7090. j++;
  7091. }
  7092. sstr[j] = '\0';
  7093. strcpy(idTagstatus, sstr);
  7094. OCPP_getIdTag(idTagstr);
  7095. //OCPP_getIdTag("test"); For Test
  7096. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7097. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7098. {
  7099. //Local list full update
  7100. DEBUG_INFO("Local list full update.\n");
  7101. // update list
  7102. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7103. OCPP_get_TableAuthlocalAllData();
  7104. }
  7105. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7106. {
  7107. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7108. {
  7109. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7110. }
  7111. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7112. {
  7113. OCPP_deleteIdTag(idTagstr);
  7114. }
  7115. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7116. {
  7117. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7118. }
  7119. }
  7120. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7121. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7122. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7123. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7124. c++;
  7125. }
  7126. }
  7127. else
  7128. {
  7129. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7130. {
  7131. //Local list different update
  7132. DEBUG_INFO("Local list different update.\n");
  7133. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7134. goto end;
  7135. }
  7136. }
  7137. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7138. end:
  7139. sendSendLocalListConfirmation(uuid, comfirmstr);
  7140. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7141. #if 0
  7142. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7143. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7144. #endif
  7145. return result;
  7146. }
  7147. /*
  7148. enum _SYSTEM_STATUS
  7149. {
  7150. S_BOOTING = 0,
  7151. S_IDLE, =1
  7152. S_AUTHORIZING, =2
  7153. S_REASSIGN_CHECK, =3
  7154. S_REASSIGN, =4
  7155. S_PRECHARGE, =5
  7156. S_PREPARING_FOR_EV, =6
  7157. S_PREPARING_FOR_EVSE, =7
  7158. S_CHARGING, =8
  7159. S_TERMINATING, =9
  7160. S_COMPLETE, =10
  7161. S_ALARM, =11
  7162. S_FAULT =12
  7163. };
  7164. */
  7165. #define MAX 200
  7166. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7167. {
  7168. mtrace();
  7169. int result = FAIL;
  7170. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7171. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7172. char chargingProfilePurposeStr[30]={0};
  7173. char chargingProfileKindStr[16]={0};
  7174. char recurrencyKindStr[10]={0};
  7175. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7176. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7177. int chargingSchedulePeriodCount = 0;
  7178. //int updateflag = FALSE;
  7179. char comfirmstr[20]={0};
  7180. int meet= FALSE;
  7181. char sstr[10]={0};
  7182. int c = 0;
  7183. char *loc;
  7184. FILE *fptr1;//, *fptr2;
  7185. //int lno=0;//, linectr = 0;
  7186. //int modifyflag = FALSE;
  7187. char filename[MAX]={0};
  7188. char tempfile[] = "../Storage/OCPP/temp.json";
  7189. int resultRename=0;
  7190. char rmFileCmd[50]={0};
  7191. char tempchargingProfilePurposeStr[30]={0};
  7192. //[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}}}]
  7193. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7194. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7195. //*********************connectorId***************************/
  7196. loc = strstr(payload, "connectorId");
  7197. c = 0;
  7198. memset(sstr ,0, sizeof(sstr) );
  7199. while (loc[strlen("connectorId")+2+c] != ',')
  7200. {
  7201. sstr[c] = loc[strlen("connectorId")+2+c];
  7202. c++;
  7203. }
  7204. sstr[c] = '\0';
  7205. connectorIdInt = atoi(sstr);
  7206. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7207. {
  7208. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7209. }
  7210. else
  7211. {
  7212. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7213. }
  7214. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7215. //*********************chargingProfileId***************************/
  7216. loc = strstr(payload, "chargingProfileId");
  7217. c = 0;
  7218. memset(sstr ,0, sizeof(sstr) );
  7219. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7220. {
  7221. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7222. c++;
  7223. }
  7224. sstr[c] = '\0';
  7225. chargingProfileIdInt = atoi(sstr);
  7226. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7227. {
  7228. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7229. }
  7230. else
  7231. {
  7232. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7233. }
  7234. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7235. //*********************transactionId***************************/
  7236. loc = strstr(payload, "transactionId");
  7237. if(loc != NULL)
  7238. {
  7239. c = 0;
  7240. memset(sstr ,0, sizeof(sstr) );
  7241. while (loc[strlen("transactionId")+2+c] != ',')
  7242. {
  7243. sstr[c] = loc[strlen("transactionId")+2+c];
  7244. c++;
  7245. }
  7246. sstr[c] = '\0';
  7247. transactionIdInt = atoi(sstr);
  7248. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7249. {
  7250. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7251. }
  7252. else
  7253. {
  7254. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7255. }
  7256. }
  7257. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7258. //*********************stackLevel***************************/
  7259. loc = strstr(payload, "stackLevel");
  7260. c = 0;
  7261. memset(sstr ,0, sizeof(sstr) );
  7262. while (loc[strlen("stackLevel")+2+c] != ',')
  7263. {
  7264. sstr[c] = loc[strlen("stackLevel")+2+c];
  7265. c++;
  7266. }
  7267. sstr[c] = '\0';
  7268. stackLevelInt = atoi(sstr);
  7269. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7270. {
  7271. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7272. }
  7273. else
  7274. {
  7275. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7276. }
  7277. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7278. //*********************chargingProfilePurpose***************************/
  7279. loc = strstr(payload, "chargingProfilePurpose");
  7280. c = 0;
  7281. memset(sstr ,0, sizeof(sstr) );
  7282. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7283. {
  7284. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7285. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7286. c++;
  7287. }
  7288. sstr[c] = '\0';
  7289. strcpy(chargingProfilePurposeStr,sstr);
  7290. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7291. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7292. {
  7293. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7294. }
  7295. else
  7296. {
  7297. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7298. }
  7299. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7300. //*********************chargingProfileKind***************************/
  7301. loc = strstr(payload, "chargingProfileKind");
  7302. c = 0;
  7303. memset(sstr ,0, sizeof(sstr) );
  7304. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7305. {
  7306. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7307. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7308. c++;
  7309. }
  7310. sstr[c] = '\0';
  7311. strcpy(chargingProfileKindStr,sstr);
  7312. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7313. {
  7314. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7315. }
  7316. else
  7317. {
  7318. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7319. }
  7320. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7321. //*********************recurrencyKind***************************/
  7322. loc = strstr(payload, "recurrencyKind");
  7323. if(loc != NULL)
  7324. {
  7325. c = 0;
  7326. memset(sstr ,0, sizeof(sstr) );
  7327. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7328. {
  7329. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7330. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7331. c++;
  7332. }
  7333. sstr[c] = '\0';
  7334. strcpy(recurrencyKindStr,sstr);
  7335. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7336. {
  7337. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7338. }
  7339. else
  7340. {
  7341. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7342. }
  7343. }
  7344. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7345. //*********************validFrom***************************/
  7346. loc = strstr(payload, "validFrom");
  7347. if(loc != NULL)
  7348. {
  7349. c = 0;
  7350. memset(sstr ,0, sizeof(sstr) );
  7351. while (loc[3+strlen("validFrom")+c] != '\"')
  7352. {
  7353. sstr[c] = loc[3+strlen("validFrom")+c];
  7354. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7355. c++;
  7356. }
  7357. sstr[c] = '\0';
  7358. strcpy(validFromStr,sstr);
  7359. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7360. {
  7361. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7362. }
  7363. else
  7364. {
  7365. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7366. }
  7367. }
  7368. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7369. //*********************validTo***************************/
  7370. loc = strstr(payload, "validTo");
  7371. if(loc != NULL)
  7372. {
  7373. c = 0;
  7374. memset(sstr ,0, sizeof(sstr) );
  7375. while (loc[3+strlen("validTo")+c] != '\"')
  7376. {
  7377. sstr[c] = loc[3+strlen("validTo")+c];
  7378. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7379. c++;
  7380. }
  7381. sstr[c] = '\0';
  7382. strcpy(validToStr,sstr);
  7383. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7384. {
  7385. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7386. }
  7387. else
  7388. {
  7389. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7390. }
  7391. }
  7392. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7393. //*********************duration***************************/
  7394. loc = strstr(payload, "duration");
  7395. if(loc != NULL)
  7396. {
  7397. c = 0;
  7398. memset(sstr ,0, sizeof(sstr) );
  7399. while (loc[strlen("duration")+2+c] != ',')
  7400. {
  7401. sstr[c] = loc[strlen("duration")+2+c];
  7402. c++;
  7403. }
  7404. sstr[c] = '\0';
  7405. durationInt = atoi(sstr);
  7406. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7407. {
  7408. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7409. }
  7410. else
  7411. {
  7412. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7413. }
  7414. }
  7415. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7416. //*********************startSchedule***************************/
  7417. loc = strstr(payload, "startSchedule");
  7418. if(loc != NULL)
  7419. {
  7420. c = 0;
  7421. memset(sstr ,0, sizeof(sstr) );
  7422. while (loc[3+strlen("startSchedule")+c] != '\"')
  7423. {
  7424. sstr[c] = loc[3+strlen("startSchedule")+c];
  7425. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7426. c++;
  7427. }
  7428. sstr[c] = '\0';
  7429. strcpy(startScheduleStr,sstr);
  7430. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7431. {
  7432. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7433. }
  7434. else
  7435. {
  7436. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7437. }
  7438. }
  7439. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7440. //*********************chargingRateUnit***************************/
  7441. loc = strstr(payload, "chargingRateUnit");
  7442. if(loc != NULL)
  7443. {
  7444. c = 0;
  7445. memset(sstr ,0, sizeof(sstr) );
  7446. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7447. {
  7448. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7449. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7450. c++;
  7451. }
  7452. sstr[c] = '\0';
  7453. strcpy(chargingRateUnitStr,sstr);
  7454. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7455. {
  7456. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7457. }
  7458. else
  7459. {
  7460. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7461. }
  7462. }
  7463. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7464. //****************chargingSchedulePeriod count start*******************/
  7465. int what_len = strlen("startPeriod");
  7466. char *where = payload;
  7467. if (what_len)
  7468. while ((where = strstr(where, "startPeriod"))) {
  7469. where += what_len;
  7470. chargingSchedulePeriodCount++;
  7471. }
  7472. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7473. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7474. where = payload;
  7475. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7476. {
  7477. //****************startPeriod*******************/
  7478. c=0;
  7479. loc = strstr(where, "startPeriod");
  7480. memset(sstr ,0, sizeof(sstr) );
  7481. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7482. {
  7483. sstr[c] = loc[strlen("startPeriod")+2+c];
  7484. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7485. c++;
  7486. }
  7487. sstr[c] = '\0';
  7488. startPeriodInt[periodNums] = atoi(sstr);
  7489. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7490. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7491. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7492. {
  7493. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7494. }
  7495. else
  7496. {
  7497. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7498. }
  7499. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7500. //****************limit*******************/
  7501. c=0;
  7502. loc = strstr(where, "limit");
  7503. memset(sstr ,0, sizeof(sstr) );
  7504. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7505. {
  7506. sstr[c] = loc[strlen("limit")+2+c];
  7507. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7508. c++;
  7509. }
  7510. sstr[c] = '\0';
  7511. limitflaot[periodNums] = atof(sstr);
  7512. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7513. {
  7514. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7515. }
  7516. else
  7517. {
  7518. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7519. }
  7520. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7521. //****************numberPhases*******************/
  7522. loc = strstr(where, "numberPhases");
  7523. if(loc != NULL)
  7524. {
  7525. c=0;
  7526. memset(sstr ,0, sizeof(sstr) );
  7527. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7528. {
  7529. sstr[c] = loc[strlen("numberPhases")+2+c];
  7530. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7531. c++;
  7532. }
  7533. sstr[c] = '\0';
  7534. numberPhasesInt[periodNums] = atoi(sstr);
  7535. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7536. {
  7537. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7538. }
  7539. else
  7540. {
  7541. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7542. }
  7543. }
  7544. where = loc;
  7545. }
  7546. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7547. //****************chargingSchedulePeriod count end*******************/
  7548. //*********************minChargingRate***************************/
  7549. loc = strstr(payload, "minChargingRate");
  7550. if(loc != NULL)
  7551. {
  7552. c = 0;
  7553. memset(sstr ,0, sizeof(sstr) );
  7554. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7555. {
  7556. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7557. c++;
  7558. }
  7559. sstr[c] = '\0';
  7560. minChargingRateFloat = atof(sstr);
  7561. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7562. {
  7563. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7564. }
  7565. else
  7566. {
  7567. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7568. }
  7569. }
  7570. DEBUG_INFO("\n\n Replace a specific line in a text file with a new text :\n");
  7571. DEBUG_INFO("-------------------------------------------------------------\n");
  7572. DEBUG_INFO(" Input the file name to be opened : ");
  7573. //fgets(fname, MAX, stdin);
  7574. //fname[strlen(fname) - 1] = '\0';
  7575. #if 0
  7576. switch(connectorIdInt)
  7577. {
  7578. case 0:
  7579. strcpy(filename, ChargingProfile_0_JSON );
  7580. break;
  7581. case 1:
  7582. strcpy(filename, ChargingProfile_1_JSON );
  7583. break;
  7584. case 2:
  7585. strcpy(filename, ChargingProfile_2_JSON );
  7586. break;
  7587. default:
  7588. strcpy(filename, ChargingProfile_0_JSON );
  7589. break;
  7590. }
  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. #endif
  7600. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7601. //DEBUG_INFO(" ChargingProfilePurposeTypeStr[TxProfile]=%s\n", ChargingProfilePurposeTypeStr[TxProfile]);
  7602. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7603. {
  7604. //printf("set chargingProfile 1-2\n");
  7605. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7606. if(connectorIdInt != 0)
  7607. {
  7608. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7609. goto end;
  7610. }
  7611. strcpy(filename, ChargePointMaxProfile_JSON );
  7612. fptr1 = fopen(filename, "r");
  7613. if (!fptr1)
  7614. {
  7615. //file not exist
  7616. DEBUG_INFO("Unable to open the input file!!\n");
  7617. fptr1 = fopen(filename, "w+");
  7618. }
  7619. fclose(fptr1);
  7620. }
  7621. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7622. {
  7623. //printf("set chargingProfile 1-3\n");
  7624. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7625. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7626. {
  7627. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7628. goto end;
  7629. }
  7630. switch(connectorIdInt)
  7631. {
  7632. case 0:
  7633. strcpy(filename, TxDefaultProfile_0_JSON );
  7634. break;
  7635. case 1:
  7636. strcpy(filename, TxDefaultProfile_1_JSON );
  7637. break;
  7638. case 2:
  7639. strcpy(filename, TxDefaultProfile_2_JSON );
  7640. break;
  7641. default:
  7642. strcpy(filename, TxDefaultProfile_0_JSON );
  7643. break;
  7644. }
  7645. fptr1 = fopen(filename, "r");
  7646. if (!fptr1)
  7647. {
  7648. //file not exist
  7649. DEBUG_INFO("Unable to open the input file!!\n");
  7650. fptr1 = fopen(filename, "w+");
  7651. }
  7652. fclose(fptr1);
  7653. }
  7654. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7655. {
  7656. //printf("set chargingProfile 1-4\n");
  7657. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7658. //check Transaction active
  7659. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7660. {
  7661. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7662. {
  7663. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7664. {
  7665. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7666. {
  7667. meet = TRUE;
  7668. break;
  7669. }
  7670. }
  7671. }
  7672. }
  7673. for (int index = 0; index < CCS_QUANTITY; index++)
  7674. {
  7675. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7676. {
  7677. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7678. {
  7679. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7680. {
  7681. meet = TRUE;
  7682. break;
  7683. }
  7684. }
  7685. }
  7686. }
  7687. for (int index = 0; index < GB_QUANTITY; index++)
  7688. {
  7689. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7690. {
  7691. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7692. {
  7693. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7694. {
  7695. meet = TRUE;
  7696. break;
  7697. }
  7698. }
  7699. }
  7700. }
  7701. if(meet == FALSE)
  7702. {
  7703. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7704. goto end;
  7705. }
  7706. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7707. {
  7708. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7709. goto end;
  7710. }
  7711. switch(connectorIdInt)
  7712. {
  7713. case 0:
  7714. break;
  7715. case 1:
  7716. strcpy(filename, TxProfile_1_JSON);
  7717. break;
  7718. case 2:
  7719. strcpy(filename, TxProfile_2_JSON);
  7720. break;
  7721. default:
  7722. strcpy(filename, TxProfile_1_JSON);
  7723. break;
  7724. }
  7725. fptr1 = fopen(filename, "r");
  7726. if (!fptr1)
  7727. {
  7728. //file not exist
  7729. DEBUG_INFO("Unable to open the input file!!\n");
  7730. fptr1 = fopen(filename, "w+");
  7731. }
  7732. fclose(fptr1);
  7733. }
  7734. //**********************************Write to File********************************************************/
  7735. FILE *infile;
  7736. FILE *outfile;
  7737. // open file for writing
  7738. infile = fopen (filename, "r");
  7739. outfile = fopen (tempfile, "w");
  7740. int d =0;
  7741. d = fgetc(infile);
  7742. DEBUG_INFO("d:%d\n",d);
  7743. rewind(infile);
  7744. //*检测到文件结束标识返回1,否则返回0。*/
  7745. if(d == EOF)
  7746. {
  7747. DEBUG_INFO("ChargingProfile content is NULL\n");
  7748. fprintf(outfile,"[%s]\n",payload);
  7749. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7750. fclose(infile);
  7751. fclose(outfile);
  7752. sprintf(rmFileCmd,"rm -f %s",filename);
  7753. system(rmFileCmd);
  7754. resultRename = rename(tempfile, filename);
  7755. if(resultRename == 0)
  7756. {
  7757. DEBUG_INFO("File chargingProfile renamed successfully");
  7758. }
  7759. else
  7760. {
  7761. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7762. }
  7763. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7764. //system(rmFileCmd);
  7765. }
  7766. else
  7767. {
  7768. char buf[1000]={0};
  7769. while (fgets(buf, sizeof(buf), infile) != NULL)
  7770. {
  7771. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7772. //*************************tempconnectorIdInt*********************************/
  7773. loc = strstr(buf, "connectorId");
  7774. c = 0;
  7775. memset(sstr ,0, sizeof(sstr) );
  7776. while (loc[strlen("connectorId")+2+c] != ',')
  7777. {
  7778. sstr[c] = loc[strlen("connectorId")+2+c];
  7779. c++;
  7780. }
  7781. sstr[c] = '\0';
  7782. tempconnectorIdInt = atoi(sstr);
  7783. //*************************tempchargingProfileIdInt*********************************/
  7784. loc = strstr(buf, "chargingProfileId");
  7785. c = 0;
  7786. memset(sstr ,0, sizeof(sstr) );
  7787. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7788. {
  7789. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7790. c++;
  7791. }
  7792. sstr[c] = '\0';
  7793. tempchargingProfileIdInt = atoi(sstr);
  7794. //*************************tempstackLevelInt*********************************/
  7795. loc = strstr(buf, "stackLevel");
  7796. c = 0;
  7797. memset(sstr ,0, sizeof(sstr) );
  7798. while (loc[strlen("stackLevel")+2+c] != ',')
  7799. {
  7800. sstr[c] = loc[strlen("stackLevel")+2+c];
  7801. c++;
  7802. }
  7803. sstr[c] = '\0';
  7804. tempstackLevelInt = atoi(sstr);
  7805. //*************************tempchargingProfilePurposeStr*********************************/
  7806. loc = strstr(payload, "chargingProfilePurpose");
  7807. c = 0;
  7808. memset(sstr ,0, sizeof(sstr) );
  7809. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7810. {
  7811. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7812. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7813. c++;
  7814. }
  7815. sstr[c] = '\0';
  7816. strcpy(tempchargingProfilePurposeStr,sstr);
  7817. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7818. {
  7819. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7820. {
  7821. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7822. fprintf(outfile,"[%s]\n",payload);
  7823. }
  7824. else
  7825. {
  7826. //DEBUG_INFO("update set chargingProfile to file -1\n");
  7827. if(tempstackLevelInt < stackLevelInt)
  7828. {
  7829. //DEBUG_INFO("update set chargingProfile to file -2\n");
  7830. fprintf(outfile,"[%s]\n",payload);
  7831. fprintf(outfile,"[%s]\n",buf);
  7832. }
  7833. else
  7834. {
  7835. fprintf(outfile,"[%s]\n",buf);
  7836. fprintf(outfile,"[%s]\n",payload);
  7837. }
  7838. }
  7839. DEBUG_INFO("update set chargingProfile to file\n");
  7840. }
  7841. else
  7842. {
  7843. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7844. {
  7845. fprintf(outfile,"[%s]\n",payload);
  7846. fprintf(outfile,"[%s]\n",buf);
  7847. }
  7848. else if(tempstackLevelInt < stackLevelInt)
  7849. {
  7850. fprintf(outfile,"[%s]\n",payload);
  7851. fprintf(outfile,"[%s]\n",buf);
  7852. }
  7853. else
  7854. {
  7855. fprintf(outfile,"[%s]\n",buf);
  7856. fprintf(outfile,"[%s]\n",payload);
  7857. }
  7858. fprintf(outfile,"[%s]\n",buf);
  7859. DEBUG_INFO("add set chargingProfile to file\n");
  7860. }
  7861. } // end of while loop
  7862. fclose(infile);
  7863. fclose(outfile);
  7864. sprintf(rmFileCmd,"rm -f %s",filename);
  7865. system(rmFileCmd);
  7866. resultRename = rename(tempfile, filename);
  7867. if(resultRename == 0)
  7868. {
  7869. DEBUG_INFO("File chargingProfile renamed successfully");
  7870. }
  7871. else
  7872. {
  7873. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7874. }
  7875. result = TRUE;
  7876. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7877. }
  7878. end:
  7879. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7880. return result;
  7881. return result;
  7882. }
  7883. int handleTriggerMessageRequest(char *uuid, char *payload)
  7884. {
  7885. mtrace();
  7886. int result = FAIL;
  7887. int connectorIdIsNULL = FALSE;
  7888. int connectorIdInt =0;
  7889. char sstr[40]={0};
  7890. char requestedMessagestr[40]={0};
  7891. char comfirmstr[20]={0};
  7892. int c = 0;
  7893. char *loc;
  7894. DEBUG_INFO("handleTriggerMessageRequest\n");
  7895. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7896. c = 0;
  7897. loc = strstr(payload, "requestedMessage");
  7898. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7899. {
  7900. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7901. c++;
  7902. }
  7903. sstr[c] = '\0';
  7904. strcpy(requestedMessagestr, sstr);
  7905. c = 0;
  7906. loc = strstr(payload, "connectorId");
  7907. if(loc == NULL)
  7908. {
  7909. connectorIdIsNULL = TRUE;
  7910. }
  7911. else
  7912. {
  7913. memset(sstr ,0, sizeof(sstr) );
  7914. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7915. {
  7916. sstr[c] = loc[strlen("connectorId")+2+c];
  7917. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7918. c++;
  7919. }
  7920. sstr[c] = '\0';
  7921. connectorIdInt = atoi(sstr);
  7922. }
  7923. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7924. {
  7925. //connectorIdInt = json_object_get_int(connectorId);
  7926. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7927. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7928. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7929. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7930. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7931. }
  7932. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7933. {
  7934. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7935. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7936. return TRUE;
  7937. }
  7938. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7939. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7940. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7941. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7942. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7943. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7944. {
  7945. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7946. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7947. return TRUE;
  7948. }
  7949. else
  7950. {
  7951. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7952. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7953. }
  7954. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7955. {
  7956. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  7957. {
  7958. FirmwareStatusNotificationStatus = 3;
  7959. }
  7960. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7961. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7962. }
  7963. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7964. {
  7965. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7966. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7967. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7968. }
  7969. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7970. {
  7971. sendBootNotificationRequest();
  7972. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7973. }
  7974. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7975. {
  7976. sendHeartbeatRequest(connectorIdInt);
  7977. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7978. }
  7979. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7980. {
  7981. if(connectorIdIsNULL == FALSE)
  7982. {
  7983. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7984. {
  7985. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7986. sendMeterValuesRequest(connectorIdInt -1);
  7987. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7988. }
  7989. }
  7990. else
  7991. {
  7992. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7993. {
  7994. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  7995. sendMeterValuesRequest(idx);
  7996. }
  7997. }
  7998. }
  7999. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8000. {
  8001. if(connectorIdIsNULL == FALSE)
  8002. {
  8003. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8004. {
  8005. sendStatusNotificationRequest(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. sendStatusNotificationRequest(idx);
  8013. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8014. }
  8015. }
  8016. return result;
  8017. }
  8018. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8019. {
  8020. mtrace();
  8021. int result = FAIL;
  8022. char sstr[6]={0};
  8023. int connectorIdInt =0;
  8024. char comfirmstr[20]={0};
  8025. int c = 0;
  8026. char *loc;
  8027. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8028. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8029. c = 0;
  8030. loc = strstr(payload, "connectorId");
  8031. memset(sstr ,0, sizeof(sstr) );
  8032. while (loc[strlen("connectorId")+2+c] != '}')
  8033. {
  8034. sstr[c] = loc[strlen("connectorId")+2+c];
  8035. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8036. c++;
  8037. }
  8038. sstr[c] = '\0';
  8039. connectorIdInt = atoi(sstr);
  8040. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8041. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8042. {
  8043. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8044. goto end;
  8045. }
  8046. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8047. {
  8048. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8049. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8050. goto end;
  8051. }
  8052. else
  8053. {
  8054. //check Transaction active
  8055. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8056. {
  8057. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8058. {
  8059. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8060. {
  8061. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8062. }
  8063. }
  8064. for (int index = 0; index < CCS_QUANTITY; index++)
  8065. {
  8066. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8067. {
  8068. //stop Transaction
  8069. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8070. }
  8071. }
  8072. for (int index = 0; index < GB_QUANTITY; index++)
  8073. {
  8074. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8075. {
  8076. //stop Transaction
  8077. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8078. }
  8079. }
  8080. }
  8081. else
  8082. {
  8083. for (int index = 0; index < AC_QUANTITY; index++)
  8084. {
  8085. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8086. {
  8087. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8088. }
  8089. }
  8090. }// END FOR AC ELSE
  8091. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8092. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8093. result = TRUE;
  8094. return result;
  8095. }
  8096. end:
  8097. //json_object_put(obj); --- remove temporally
  8098. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8099. return result;
  8100. }
  8101. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8102. {
  8103. mtrace();
  8104. int result = FAIL;
  8105. pthread_t t;
  8106. sendUpdateFirmwareConfirmation(uuid);
  8107. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8108. ////pthread_join(t, NULL); //
  8109. pthread_detach(t);
  8110. //sendUpdateFirmwareConfirmation(uuid);
  8111. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8112. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8113. return result;
  8114. }
  8115. void *UpdateFirmwareProcess(void *data)
  8116. {
  8117. mtrace();
  8118. int retriesInt =0, retryIntervalInt=0;
  8119. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8120. int port=0;
  8121. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8122. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8123. //char comfirmstr[20];
  8124. int isSuccess = 0;
  8125. char ftpbuf[200];
  8126. char temp[100];
  8127. char * pch;
  8128. int retriesISNULL=FALSE;
  8129. int retryInterval=FALSE;
  8130. int c = 0;
  8131. //int i = 0;
  8132. char *loc;
  8133. char sstr[300]={ 0 };
  8134. char *str = (char*) data; // ? ?輸入資 ?
  8135. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8136. //***************location **************/
  8137. loc = strstr(str, "location");
  8138. memset(sstr ,0, sizeof(sstr) );
  8139. c = 0;
  8140. while (loc[3+strlen("location")+c] != '\"')
  8141. {
  8142. sstr[c] = loc[3+strlen("location")+c];
  8143. c++;
  8144. }
  8145. sstr[c] = '\0';
  8146. strcpy(locationstr, sstr);
  8147. //***************retries**************/
  8148. c = 0;
  8149. loc = strstr(str, "retries");
  8150. if(loc == NULL)
  8151. {
  8152. retriesISNULL=TRUE;
  8153. }
  8154. else
  8155. {
  8156. memset(sstr ,0, sizeof(sstr) );
  8157. while (loc[strlen("retries")+2+c] != ',')
  8158. {
  8159. sstr[c] = loc[strlen("retries")+2+c];
  8160. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8161. c++;
  8162. }
  8163. sstr[c] = '\0';
  8164. }
  8165. if(retriesISNULL == FALSE)
  8166. {
  8167. retriesInt = atoi(sstr);
  8168. }
  8169. //***************retrieveDate **************/
  8170. loc = strstr(str, "retrieveDate");
  8171. memset(sstr ,0, sizeof(sstr) );
  8172. c = 0;
  8173. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8174. {
  8175. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8176. c++;
  8177. }
  8178. sstr[c] = '\0';
  8179. strcpy(retrieveDatestr, sstr);
  8180. //***************retryInterval **************/
  8181. c = 0;
  8182. loc = strstr(str, "retryInterval");
  8183. memset(sstr ,0, sizeof(sstr) );
  8184. if(loc == NULL)
  8185. {
  8186. retryInterval=TRUE;
  8187. }
  8188. else
  8189. {
  8190. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8191. {
  8192. sstr[c] = loc[strlen("retryInterval")+2+c];
  8193. DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8194. c++;
  8195. }
  8196. sstr[c] = '\0';
  8197. }
  8198. if(retryInterval==FALSE)
  8199. {
  8200. retryIntervalInt = atoi(sstr);
  8201. }
  8202. memset(ftppath, 0, sizeof(ftppath));
  8203. memset(path, 0, sizeof(path));
  8204. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8205. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8206. if(strncmp(locationstr,"http", 4) == 0)
  8207. {
  8208. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8209. protocol, host, path);
  8210. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8211. // protocol, user, password, host, path);
  8212. sprintf(ftppath,"/%s", path);
  8213. DEBUG_INFO("protocol =%s\n",protocol);
  8214. DEBUG_INFO("host =%s\n",host);
  8215. DEBUG_INFO("path =%s\n",path);
  8216. DEBUG_INFO("ftppath=%s\n",ftppath);
  8217. int ftppathlen=strlen(ftppath);
  8218. int i=1;
  8219. char filenametemp[50];
  8220. while(i < ftppathlen)
  8221. {
  8222. int len=ftppathlen-i;
  8223. if(ftppath[len]== 47) // '/' ascll code: 47
  8224. {
  8225. DEBUG_INFO("compare '/' all right\n");
  8226. break;
  8227. }
  8228. i=i+1;
  8229. }
  8230. memset(filenametemp, 0, sizeof(filenametemp));
  8231. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8232. filenametemp[i+1] = 0;
  8233. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8234. do{
  8235. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8236. sleep(retryIntervalInt);
  8237. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8238. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8239. if(!isSuccess)
  8240. {
  8241. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8242. }
  8243. else
  8244. {
  8245. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8246. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8247. isUpdateRequest = TRUE;
  8248. }
  8249. }
  8250. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8251. {
  8252. memset(ftpbuf, 0, sizeof(ftpbuf));
  8253. memset(temp, 0, sizeof(temp));
  8254. DEBUG_INFO("locationstr=%s\n",locationstr);
  8255. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8256. int ftppathlen=strlen(ftpbuf);
  8257. int i=1;
  8258. char filenametemp[50];
  8259. while(i < ftppathlen)
  8260. {
  8261. int len=ftppathlen-i;
  8262. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8263. {
  8264. DEBUG_INFO(" compare '/' all right\n");
  8265. break;
  8266. }
  8267. i=i+1;
  8268. }
  8269. memset(filenametemp, 0, sizeof(filenametemp));
  8270. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8271. filenametemp[i+1] = 0;
  8272. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8273. pch=strchr(temp,'@');
  8274. if(pch==NULL)
  8275. {
  8276. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8277. protocol, host, &port, path);
  8278. strcpy(user,"anonymous");
  8279. strcpy(password,"");
  8280. }
  8281. else
  8282. {
  8283. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8284. protocol, user, password, host, &port, path);
  8285. }
  8286. sscanf(host,"%[^/]%s",host1, path1);
  8287. sprintf(ftppath,"%s", path1);
  8288. DEBUG_INFO("protocol =%s\n",protocol);
  8289. DEBUG_INFO("user =%s\n",user);
  8290. DEBUG_INFO("password =%s\n",password);
  8291. DEBUG_INFO("host1 =%s\n",host1);
  8292. DEBUG_INFO("port =%d\n",port);
  8293. DEBUG_INFO("path1 =%s\n",path1);
  8294. DEBUG_INFO("ftppath=%s\n",ftppath);
  8295. //ftpFile(host, user, password, port, ftppath, fname);
  8296. //download firmware pthred
  8297. if(port == 0)
  8298. {
  8299. port = 21;
  8300. }
  8301. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8302. do{
  8303. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8304. sleep(retryIntervalInt);
  8305. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8306. if(!isSuccess)
  8307. {
  8308. //BulldogUtil.sleepMs(interval*1000);
  8309. DEBUG_INFO("Update firmware request and download file fail.\n");
  8310. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8311. }
  8312. else
  8313. {
  8314. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8315. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8316. isUpdateRequest = TRUE;
  8317. }
  8318. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8319. }
  8320. else
  8321. {
  8322. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8323. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8324. }
  8325. pthread_exit(NULL);
  8326. }
  8327. //==========================================
  8328. // Handle server response routine
  8329. //==========================================
  8330. void handleAuthorizeResponse(char *payload, int gun_index)
  8331. {
  8332. mtrace();
  8333. char expiryDatestr[30]={0};
  8334. char parentIdTagstr[20]={0};
  8335. char statusstr[20]={0};
  8336. char expiryDatestrtemp[30]={0};
  8337. char parentIdTagstrtemp[20]={0};
  8338. char IdTagstrtemp[20]={0};
  8339. char statusstrtemp[20]={0};
  8340. int expiryDateISNULL=FALSE;
  8341. int parentIdTagISNULL=FALSE;
  8342. char sstr[160]={ 0 };
  8343. char* filename = AuthorizationCache_JSON;
  8344. char tempfile[] = "../Storage/OCPP/temp.json";
  8345. int c = 0;
  8346. char *loc;
  8347. int resultRename=0;
  8348. int responseIdTagInfoAsZero= 0;
  8349. char rmFileCmd[50]={0};
  8350. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8351. //***********expiryDate*************/
  8352. loc = strstr(payload, "expiryDate");
  8353. memset(sstr ,0, sizeof(sstr) );
  8354. c = 0;
  8355. if(loc == NULL)
  8356. {
  8357. expiryDateISNULL = TRUE;
  8358. }
  8359. else
  8360. {
  8361. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8362. {
  8363. sstr[c] = loc[3+strlen("expiryDate")+c];
  8364. c++;
  8365. }
  8366. sstr[c] = '\0';
  8367. strcpy(expiryDatestr, sstr);
  8368. }
  8369. //***********parentIdTag*************/
  8370. loc = strstr(payload, "parentIdTag");
  8371. memset(sstr ,0, sizeof(sstr) );
  8372. c = 0;
  8373. if(loc == NULL)
  8374. {
  8375. parentIdTagISNULL = TRUE;
  8376. }
  8377. else
  8378. {
  8379. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8380. {
  8381. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8382. c++;
  8383. }
  8384. sstr[c] = '\0';
  8385. strcpy(parentIdTagstr, sstr);
  8386. }
  8387. //***********status*************/
  8388. loc = strstr(payload, "status");
  8389. memset(sstr ,0, sizeof(sstr) );
  8390. c = 0;
  8391. while (loc[3+strlen("status")+c] != '\"')
  8392. {
  8393. sstr[c] = loc[3+strlen("status")+c];
  8394. c++;
  8395. }
  8396. sstr[c] = '\0';
  8397. strcpy(statusstr, sstr);
  8398. //#ifdef SystemLogMessage
  8399. // if(expiryDateISNULL == FALSE)
  8400. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8401. // if(parentIdTagISNULL == FALSE)
  8402. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8403. // DEBUG_INFO("status: %s\n", statusstr);
  8404. //#endif
  8405. if(expiryDateISNULL == FALSE)
  8406. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8407. if(parentIdTagISNULL == FALSE)
  8408. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8409. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8410. //Update idTag information to authorization cache if supproted
  8411. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8412. {
  8413. if((access(filename,F_OK))!=-1)
  8414. {
  8415. DEBUG_INFO("AuthorizationCache exist.\n");
  8416. }
  8417. else
  8418. {
  8419. DEBUG_INFO("AuthorizationCache not exist\n");
  8420. FILE *log = fopen(filename, "w+");
  8421. if(log == NULL)
  8422. {
  8423. DEBUG_INFO("log is NULL\n");
  8424. goto out;
  8425. }
  8426. else
  8427. {
  8428. fclose(log);
  8429. }
  8430. }
  8431. FILE *infile;
  8432. FILE *outfile;
  8433. // open file for writing
  8434. infile = fopen (filename, "r");
  8435. outfile = fopen (tempfile, "w");
  8436. //*检测到文件结束标识返回1,否则返回0。*/
  8437. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8438. int c;
  8439. c = fgetc(infile);
  8440. //DEBUG_INFO("c:%d\n",c);
  8441. rewind(infile);
  8442. if(c == EOF)
  8443. {
  8444. DEBUG_INFO("Orignal File is NULL\n");
  8445. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8446. {
  8447. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8448. }
  8449. else
  8450. {
  8451. strcpy(expiryDatestrtemp, "");
  8452. }
  8453. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8454. {
  8455. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8456. }
  8457. else
  8458. {
  8459. //write Authorize IdTag
  8460. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8461. }
  8462. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8463. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8464. fclose(infile);
  8465. fclose(outfile);
  8466. sprintf(rmFileCmd,"rm -f %s",filename);
  8467. system(rmFileCmd);
  8468. resultRename = rename(tempfile, filename);
  8469. if(resultRename == 0)
  8470. {
  8471. DEBUG_INFO("File renamed successfully");
  8472. }
  8473. else
  8474. {
  8475. DEBUG_INFO("Error: unable to rename the file");
  8476. }
  8477. }
  8478. else
  8479. {
  8480. char buf[160]={0};
  8481. //DEBUG_INFO("Orignal File is not NULL\n");
  8482. while (fgets(buf, sizeof(buf), infile) != NULL)
  8483. {
  8484. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8485. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8486. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8487. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8488. memset(statusstr, 0, sizeof(statusstrtemp));
  8489. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8490. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8491. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8492. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8493. //------------------IdTag-----------------------
  8494. loc = strstr(buf, "idTag");
  8495. memset(sstr ,0, sizeof(sstr) );
  8496. c = 0;
  8497. while (loc[3+strlen("idTag")+c] != '\"')
  8498. {
  8499. sstr[c] = loc[3+strlen("idTag")+c];
  8500. c++;
  8501. }
  8502. sstr[c] = '\0';
  8503. strcpy(IdTagstrtemp,sstr);
  8504. //*********************expiryDate***************/
  8505. loc = strstr(buf, "expiryDate");
  8506. memset(sstr ,0, sizeof(sstr) );
  8507. c = 0;
  8508. while (loc[3+strlen("expiryDate")+c] != '\"')
  8509. {
  8510. sstr[c] = loc[3+strlen("expiryDate")+c];
  8511. c++;
  8512. }
  8513. sstr[c] = '\0';
  8514. strcpy(expiryDatestr,sstr);
  8515. //*********************parentIdTag***************/
  8516. loc = strstr(buf, "parentIdTag");
  8517. memset(sstr ,0, sizeof(sstr) );
  8518. c = 0;
  8519. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8520. {
  8521. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8522. c++;
  8523. }
  8524. sstr[c] = '\0';
  8525. strcpy(parentIdTagstr,sstr);
  8526. //*********************status***************/
  8527. loc = strstr(buf, "status");
  8528. memset(sstr ,0, sizeof(sstr) );
  8529. c = 0;
  8530. while (loc[3+strlen("status")+c] != '\"')
  8531. {
  8532. sstr[c] = loc[3+strlen("status")+c];
  8533. c++;
  8534. }
  8535. sstr[c] = '\0';
  8536. strcpy(statusstr,sstr);
  8537. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8538. {
  8539. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8540. responseIdTagInfoAsZero = 1;
  8541. }
  8542. else
  8543. {
  8544. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8545. }
  8546. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8547. {
  8548. //modify item
  8549. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8550. {
  8551. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8552. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8553. }
  8554. else
  8555. {
  8556. strcpy(expiryDatestrtemp, "");
  8557. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8558. }
  8559. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8560. {
  8561. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8562. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8563. }
  8564. else
  8565. {
  8566. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8567. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8568. }
  8569. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8570. }
  8571. else
  8572. {
  8573. //wrie original item
  8574. strcpy(expiryDatestrtemp, expiryDatestr);
  8575. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8576. strcpy(statusstrtemp, statusstr);
  8577. }
  8578. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8579. }
  8580. fclose(infile);
  8581. fclose(outfile);
  8582. sprintf(rmFileCmd,"rm -f %s",filename);
  8583. system(rmFileCmd);
  8584. resultRename = rename(tempfile, filename);
  8585. if(resultRename == 0)
  8586. {
  8587. DEBUG_INFO("File renamed successfully");
  8588. }
  8589. else
  8590. {
  8591. DEBUG_INFO("Error: unable to rename the file");
  8592. }
  8593. }
  8594. }
  8595. out:
  8596. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8597. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8598. authorizeRetryTimes = 0;
  8599. }
  8600. void handleBootNotificationResponse(char *payload, int gun_index)
  8601. {
  8602. mtrace();
  8603. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8604. char statusStr[12]={0};
  8605. char currentTimeStr[30]={0};
  8606. char *loc;
  8607. int intervalInt = 0;
  8608. int c = 0;
  8609. //double diff_t;
  8610. struct tm tp;
  8611. char buf[28]={0};
  8612. char timebuf[50]={0};
  8613. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8614. //*** interval ****/
  8615. c = 0;
  8616. loc = strstr(payload, "interval");
  8617. //printf("loc=%s\n",loc);
  8618. memset(sstr ,0, sizeof(sstr) );
  8619. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8620. {
  8621. sstr[c] = loc[strlen("interval")+2+c];
  8622. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8623. c++;
  8624. }
  8625. sstr[c] = '\0';
  8626. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8627. intervalInt = atoi(sstr);
  8628. //***status ****/
  8629. loc = strstr(payload, "status");
  8630. memset(sstr ,0, sizeof(sstr) );
  8631. c = 0;
  8632. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8633. {
  8634. sstr[c] = loc[3+strlen("status")+c];
  8635. c++;
  8636. }
  8637. sstr[c] = '\0';
  8638. strcpy(statusStr, sstr);
  8639. //***currentTime ****/
  8640. loc = strstr(payload, "currentTime");
  8641. //printf("loc=%s\n",loc);
  8642. memset(sstr ,0, sizeof(sstr) );
  8643. c = 0;
  8644. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8645. {
  8646. sstr[c] = loc[3+strlen("currentTime")+c];
  8647. c++;
  8648. }
  8649. sstr[c] = '\0';
  8650. strcpy(currentTimeStr, sstr);
  8651. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8652. HeartBeatWaitTime = BootNotificationInterval;
  8653. //#ifdef SystemLogMessage
  8654. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8655. // DEBUG_INFO("interval: %d\n", intervalInt);
  8656. // DEBUG_INFO("status: %s\n", statusStr);
  8657. //#endif
  8658. //write back to ShmOCPP16Data->BootNotification
  8659. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8660. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8661. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8662. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8663. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8664. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8665. {
  8666. server_sign = TRUE;
  8667. server_pending =FALSE;
  8668. }
  8669. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8670. {
  8671. server_pending = TRUE;
  8672. }
  8673. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8674. tp.tm_isdst = -1;
  8675. //time_t utc = mktime(&tp);
  8676. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8677. memset(timebuf, 0, sizeof timebuf);
  8678. sprintf(timebuf,"date -s '%s'",buf);
  8679. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8680. system(timebuf);
  8681. //==============================================
  8682. // RTC sync
  8683. //==============================================
  8684. system("/sbin/hwclock -w --systohc");
  8685. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8686. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8687. }
  8688. void handleDataTransferResponse(char *payload, int gun_index)
  8689. {
  8690. char sstr[160]={0};//sstr[200]={ 0 };
  8691. int c = 0;
  8692. char *loc;
  8693. DEBUG_INFO("handleDataTransferResponse ...\n");
  8694. loc = strstr(payload, "status");
  8695. printf("loc=%s\n",loc);
  8696. c = 0;
  8697. while (loc[3+strlen("status")+c] != '\"')
  8698. {
  8699. sstr[c] = loc[3+strlen("status")+c];
  8700. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8701. c++;
  8702. }
  8703. sstr[c] = '\0';
  8704. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8705. //#ifdef SystemLogMessage
  8706. //DEBUG_INFO("data: %s\n", payload);
  8707. //#endif
  8708. }
  8709. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8710. {
  8711. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8712. //struct json_object *obj;
  8713. // obj = json_tokener_parse(payload);
  8714. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8715. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8716. //No fields are defined.
  8717. }
  8718. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8719. {
  8720. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8721. //struct json_object *obj;
  8722. // obj = json_tokener_parse(payload);
  8723. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8724. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8725. //No fields are defined.
  8726. }
  8727. void handleHeartbeatResponse(char *payload, int gun_index)
  8728. {
  8729. mtrace();
  8730. //double diff_t;
  8731. struct tm tp;
  8732. char buf[28]={0};
  8733. char timebuf[50]={0};
  8734. char sstr[30]={ 0 };
  8735. int c = 0;
  8736. char *loc;
  8737. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8738. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8739. c = 0;
  8740. loc = strstr(payload, "currentTime");
  8741. memset(sstr ,0, sizeof(sstr) );
  8742. while (loc[3+strlen("currentTime")+c] != '\"')
  8743. {
  8744. sstr[c] = loc[3+strlen("currentTime")+c];
  8745. c++;
  8746. }
  8747. sstr[c] = '\0';
  8748. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8749. // #ifdef SystemLogMessage
  8750. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8751. // #endif
  8752. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8753. tp.tm_isdst = -1;
  8754. //time_t utc = mktime(&tp);
  8755. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8756. memset(timebuf, 0, sizeof timebuf);
  8757. sprintf(timebuf,"date -s '%s'",buf);
  8758. system(timebuf);
  8759. //==============================================
  8760. // RTC sync
  8761. //==============================================
  8762. system("/sbin/hwclock -w --systohc");
  8763. if(FirstHeartBeat == 0)
  8764. {
  8765. FirstHeartBeat = 1;
  8766. }
  8767. HeartBeatWithNOResponse = 0;
  8768. }
  8769. void handleMeterValuesResponse(char *payload, int gun_index)
  8770. {
  8771. mtrace();
  8772. //struct json_object *obj;
  8773. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8774. //No fields are defined.
  8775. }
  8776. void handleStartTransactionResponse(char *payload, int gun_index)
  8777. {
  8778. mtrace();
  8779. char sstr[28]={ 0 };
  8780. int c = 0;
  8781. char *loc;
  8782. int transactionIdInt = 0;
  8783. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8784. DEBUG_INFO("handleStartTransactionResponse\n");
  8785. //****************expiryDate********************/
  8786. loc = strstr(payload, "expiryDate");
  8787. if(loc == NULL)
  8788. {
  8789. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8790. }
  8791. else
  8792. {
  8793. c = 0;
  8794. memset(sstr ,0, sizeof(sstr) );
  8795. while (loc[3+strlen("expiryDate")+c] != '\"')
  8796. {
  8797. sstr[c] = loc[3+strlen("expiryDate")+c];
  8798. c++;
  8799. }
  8800. sstr[c] = '\0';
  8801. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8802. }
  8803. //****************parentIdTag********************/
  8804. loc = strstr(payload, "parentIdTag");
  8805. if(loc == NULL)
  8806. {
  8807. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8808. }
  8809. else
  8810. {
  8811. c = 0;
  8812. memset(sstr ,0, sizeof(sstr) );
  8813. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8814. {
  8815. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8816. c++;
  8817. }
  8818. sstr[c] = '\0';
  8819. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8820. }
  8821. //****************status********************/
  8822. loc = strstr(payload, "status");
  8823. if(loc == NULL)
  8824. {
  8825. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8826. }
  8827. else
  8828. {
  8829. c = 0;
  8830. memset(sstr ,0, sizeof(sstr) );
  8831. while (loc[3+strlen("status")+c] != '\"')
  8832. {
  8833. sstr[c] = loc[3+strlen("status")+c];
  8834. c++;
  8835. }
  8836. sstr[c] = '\0';
  8837. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8838. }
  8839. //****************transactionId********************/
  8840. c=0;
  8841. loc = strstr(payload, "transactionId");
  8842. memset(sstr ,0, sizeof(sstr) );
  8843. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8844. {
  8845. sstr[c] = loc[strlen("transactionId")+2+c];
  8846. c++;
  8847. }
  8848. sstr[c] = '\0';
  8849. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8850. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8851. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8852. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8853. #ifdef SystemLogMessage
  8854. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8855. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8856. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8857. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8858. #endif
  8859. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8860. {
  8861. //add Charging Record
  8862. SettingChargingRecord(gun_index, transactionIdInt);
  8863. }
  8864. DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8865. }
  8866. void handleStatusNotificationResponse(char *payload, int gun_index)
  8867. {
  8868. mtrace();
  8869. printf("handleStatusNotificationResponse\n");
  8870. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8871. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8872. }
  8873. void handleStopTransactionnResponse(char *payload, int gun_index)
  8874. {
  8875. mtrace();
  8876. char sstr[30]={ 0 };
  8877. int c = 0;
  8878. char *loc;
  8879. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8880. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8881. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8882. loc = strstr(payload, "idTagInfo");
  8883. //***********************idTagInfo************************/
  8884. if(loc != NULL)
  8885. {
  8886. //***********************expiryDate************************/
  8887. loc = strstr(payload, "expiryDate");
  8888. if(loc != NULL)
  8889. {
  8890. memset(sstr ,0, sizeof(sstr) );
  8891. c = 0;
  8892. while (loc[3+strlen("expiryDate")+c] != '\"')
  8893. {
  8894. sstr[c] = loc[3+strlen("expiryDate")+c];
  8895. c++;
  8896. }
  8897. sstr[c] = '\0';
  8898. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8899. }
  8900. //***********************parentIdTag************************/
  8901. loc = strstr(payload, "parentIdTag");
  8902. if(loc != NULL)
  8903. {
  8904. memset(sstr ,0, sizeof(sstr) );
  8905. c = 0;
  8906. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8907. {
  8908. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8909. c++;
  8910. }
  8911. sstr[c] = '\0';
  8912. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8913. }
  8914. //***********************status************************/
  8915. loc = strstr(payload, "status");
  8916. memset(sstr ,0, sizeof(sstr) );
  8917. c = 0;
  8918. while (loc[3+strlen("status")+c] != '\"')
  8919. {
  8920. sstr[c] = loc[3+strlen("status")+c];
  8921. c++;
  8922. }
  8923. sstr[c] = '\0';
  8924. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8925. }
  8926. #ifdef SystemLogMessage
  8927. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8928. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8929. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8930. #endif
  8931. }
  8932. //==========================================
  8933. // Handle Error routine
  8934. //==========================================
  8935. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8936. {
  8937. mtrace();
  8938. #ifdef SystemLogMessage
  8939. DEBUG_INFO("errorCode: %s\n", errorCode);
  8940. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8941. DEBUG_INFO("errorDetails: %s\n", payload);
  8942. #endif
  8943. }
  8944. //===============================================
  8945. // Common routine
  8946. //===============================================
  8947. int initialConfigurationTable(void)
  8948. {
  8949. printf("initialConfigurationTable \n");
  8950. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8951. /*Core Profile*/
  8952. //AllowOfflineTxForUnknownId
  8953. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8954. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8957. //AuthorizationCacheEnabled
  8958. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8961. //AuthorizeRemoteTxRequests
  8962. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8965. //BlinkRepeat
  8966. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8969. //ClockAlignedDataInterval
  8970. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8973. //ConnectionTimeOut
  8974. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8977. //GetConfigurationMaxKeys
  8978. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8980. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  8981. // HeartbeatInterval
  8982. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  8983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  8984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  8985. // LightIntensity
  8986. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  8987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  8988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  8989. // LocalAuthorizeOffline
  8990. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  8991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  8992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  8993. // LocalPreAuthorize
  8994. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  8995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  8996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  8997. // MaxEnergyOnInvalidId
  8998. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  8999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9001. // MeterValuesAlignedData
  9002. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9005. // MeterValuesAlignedDataMaxLength
  9006. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9009. // MeterValuesSampledData
  9010. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9013. // MeterValuesSampledDataMaxLength
  9014. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9017. // MeterValueSampleInterval
  9018. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9021. // MinimumStatusDuration
  9022. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9025. // NumberOfConnectors
  9026. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  9029. // ResetRetries
  9030. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9033. // ConnectorPhaseRotation
  9034. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  9037. // ConnectorPhaseRotationMaxLength
  9038. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9041. // StopTransactionOnEVSideDisconnect
  9042. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9045. // StopTransactionOnInvalidId
  9046. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9049. // StopTxnAlignedData
  9050. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9053. // StopTxnAlignedDataMaxLength
  9054. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9057. // StopTxnSampledData
  9058. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9061. // StopTxnSampledDataMaxLength
  9062. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9065. // SupportedFeatureProfiles
  9066. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9069. // SupportedFeatureProfilesMaxLength
  9070. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9073. // TransactionMessageAttempts
  9074. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9077. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9078. // TransactionMessageRetryInterval
  9079. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9082. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9083. // UnlockConnectorOnEVSideDisconnect
  9084. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9087. // WebSocketPingInterval
  9088. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9091. //* Local Auth List Management Profile*/
  9092. #if 0
  9093. //For OCTT Test Case
  9094. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9097. #endif
  9098. #if 1
  9099. //LocalAuthListEnabled
  9100. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9103. #endif
  9104. //LocalAuthListMaxLength
  9105. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9108. //SendLocalListMaxLength
  9109. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9112. //ReserveConnectorZeroSupported
  9113. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9116. //* Smart Charging Profile */
  9117. //ChargeProfileMaxStackLevel
  9118. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9121. // ChargingScheduleAllowedChargingRateUnit
  9122. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9125. // ChargingScheduleMaxPeriods
  9126. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9128. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9129. // ConnectorSwitch3to1PhaseSupported
  9130. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9133. // MaxChargingProfilesInstalled
  9134. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9137. return 0;
  9138. }
  9139. void getKeyValue(char *keyReq)
  9140. {
  9141. int isEmpty = FALSE;
  9142. int isKnowKey = FALSE;
  9143. //int unKnowIndex = 0;
  9144. DEBUG_INFO("getKeyValue \n");
  9145. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9146. isEmpty = TRUE;
  9147. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9148. {
  9149. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9152. {
  9153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9154. }
  9155. else
  9156. {
  9157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9158. }
  9159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9160. isKnowKey = TRUE;
  9161. }
  9162. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9163. {
  9164. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9166. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9167. {
  9168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9169. }
  9170. else
  9171. {
  9172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9173. }
  9174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9175. isKnowKey = TRUE;
  9176. }
  9177. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9178. {
  9179. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9182. {
  9183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9184. }
  9185. else
  9186. {
  9187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9188. }
  9189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9190. isKnowKey = TRUE;
  9191. }
  9192. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9193. {
  9194. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9197. {
  9198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9199. }
  9200. else
  9201. {
  9202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9203. }
  9204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9205. isKnowKey = TRUE;
  9206. }
  9207. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9208. {
  9209. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9211. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9212. {
  9213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9214. }
  9215. else
  9216. {
  9217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9218. }
  9219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9220. isKnowKey = TRUE;
  9221. }
  9222. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9223. {
  9224. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9227. {
  9228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9229. }
  9230. else
  9231. {
  9232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9233. }
  9234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9235. isKnowKey = TRUE;
  9236. }
  9237. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9238. {
  9239. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9242. {
  9243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9244. }
  9245. else
  9246. {
  9247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9248. }
  9249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9250. isKnowKey = TRUE;
  9251. }
  9252. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9253. {
  9254. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9257. {
  9258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9259. }
  9260. else
  9261. {
  9262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9263. }
  9264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9265. isKnowKey = TRUE;
  9266. }
  9267. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9268. {
  9269. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9272. {
  9273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9274. }
  9275. else
  9276. {
  9277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9278. }
  9279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9280. isKnowKey = TRUE;
  9281. }
  9282. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9283. {
  9284. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9287. {
  9288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9289. }
  9290. else
  9291. {
  9292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9293. }
  9294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9295. isKnowKey = TRUE;
  9296. }
  9297. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9298. {
  9299. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9302. {
  9303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9304. }
  9305. else
  9306. {
  9307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9308. }
  9309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9310. isKnowKey = TRUE;
  9311. }
  9312. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9313. {
  9314. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9317. {
  9318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9319. }
  9320. else
  9321. {
  9322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9323. }
  9324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9325. isKnowKey = TRUE;
  9326. }
  9327. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9328. {
  9329. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9332. {
  9333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9334. }
  9335. else
  9336. {
  9337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9338. }
  9339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9340. isKnowKey = TRUE;
  9341. }
  9342. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9343. {
  9344. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9347. {
  9348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9349. }
  9350. else
  9351. {
  9352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9353. }
  9354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9355. isKnowKey = TRUE;
  9356. }
  9357. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9358. {
  9359. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9362. {
  9363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9364. }
  9365. else
  9366. {
  9367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9368. }
  9369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9370. isKnowKey = TRUE;
  9371. }
  9372. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9373. {
  9374. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9377. {
  9378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9379. }
  9380. else
  9381. {
  9382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9383. }
  9384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9385. isKnowKey = TRUE;
  9386. }
  9387. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9388. {
  9389. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9392. {
  9393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9394. }
  9395. else
  9396. {
  9397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9398. }
  9399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9400. isKnowKey = TRUE;
  9401. }
  9402. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9403. {
  9404. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9407. {
  9408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9409. }
  9410. else
  9411. {
  9412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9413. }
  9414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9415. isKnowKey = TRUE;
  9416. }
  9417. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9418. {
  9419. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9422. {
  9423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9424. }
  9425. else
  9426. {
  9427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9428. }
  9429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9430. isKnowKey = TRUE;
  9431. }
  9432. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9433. {
  9434. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9437. {
  9438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9439. }
  9440. else
  9441. {
  9442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9443. }
  9444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9445. isKnowKey = TRUE;
  9446. }
  9447. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9448. {
  9449. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9452. {
  9453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9454. }
  9455. else
  9456. {
  9457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9458. }
  9459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9460. isKnowKey = TRUE;
  9461. }
  9462. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9463. {
  9464. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9466. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9467. {
  9468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9469. }
  9470. else
  9471. {
  9472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9473. }
  9474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9475. isKnowKey = TRUE;
  9476. }
  9477. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9478. {
  9479. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9482. {
  9483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9484. }
  9485. else
  9486. {
  9487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9488. }
  9489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9490. isKnowKey = TRUE;
  9491. }
  9492. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9493. {
  9494. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9496. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9497. {
  9498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9499. }
  9500. else
  9501. {
  9502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9503. }
  9504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9505. isKnowKey = TRUE;
  9506. }
  9507. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9508. {
  9509. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9511. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9512. {
  9513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9514. }
  9515. else
  9516. {
  9517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9518. }
  9519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9520. isKnowKey = TRUE;
  9521. }
  9522. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9523. {
  9524. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9527. {
  9528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9529. }
  9530. else
  9531. {
  9532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9533. }
  9534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9535. isKnowKey = TRUE;
  9536. }
  9537. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9538. {
  9539. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9542. {
  9543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9544. }
  9545. else
  9546. {
  9547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9548. }
  9549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9550. isKnowKey = TRUE;
  9551. }
  9552. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9553. {
  9554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9557. {
  9558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9559. }
  9560. else
  9561. {
  9562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9563. }
  9564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9565. isKnowKey = TRUE;
  9566. }
  9567. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9568. {
  9569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9572. {
  9573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9574. }
  9575. else
  9576. {
  9577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9578. }
  9579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9580. isKnowKey = TRUE;
  9581. }
  9582. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9583. {
  9584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9587. {
  9588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9589. }
  9590. else
  9591. {
  9592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9593. }
  9594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9595. isKnowKey = TRUE;
  9596. }
  9597. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9598. {
  9599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9602. {
  9603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9604. }
  9605. else
  9606. {
  9607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9608. }
  9609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9610. isKnowKey = TRUE;
  9611. }
  9612. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9613. {
  9614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9617. {
  9618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9619. }
  9620. else
  9621. {
  9622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9623. }
  9624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9625. isKnowKey = TRUE;
  9626. }
  9627. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9628. {
  9629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9632. {
  9633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9634. }
  9635. else
  9636. {
  9637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9638. }
  9639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9640. isKnowKey = TRUE;
  9641. }
  9642. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9643. {
  9644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9647. {
  9648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9649. }
  9650. else
  9651. {
  9652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9653. }
  9654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9655. isKnowKey = TRUE;
  9656. }
  9657. #if 0
  9658. //For OCTT Test Case
  9659. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9660. {
  9661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9663. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9664. {
  9665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9666. }
  9667. else
  9668. {
  9669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9670. }
  9671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9672. isKnowKey = TRUE;
  9673. }
  9674. #endif
  9675. #if 1
  9676. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9677. {
  9678. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9680. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9681. {
  9682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9683. }
  9684. else
  9685. {
  9686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9687. }
  9688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9689. isKnowKey = TRUE;
  9690. }
  9691. #endif
  9692. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9693. {
  9694. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9696. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9697. {
  9698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9699. }
  9700. else
  9701. {
  9702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9703. }
  9704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9705. isKnowKey = TRUE;
  9706. }
  9707. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9708. {
  9709. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9711. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9712. {
  9713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9714. }
  9715. else
  9716. {
  9717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9718. }
  9719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9720. isKnowKey = TRUE;
  9721. }
  9722. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9723. {
  9724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9726. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9727. {
  9728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9729. }
  9730. else
  9731. {
  9732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9733. }
  9734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9735. isKnowKey = TRUE;
  9736. }
  9737. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9738. {
  9739. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9741. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9742. {
  9743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9744. }
  9745. else
  9746. {
  9747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9748. }
  9749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9750. isKnowKey = TRUE;
  9751. }
  9752. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9753. {
  9754. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9756. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9757. {
  9758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9759. }
  9760. else
  9761. {
  9762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9763. }
  9764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9765. isKnowKey = TRUE;
  9766. }
  9767. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9768. {
  9769. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9771. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9772. {
  9773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9774. }
  9775. else
  9776. {
  9777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9778. }
  9779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9780. isKnowKey = TRUE;
  9781. }
  9782. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9783. {
  9784. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9786. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9787. {
  9788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9789. }
  9790. else
  9791. {
  9792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9793. }
  9794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9795. isKnowKey = TRUE;
  9796. }
  9797. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9798. {
  9799. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9801. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9802. {
  9803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9804. }
  9805. else
  9806. {
  9807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9808. }
  9809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9810. isKnowKey = TRUE;
  9811. }
  9812. //=========================================================
  9813. if(!isEmpty && !isKnowKey)
  9814. {
  9815. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9816. strcpy(unknownkey[UnknownKeynum], keyReq);
  9817. UnknownKeynum = UnknownKeynum + 1;
  9818. }
  9819. }
  9820. void processUnkownKey(void)
  9821. {
  9822. DEBUG_INFO("processUnkownKey\n");
  9823. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9824. for(int index=0; index < UnknownKeynum; index++)
  9825. {
  9826. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9827. {
  9828. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9829. }
  9830. }
  9831. }
  9832. int setKeyValue(char *key, char *value)
  9833. {
  9834. int isSuccess = NotSupported;
  9835. int check_ascii=0;
  9836. #ifdef Debug
  9837. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9838. #endif
  9839. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9840. {
  9841. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9843. {
  9844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9845. isSuccess = ConfigurationStatus_Accepted;
  9846. }
  9847. else
  9848. {
  9849. isSuccess = ConfigurationStatus_Rejected;
  9850. }
  9851. }
  9852. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9853. {
  9854. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9856. {
  9857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9858. isSuccess = ConfigurationStatus_Accepted;
  9859. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9860. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9861. }
  9862. else
  9863. {
  9864. isSuccess = ConfigurationStatus_Rejected;
  9865. }
  9866. }
  9867. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9868. {
  9869. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9870. {
  9871. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9873. isSuccess = ConfigurationStatus_Accepted;
  9874. }
  9875. else
  9876. {
  9877. isSuccess = ConfigurationStatus_Rejected;
  9878. }
  9879. }
  9880. if(strcmp(key, "BlinkRepeat") == 0)
  9881. {
  9882. //Charger.BlinkRepeat = Integer.parseInt(value);
  9883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9884. {
  9885. check_ascii = value[0];
  9886. if( (check_ascii < 48) || (check_ascii > 57) )
  9887. {
  9888. isSuccess = ConfigurationStatus_Rejected;
  9889. }
  9890. else
  9891. {
  9892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9893. isSuccess = ConfigurationStatus_Accepted;
  9894. }
  9895. }
  9896. else
  9897. {
  9898. isSuccess = ConfigurationStatus_Rejected;
  9899. }
  9900. }
  9901. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9902. {
  9903. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9904. {
  9905. check_ascii = value[0];
  9906. if( (check_ascii < 48) || (check_ascii > 57) )
  9907. {
  9908. isSuccess = ConfigurationStatus_Rejected;
  9909. }
  9910. else
  9911. {
  9912. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9914. isSuccess = ConfigurationStatus_Accepted;
  9915. }
  9916. }
  9917. else
  9918. {
  9919. isSuccess = ConfigurationStatus_Rejected;
  9920. }
  9921. }
  9922. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9923. {
  9924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9925. {
  9926. check_ascii = value[0];
  9927. if( (check_ascii < 48) || (check_ascii > 57) )
  9928. {
  9929. isSuccess = ConfigurationStatus_Rejected;
  9930. }
  9931. else
  9932. {
  9933. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9935. isSuccess = ConfigurationStatus_Accepted;
  9936. }
  9937. }
  9938. else
  9939. {
  9940. isSuccess = ConfigurationStatus_Rejected;
  9941. }
  9942. }
  9943. if(strcmp(key, "HeartbeatInterval") == 0)
  9944. {
  9945. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9946. {
  9947. check_ascii = value[0];
  9948. if( (check_ascii < 48) || (check_ascii > 57) )
  9949. {
  9950. isSuccess = ConfigurationStatus_Rejected;
  9951. }
  9952. else
  9953. {
  9954. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9956. HeartBeatWaitTime = atoi(value);
  9957. isSuccess = ConfigurationStatus_Accepted;
  9958. }
  9959. }
  9960. else
  9961. {
  9962. isSuccess = ConfigurationStatus_Rejected;
  9963. }
  9964. }
  9965. if(strcmp(key, "LightIntensity") == 0)
  9966. {
  9967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9968. {
  9969. check_ascii = value[0];
  9970. if( (check_ascii < 48) || (check_ascii > 57) )
  9971. {
  9972. isSuccess = ConfigurationStatus_Rejected;
  9973. }
  9974. else
  9975. {
  9976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9977. isSuccess = ConfigurationStatus_Accepted;
  9978. }
  9979. }
  9980. else
  9981. {
  9982. isSuccess = ConfigurationStatus_Rejected;
  9983. }
  9984. }
  9985. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  9986. {
  9987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9988. {
  9989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9990. isSuccess = ConfigurationStatus_Accepted;
  9991. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9992. }
  9993. else
  9994. {
  9995. isSuccess = ConfigurationStatus_Rejected;
  9996. }
  9997. }
  9998. if(strcmp(key, "LocalPreAuthorize") == 0)
  9999. {
  10000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10001. {
  10002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10003. isSuccess = ConfigurationStatus_Accepted;
  10004. }
  10005. else
  10006. {
  10007. isSuccess = ConfigurationStatus_Rejected;
  10008. }
  10009. }
  10010. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10011. {
  10012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10013. {
  10014. check_ascii = value[0];
  10015. if( (check_ascii < 48) || (check_ascii > 57) )
  10016. {
  10017. isSuccess = ConfigurationStatus_Rejected;
  10018. }
  10019. else
  10020. {
  10021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10022. isSuccess = ConfigurationStatus_Accepted;
  10023. }
  10024. }
  10025. else
  10026. {
  10027. isSuccess = ConfigurationStatus_Rejected;
  10028. }
  10029. }
  10030. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10031. {
  10032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10033. {
  10034. //int valueLength = strlen(value);
  10035. for(int i = 0; value[i]; i++){
  10036. value[i] = tolower(value[i]);
  10037. }
  10038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10039. isSuccess = ConfigurationStatus_Accepted;
  10040. }
  10041. else
  10042. {
  10043. isSuccess = ConfigurationStatus_Rejected;
  10044. }
  10045. }
  10046. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10047. {
  10048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10049. {
  10050. //int valueLength = strlen(value);
  10051. for(int i = 0; value[i]; i++){
  10052. value[i] = tolower(value[i]);
  10053. }
  10054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10055. isSuccess = ConfigurationStatus_Accepted;
  10056. }
  10057. else
  10058. {
  10059. isSuccess = ConfigurationStatus_Rejected;
  10060. }
  10061. }
  10062. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10063. {
  10064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10065. {
  10066. check_ascii = value[0];
  10067. if( (check_ascii < 48) || (check_ascii > 57) )
  10068. {
  10069. isSuccess = ConfigurationStatus_Rejected;
  10070. }
  10071. else
  10072. {
  10073. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10075. isSuccess = ConfigurationStatus_Accepted;
  10076. }
  10077. #ifdef Debug
  10078. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10079. #endif
  10080. }
  10081. else
  10082. {
  10083. isSuccess = ConfigurationStatus_Rejected;
  10084. #ifdef Debug
  10085. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10086. #endif
  10087. }
  10088. }
  10089. if(strcmp(key, "MinimumStatusDuration") == 0)
  10090. {
  10091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10092. {
  10093. check_ascii = value[0];
  10094. if( (check_ascii < 48) || (check_ascii > 57) )
  10095. {
  10096. isSuccess = ConfigurationStatus_Rejected;
  10097. }
  10098. else
  10099. {
  10100. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10101. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10102. isSuccess = ConfigurationStatus_Accepted;
  10103. }
  10104. }
  10105. else
  10106. {
  10107. isSuccess = ConfigurationStatus_Rejected;
  10108. }
  10109. }
  10110. if(strcmp(key, "ResetRetries") == 0)
  10111. {
  10112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10113. {
  10114. check_ascii = value[0];
  10115. if( (check_ascii < 48) || (check_ascii > 57) )
  10116. {
  10117. isSuccess = ConfigurationStatus_Rejected;
  10118. }
  10119. else
  10120. {
  10121. //Charger.ResetRetries = Integer.parseInt(value);
  10122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10123. isSuccess = ConfigurationStatus_Accepted;
  10124. }
  10125. }
  10126. else
  10127. {
  10128. isSuccess = ConfigurationStatus_Rejected;
  10129. }
  10130. }
  10131. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10132. {
  10133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10134. {
  10135. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10136. //int valueLength = strlen(value);
  10137. for(int i = 0; value[i]; i++){
  10138. value[i] = tolower(value[i]);
  10139. }
  10140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10141. isSuccess = ConfigurationStatus_Accepted;
  10142. }
  10143. else
  10144. {
  10145. isSuccess = ConfigurationStatus_Rejected;
  10146. }
  10147. }
  10148. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10149. {
  10150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10151. {
  10152. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10154. isSuccess = ConfigurationStatus_Accepted;
  10155. }
  10156. else
  10157. {
  10158. isSuccess = ConfigurationStatus_Rejected;
  10159. }
  10160. }
  10161. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10162. {
  10163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10164. {
  10165. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10167. isSuccess = ConfigurationStatus_Accepted;
  10168. }
  10169. else
  10170. {
  10171. isSuccess = ConfigurationStatus_Rejected;
  10172. }
  10173. }
  10174. if(strcmp(key, "StopTxnAlignedData") == 0)
  10175. {
  10176. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10177. {
  10178. //Charger.StopTxnAlignedData = value.toLowerCase();
  10179. //int valueLength = strlen(value);
  10180. for(int i = 0; value[i]; i++){
  10181. value[i] = tolower(value[i]);
  10182. }
  10183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10184. isSuccess = ConfigurationStatus_Accepted;
  10185. }
  10186. else
  10187. {
  10188. isSuccess = ConfigurationStatus_Rejected;
  10189. }
  10190. }
  10191. if(strcmp(key, "StopTxnSampledData") == 0)
  10192. {
  10193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10194. {
  10195. //Charger.StopTxnSampledData = value.toLowerCase();
  10196. //int valueLength = strlen(value);
  10197. for(int i = 0; value[i]; i++){
  10198. value[i] = tolower(value[i]);
  10199. }
  10200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10201. isSuccess = ConfigurationStatus_Accepted;
  10202. }
  10203. else
  10204. {
  10205. isSuccess = ConfigurationStatus_Rejected;
  10206. }
  10207. }
  10208. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10209. {
  10210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10211. {
  10212. check_ascii = value[0];
  10213. if( (check_ascii < 48) || (check_ascii > 57) )
  10214. {
  10215. isSuccess = ConfigurationStatus_Rejected;
  10216. }
  10217. else
  10218. {
  10219. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10221. TransactionMessageAttemptsValue = atoi(value);
  10222. isSuccess = ConfigurationStatus_Accepted;
  10223. }
  10224. }
  10225. else
  10226. {
  10227. isSuccess = ConfigurationStatus_Rejected;
  10228. }
  10229. }
  10230. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10231. {
  10232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10233. {
  10234. check_ascii = value[0];
  10235. if( (check_ascii < 48) || (check_ascii > 57) )
  10236. {
  10237. isSuccess = ConfigurationStatus_Rejected;
  10238. }
  10239. else
  10240. {
  10241. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10243. TransactionMessageRetryIntervalValue = atoi(value);
  10244. isSuccess = ConfigurationStatus_Accepted;
  10245. }
  10246. }
  10247. else
  10248. {
  10249. isSuccess = ConfigurationStatus_Rejected;
  10250. }
  10251. }
  10252. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10253. {
  10254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10255. {
  10256. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10258. isSuccess = ConfigurationStatus_Accepted;
  10259. }
  10260. else
  10261. {
  10262. isSuccess = ConfigurationStatus_Rejected;
  10263. }
  10264. }
  10265. if(strcmp(key, "WebSocketPingInterval") == 0)
  10266. {
  10267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10268. {
  10269. check_ascii = value[0];
  10270. if( (check_ascii < 48) || (check_ascii > 57) )
  10271. {
  10272. isSuccess = ConfigurationStatus_Rejected;
  10273. }
  10274. else
  10275. {
  10276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10277. isSuccess = ConfigurationStatus_Accepted;
  10278. }
  10279. }
  10280. else
  10281. {
  10282. isSuccess = ConfigurationStatus_Rejected;
  10283. }
  10284. }
  10285. #if 0
  10286. //For OCPP Test Case
  10287. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10288. {
  10289. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10290. {
  10291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10292. isSuccess = ConfigurationStatus_Accepted;
  10293. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10294. }
  10295. else
  10296. {
  10297. isSuccess = ConfigurationStatus_Rejected;
  10298. }
  10299. }
  10300. #endif
  10301. #if 1
  10302. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10303. {
  10304. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10305. {
  10306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10307. isSuccess = ConfigurationStatus_Accepted;
  10308. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10309. }
  10310. else
  10311. {
  10312. isSuccess = ConfigurationStatus_Rejected;
  10313. }
  10314. }
  10315. #endif
  10316. return isSuccess;
  10317. }
  10318. int updateSetting(char *key, char *value)
  10319. {
  10320. mtrace();
  10321. int isSuccess = FALSE;
  10322. char string[1000]={0}, buffer[1000]={0};
  10323. char strtemp[50]={0};
  10324. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10325. int pos, c = 0;
  10326. char *loc;
  10327. int pos1=0;
  10328. FILE *f = fopen("/var/www/settings1", "r");
  10329. if(f == NULL)
  10330. {
  10331. #ifdef Debug
  10332. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10333. #endif
  10334. return isSuccess;
  10335. }
  10336. fseek(f, 0, SEEK_END);
  10337. long fsize = ftell(f);
  10338. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10339. fread(string, 1, fsize, f);
  10340. fclose(f);
  10341. string[fsize] = 0;
  10342. loc = strstr(string, key);
  10343. if(loc != NULL)
  10344. {
  10345. DEBUG_INFO("key exist!\n");
  10346. pos = loc - string-1;
  10347. f = fopen("/var/www/settings1", "w");
  10348. strncpy(buffer, string, pos);
  10349. fprintf(f, "%s", buffer);
  10350. memset(sstr ,0, sizeof(sstr) );
  10351. c = 0;
  10352. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10353. {
  10354. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10356. c++;
  10357. }
  10358. sstr[c] = '\0';
  10359. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10360. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10361. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10362. memset(buffer ,0, sizeof(buffer) );
  10363. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10364. //printf("buffer=%s",buffer);
  10365. fprintf(f, "%s", buffer);
  10366. fclose(f);
  10367. }
  10368. else
  10369. {
  10370. printf("key not exist!\n");
  10371. f = fopen("/var/www/settings1", "w+");
  10372. fputs(string, f);
  10373. fseek(f, -1, SEEK_CUR);
  10374. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10375. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10376. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10377. fclose(f);
  10378. }
  10379. isSuccess = TRUE;
  10380. return isSuccess;
  10381. }
  10382. int TransactionMessageAttemptsGet(void)
  10383. {
  10384. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10385. }
  10386. int FirstHeartBeatResponse(void)
  10387. {
  10388. return FirstHeartBeat;
  10389. }
  10390. int TransactionMessageRetryIntervalGet(void)
  10391. {
  10392. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10393. }
  10394. #define SA struct sockaddr
  10395. #define MAXBUF 1024
  10396. //static int m_socket_data;
  10397. //static int sockfd;
  10398. int ReadHttpStatus(int sock){
  10399. //char c;
  10400. char buff[1024]="",*ptr=buff+1;
  10401. int bytes_received, status;
  10402. DEBUG_INFO("Begin Response ..\n");
  10403. while((bytes_received = recv(sock, ptr, 1, 0))){
  10404. if(bytes_received==-1){
  10405. perror("ReadHttpStatus");
  10406. exit(1);
  10407. }
  10408. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10409. ptr++;
  10410. }
  10411. *ptr=0;
  10412. ptr=buff+1;
  10413. sscanf(ptr,"%*s %d ", &status);
  10414. DEBUG_INFO("%s\n",ptr);
  10415. DEBUG_INFO("status=%d\n",status);
  10416. DEBUG_INFO("End Response ..\n");
  10417. return (bytes_received>0)?status:0;
  10418. }
  10419. //the only filed that it parsed is 'Content-Length'
  10420. int ParseHeader(int sock){
  10421. //char c;
  10422. char buff[1024]="",*ptr=buff+4;
  10423. int bytes_received;
  10424. DEBUG_INFO("Begin HEADER ..\n");
  10425. while((bytes_received = recv(sock, ptr, 1, 0))){
  10426. if(bytes_received==-1){
  10427. perror("Parse Header");
  10428. exit(1);
  10429. }
  10430. if(
  10431. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10432. (ptr[-1]=='\r') && (*ptr=='\n' )
  10433. ) break;
  10434. ptr++;
  10435. }
  10436. *ptr=0;
  10437. ptr=buff+4;
  10438. //printf("%s",ptr);
  10439. if(bytes_received){
  10440. ptr=strstr(ptr,"Content-Length:");
  10441. if(ptr){
  10442. sscanf(ptr,"%*s %d",&bytes_received);
  10443. }else
  10444. bytes_received=-1; //unknown size
  10445. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10446. }
  10447. DEBUG_INFO("End HEADER ..\n");
  10448. return bytes_received ;
  10449. }
  10450. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10451. {
  10452. char rmFileCmd[100]={0};
  10453. char FilePath[100]={0};
  10454. char ftpbuf[200];
  10455. int systemresult;
  10456. DEBUG_INFO("filename=%s\n",filename);
  10457. DEBUG_INFO("url=%s\n",url);
  10458. sprintf(FilePath,"../mnt/%s",filename);
  10459. if((access(FilePath,F_OK))!=-1)
  10460. {
  10461. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10462. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10463. system(rmFileCmd);
  10464. }
  10465. memset(ftpbuf, 0, sizeof(ftpbuf));
  10466. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10467. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10468. systemresult = system(ftpbuf);
  10469. DEBUG_INFO("systemresult=%d\n",systemresult);
  10470. if(systemresult != 0)
  10471. {
  10472. DEBUG_INFO("http DownLoad error!\n");
  10473. return FALSE;
  10474. }
  10475. return TRUE;
  10476. }
  10477. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10478. {
  10479. char rmFileCmd[100]={0};
  10480. char FilePath[100]={0};
  10481. char ftpbuf[200];
  10482. int systemresult;
  10483. //char temp[100];
  10484. #if 0
  10485. struct hostent* server;
  10486. char *IPbuffer;
  10487. server = gethostbyname(location);
  10488. // To convert an Internet network
  10489. // address into ASCII string
  10490. IPbuffer = inet_ntoa(*((struct in_addr*)
  10491. server->h_addr_list[0]));
  10492. #endif
  10493. sprintf(FilePath,"../mnt/%s",filename);
  10494. if((access(FilePath,F_OK))!=-1)
  10495. {
  10496. DEBUG_INFO("filename=%s exist.\n",FilePath);
  10497. sprintf(rmFileCmd,"rm -f %s",FilePath);
  10498. system(rmFileCmd);
  10499. }
  10500. memset(ftpbuf, 0, sizeof(ftpbuf));
  10501. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  10502. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10503. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10504. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10505. systemresult = system(ftpbuf);
  10506. DEBUG_INFO("systemresult=%d\n",systemresult);
  10507. if(systemresult != 0)
  10508. {
  10509. printf("ftpget error!\n");
  10510. return FALSE;
  10511. }
  10512. return TRUE;
  10513. }
  10514. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10515. {
  10516. struct hostent* server;
  10517. char *IPbuffer;
  10518. char ftpbuf[200];
  10519. int systemresult;
  10520. // To retrieve host information
  10521. server = gethostbyname(location);
  10522. // To convert an Internet network
  10523. // address into ASCII string
  10524. IPbuffer = inet_ntoa(*((struct in_addr*)
  10525. server->h_addr_list[0]));
  10526. memset(ftpbuf, 0, sizeof(ftpbuf));
  10527. /* format : ftpput -u username -p passwd IP target source*/
  10528. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10529. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10530. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10531. systemresult = system(ftpbuf);
  10532. DEBUG_INFO("systemresult=%d\n",systemresult);
  10533. if(systemresult != 0)
  10534. {
  10535. DEBUG_INFO("ftpput error!\n");
  10536. return FALSE;
  10537. }
  10538. return TRUE;
  10539. }
  10540. int SettingChargingRecord(int target, int transactionId)
  10541. {
  10542. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10543. {
  10544. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10545. {
  10546. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10547. {
  10548. addBuff(target, transactionId, 0);
  10549. return TRUE;
  10550. }
  10551. }
  10552. for (int index = 0; index < CCS_QUANTITY; index++)
  10553. {
  10554. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10555. {
  10556. addBuff(target, transactionId, 0);
  10557. return TRUE;
  10558. }
  10559. }
  10560. for (int index = 0; index < GB_QUANTITY; index++)
  10561. {
  10562. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10563. {
  10564. addBuff(target, transactionId, 0);
  10565. return TRUE;
  10566. }
  10567. }
  10568. }
  10569. else
  10570. {
  10571. for (int index = 0; index < AC_QUANTITY; index++)
  10572. {
  10573. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10574. {
  10575. addBuff(target, transactionId, 0);
  10576. return TRUE;
  10577. }
  10578. }
  10579. }
  10580. return FALSE;
  10581. }
  10582. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10583. {
  10584. int isSuccess = FALSE;
  10585. //char *query = NULL;
  10586. sqlite3_stmt *stmt;
  10587. int rc; // return code
  10588. char str[20];
  10589. sprintf(str,"%d",user_id);
  10590. 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 */
  10591. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10592. rc = sqlite3_step(stmt); /* 3 */
  10593. if (rc != SQLITE_DONE) {
  10594. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10595. goto out;
  10596. }
  10597. sqlite3_finalize(stmt);
  10598. // free(query);
  10599. out:
  10600. //----------------------
  10601. // close SQLite database
  10602. //----------------------
  10603. sqlite3_close(db);
  10604. printf("database closed.\n");
  10605. return isSuccess;
  10606. }
  10607. /**
  10608. * Place the contents of the specified file into a memory buffer
  10609. *
  10610. * @param[in] filename The path and name of the file to read
  10611. * @param[out] filebuffer A pointer to the contents in memory
  10612. * @return status 0 success, 1 on failure
  10613. */
  10614. int get_file_contents(const char* filename, char** outbuffer) {
  10615. FILE* file = NULL;
  10616. long filesize;
  10617. const int blocksize = 1;
  10618. size_t readsize;
  10619. char* filebuffer;
  10620. // Open the file
  10621. file = fopen(filename, "r");
  10622. if (NULL == file)
  10623. {
  10624. printf("'%s' not opened\n", filename);
  10625. exit(EXIT_FAILURE);
  10626. }
  10627. // Determine the file size
  10628. fseek(file, 0, SEEK_END);
  10629. filesize = ftell(file);
  10630. rewind (file);
  10631. // Allocate memory for the file contents
  10632. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10633. *outbuffer = filebuffer;
  10634. if (filebuffer == NULL)
  10635. {
  10636. fputs ("malloc out-of-memory", stderr);
  10637. exit(EXIT_FAILURE);
  10638. }
  10639. // Read in the file
  10640. readsize = fread(filebuffer, blocksize, filesize, file);
  10641. if (readsize != filesize)
  10642. {
  10643. fputs ("didn't read file completely",stderr);
  10644. exit(EXIT_FAILURE);
  10645. }
  10646. // Clean exit
  10647. fclose(file);
  10648. return EXIT_SUCCESS;
  10649. }
  10650. static int selectSqlCount = 0;
  10651. static int callback(void *data, int argc, char **argv, char **azColName){
  10652. int i;
  10653. printf("%s: ", (const char*)data);
  10654. selectSqlCount = argc;
  10655. for(i = 0; i<argc; i++){
  10656. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10657. }
  10658. printf("\n");
  10659. return 0;
  10660. }
  10661. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10662. //int i;
  10663. //printf("%s:\n", (const char*)data);
  10664. localversion = argv[5] ? atoi(argv[5]) : 0;
  10665. printf("localversion=%d\n", localversion);
  10666. return 0;
  10667. }
  10668. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10669. //int i;
  10670. //printf("%s:\n", (const char*)data);
  10671. //idTag
  10672. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10673. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10674. //parentIdTag
  10675. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10676. //expir_date
  10677. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10678. //status
  10679. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10680. //version
  10681. idTagQuery.listVersionInt = atoi(argv[5]);
  10682. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10683. return 0;
  10684. }
  10685. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10686. int i;
  10687. //printf("%s:\n", (const char*)data);
  10688. #if 1
  10689. for(i=0; i<argc; i++){
  10690. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10691. }
  10692. //printf("");
  10693. #endif
  10694. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10695. // printf("localversion=%d\n", localversion);
  10696. return 0;
  10697. }
  10698. /** sqlite3_exec的回调。
  10699. *
  10700. * 向控制台打印查询的结果。
  10701. *
  10702. * @param in data 传递给回调函数的数据。
  10703. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10704. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10705. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10706. * @return 状态码。
  10707. */
  10708. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10709. {
  10710. for (int i = 0; i < n_columns; i++)
  10711. {
  10712. DEBUG_INFO("%s/t", col_values[i]);
  10713. }
  10714. DEBUG_INFO("/n");
  10715. return 0;
  10716. }
  10717. void OCPP_getListVerion()
  10718. {
  10719. int rc = 0;
  10720. // const char* data = "Callback function called";
  10721. char sql[100];
  10722. char zErrMsg[100];
  10723. memset(sql, 0, 100);
  10724. memset(zErrMsg, 0, 100);
  10725. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10726. /* Execute SQL statement */
  10727. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10728. DEBUG_INFO("rc=%d\n",rc);
  10729. if( rc != SQLITE_OK ){
  10730. DEBUG_INFO("SQL error: %s", zErrMsg);
  10731. //sqlite3_free(zErrMsg);
  10732. }else{
  10733. DEBUG_INFO("Operation done successfully");
  10734. }
  10735. }
  10736. void OCPP_getIdTag(char *idTag)
  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. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10745. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10746. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10747. /* Execute SQL statement */
  10748. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10749. if( rc != SQLITE_OK ){
  10750. DEBUG_INFO("SQL error: %s", zErrMsg);
  10751. //sqlite3_free(zErrMsg);
  10752. }else{
  10753. printf("Operation done successfully");
  10754. }
  10755. //return ver;
  10756. }
  10757. void OCPP_get_TableAuthlocalAllData(void)
  10758. {
  10759. int rc = 0;
  10760. // const char* data = "Callback function called";
  10761. char sql[100];
  10762. char zErrMsg[100];
  10763. memset(sql, 0, 100);
  10764. memset(zErrMsg, 0, 100);
  10765. sprintf(sql,"select * from ocpp_auth_local ");
  10766. /* Execute SQL statement */
  10767. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10768. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10769. if( rc != SQLITE_OK ){
  10770. DEBUG_INFO("SQL error: %s", zErrMsg);
  10771. //sqlite3_free(zErrMsg);
  10772. }else{
  10773. DEBUG_INFO("Operation done successfully");
  10774. }
  10775. //return ver;
  10776. }
  10777. int OCPP_cleanLocalList()
  10778. {
  10779. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10780. char *errMsg = 0;
  10781. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10782. if (SQLITE_OK != rc)
  10783. {
  10784. DEBUG_INFO("%s\n",errMsg);
  10785. return FALSE;
  10786. }
  10787. else
  10788. {
  10789. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10790. }
  10791. return TRUE;
  10792. }
  10793. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10794. {
  10795. int isSuccess = FALSE;
  10796. int ret = 0;
  10797. //const char* data = "Callback function called";
  10798. char sql[200];
  10799. char zErrMsg[100];
  10800. memset(sql, 0, 200);
  10801. memset(zErrMsg, 0, 100);
  10802. 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);
  10803. //* Execute SQL statement */
  10804. //zErrMsg = 0;
  10805. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10806. if( ret != SQLITE_OK ){
  10807. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10808. // free(zErrMsg);
  10809. // free(sql);
  10810. return isSuccess;
  10811. }
  10812. DEBUG_INFO("successfully Insert records created\n");
  10813. isSuccess = TRUE;
  10814. return isSuccess;
  10815. }
  10816. void OCPP_deleteIdTag(char *idTag)
  10817. {
  10818. //int ver = 0;
  10819. //int isSuccess = FALSE;
  10820. int rc = 0;
  10821. char sql[100];
  10822. char zErrMsg[100];
  10823. memset(sql, 0, 100);
  10824. memset(zErrMsg, 0, 100);
  10825. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10826. //* Execute SQL statement */
  10827. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10828. if( rc != SQLITE_OK ){
  10829. DEBUG_INFO("SQL error: %s", zErrMsg);
  10830. //sqlite3_free(zErrMsg);
  10831. }else{
  10832. DEBUG_INFO("Operation done successfully");
  10833. }
  10834. }
  10835. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10836. {
  10837. int isSuccess = FALSE;
  10838. int ret = 0;
  10839. const char* data = "Callback function called";
  10840. char sql[200];
  10841. char zErrMsg[100];
  10842. memset(sql, 0, 200);
  10843. memset(zErrMsg, 0, 100);
  10844. //* selectFromTable */
  10845. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10846. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10847. //* Execute SQL statement */
  10848. selectSqlCount = 0;
  10849. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10850. if( ret != SQLITE_OK ){
  10851. printf("Error SQL: %s\n", zErrMsg);
  10852. }
  10853. printf("successfully select operation done\n");
  10854. memset(sql, 0, 200);
  10855. memset(zErrMsg, 0, 100);
  10856. if(selectSqlCount == 0)
  10857. {
  10858. //Insert
  10859. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  10860. 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);
  10861. DEBUG_INFO("sql:%s\n", sql);
  10862. //* Execute SQL statement */
  10863. //zErrMsg = 0;
  10864. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10865. if( ret != SQLITE_OK ){
  10866. printf("SQL error: %s\n", zErrMsg);
  10867. return isSuccess;
  10868. }
  10869. DEBUG_INFO("successfully Insert records created\n");
  10870. isSuccess = TRUE;
  10871. }
  10872. else
  10873. {
  10874. //Update
  10875. //* Create merged SQL statement */
  10876. 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);
  10877. /* Execute SQL statement */
  10878. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10879. if( ret != SQLITE_OK ){
  10880. printf("SQL error: %s\n", zErrMsg);
  10881. //sqlite3_free(zErrMsg);
  10882. //sqlite3_free(sql);
  10883. return isSuccess;
  10884. }
  10885. DEBUG_INFO("Successfully operation done \n");
  10886. isSuccess = TRUE;
  10887. }
  10888. return isSuccess;
  10889. }
  10890. char *GetOcppServerURL()
  10891. {
  10892. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10893. memset(OcppHost, 0, sizeof(OcppHost));
  10894. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10895. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  10896. {
  10897. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  10898. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  10899. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10900. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10901. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10902. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10903. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10904. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10905. goto End;
  10906. }
  10907. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  10908. {
  10909. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  10910. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10911. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10912. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10913. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10914. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10915. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10916. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10917. goto End;
  10918. }
  10919. else
  10920. {
  10921. strcpy(OcppHost,"");
  10922. }
  10923. End:
  10924. return OcppHost;
  10925. }
  10926. char *GetOcppPath()
  10927. {
  10928. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  10929. {
  10930. if(OcppTempPath == NULL)
  10931. {
  10932. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10933. }
  10934. else
  10935. {
  10936. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  10937. }
  10938. goto End;
  10939. }
  10940. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  10941. {
  10942. if(OcppTempPath == NULL)
  10943. {
  10944. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10945. }
  10946. else
  10947. {
  10948. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10949. }
  10950. goto End;
  10951. }
  10952. else
  10953. {
  10954. strcpy(OcppHost,"");
  10955. }
  10956. End:
  10957. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10958. return OcppPath;
  10959. }
  10960. int GetOcppPort()
  10961. {
  10962. return OcppPort;
  10963. }
  10964. int GetOcppConnStatus(void)
  10965. {
  10966. return ShmOCPP16Data->OcppConnStatus;
  10967. }
  10968. void SetOcppConnStatus(uint8_t status)
  10969. {
  10970. ShmOCPP16Data->OcppConnStatus = status;
  10971. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  10972. if(status == FALSE)
  10973. {
  10974. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10975. {
  10976. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  10977. }
  10978. else
  10979. {
  10980. SystemInitial = AC_QUANTITY;
  10981. }
  10982. }
  10983. }
  10984. int GetHeartBeatWithNOResponse(void)
  10985. {
  10986. return HeartBeatWithNOResponse;
  10987. }
  10988. void SetHeartBeatWithNOResponse(void)
  10989. {
  10990. HeartBeatWithNOResponse = 0;
  10991. }
  10992. int InternetDisconnect(void)
  10993. {
  10994. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  10995. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  10996. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  10997. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  10998. }
  10999. #if 0
  11000. void Send(struct json_object *message)
  11001. {
  11002. printf("Send -1 \n");
  11003. printf("message=%s\n",json_object_to_json_string(message));
  11004. LWS_Send(json_object_to_json_string(message));
  11005. }
  11006. #endif
  11007. void LWS_Send(char * str)
  11008. {
  11009. #if 1
  11010. //=====================================================
  11011. // Check InternetConn 0: disconnected, 1: connected
  11012. //====================================================
  11013. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  11014. {
  11015. DEBUG_INFO("\n offline now !!!\n");
  11016. return;
  11017. }
  11018. #endif
  11019. pthread_mutex_lock(&lock);
  11020. memset(SendBuffer,0,SendBufLen);
  11021. sprintf((char *)SendBuffer, "%s", str);
  11022. pthread_mutex_unlock(&lock);
  11023. lws_callback_on_writable(wsi_client);
  11024. lws_service(context, 10000);//timeout_ms
  11025. //usleep(10000); // 等 ?? ?微 ?
  11026. //DEBUG_INFO("Send message end\n");
  11027. }