MessageHandler.c 453 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881
  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 "./json-c/JsonParser.h"
  21. #include "hashmap.h"
  22. #include "ShareMemory.h"
  23. #include "TransactionQueue.h"
  24. #include "SystemLogMessage.h"
  25. #include "../../Projects/define.h"
  26. #include "ShareMemory.h"
  27. #include "SystemLogMessage.h"
  28. //#include "config.h"
  29. #include <sys/socket.h>
  30. #include <netinet/in.h>
  31. #include <stdlib.h>
  32. /*for sendfile()*/
  33. #include <sys/sendfile.h>
  34. /*for O_RDONLY*/
  35. #include <fcntl.h>
  36. #include "sqlite3.h"
  37. #include <arpa/inet.h>
  38. //#define _GNU_SOURCE
  39. #include <time.h>
  40. #include "MessageHandler.h"
  41. #include <assert.h>
  42. #include <pthread.h>
  43. #include <mcheck.h>
  44. #define PASS 1
  45. #define FAIL -1
  46. #define FALSE 0
  47. #define TRUE 1 // Option 1
  48. //ChargePointMaxProfile
  49. #define ChargePointMaxProfile_JSON "../Storage/OCPP/ChargePointMaxProfile.json"
  50. //TxDefaultProfile
  51. #define TxDefaultProfile_0_JSON "../Storage/OCPP/TxDefaultProfile_0.json"
  52. #define TxDefaultProfile_1_JSON "../Storage/OCPP/TxDefaultProfile_1.json"
  53. #define TxDefaultProfile_2_JSON "../Storage/OCPP/TxDefaultProfile_2.json"
  54. //TxProfile
  55. #define TxProfile_1_JSON "../Storage/OCPP/TxProfile_1.json"
  56. #define TxProfile_2_JSON "../Storage/OCPP/TxProfile_2.json"
  57. #define ChargingProfile_0_JSON "../Storage/OCPP/chargingprofile_0.json"
  58. #define ChargingProfile_1_JSON "../Storage/OCPP/chargingprofile_1.json"
  59. #define ChargingProfile_2_JSON "../Storage/OCPP/chargingprofile_2.json"
  60. #define AuthorizationCache_JSON "../Storage/OCPP/AuthorizationCache.json"
  61. #define LocalAuthorizationList_JSON "../Storage/OCPP/LocalAuthorizationList.json"
  62. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  63. struct StatusCodeData *ShmStatusCodeData;
  64. struct PsuData *ShmPsuData ;
  65. struct OCPP16Data *ShmOCPP16Data;
  66. // define Macro
  67. #define SystemLogMessage
  68. // OCPP Message Type
  69. #define MESSAGE_TYPE_CALL 2
  70. #define MESSAGE_TYPE_CALLRESULT 3
  71. #define MESSAGE_TYPE_CALLERROR 4
  72. //
  73. #define server_cycle_Status 120
  74. #define MACROSTR(k) #k
  75. //ConfigurationMaxKeys
  76. #define GetConfigurationMaxKeysNUM 43
  77. //char guid[37];
  78. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  79. char queuedata[2000]={0};
  80. //===============================
  81. // Configuration: unknownkey
  82. //===============================
  83. static char unknownkey[10][20]={0};
  84. static int UnknownKeynum = 0;
  85. //===============================
  86. // Gun Total Numbers
  87. //===============================
  88. //#define gunTotalNumber (strstr(ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL) ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  89. static int gunTotalNumber=0;
  90. //===============================
  91. // Local List Version
  92. //===============================
  93. static int localversion=0;
  94. static char idTagAuthorization[32]={0};
  95. //===============================
  96. // OCPP Path
  97. //===============================
  98. char OcppPath[160]={};
  99. char OcppProtocol[10]={0},OcppHost[50]={0}, OcppTempPath[50]={0};
  100. int OcppPort=0;
  101. //===============================
  102. // OCPP sign variable
  103. //===============================
  104. int server_sign = FALSE;
  105. int server_pending = FALSE;
  106. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  107. int BootNotificationInterval = 0;
  108. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  109. //===============================
  110. // OCPP auth variable
  111. //===============================
  112. int authenrequest = FALSE;
  113. int authorizeRetryTimes = 0; //number of Retry times
  114. //===============================
  115. // OCPP other variables
  116. //===============================
  117. int isUpdateRequest = FALSE;
  118. static int HeartBeatWaitTime = 10;
  119. static int FirstHeartBeat = 0;
  120. static int FirmwareStatusNotificationStatus = 3; // Idle
  121. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  122. //========================================
  123. // OCPP status/previous related variables
  124. //========================================
  125. static int GunStatusInterval = 10;
  126. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_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. extern struct lws *wsi_client;
  142. extern struct lws_context *context;
  143. #if 0
  144. extern unsigned char *SendBuffer;
  145. #endif
  146. extern unsigned char SendBuffer[4096];
  147. extern int SendBufLen;
  148. //extern map_t hashMap;
  149. //extern data_struct_t* mapItem; --- remove for temporally
  150. //extern data_struct_t mapItem[0];
  151. extern char *random_uuid( char buf[37] );
  152. extern void split(char **arr, char *str, const char *del);
  153. extern pthread_mutex_t mutex1;
  154. extern struct Charger_Info Charger;
  155. extern sqlite3 *db;
  156. int TransactionMessageAttemptsGet(void);
  157. int TransactionMessageRetryIntervalGet(void);
  158. int GetOcppConnStatus(void);
  159. int updateSetting(char *key, char *value);
  160. int setKeyValue(char *key, char *value);
  161. void OCPP_get_TableAuthlocalAllData(void);
  162. void processUnkownKey(void);
  163. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  164. struct StructOCPPMeterValue
  165. {
  166. unsigned char TimeStamp[28];
  167. struct StructSampledValue SampledValue[10];
  168. };
  169. struct ClientTime
  170. {
  171. unsigned int Heartbeat;
  172. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  173. unsigned int StartTransaction;
  174. unsigned int StopTransaction;
  175. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  176. }clientTime;
  177. typedef union
  178. {
  179. //Operations Initiated by Central System
  180. unsigned char CsMsgValue[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  181. struct
  182. {
  183. //CsMsgValue[0]
  184. unsigned char StatusNotificationReq :1; //bit 0,
  185. unsigned char StatusNotificationConf :1; //bit 0,
  186. unsigned char :6; //bit 2~7
  187. }bits[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  188. }CpinitiateMsg;
  189. CpinitiateMsg cpinitateMsg;
  190. //==========================================
  191. // Init all Enumeration & Mapping String
  192. //==========================================
  193. /*ChargePointErrorCode*/
  194. typedef enum {
  195. ConnectorLockFailure,
  196. EVCommunicationError,
  197. GroundFailure,
  198. HighTemperature,
  199. InternalError,
  200. LocalListConflict,
  201. NoError,
  202. OtherError,
  203. OverCurrentFailure,
  204. OverVoltage,
  205. PowerMeterFailure,
  206. PowerSwitchFailure,
  207. ReaderFailure,
  208. ResetFailure,
  209. UnderVoltage,
  210. WeakSignal
  211. } ChargePointErrorCode;
  212. #if 0
  213. static char *ChargePointErrorCodeStr[] = {
  214. MACROSTR(ConnectorLockFailure),
  215. MACROSTR(EVCommunicationError),
  216. MACROSTR(GroundFailure),
  217. MACROSTR(HighTemperature),
  218. MACROSTR(InternalError),
  219. MACROSTR(LocalListConflict),
  220. MACROSTR(NoError),
  221. MACROSTR(OtherError),
  222. MACROSTR(OverCurrentFailure),
  223. MACROSTR(OverVoltage),
  224. MACROSTR(PowerMeterFailure),
  225. MACROSTR(PowerSwitchFailure),
  226. MACROSTR(ReaderFailure),
  227. MACROSTR(ResetFailure),
  228. MACROSTR(UnderVoltage),
  229. MACROSTR(WeakSignal)
  230. };
  231. #endif
  232. /*ChargePointStatus*/
  233. typedef enum {
  234. Available =0,
  235. Preparing,
  236. Charging,
  237. SuspendedEVSE,
  238. SuspendedEV,
  239. Finishing,
  240. Reserved,
  241. Unavailable,
  242. Faulted
  243. } ChargePointStatus;
  244. static char * ChargePointStatusStr[] = {
  245. MACROSTR(Available),
  246. MACROSTR(Preparing),
  247. MACROSTR(Charging),
  248. MACROSTR(SuspendedEVSE),
  249. MACROSTR(SuspendedEV),
  250. MACROSTR(Finishing),
  251. MACROSTR(Reserved),
  252. MACROSTR(Unavailable),
  253. MACROSTR(Faulted)
  254. };
  255. /*AvailabilityType*/
  256. typedef enum {
  257. RegistrationStatus_Accepted,
  258. RegistrationStatus_Pending,
  259. RegistrationStatus_Rejected
  260. } RegistrationStatus;
  261. static char *RegistrationStatusStr[] = {
  262. MACROSTR(Accepted),
  263. MACROSTR(Pending),
  264. MACROSTR(Rejected)
  265. };
  266. /*AvailabilityType*/
  267. typedef enum {
  268. Inoperative,
  269. Operative
  270. } AvailabilityType;
  271. static char *AvailabilityTypeStr[] = {
  272. MACROSTR(Inoperative),
  273. MACROSTR(Operative)
  274. };
  275. /*AvailabilityStatus*/
  276. typedef enum {
  277. Accepted,
  278. Rejected,
  279. Scheduled
  280. } AvailabilityStatus;
  281. static char *AvailabilityStatusStr[] = {
  282. MACROSTR(Accepted),
  283. MACROSTR(Rejected),
  284. MACROSTR(Scheduled)
  285. };
  286. /*ConfigurationStatus*/
  287. typedef enum {
  288. ConfigurationStatus_Accepted,
  289. ConfigurationStatus_Rejected,
  290. RebootRequired,
  291. NotSupported
  292. } ConfigurationStatus;
  293. static char *ConfigurationStatusStr[] = {
  294. MACROSTR(Accepted),
  295. MACROSTR(Rejected),
  296. MACROSTR(RebootRequired),
  297. MACROSTR(NotSupported)
  298. };
  299. /*ClearCacheStatus*/
  300. typedef enum {
  301. ClearCacheStatus_Accepted,
  302. ClearCacheStatus_Rejected
  303. } ClearCacheStatus;
  304. static char *ClearCacheStatusStr[] = {
  305. MACROSTR(Accepted),
  306. MACROSTR(Rejected)
  307. };
  308. /*ChargingProfilePurposeType*/
  309. typedef enum {
  310. ChargePointMaxProfile,
  311. TxDefaultProfile,
  312. TxProfile
  313. } ChargingProfilePurposeType;
  314. static char *ChargingProfilePurposeTypeStr[] = {
  315. MACROSTR(ChargePointMaxProfile),
  316. MACROSTR(TxDefaultProfile),
  317. MACROSTR(TxProfile)
  318. };
  319. /*ChargingProfileStatus*/
  320. typedef enum {
  321. ChargingProfileStatus_Accepted,
  322. ChargingProfileStatus_Rejected,
  323. ChargingProfileStatus_NotSupported
  324. } ChargingProfileStatus;
  325. static char *ChargingProfileStatusStr[] = {
  326. MACROSTR(Accepted),
  327. MACROSTR(Rejected),
  328. MACROSTR(NotSupported)
  329. };
  330. /*ClearChargingProfileStatus*/
  331. typedef enum {
  332. ClearChargingProfileStatus_Accepted,
  333. ClearChargingProfileStatus_Unknown
  334. } ClearChargingProfileStatus;
  335. static char *ClearChargingProfileStatusStr[] = {
  336. MACROSTR(Accepted),
  337. MACROSTR(Unknown)
  338. };
  339. /*GetCompositeScheduleStatus*/
  340. typedef enum {
  341. GetCompositeScheduleStatus_Accepted,
  342. GetCompositeScheduleStatus_Rejected
  343. } GetCompositeScheduleStatus;
  344. static char *GetCompositeScheduleStatusStr[] = {
  345. MACROSTR(Accepted),
  346. MACROSTR(Rejected)
  347. };
  348. /*ChargingRateUnitType*/
  349. typedef enum {
  350. ChargingRateUnitType_W,
  351. ChargingRateUnitType_A
  352. } ChargingRateUnitType;
  353. /*AuthorizationStatus*/
  354. typedef enum {
  355. AuthorizationStatus_Accepted ,
  356. AuthorizationStatus_Blocked ,
  357. AuthorizationStatus_Expired ,
  358. AuthorizationStatus_Invalid ,
  359. AuthorizationStatus_ConcurrentTx
  360. } AuthorizationStatus;
  361. /*UpdateType*/
  362. typedef enum {
  363. Differential ,
  364. Full
  365. } UpdateType;
  366. static char *UpdateTypeStr[] = {
  367. MACROSTR(Differential),
  368. MACROSTR(Full)
  369. };
  370. /*UpdateStatus*/
  371. typedef enum {
  372. UpdateStatus_Accepted ,
  373. UpdateStatus_Failed ,
  374. UpdateStatus_NotSupported ,
  375. UpdateStatus_VersionMismatch
  376. } UpdateStatus;
  377. static char *UpdateStatusStr[] = {
  378. MACROSTR(Accepted),
  379. MACROSTR(Failed),
  380. MACROSTR(NotSupported),
  381. MACROSTR(VersionMismatch)
  382. };
  383. /*RemoteStartStopStatus*/
  384. typedef enum {
  385. RemoteStartStopStatus_Accepted,
  386. RemoteStartStopStatus_Rejected
  387. } RemoteStartStopStatus;
  388. static char *RemoteStartStopStatusStr[] = {
  389. MACROSTR(Accepted),
  390. MACROSTR(Rejected)
  391. };
  392. /*ReservationStatus*/
  393. typedef enum {
  394. ReservationStatus_Accepted,
  395. ReservationStatus_Faulted,
  396. ReservationStatus_Occupied,
  397. ReservationStatus_Rejected,
  398. ReservationStatus_Unavailable
  399. } ReservationStatus;
  400. static char *ReservationStatusStr[] = {
  401. MACROSTR(Accepted),
  402. MACROSTR(Faulted),
  403. MACROSTR(Occupied),
  404. MACROSTR(Rejected),
  405. MACROSTR(Unavailable)
  406. };
  407. /*ResetType*/
  408. typedef enum {
  409. Hard,
  410. Soft
  411. } ResetType;
  412. static char *ResetTypeStr[] = {
  413. MACROSTR(Hard),
  414. MACROSTR(Soft)
  415. };
  416. /*ResetStatus*/
  417. typedef enum {
  418. ResetStatus_Accepted,
  419. ResetStatus_Rejected
  420. } ResetStatus;
  421. static char *ResetStatusStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Rejected)
  424. };
  425. /*DiagnosticsStatus*/
  426. typedef enum {
  427. DiagnosticsStatus_Idle,
  428. DiagnosticsStatus_Uploaded,
  429. DiagnosticsStatus_UploadFailed,
  430. DiagnosticsStatus_Uploading
  431. } DiagnosticsStatus;
  432. static char * DiagnosticsStatusStr[] = {
  433. MACROSTR(Idle),
  434. MACROSTR(Uploaded),
  435. MACROSTR(UploadFailed),
  436. MACROSTR(Uploading)
  437. };
  438. /*FirmwareStatus*/
  439. typedef enum {
  440. FirmwareStatus_Downloaded,
  441. FirmwareStatus_DownloadFailed,
  442. FirmwareStatus_Downloading,
  443. FirmwareStatus_Idle,
  444. FirmwareStatus_InstallationFailed,
  445. FirmwareStatus_Installing,
  446. FirmwareStatus_Installed
  447. } FirmwareStatus;
  448. static char * FirmwareStatusStr[] = {
  449. MACROSTR(Downloaded),
  450. MACROSTR(DownloadFailed),
  451. MACROSTR(Downloading),
  452. MACROSTR(Idle),
  453. MACROSTR(InstallationFailed),
  454. MACROSTR(Installing),
  455. MACROSTR(Installed)
  456. };
  457. /*MessageTrigger*/
  458. typedef enum {
  459. BootNotification,
  460. DiagnosticsStatusNotification,
  461. FirmwareStatusNotification,
  462. Heartbeat,
  463. MeterValues,
  464. StatusNotification
  465. } MessageTrigger;
  466. static char * MessageTriggerStr[] = {
  467. MACROSTR(BootNotification),
  468. MACROSTR(DiagnosticsStatusNotification),
  469. MACROSTR(FirmwareStatusNotification),
  470. MACROSTR(Heartbeat),
  471. MACROSTR(MeterValues),
  472. MACROSTR(StatusNotification)
  473. };
  474. /*TriggerMessageStatus*/
  475. typedef enum {
  476. TriggerMessageStatus_Accepted ,
  477. TriggerMessageStatus_Rejected ,
  478. TriggerMessageStatus_NotImplemented
  479. } TriggerMessageStatus;
  480. static char * TriggerMessageStatusStr[] = {
  481. MACROSTR(Accepted),
  482. MACROSTR(Rejected),
  483. MACROSTR(NotImplemented)
  484. };
  485. /*UnlockStatus*/
  486. typedef enum {
  487. Unlocked,
  488. UnlockFailed,
  489. UnlockStatus_NotSupported
  490. } UnlockStatus;
  491. static char * UnlockStatusStr[] = {
  492. MACROSTR(Unlocked),
  493. MACROSTR(UnlockFailed),
  494. MACROSTR(NotSupported)
  495. };
  496. /*StopTransactionReason*/
  497. typedef enum {
  498. EmergencyStop,
  499. EVDisconnected,
  500. HardReset,
  501. Local,
  502. Other,
  503. PowerLoss,
  504. Reboot,
  505. Remote,
  506. SoftReset,
  507. UnlockCommand,
  508. DeAuthorized
  509. } StopTransactionReason;
  510. static char * StopTransactionReasonStr[] = {
  511. MACROSTR(EmergencyStop),
  512. MACROSTR(EVDisconnected),
  513. MACROSTR(HardReset),
  514. MACROSTR(Local),
  515. MACROSTR(Other),
  516. MACROSTR(PowerLoss),
  517. MACROSTR(Reboot),
  518. MACROSTR(Remote),
  519. MACROSTR(SoftReset),
  520. MACROSTR(UnlockCommand),
  521. MACROSTR(DeAuthorized)
  522. };
  523. /*CancelReservationStatus*/
  524. typedef enum {
  525. CancelReservationStatus_Accepted,
  526. CancelReservationStatus_Rejected
  527. } CancelReservationStatus;
  528. static char * CancelReservationStatusStr[] = {
  529. MACROSTR(Accepted),
  530. MACROSTR(Rejected)
  531. };
  532. /*ReadingContext*/
  533. typedef enum {
  534. ReadingContext_Interruption_Begin,
  535. ReadingContext_Interruption_End,
  536. ReadingContext_Other,
  537. ReadingContext_Sample_Clock,
  538. ReadingContext_Sample_Periodic ,
  539. ReadingContext_Transaction_Begin ,
  540. ReadingContext_Transaction_End,
  541. ReadingContext_Trigger
  542. } ReadingContext;
  543. static char * ReadingContextStr[] = {
  544. MACROSTR(Interruption.Begin),
  545. MACROSTR(Interruption.End),
  546. MACROSTR(Other),
  547. MACROSTR(Sample.Clock),
  548. MACROSTR(Sample.Periodic),
  549. MACROSTR(Transaction.Begin),
  550. MACROSTR(Transaction.End),
  551. MACROSTR(Trigger)
  552. };
  553. /*ValueFormat*/
  554. typedef enum {
  555. Raw,
  556. SignedData
  557. } ValueFormat;
  558. static char * ValueFormatStr[] = {
  559. MACROSTR(Raw),
  560. MACROSTR(SignedData)
  561. };
  562. /*Measurand*/
  563. typedef enum {
  564. Current_Export ,
  565. Current_Import,
  566. Current_Offered,
  567. Energy_Active_Export_Register,
  568. Energy_Active_Import_Register,
  569. Energy_Reactive_Export_Register,
  570. Energy_Reactive_Import_Register,
  571. Energy_Active_Export_Interval,
  572. Energy_Active_Import_Interval,
  573. Energy_Reactive_Export_Interval,
  574. Energy_Reactive_Import_Interval,
  575. Frequency,
  576. Power_Active_Export ,
  577. Power_Active_Import,
  578. Power_Factor,
  579. Power_Offered,
  580. Power_Reactive_Export,
  581. Power_Reactive_Import,
  582. RPM,
  583. SoC,
  584. Temperature ,
  585. Voltage
  586. } Measurand;
  587. static char * MeasurandStr[] = {
  588. MACROSTR(Current.Export),
  589. MACROSTR(Current.Import),
  590. MACROSTR(Current.Offered),
  591. MACROSTR(Energy.Active.Export.Register),
  592. MACROSTR(Energy.Active.Import.Register),
  593. MACROSTR(Energy.Reactive.Export.Register),
  594. MACROSTR(Energy.Reactive.Import.Register),
  595. MACROSTR(Energy.Active.Export.Interval),
  596. MACROSTR(Energy.Active.Import.Interval),
  597. MACROSTR(Energy.Reactive.Export.Interval),
  598. MACROSTR(Energy.Reactive.Import.Interval),
  599. MACROSTR(Frequency),
  600. MACROSTR(Power.Active.Export),
  601. MACROSTR(Power.Active.Import),
  602. MACROSTR(Power.Factor),
  603. MACROSTR(Power.Offered),
  604. MACROSTR(Power.Reactive.ExportMACROSTR),
  605. MACROSTR(Power.Reactive.Import),
  606. MACROSTR(RPM),
  607. MACROSTR(SoC),
  608. MACROSTR(Temperature),
  609. MACROSTR(Voltage)
  610. };
  611. /*Location*/
  612. typedef enum {
  613. Location_Body,
  614. Location_Cable,
  615. Location_EV,
  616. Location_Inlet ,
  617. Location_Outlet
  618. } Location;
  619. static char * LocationStr[] = {
  620. MACROSTR(Body),
  621. MACROSTR(Cable),
  622. MACROSTR(EV),
  623. MACROSTR(Inlet),
  624. MACROSTR(Outlet)
  625. };
  626. /*Phase*/
  627. typedef enum {
  628. L1,
  629. L2,
  630. L3,
  631. N,
  632. L1_N,
  633. L2_N,
  634. L3_N,
  635. L1_L2,
  636. L2_L3,
  637. L3_L1
  638. } Phase;
  639. static char * PhaseStr[] = {
  640. MACROSTR(L1),
  641. MACROSTR(L2),
  642. MACROSTR(L3),
  643. MACROSTR(N),
  644. MACROSTR(L1-N),
  645. MACROSTR(L2-N),
  646. MACROSTR(L3-N),
  647. MACROSTR(L1-L2),
  648. MACROSTR(L2-L3),
  649. MACROSTR(L3-L1)
  650. };
  651. /*UnitOfMeasure*/
  652. typedef enum {
  653. UnitOfMeasure_Wh,
  654. UnitOfMeasure_kWh ,
  655. UnitOfMeasure_varh ,
  656. UnitOfMeasure_kvarh ,
  657. UnitOfMeasure_W ,
  658. UnitOfMeasure_kW ,
  659. UnitOfMeasure_VA ,
  660. UnitOfMeasure_kVA ,
  661. UnitOfMeasure_var ,
  662. UnitOfMeasure_kvar ,
  663. UnitOfMeasure_A ,
  664. UnitOfMeasure_V ,
  665. UnitOfMeasure_Celsius ,
  666. UnitOfMeasure_Fahrenheit ,
  667. UnitOfMeasure_K ,
  668. UnitOfMeasure_Percent
  669. } UnitOfMeasure;
  670. static char * UnitOfMeasureStr[] = {
  671. MACROSTR(Wh),
  672. MACROSTR(kWh),
  673. MACROSTR(varh),
  674. MACROSTR(kvarh),
  675. MACROSTR(W),
  676. MACROSTR(kW),
  677. MACROSTR(VA),
  678. MACROSTR(kVA),
  679. MACROSTR(var),
  680. MACROSTR(kvar),
  681. MACROSTR(A),
  682. MACROSTR(V),
  683. MACROSTR(Celsius),
  684. MACROSTR(Fahrenheit),
  685. MACROSTR(K),
  686. MACROSTR(Percent)
  687. };
  688. /*Configuration enum*/
  689. enum CoreProfile {
  690. AllowOfflineTxForUnknownId=0,
  691. AuthorizationCacheEnabled,
  692. AuthorizeRemoteTxRequests,
  693. BlinkRepeat,
  694. ClockAlignedDataInterval,
  695. ConnectionTimeOut,
  696. GetConfigurationMaxKeys,
  697. HeartbeatInterval,
  698. LightIntensity,
  699. LocalAuthorizeOffline,
  700. LocalPreAuthorize,
  701. MaxEnergyOnInvalidId,
  702. MeterValuesAlignedData,
  703. MeterValuesAlignedDataMaxLength,
  704. MeterValuesSampledData,
  705. MeterValuesSampledDataMaxLength,
  706. MeterValueSampleInterval,
  707. MinimumStatusDuration,
  708. NumberOfConnectors,
  709. ResetRetries,
  710. ConnectorPhaseRotation,
  711. ConnectorPhaseRotationMaxLength,
  712. StopTransactionOnEVSideDisconnect,
  713. StopTransactionOnInvalidId,
  714. StopTxnAlignedData,
  715. StopTxnAlignedDataMaxLength,
  716. StopTxnSampledData,
  717. StopTxnSampledDataMaxLength,
  718. SupportedFeatureProfiles,
  719. SupportedFeatureProfilesMaxLength,
  720. TransactionMessageAttempts,
  721. TransactionMessageRetryInterval,
  722. UnlockConnectorOnEVSideDisconnect,
  723. WebSocketPingInterval,
  724. _CoreProfile_CNT
  725. };
  726. enum LocalAuthListManagementProfile{
  727. LocalAuthListEnabled=0,
  728. LocalAuthListMaxLength,
  729. SendLocalListMaxLength,
  730. _LocalAuthListManagementProfile_CNT
  731. };
  732. enum ReservationProfile{
  733. ReserveConnectorZeroSupported
  734. };
  735. enum SmartChargingProfile{
  736. ChargeProfileMaxStackLevel,
  737. ChargingScheduleAllowedChargingRateUnit,
  738. ChargingScheduleMaxPeriods,
  739. ConnectorSwitch3to1PhaseSupported,
  740. MaxChargingProfilesInstalled
  741. };
  742. enum ChargerSystemStatus{
  743. ChargerSystemStatus_Booting,
  744. ChargerSystemStatus_Idle,
  745. ChargerSystemStatus_Authorizing,
  746. ChargerSystemStatus_Preparing,
  747. ChargerSystemStatus_Charging,
  748. ChargerSystemStatus_Terminating,
  749. ChargerSystemStatus_Alarm,
  750. ChargerSystemStatus_Fault
  751. };
  752. enum GetConfigurationKey {
  753. GetConfiguration_AllowOfflineTxForUnknownId=0,
  754. GetConfiguration_AuthorizationCacheEnabled,
  755. GetConfiguration_AuthorizeRemoteTxRequests,
  756. GetConfiguration_BlinkRepeat,
  757. GetConfiguration_ClockAlignedDataInterval,
  758. GetConfiguration_ConnectionTimeOut,
  759. GetConfiguration_GetConfigurationMaxKeys,
  760. GetConfiguration_HeartbeatInterval,
  761. GetConfiguration_LightIntensity,
  762. GetConfiguration_LocalAuthorizeOffline,
  763. GetConfiguration_LocalPreAuthorize,
  764. GetConfiguration_MaxEnergyOnInvalidId,
  765. GetConfiguration_MeterValuesAlignedData,
  766. GetConfiguration_MeterValuesAlignedDataMaxLength,
  767. GetConfiguration_MeterValuesSampledData,
  768. GetConfiguration_MeterValuesSampledDataMaxLength,
  769. GetConfiguration_MeterValueSampleInterval,
  770. GetConfiguration_MinimumStatusDuration,
  771. GetConfiguration_NumberOfConnectors,
  772. GetConfiguration_ResetRetries,
  773. GetConfiguration_ConnectorPhaseRotation,
  774. GetConfiguration_ConnectorPhaseRotationMaxLength,
  775. GetConfiguration_StopTransactionOnEVSideDisconnect,
  776. GetConfiguration_StopTransactionOnInvalidId,
  777. GetConfiguration_StopTxnAlignedData,
  778. GetConfiguration_StopTxnAlignedDataMaxLength,
  779. GetConfiguration_StopTxnSampledData,
  780. GetConfiguration_StopTxnSampledDataMaxLength,
  781. GetConfiguration_SupportedFeatureProfiles,
  782. GetConfiguration_SupportedFeatureProfilesMaxLength,
  783. GetConfiguration_TransactionMessageAttempts,
  784. GetConfiguration_TransactionMessageRetryInterval,
  785. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  786. GetConfiguration_WebSocketPingInterval,
  787. GetConfiguration_LocalAuthListEnabled,
  788. GetConfiguration_LocalAuthListMaxLength,
  789. GetConfiguration_SendLocalListMaxLength,
  790. GetConfiguration_ReserveConnectorZeroSupported,
  791. GetConfiguration_ChargeProfileMaxStackLevel,
  792. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  793. GetConfiguration_ChargingScheduleMaxPeriods,
  794. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  795. GetConfiguration_MaxChargingProfilesInstalled,
  796. };
  797. //GetConfiguration Array
  798. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  799. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  800. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  801. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  802. struct StructChargingSchedulePeriod staticCHAdeMOChargingSchedulePeriod[10]={0};
  803. struct StructChargingSchedulePeriod staticCCSChargingSchedulePeriod[10]={0};
  804. struct StructChargingSchedulePeriod staticGBChargingSchedulePeriod[10]={0};
  805. struct StructChargingSchedulePeriod staticACChargingSchedulePeriod[10]={0};
  806. struct StructChargingSchedulePeriod staticCHAdeMOCompositeChargingSchedulePeriod[10]={0};
  807. struct StructChargingSchedulePeriod staticCCSCompositeChargingSchedulePeriod[10]={0};
  808. struct StructChargingSchedulePeriod staticGBCompositeChargingSchedulePeriod[10]={0};
  809. struct StructChargingSchedulePeriod staticACCompositeChargingSchedulePeriod[10]={0};
  810. struct StructChargingSchedulePeriod staticCHAdeMORemoteStartTransactionChargingSchedulePeriod[10]={0};
  811. struct StructChargingSchedulePeriod staticCCSRemoteStartTransactionChargingSchedulePeriod[10]={0};
  812. struct StructChargingSchedulePeriod staticGBRemoteStartTransactionChargingSchedulePeriod[10]={0};
  813. struct StructChargingSchedulePeriod staticACRemoteStartTransactionChargingSchedulePeriod[10]={0};
  814. struct StructOCPPMeterValue staticCHAdeMOTransactionDataForMeterValueRequest={0};
  815. struct StructOCPPMeterValue staticCCSTransactionDataForMeterValueRequest={0};
  816. struct StructOCPPMeterValue staticGBTransactionDataForMeterValueRequest={0};
  817. struct StructOCPPMeterValue staticACTransactionDataForMeterValueRequest={0};
  818. struct StructOCPPMeterValue staticCHAdeMOTransactionDataForStopTransactionRequest[0];
  819. struct StructOCPPMeterValue staticCCSTransactionDataForStopTransactionRequest[0];
  820. struct StructOCPPMeterValue staticGBTransactionDataForStopTransactionRequest[0];
  821. struct StructOCPPMeterValue staticACTransactionDataForStopTransactionRequest[0];
  822. //==========================================
  823. // Init all share memory
  824. //==========================================
  825. int InitShareMemory()
  826. {
  827. int result = PASS;
  828. int MeterSMId;
  829. //printf("1\n");
  830. //creat ShmSysConfigAndInfo
  831. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  832. {
  833. #ifdef SystemLogMessage
  834. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  835. #endif
  836. result = FAIL;
  837. }
  838. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  839. {
  840. #ifdef SystemLogMessage
  841. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  842. #endif
  843. result = FAIL;
  844. }
  845. else
  846. {}
  847. //printf("2\n");
  848. //creat ShmStatusCodeData
  849. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  850. {
  851. #ifdef SystemLogMessage
  852. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  853. #endif
  854. result = FAIL;
  855. }
  856. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  857. {
  858. #ifdef SystemLogMessage
  859. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  860. #endif
  861. result = FAIL;
  862. }
  863. else
  864. {}
  865. //printf("3\n");
  866. //creat ShmPsuData
  867. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  868. {
  869. #ifdef SystemLogMessage
  870. DEBUG_ERROR("shmget ShmPsuData NG\n");
  871. #endif
  872. result = FAIL;
  873. }
  874. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  875. {
  876. #ifdef SystemLogMessage
  877. DEBUG_ERROR("shmat ShmPsuData NG\n");
  878. #endif
  879. result = FAIL;
  880. }
  881. else
  882. {}
  883. //creat ShmOCPP16Data
  884. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  885. {
  886. #ifdef SystemLogMessage
  887. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  888. #endif
  889. result = FAIL;
  890. }
  891. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  892. {
  893. #ifdef SystemLogMessage
  894. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  895. #endif
  896. result = FAIL;
  897. }
  898. else
  899. {}
  900. /****************************** For TEST ************************************************/
  901. //inital settings
  902. gunTotalNumber = (strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL) ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  903. memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/);
  904. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  905. {
  906. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  907. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  908. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  909. }
  910. // Charger PRE_SYS_MODE
  911. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  912. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  913. clientTime.Heartbeat=time((time_t*)NULL);
  914. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  915. {
  916. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  917. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  918. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  919. }
  920. //HeartBeatWaitTime = 10;
  921. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  922. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  923. // allocate Configuration memory address
  924. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  925. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  926. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  927. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  928. //ShmOCPP16Data->OcppConnStatus = 1;
  929. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  930. {
  931. if(CHAdeMO_QUANTITY != 0)
  932. {
  933. int index = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].Index;
  934. ShmOCPP16Data->SetChargingProfile[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticCHAdeMOChargingSchedulePeriod;
  935. ShmOCPP16Data->GetCompositeSchedule[index].ResponseChargingSchedule.ChargingSchedulePeriod = staticCHAdeMOCompositeChargingSchedulePeriod;
  936. ShmOCPP16Data->RemoteStartTransaction[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticCHAdeMORemoteStartTransactionChargingSchedulePeriod;
  937. //ShmOCPP16Data->StopTransaction[index].TransactionData = (struct StructMeterValue *)&staticCHAdeMOTransactionDataForStopTransactionRequest;
  938. //ShmOCPP16Data->StopTransaction[index].TransactionData[0].SampledValue = staticCHAdeMOTransactionDataForStopTransactionRequest[0].SampledValue;
  939. }
  940. if(CCS_QUANTITY != 0)
  941. {
  942. int index = ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].Index;
  943. ShmOCPP16Data->SetChargingProfile[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticCCSChargingSchedulePeriod;
  944. ShmOCPP16Data->GetCompositeSchedule[index].ResponseChargingSchedule.ChargingSchedulePeriod = staticCCSCompositeChargingSchedulePeriod;
  945. ShmOCPP16Data->RemoteStartTransaction[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticCCSRemoteStartTransactionChargingSchedulePeriod;
  946. //ShmOCPP16Data->StopTransaction[index].TransactionData = (struct StructMeterValue *)&staticCCSTransactionDataForStopTransactionRequest;
  947. //ShmOCPP16Data->StopTransaction[index].TransactionData[0].SampledValue = staticCCSTransactionDataForStopTransactionRequest[0].SampledValue;
  948. }
  949. if(GB_QUANTITY != 0)
  950. {
  951. int index = ShmSysConfigAndInfo->SysInfo.GbChargingData[0].Index;
  952. ShmOCPP16Data->SetChargingProfile[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticGBChargingSchedulePeriod;
  953. ShmOCPP16Data->GetCompositeSchedule[index].ResponseChargingSchedule.ChargingSchedulePeriod = staticGBCompositeChargingSchedulePeriod;
  954. ShmOCPP16Data->RemoteStartTransaction[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticGBRemoteStartTransactionChargingSchedulePeriod;
  955. //ShmOCPP16Data->StopTransaction[index].TransactionData = (struct StructMeterValue *)&staticGBTransactionDataForStopTransactionRequest;
  956. //ShmOCPP16Data->StopTransaction[index].TransactionData[0].SampledValue = staticGBTransactionDataForStopTransactionRequest[0].SampledValue;
  957. }
  958. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  959. DEBUG_INFO("DC ...\n");
  960. }
  961. else
  962. {
  963. if(AC_QUANTITY)
  964. {
  965. int index = ShmSysConfigAndInfo->SysInfo.AcChargingData[0].Index;
  966. ShmOCPP16Data->SetChargingProfile[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticACChargingSchedulePeriod;
  967. ShmOCPP16Data->GetCompositeSchedule[index].ResponseChargingSchedule.ChargingSchedulePeriod = staticACCompositeChargingSchedulePeriod;
  968. ShmOCPP16Data->RemoteStartTransaction[index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod = staticACRemoteStartTransactionChargingSchedulePeriod;
  969. //ShmOCPP16Data->StopTransaction[index].TransactionData = (struct StructMeterValue *)&staticACTransactionDataForStopTransactionRequest;
  970. //ShmOCPP16Data->StopTransaction[index].TransactionData[0].SampledValue = staticACTransactionDataForStopTransactionRequest[0].SampledValue;
  971. }
  972. SystemInitial = AC_QUANTITY;
  973. DEBUG_INFO("AC ...\n");
  974. DEBUG_INFO("gunTotalNumber=%d\n",gunTotalNumber);
  975. }
  976. //Status Setting
  977. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  978. {
  979. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  980. }
  981. for (int index = 0; index < CCS_QUANTITY; index++)
  982. {
  983. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  984. }
  985. for (int index = 0; index < GB_QUANTITY; index++)
  986. {
  987. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  988. }
  989. for (int index = 0; index < AC_QUANTITY; index++)
  990. {
  991. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  992. }
  993. //memset(unknownkey, 0, 10);
  994. return result;
  995. }
  996. int ProcessShareMemory()
  997. {
  998. if(InitShareMemory() == FAIL)
  999. {
  1000. #ifdef SystemLogMessage
  1001. DEBUG_ERROR("InitShareMemory NG\n");
  1002. #endif
  1003. if(ShmStatusCodeData!=NULL)
  1004. {
  1005. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1006. }
  1007. sleep(5);
  1008. return FAIL;
  1009. }
  1010. return PASS;
  1011. }
  1012. //---------------------------------------------
  1013. // new:
  1014. // enum SYSTEM_STATUS
  1015. // {
  1016. // SYS_MODE_BOOTING = 0,
  1017. // SYS_MODE_IDLE = 1,
  1018. // SYS_MODE_AUTHORIZING = 2,
  1019. // SYS_MODE_PREPARING = 3,
  1020. // SYS_MODE_CHARGING = 4,
  1021. // SYS_MODE_TERMINATING = 5,
  1022. // SYS_MODE_ALARM = 6,
  1023. // SYS_MODE_FAULT = 7,
  1024. // SYS_MODE_RESERVATION = 8,
  1025. // SYS_MODE_BOOKING = 9,
  1026. // SYS_MODE_MAINTAIN = 10,
  1027. // SYS_MODE_DEBUG = 11,
  1028. // SYS_MODE_REASSIGN_CHECK = 12,
  1029. // SYS_MODE_REASSIGN = 13,
  1030. // SYS_MODE_PRECHARGE = 14,
  1031. // SYS_MODE_PREPARING_EV = 15,
  1032. // SYS_MODE_PREPARING_EVSE = 16,
  1033. // SYS_MODE_COMPLETE = 17
  1034. // };
  1035. //
  1036. // old:
  1037. // enum _SYSTEM_STATUS
  1038. // {
  1039. // S_BOOTING = 0,
  1040. // S_IDLE, =1
  1041. // S_AUTHORIZING, =2
  1042. // S_REASSIGN_CHECK, =3
  1043. // S_REASSIGN, =4
  1044. // S_PRECHARGE, =5
  1045. // S_PREPARING_FOR_EV, =6
  1046. // S_PREPARING_FOR_EVSE, =7
  1047. // S_CHARGING, =8
  1048. // S_TERMINATING, =9
  1049. // S_COMPLETE, =10
  1050. // S_ALARM, =11
  1051. // S_FAULT =12
  1052. // };
  1053. //
  1054. //-----------------------------------------
  1055. void CheckSystemValue(void)
  1056. {
  1057. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY]={0};
  1058. int IdleModeCnt = 0;
  1059. char filenmae[100]={0};
  1060. char str[100]={0};
  1061. //===============================
  1062. // send Heartbeat
  1063. //===============================
  1064. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1065. {
  1066. //parameter for test
  1067. sendHeartbeatRequest(0);
  1068. //==============================================
  1069. // Reset Waiting Time
  1070. //==============================================
  1071. clientTime.Heartbeat=time((time_t*)NULL);
  1072. }
  1073. //=====================================================
  1074. // Check InternetConn 0: disconnected, 1: connected
  1075. //====================================================
  1076. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0 )
  1077. {
  1078. ShmOCPP16Data->OcppConnStatus = 0; // it is disconnected
  1079. }
  1080. // else
  1081. // {
  1082. // ShmOCPP16Data->OcppConnStatus = 1; // ocpp sign in ocpp server
  1083. // }
  1084. //==============================================
  1085. // Update firmware request
  1086. //==============================================
  1087. if(isUpdateRequest == TRUE )
  1088. {
  1089. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1090. {
  1091. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1092. {
  1093. //check SystemStatus
  1094. /*************************DC*******************************/
  1095. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1096. {
  1097. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1098. {
  1099. IdleModeCnt = IdleModeCnt + 1;
  1100. }
  1101. }
  1102. for (int index = 0; index < CCS_QUANTITY; index++)
  1103. {
  1104. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1105. {
  1106. IdleModeCnt = IdleModeCnt + 1;
  1107. }
  1108. }
  1109. for (int index = 0; index < GB_QUANTITY; index++)
  1110. {
  1111. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1112. {
  1113. IdleModeCnt = IdleModeCnt + 1;
  1114. }
  1115. }
  1116. }
  1117. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1118. {
  1119. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1120. isUpdateRequest = FALSE;
  1121. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1122. }
  1123. }
  1124. else
  1125. {
  1126. /*************************AC*******************************/
  1127. for (int index = 0; index < AC_QUANTITY; index++)
  1128. {
  1129. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1130. {
  1131. IdleModeCnt = IdleModeCnt + 1;
  1132. }
  1133. }
  1134. if(IdleModeCnt == AC_QUANTITY)
  1135. {
  1136. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1137. isUpdateRequest = FALSE;
  1138. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1139. }
  1140. }
  1141. }
  1142. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1143. for(int gun_index=0;gun_index < gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY )*/ ;gun_index++)
  1144. {
  1145. //===============================
  1146. // CSU Trigger Reset Conf
  1147. //===============================
  1148. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1149. {
  1150. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1151. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1152. {
  1153. server_sign = FALSE;
  1154. }
  1155. }
  1156. //===============================
  1157. // CSU Trigger Authorize Request
  1158. //===============================
  1159. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1160. {
  1161. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1162. {
  1163. sendAuthorizeRequest(0);
  1164. authorizeRetryTimes = authorizeRetryTimes + 1;
  1165. // authenrequest = TRUE
  1166. if(authorizeRetryTimes < 3)
  1167. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1168. }
  1169. }
  1170. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1171. {
  1172. authorizeRetryTimes = 0;
  1173. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1174. server_sign = FALSE;
  1175. }
  1176. //==============================================
  1177. // Charger start transaction
  1178. //==============================================
  1179. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1180. {
  1181. sendStartTransactionRequest(gun_index);
  1182. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1183. clientTime.StartTransaction = time((time_t*)NULL);
  1184. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1185. }
  1186. //==============================================
  1187. // Charger stop transaction
  1188. //==============================================
  1189. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1190. {
  1191. sendStopTransactionRequest(gun_index);
  1192. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1193. clientTime.StopTransaction = time((time_t*)NULL);
  1194. }
  1195. //==============================================
  1196. // Charger status report
  1197. //==============================================
  1198. /* Check Mode Change */
  1199. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1200. {
  1201. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1202. {
  1203. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1204. {
  1205. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1206. {
  1207. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1208. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1209. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1210. statusModeChage[gun_index] = TRUE;
  1211. }
  1212. }
  1213. }
  1214. for (int index = 0; index < CCS_QUANTITY; index++)
  1215. {
  1216. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1217. {
  1218. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1219. {
  1220. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1221. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1222. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1223. statusModeChage[gun_index] = TRUE;
  1224. }
  1225. }
  1226. }
  1227. for (int index = 0; index < GB_QUANTITY; index++)
  1228. {
  1229. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1230. {
  1231. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1232. {
  1233. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1234. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1235. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1236. statusModeChage[gun_index] = TRUE;
  1237. }
  1238. }
  1239. }
  1240. }
  1241. else //AC
  1242. {
  1243. for (int index = 0; index < AC_QUANTITY; index++)
  1244. {
  1245. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1246. {
  1247. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1248. {
  1249. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1250. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1251. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1252. statusModeChage[gun_index] = TRUE;
  1253. }
  1254. }
  1255. }// END OF FOR
  1256. }// END OF ELSE
  1257. if((SystemInitial != 0)||
  1258. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1259. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1260. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1261. {
  1262. if(SystemInitial != 0)
  1263. SystemInitial = SystemInitial -1;
  1264. //GunStatusInterval= GunStatusInterval* gun_index;
  1265. sendStatusNotificationRequest(gun_index);
  1266. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1267. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1268. statusModeChage[gun_index] = FALSE;
  1269. //sleep(30); // sleep for 30 seconds
  1270. }
  1271. //==============================================
  1272. // Meter report
  1273. //==============================================
  1274. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1275. {
  1276. //check Transaction active
  1277. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1278. {
  1279. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1280. {
  1281. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1282. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1283. {
  1284. meterValueSend[gun_index] =1;
  1285. }
  1286. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1287. {
  1288. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1289. if((access(filenmae,F_OK))!=-1)
  1290. {
  1291. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1292. sprintf(str,"rm -f %s",filenmae);
  1293. system(str);
  1294. }
  1295. }
  1296. }// End for CHAdeMO
  1297. for (int index = 0; index < CCS_QUANTITY; index++)
  1298. {
  1299. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1300. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1301. {
  1302. meterValueSend[gun_index] =1;
  1303. }
  1304. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1305. {
  1306. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1307. if((access(filenmae,F_OK))!=-1)
  1308. {
  1309. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1310. sprintf(str,"rm -f %s",filenmae);
  1311. system(str);
  1312. }
  1313. }
  1314. } // End for CCS
  1315. for (int index = 0; index < GB_QUANTITY; index++)
  1316. {
  1317. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1318. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1319. {
  1320. meterValueSend[gun_index] =1;
  1321. }
  1322. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1323. {
  1324. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1325. if((access(filenmae,F_OK))!=-1)
  1326. {
  1327. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1328. sprintf(str,"rm -f %s",filenmae);
  1329. system(str);
  1330. }
  1331. }
  1332. }// End for GB
  1333. }
  1334. else
  1335. {
  1336. for (int index = 0; index < AC_QUANTITY; index++)
  1337. {
  1338. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1339. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1340. {
  1341. meterValueSend[gun_index] =1;
  1342. }
  1343. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1344. {
  1345. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1346. if((access(filenmae,F_OK))!=-1)
  1347. {
  1348. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1349. sprintf(str,"rm -f %s",filenmae);
  1350. system(str);
  1351. }
  1352. }
  1353. }//End for AC
  1354. }//END OF ELSE
  1355. // sleep(1);
  1356. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1357. if(meterValueSend[gun_index] == 1)
  1358. sendMeterValuesRequest(gun_index);
  1359. }
  1360. //==============================================
  1361. // Check Connector reserved
  1362. //==============================================
  1363. //===============================
  1364. // Check if Reserve is expired
  1365. //===============================
  1366. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1367. {
  1368. double diff_t;
  1369. struct tm tp;
  1370. // current time
  1371. time_t t = time(NULL);
  1372. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1373. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1374. tp.tm_isdst = -1;
  1375. time_t utc = mktime(&tp);
  1376. diff_t = difftime(utc, t);
  1377. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1378. if(diff_t <= 0)
  1379. {
  1380. DEBUG_INFO("reserve expired !!! \n");
  1381. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1382. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1383. }
  1384. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1385. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1386. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1387. {
  1388. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1389. }
  1390. else
  1391. {
  1392. //check Transaction active
  1393. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1394. {
  1395. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1396. {
  1397. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1398. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1399. {
  1400. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1401. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1402. {
  1403. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1404. }
  1405. }
  1406. }
  1407. for (int index = 0; index < CCS_QUANTITY; index++)
  1408. {
  1409. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1410. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1411. {
  1412. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1413. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1414. {
  1415. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1416. }
  1417. }
  1418. }
  1419. for (int index = 0; index < GB_QUANTITY; index++)
  1420. {
  1421. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1422. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1423. {
  1424. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1425. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1426. {
  1427. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1428. }
  1429. }
  1430. }
  1431. }
  1432. else //AC
  1433. {
  1434. for (int index = 0; index < AC_QUANTITY; index++)
  1435. {
  1436. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1437. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1438. {
  1439. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1440. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1441. {
  1442. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1443. }
  1444. }
  1445. }
  1446. }// END OF ELSE
  1447. }// END OF check Transaction active
  1448. }//END OF Check if Reserve is expired
  1449. //==========================================
  1450. // csu trigger FirmwareStatusNotificationReq
  1451. //==========================================
  1452. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1453. {
  1454. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1455. }
  1456. //==========================================
  1457. // csu trigger CancelReservationConf
  1458. //==========================================
  1459. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1460. {
  1461. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1462. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1463. }
  1464. //==========================================
  1465. // csu trigger ChangeAvailabilityConf
  1466. //==========================================
  1467. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1468. {
  1469. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1470. }
  1471. //==========================================
  1472. // csu trigger UnlockConnectorConf
  1473. //==========================================
  1474. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1475. {
  1476. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1477. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1478. }
  1479. //==========================================
  1480. // csu trigger ReserveNowConf
  1481. //==========================================
  1482. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1483. {
  1484. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1485. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1486. }
  1487. //==========================================
  1488. // csu trigger DataTransferReq
  1489. //==========================================
  1490. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1491. {
  1492. sendDataTransferRequest(gun_index);
  1493. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1494. }
  1495. }
  1496. }
  1497. //==========================================
  1498. // send request routine
  1499. //==========================================
  1500. int sendAuthorizeRequest(int gun_index)
  1501. {
  1502. mtrace();
  1503. int result = FAIL;
  1504. char message[100]={0};
  1505. char guid[37];
  1506. char tempdata[65]={0};
  1507. DEBUG_INFO("sendAuthorizeRequest \n");
  1508. //Local Authorize
  1509. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1510. {
  1511. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1512. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1513. {
  1514. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1515. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1516. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1517. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1518. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1519. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1520. authorizeRetryTimes = 0;
  1521. return result;
  1522. }
  1523. else
  1524. {
  1525. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1526. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1527. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1528. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1529. result = PASS;
  1530. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1531. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1532. authorizeRetryTimes = 0;
  1533. return result;
  1534. }
  1535. }
  1536. //initailize struct Authorize
  1537. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1538. //get data from shared memory
  1539. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1540. random_uuid(guid);
  1541. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1542. LWS_Send(message);
  1543. sprintf(tempdata, "Authorize,%d", gun_index);
  1544. if(hashmap_operation(0, guid, tempdata) == 1)
  1545. {
  1546. result = PASS;
  1547. DEBUG_ERROR("Authorize mapItem pass\n");
  1548. }
  1549. //#ifdef SystemLogMessage
  1550. //DEBUG_INFO(">>>>>Authorize request\n");
  1551. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1552. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1553. //#endif
  1554. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1555. return result;
  1556. }
  1557. int sendBootNotificationRequest(void)
  1558. {
  1559. mtrace();
  1560. int result = FAIL;
  1561. char message[500]={0}, payload[700]={0};
  1562. char guid[37]={0};
  1563. char tempdata[65]={0};
  1564. int IsGunCharging = FALSE;
  1565. //check Transaction active
  1566. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1567. {
  1568. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1569. {
  1570. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1571. {
  1572. IsGunCharging = TRUE;
  1573. }
  1574. }
  1575. for (int index = 0; index < CCS_QUANTITY; index++)
  1576. {
  1577. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1578. {
  1579. IsGunCharging = TRUE;
  1580. }
  1581. }
  1582. for (int index = 0; index < GB_QUANTITY; index++)
  1583. {
  1584. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1585. {
  1586. IsGunCharging = TRUE;
  1587. }
  1588. }
  1589. }
  1590. else
  1591. {
  1592. for (int index = 0; index < AC_QUANTITY; index++)
  1593. {
  1594. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1595. {
  1596. IsGunCharging = TRUE;
  1597. }
  1598. }
  1599. }
  1600. if(IsGunCharging == TRUE)
  1601. {
  1602. server_sign = TRUE;
  1603. return result;
  1604. }
  1605. // Fill BootNotification fields
  1606. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1607. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1608. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1609. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1610. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1611. ShmOCPP16Data->ChargeBoxId
  1612. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1613. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1614. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1615. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1616. ,ShmOCPP16Data->BootNotification.CpIccid
  1617. ,ShmOCPP16Data->BootNotification.CpImsi
  1618. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1619. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1620. random_uuid(guid);
  1621. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1622. LWS_Send(message);
  1623. sprintf(tempdata, "BootNotification,0");
  1624. 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*/)
  1625. {
  1626. result = PASS;
  1627. }
  1628. memset(queuedata, 0, sizeof(queuedata));
  1629. strcpy(queuedata,message);
  1630. //#ifdef SystemLogMessage
  1631. //DEBUG_INFO(">>>>>BootNotification request\n");
  1632. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1633. //#endif
  1634. return result;
  1635. }
  1636. int sendDataTransferRequest(int gun_index)
  1637. {
  1638. mtrace();
  1639. char message[1000]={0};
  1640. char guid[37]={0};
  1641. char tempdata[65]={0};
  1642. int result = FAIL;
  1643. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1644. random_uuid(guid);
  1645. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1646. MESSAGE_TYPE_CALL,
  1647. guid,
  1648. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1649. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1650. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1651. LWS_Send(message);
  1652. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1653. 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*/)
  1654. {
  1655. result = PASS;
  1656. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1657. }
  1658. //#ifdef SystemLogMessage
  1659. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1660. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1661. //#endif
  1662. return result;
  1663. }
  1664. int sendDiagnosticsStatusNotificationRequest(char *status)
  1665. {
  1666. mtrace();
  1667. int result = FAIL;
  1668. char message[110]={0};
  1669. char guid[37]={0};
  1670. char tempdata[65]={0};
  1671. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1672. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1673. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1674. random_uuid(guid);
  1675. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1676. LWS_Send(message);
  1677. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1678. if(hashmap_operation(0, guid, tempdata) == 1)
  1679. {
  1680. result = PASS;
  1681. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1682. }
  1683. //#ifdef SystemLogMessage
  1684. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1685. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1686. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1687. //#endif
  1688. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1689. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1690. //record status
  1691. if(strcmp(status,"Idle")==0)
  1692. {
  1693. DiagnosticsStatusNotificationStatus = 0;
  1694. }
  1695. else if(strcmp(status,"Uploaded")==0)
  1696. {
  1697. DiagnosticsStatusNotificationStatus = 1;
  1698. }
  1699. else if(strcmp(status,"UploadFailed")==0)
  1700. {
  1701. DiagnosticsStatusNotificationStatus = 2;
  1702. }
  1703. else if(strcmp(status,"Uploading")==0)
  1704. {
  1705. DiagnosticsStatusNotificationStatus = 3;
  1706. }
  1707. return result;
  1708. }
  1709. int sendFirmwareStatusNotificationRequest(char *status)
  1710. {
  1711. mtrace();
  1712. int result = FAIL;
  1713. char message[110]={0};
  1714. char guid[37]={0};
  1715. char tempdata[65]={0};
  1716. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1717. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1718. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1719. random_uuid(guid);
  1720. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1721. LWS_Send(message);
  1722. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1723. 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*/)
  1724. {
  1725. result = PASS;
  1726. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1727. }
  1728. //#ifdef SystemLogMessage
  1729. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1730. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1731. //#endif
  1732. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1733. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1734. //record status
  1735. if(strcmp(status,"Downloaded")==0)
  1736. {
  1737. FirmwareStatusNotificationStatus = 0;
  1738. }
  1739. else if(strcmp(status,"DownloadFailed")==0)
  1740. {
  1741. FirmwareStatusNotificationStatus = 1;
  1742. }
  1743. else if(strcmp(status,"Downloading")==0)
  1744. {
  1745. FirmwareStatusNotificationStatus = 2;
  1746. }
  1747. else if(strcmp(status,"Idle")==0)
  1748. {
  1749. FirmwareStatusNotificationStatus = 3;
  1750. }
  1751. else if(strcmp(status,"InstallationFailed")==0)
  1752. {
  1753. FirmwareStatusNotificationStatus = 4;
  1754. }
  1755. else if(strcmp(status,"Installing")==0)
  1756. {
  1757. FirmwareStatusNotificationStatus = 5;
  1758. }
  1759. else if(strcmp(status,"Installed")==0)
  1760. {
  1761. FirmwareStatusNotificationStatus = 6;
  1762. }
  1763. return result;
  1764. }
  1765. int sendHeartbeatRequest(int gun_index)
  1766. {
  1767. mtrace();
  1768. int result = FAIL;
  1769. char message[80]={0};
  1770. char guid[37]={0};
  1771. char tempdata[65]={0};
  1772. random_uuid(guid);
  1773. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1774. , MESSAGE_TYPE_CALL
  1775. , guid );
  1776. LWS_Send(message);
  1777. sprintf(tempdata, "Heartbeat,%d", 0);
  1778. 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*/)
  1779. {
  1780. result = PASS;
  1781. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1782. }
  1783. //#ifdef SystemLogMessage
  1784. //DEBUG_INFO(">>>>>Heartbeat request\n");
  1785. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1786. //#endif
  1787. return result;
  1788. }
  1789. int sendStartTransactionRequest(int gun_index)
  1790. {
  1791. mtrace();
  1792. int result = FAIL;
  1793. char message[250]={0};
  1794. char guid[37]={0};
  1795. struct timeval tmnow;
  1796. struct tm *tm;
  1797. char buf[30];//, usec_buf[6];
  1798. char tempdata[65]={0};
  1799. DEBUG_INFO("sendStartTransactionRequest...");
  1800. gettimeofday(&tmnow, NULL);
  1801. time_t t;
  1802. t = time(NULL);
  1803. /*UTC time and date*/
  1804. tm = gmtime(&t);
  1805. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1806. #if 0 // remove temporally
  1807. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1808. strcat(buf,".");
  1809. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1810. strcat(buf,usec_buf);
  1811. #endif
  1812. //printf("Start Charging Time :%s",buf);
  1813. // set value
  1814. if(ShmOCPP16Data->OcppConnStatus == 1 )
  1815. {
  1816. memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1817. }
  1818. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1819. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1820. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1821. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1822. {
  1823. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1824. {
  1825. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1826. {
  1827. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1828. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1829. }
  1830. }
  1831. for (int index = 0; index < CCS_QUANTITY; index++)
  1832. {
  1833. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1834. {
  1835. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1836. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1837. }
  1838. }
  1839. for (int index = 0; index < GB_QUANTITY; index++)
  1840. {
  1841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1842. {
  1843. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1844. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1845. }
  1846. }
  1847. }
  1848. else
  1849. {
  1850. for (int index = 0; index < AC_QUANTITY; index++)
  1851. {
  1852. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1853. {
  1854. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1855. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1856. }
  1857. }
  1858. }//END OF ELSE
  1859. random_uuid(guid);
  1860. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1861. , MESSAGE_TYPE_CALL
  1862. , guid
  1863. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1864. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1865. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1866. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1867. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1868. LWS_Send(message);
  1869. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1870. 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*/)
  1871. {
  1872. result = PASS;
  1873. }
  1874. strcpy(queuedata, message);
  1875. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1876. //#ifdef SystemLogMessage
  1877. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1878. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1879. //#endif
  1880. return result;
  1881. }
  1882. int sendStatusNotificationRequest(int gun_index)
  1883. {
  1884. mtrace();
  1885. int result = FAIL;
  1886. char message[600]={0};
  1887. char guid[37];
  1888. int currentStatus = 0;
  1889. struct timeval tmnow;
  1890. struct tm *tm;
  1891. char buf[30];//, usec_buf[6];
  1892. char tempdata[65]={0};
  1893. gettimeofday(&tmnow, NULL);
  1894. time_t t;
  1895. t = time(NULL);
  1896. /*UTC time and date*/
  1897. tm = gmtime(&t);
  1898. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1899. #if 0 // remove temporally
  1900. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1901. strcat(buf,".");
  1902. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1903. strcat(buf,usec_buf);
  1904. #endif
  1905. printf("%s",buf);
  1906. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1907. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1908. // it's option
  1909. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1910. /*
  1911. enum _SYSTEM_STATUS
  1912. {
  1913. S_BOOTING = 0,
  1914. S_IDLE, = 1
  1915. S_AUTHORIZING, =2
  1916. S_REASSIGN_CHECK, =3
  1917. S_REASSIGN, =4
  1918. S_PRECHARGE, =5
  1919. S_PREPARING_FOR_EV, =6
  1920. S_PREPARING_FOR_EVSE, =7
  1921. S_CHARGING, =8
  1922. S_TERMINATING, =9
  1923. S_COMPLETE, =10
  1924. S_ALARM, =11
  1925. S_FAULT =12
  1926. }
  1927. */
  1928. //check Transaction active
  1929. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1930. {
  1931. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1932. {
  1933. //printf("gun_index=%d\n",gun_index);
  1934. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1935. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1936. {
  1937. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1938. currentStatus = 0; //OCPP Status
  1939. }
  1940. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1941. {
  1942. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1943. currentStatus = 1; //OCPP Status
  1944. }
  1945. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1946. {
  1947. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1948. currentStatus = 2; //OCPP Status
  1949. }
  1950. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1951. {
  1952. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1953. currentStatus = 5; //OCPP Status
  1954. }
  1955. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1956. {
  1957. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1958. currentStatus = 4; //OCPP Status
  1959. }
  1960. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  1961. {
  1962. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1963. currentStatus = 7; //OCPP Status: Unavailable
  1964. }
  1965. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1966. {
  1967. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1968. currentStatus = 8; //OCPP Status: Faulted
  1969. }
  1970. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1971. {
  1972. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1973. currentStatus = 6; //OCPP Status: Reserved
  1974. }
  1975. }//end of for CHAdeMO_QUANTITY
  1976. for (int index = 0; index < CCS_QUANTITY; index++)
  1977. {
  1978. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1979. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1980. {
  1981. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1982. currentStatus = 0; //OCPP Status
  1983. }
  1984. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1985. {
  1986. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1987. currentStatus = 1; //OCPP Status
  1988. }
  1989. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1990. {
  1991. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1992. currentStatus = 2; //OCPP Status
  1993. }
  1994. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1995. {
  1996. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1997. currentStatus = 5; //OCPP Status
  1998. }
  1999. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2000. {
  2001. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2002. currentStatus = 4; //OCPP Status
  2003. }
  2004. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  2005. {
  2006. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2007. currentStatus = 7; //OCPP Status
  2008. }
  2009. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2010. {
  2011. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2012. currentStatus = 8; //OCPP Status
  2013. }
  2014. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2015. {
  2016. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2017. currentStatus = 6; //OCPP Status
  2018. }
  2019. }
  2020. for (int index = 0; index < GB_QUANTITY; index++)
  2021. {
  2022. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  2023. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2024. {
  2025. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2026. currentStatus = 0; //OCPP Status
  2027. }
  2028. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2029. {
  2030. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2031. currentStatus = 1; //OCPP Status
  2032. }
  2033. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2034. {
  2035. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2036. currentStatus = 2; //OCPP Status
  2037. }
  2038. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2039. {
  2040. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2041. currentStatus = 5; //OCPP Status
  2042. }
  2043. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2044. {
  2045. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2046. currentStatus = 4; //OCPP Status
  2047. }
  2048. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  2049. {
  2050. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2051. currentStatus = 7; //OCPP Status: Unavailable
  2052. }
  2053. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2054. {
  2055. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2056. currentStatus = 8; //OCPP Status: Faulted
  2057. }
  2058. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2059. {
  2060. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2061. currentStatus = 6; //OCPP Status: Faulted
  2062. }
  2063. }
  2064. }
  2065. else
  2066. {
  2067. for (int index = 0; index < AC_QUANTITY; index++)
  2068. {
  2069. //printf("gun_index=%d\n",gun_index);
  2070. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2071. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2072. {
  2073. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2074. currentStatus = 0; //OCPP Status
  2075. }
  2076. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2077. {
  2078. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2079. currentStatus = 1; //OCPP Status
  2080. }
  2081. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2082. {
  2083. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2084. currentStatus = 2; //OCPP Status
  2085. }
  2086. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2087. {
  2088. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2089. currentStatus = 5; //OCPP Status
  2090. }
  2091. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2092. {
  2093. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2094. currentStatus = 4; //OCPP Status
  2095. }
  2096. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG))) //S_TERMINATING ---> Unavailable
  2097. {
  2098. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2099. currentStatus = 7; //OCPP Status: Unavailable
  2100. }
  2101. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2102. {
  2103. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2104. currentStatus = 8; //OCPP Status: Faulted
  2105. }
  2106. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2107. {
  2108. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2109. currentStatus = 6; //OCPP Status: Reserved
  2110. }
  2111. }//end of for AC_QUANTITY
  2112. }//END OF ELSE
  2113. //it's option
  2114. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2115. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2116. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2117. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2118. random_uuid(guid);
  2119. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2120. , MESSAGE_TYPE_CALL
  2121. , guid
  2122. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2123. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2124. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2125. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2126. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2127. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2128. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2129. LWS_Send(message);
  2130. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2131. 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*/)
  2132. {
  2133. DEBUG_ERROR("statusNotification mapitem pass");
  2134. result = PASS;
  2135. }
  2136. //#ifdef SystemLogMessage
  2137. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2138. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2139. //#endif
  2140. return result;
  2141. }
  2142. int sendStopTransactionRequest(int gun_index)
  2143. {
  2144. mtrace();
  2145. int result = FAIL;
  2146. char message[1500]={0};
  2147. char guid[37]={0};
  2148. char tempdata[65]={0};
  2149. int idx_sample=0;
  2150. DEBUG_ERROR("sendStopTransactionRequest \n");
  2151. //memset(&(ShmOCPP16Data->StopTransaction[gun_index].TransactionData), 0, sizeof(struct StructMeterValue));
  2152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId/*ShmOCPP16Data->Authorize.IdTag*/);
  2153. //ENERGY_ACTIVE_IMPORT_REGISTER
  2154. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2155. {
  2156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2157. {
  2158. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2159. {
  2160. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2161. //Check Status
  2162. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2163. {
  2164. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2165. }
  2166. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2167. }
  2168. }// END OF CHAdeMO_QUANTITY
  2169. for (int index = 0; index < CCS_QUANTITY; index++)
  2170. {
  2171. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2172. {
  2173. //for test
  2174. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2175. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2176. //Check Status
  2177. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2178. {
  2179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2180. }
  2181. else
  2182. {
  2183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2184. }
  2185. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2186. }
  2187. }// END OF CCS_QUANTITY
  2188. for (int index = 0; index < GB_QUANTITY; index++)
  2189. {
  2190. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2191. {
  2192. // for test
  2193. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2194. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2195. //Check Status
  2196. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2197. {
  2198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2199. }
  2200. else
  2201. {
  2202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2203. }
  2204. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2205. }
  2206. }// END OF GB_QUANTITY
  2207. }
  2208. else
  2209. {
  2210. for (int index = 0; index < AC_QUANTITY; index++)
  2211. {
  2212. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2213. {
  2214. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2215. //Check Status
  2216. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2217. {
  2218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2219. }
  2220. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2221. }
  2222. }// END OF AC_QUANTITY
  2223. }//END OF ELSE
  2224. //Stop Transaction Time
  2225. struct timeval tmnow;
  2226. struct tm *tm;
  2227. char buf[30];//, usec_buf[6];
  2228. gettimeofday(&tmnow, NULL);
  2229. time_t t;
  2230. t = time(NULL);
  2231. /*UTC time and date*/
  2232. tm = gmtime(&t);
  2233. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2234. #if 0 // remove temporally
  2235. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2236. strcat(buf,".");
  2237. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2238. strcat(buf,usec_buf);
  2239. #endif
  2240. printf("StopTransaction Time %s\n",buf);
  2241. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2243. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2244. random_uuid(guid);
  2245. sprintf(message,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":"
  2246. ,MESSAGE_TYPE_CALL
  2247. ,guid
  2248. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2249. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2250. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2251. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2252. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
  2253. /***********************************transactionData******************************************************/
  2254. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2255. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2256. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2257. {
  2258. //transactionData = json_object_new_object();
  2259. //json_object_object_add(transactionData, "timestamp", json_object_new_string("2019-05-04T18:15:33Z"));
  2260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp, buf/*"2019-05-04T18:15:33Z"*/);
  2261. sprintf(message + strlen(message), "[{\"timestamp\":\"%s\",\"sampledValue\":[", (const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp);
  2262. //=================================
  2263. // Transaction_Begin
  2264. //=================================
  2265. // Energy.Active.Export.Interval
  2266. idx_sample=0;
  2267. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2268. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2269. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2270. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2272. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2274. sprintf(message + strlen(message), "{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2275. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2276. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2277. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2278. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2279. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2280. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2281. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2282. );
  2283. //=================================
  2284. // Transaction_End
  2285. //=================================
  2286. //Current.Export
  2287. idx_sample=1;
  2288. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2289. {
  2290. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2291. {
  2292. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2293. {
  2294. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2295. }
  2296. }
  2297. for (int index = 0; index < CCS_QUANTITY; index++)
  2298. {
  2299. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2300. {
  2301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2302. }
  2303. }
  2304. for (int index = 0; index < GB_QUANTITY; index++)
  2305. {
  2306. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2307. {
  2308. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2309. }
  2310. }
  2311. }
  2312. else
  2313. {
  2314. for (int index = 0; index < AC_QUANTITY; index++)
  2315. {
  2316. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2317. {
  2318. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2319. }
  2320. }
  2321. }// END FOR AC ELSE
  2322. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Current_Export/*Energy_Reactive_Export_Register*/]);
  2325. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A/*UnitOfMeasure_kWh*/]);
  2328. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2329. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2330. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2331. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2332. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2333. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2334. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2335. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2336. );
  2337. //Energy.Active.Export.Interval
  2338. idx_sample=2;
  2339. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2340. {
  2341. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2342. {
  2343. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2344. {
  2345. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2346. }
  2347. }
  2348. for (int index = 0; index < CCS_QUANTITY; index++)
  2349. {
  2350. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2351. {
  2352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2353. }
  2354. }
  2355. for (int index = 0; index < GB_QUANTITY; index++)
  2356. {
  2357. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2358. {
  2359. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2360. }
  2361. }
  2362. }
  2363. else
  2364. {
  2365. for (int index = 0; index < AC_QUANTITY; index++)
  2366. {
  2367. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2368. {
  2369. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2370. }
  2371. }
  2372. }// END FOR AC ELSE
  2373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2379. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2380. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2381. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2382. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2383. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2384. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2385. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2386. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2387. );
  2388. //Power.Active.Export
  2389. idx_sample=3;
  2390. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2391. {
  2392. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2393. {
  2394. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2395. {
  2396. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2397. }
  2398. }
  2399. for (int index = 0; index < CCS_QUANTITY; index++)
  2400. {
  2401. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2402. {
  2403. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2404. }
  2405. }
  2406. for (int index = 0; index < GB_QUANTITY; index++)
  2407. {
  2408. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2409. {
  2410. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2411. }
  2412. }
  2413. }
  2414. else
  2415. {
  2416. for (int index = 0; index < AC_QUANTITY; index++)
  2417. {
  2418. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2419. {
  2420. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2421. }
  2422. }
  2423. }// END FOR AC ELSE
  2424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2430. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2431. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2432. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2433. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2434. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2435. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2436. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2437. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2438. );
  2439. //Voltage
  2440. idx_sample=4;
  2441. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2442. {
  2443. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2444. {
  2445. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2446. {
  2447. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2448. }
  2449. }
  2450. for (int index = 0; index < CCS_QUANTITY; index++)
  2451. {
  2452. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2453. {
  2454. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2455. }
  2456. }
  2457. for (int index = 0; index < GB_QUANTITY; index++)
  2458. {
  2459. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2460. {
  2461. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2462. }
  2463. }
  2464. }
  2465. else
  2466. {
  2467. for (int index = 0; index < AC_QUANTITY; index++)
  2468. {
  2469. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2470. {
  2471. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  2472. }
  2473. }
  2474. }// END FOR AC ELSE
  2475. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2481. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2482. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2483. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2484. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2485. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2486. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2487. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2488. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2489. );
  2490. //SoC
  2491. idx_sample=5;
  2492. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2493. {
  2494. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2495. {
  2496. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2497. {
  2498. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2499. }
  2500. }
  2501. for (int index = 0; index < CCS_QUANTITY; index++)
  2502. {
  2503. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2504. {
  2505. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2506. }
  2507. }
  2508. for (int index = 0; index < GB_QUANTITY; index++)
  2509. {
  2510. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2511. {
  2512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2513. }
  2514. }
  2515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2521. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2522. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2523. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2524. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2525. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2526. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2527. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2528. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2529. );
  2530. } // END FOR DC CASE
  2531. sprintf(message + strlen(message)," ] } ] } ]");
  2532. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue);
  2533. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);
  2534. }
  2535. LWS_Send(message);
  2536. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2537. if(hashmap_operation(0, guid, tempdata) == 1)
  2538. {
  2539. result = PASS;
  2540. DEBUG_INFO("StopTransaction mapitem pass\n");
  2541. }
  2542. strcpy(queuedata, message);
  2543. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2544. //#ifdef SystemLogMessage
  2545. //DEBUG_INFO(">>>>>StopTransaction request\n");
  2546. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2547. //#endif
  2548. //for test
  2549. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2550. return result;
  2551. }
  2552. int sendMeterValuesRequest(int gun_index)
  2553. {
  2554. mtrace();
  2555. int result = FAIL;
  2556. char message[1500]={0};
  2557. char guid[37]={0};
  2558. int idx_sample=0;
  2559. //int length = 0;
  2560. char tempdata[65]={0};
  2561. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2562. DEBUG_ERROR("gun_index =%d\n",gun_index);
  2563. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2564. {
  2565. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2566. DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2567. DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2568. return result;
  2569. }
  2570. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2571. {
  2572. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2573. }
  2574. //set value
  2575. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2576. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2577. random_uuid(guid);
  2578. sprintf(message,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":"
  2579. ,MESSAGE_TYPE_CALL
  2580. ,guid
  2581. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2582. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId);
  2583. //,comfirmpayload);
  2584. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2585. {
  2586. //allocate memory space
  2587. //ShmOCPP16Data->MeterValues[gun_index].MeterValue = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2588. //UTC Date time
  2589. struct timeval tmnow;
  2590. struct tm *tm;
  2591. char buf[30];//, usec_buf[6];
  2592. gettimeofday(&tmnow, NULL);
  2593. time_t t;
  2594. t = time(NULL);
  2595. /*UTC time and date*/
  2596. tm = gmtime(&t);
  2597. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2598. #if 0 // remove temporally
  2599. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2600. strcat(buf,".");
  2601. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2602. strcat(buf,usec_buf);
  2603. #endif
  2604. // printf("%s",buf);
  2605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp, buf);
  2606. //allocate memory space
  2607. //ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*6);
  2608. sprintf(message + strlen(message),"[{\"timestamp\":\"%s\",\"sampledValue\":[",(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp);
  2609. idx_sample=0;
  2610. //********************************(1)Current.Export************************************************/
  2611. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2612. {
  2613. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2614. {
  2615. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2616. {
  2617. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2618. }
  2619. }
  2620. for (int index = 0; index < CCS_QUANTITY; index++)
  2621. {
  2622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2623. {
  2624. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2625. }
  2626. }
  2627. for (int index = 0; index < GB_QUANTITY; index++)
  2628. {
  2629. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2630. {
  2631. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2632. }
  2633. }
  2634. }
  2635. else
  2636. {
  2637. for (int index = 0; index < AC_QUANTITY; index++)
  2638. {
  2639. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2640. {
  2641. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2642. }
  2643. }
  2644. }// END FOR AC ELSE
  2645. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2646. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2647. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Current_Export]);
  2648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2651. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2652. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2653. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2654. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2655. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2656. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2657. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2658. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2659. );
  2660. #if 0
  2661. idx_sample=1;
  2662. //****************************************************(2)Energy.Active.Export.Register*********************************************/
  2663. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2664. {
  2665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2666. {
  2667. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2668. {
  2669. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2670. }
  2671. }
  2672. for (int index = 0; index < CCS_QUANTITY; index++)
  2673. {
  2674. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2675. {
  2676. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2677. }
  2678. }
  2679. for (int index = 0; index < GB_QUANTITY; index++)
  2680. {
  2681. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2682. {
  2683. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2684. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2685. }
  2686. }
  2687. }
  2688. else
  2689. {
  2690. for (int index = 0; index < AC_QUANTITY; index++)
  2691. {
  2692. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2693. {
  2694. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2695. }
  2696. }
  2697. }// END FOR AC ELSE
  2698. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2699. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2700. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Register]);
  2701. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2702. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2703. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2704. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2705. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2706. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2707. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2708. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2709. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2710. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2711. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2712. );
  2713. #endif
  2714. idx_sample=1;
  2715. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2716. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2717. {
  2718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2719. {
  2720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2721. {
  2722. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2723. }
  2724. }
  2725. for (int index = 0; index < CCS_QUANTITY; index++)
  2726. {
  2727. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2728. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2729. {
  2730. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2731. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2732. }
  2733. }
  2734. for (int index = 0; index < GB_QUANTITY; index++)
  2735. {
  2736. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2737. {
  2738. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2739. }
  2740. }
  2741. }
  2742. else
  2743. {
  2744. for (int index = 0; index < AC_QUANTITY; index++)
  2745. {
  2746. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2747. {
  2748. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2749. }
  2750. }
  2751. }//END FOR AC ELSE
  2752. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2753. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2754. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2755. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2756. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2757. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2758. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2759. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2760. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2761. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2762. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2763. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2764. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2765. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2766. );
  2767. idx_sample=2;
  2768. //********************************(4)Power.Active.Export************************************************/
  2769. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2770. {
  2771. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2772. {
  2773. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2774. {
  2775. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2776. }
  2777. }
  2778. for (int index = 0; index < CCS_QUANTITY; index++)
  2779. {
  2780. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2781. {
  2782. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2783. }
  2784. }
  2785. for (int index = 0; index < GB_QUANTITY; index++)
  2786. {
  2787. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2788. {
  2789. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2790. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2791. }
  2792. }
  2793. }
  2794. else
  2795. {
  2796. for (int index = 0; index < AC_QUANTITY; index++)
  2797. {
  2798. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2799. {
  2800. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2801. }
  2802. }
  2803. }// END FOR AC ELSE
  2804. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2805. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2806. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Power_Active_Export]);
  2807. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2808. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2809. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2810. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2811. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2812. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2813. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2814. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2815. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2816. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2817. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2818. );
  2819. idx_sample=3;
  2820. //***********************************************(5)VOLTAGE******************************************************/
  2821. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2822. {
  2823. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2824. {
  2825. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2826. {
  2827. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2828. }
  2829. }
  2830. for (int index = 0; index < CCS_QUANTITY; index++)
  2831. {
  2832. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2833. {
  2834. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2835. }
  2836. }
  2837. for (int index = 0; index < GB_QUANTITY; index++)
  2838. {
  2839. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2840. {
  2841. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2842. }
  2843. }
  2844. }
  2845. else
  2846. {
  2847. for (int index = 0; index < AC_QUANTITY; index++)
  2848. {
  2849. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2850. {
  2851. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2852. }
  2853. }
  2854. }//END FOR AC ELSE
  2855. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2857. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Voltage]);
  2858. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2859. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2860. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2861. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2862. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2863. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2864. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2865. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2866. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2867. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2868. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2869. );
  2870. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2871. {
  2872. idx_sample=4;
  2873. //sampledValue = NULL;
  2874. //***********************************************(6)SOC******************************************************/
  2875. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2876. {
  2877. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2878. {
  2879. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2880. {
  2881. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2882. }
  2883. }
  2884. for (int index = 0; index < CCS_QUANTITY; index++)
  2885. {
  2886. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2887. {
  2888. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2889. }
  2890. }
  2891. for (int index = 0; index < GB_QUANTITY; index++)
  2892. {
  2893. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2894. {
  2895. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2896. }
  2897. }
  2898. }
  2899. else
  2900. {
  2901. for (int index = 0; index < AC_QUANTITY; index++)
  2902. {
  2903. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2904. {
  2905. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2906. }
  2907. }
  2908. }//END FOR AC ELSE
  2909. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2910. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2911. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[SoC]);
  2912. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2913. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2915. sprintf(message + strlen(message),",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2916. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2917. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2918. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2919. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2920. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2921. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2922. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2923. );
  2924. }
  2925. //}
  2926. sprintf(message + strlen(message)," ] } ] } ]");
  2927. //free(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue);
  2928. }
  2929. LWS_Send(message);
  2930. //memset(mapItem, 0, sizeof(data_struct_t));
  2931. // Put request guid to hash map
  2932. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2933. 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*/)
  2934. {
  2935. result = PASS;
  2936. DEBUG_INFO("MeterValues mapitem pass\n");
  2937. }
  2938. strcpy(queuedata, message);
  2939. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2940. //#ifdef SystemLogMessage
  2941. //DEBUG_INFO(">>>>>MeerValues request\n");
  2942. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2943. //#endif
  2944. return result;
  2945. }
  2946. //==========================================
  2947. // send confirm routine
  2948. //==========================================
  2949. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2950. {
  2951. mtrace();
  2952. int result = FAIL;
  2953. char message[100]={0};
  2954. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2955. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2956. LWS_Send(message);
  2957. result = TRUE;
  2958. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2959. return result;
  2960. }
  2961. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2962. {
  2963. mtrace();
  2964. int result = FAIL;
  2965. char message[100]={0};
  2966. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2967. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2968. LWS_Send(message);
  2969. result = TRUE;
  2970. return result;
  2971. }
  2972. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2973. {
  2974. mtrace();
  2975. int result = FAIL;
  2976. char message[100]={0};
  2977. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2978. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2979. LWS_Send(message);
  2980. result = TRUE;
  2981. return result;
  2982. }
  2983. int sendClearCacheConfirmation(char *uuid,char *payload)
  2984. {
  2985. mtrace();
  2986. int result = FAIL;
  2987. char message[500]={0};
  2988. // int count = 0;
  2989. // int gun_index = 0;
  2990. // char guid[37];
  2991. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2992. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2993. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2994. LWS_Send(message);
  2995. return result;
  2996. }
  2997. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2998. {
  2999. mtrace();
  3000. int result = FAIL;
  3001. char message[500]={0};
  3002. // [ 3, "1571284268200", { "status": "Unknown" } ]
  3003. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  3004. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3005. LWS_Send(message);
  3006. return result;
  3007. }
  3008. int sendDataTransferConfirmation(char *uuid,char *payload)
  3009. {
  3010. mtrace();
  3011. char statusStr[20]={0};
  3012. char dataStr[10]={0};
  3013. char sstr[20]={0};
  3014. int c = 0;
  3015. char *loc;
  3016. int result = FAIL;
  3017. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  3018. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  3019. /**********************status**************************/
  3020. loc = strstr(payload, "status");
  3021. memset(sstr ,0, sizeof(sstr) );
  3022. c = 0;
  3023. while (loc[3+strlen("status")+c] != '\"')
  3024. {
  3025. sstr[c] = loc[3+strlen("status")+c];
  3026. c++;
  3027. }
  3028. sstr[c] = '\0';
  3029. strcpy(statusStr, sstr);
  3030. /**********************data**************************/
  3031. loc = strstr(payload, "data");
  3032. memset(sstr ,0, sizeof(sstr) );
  3033. c = 0;
  3034. while (loc[3+strlen("data")+c] != '\"')
  3035. {
  3036. sstr[c] = loc[3+strlen("data")+c];
  3037. c++;
  3038. }
  3039. sstr[c] = '\0';
  3040. strcpy(dataStr, sstr);
  3041. return result;
  3042. }
  3043. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  3044. {
  3045. mtrace();
  3046. int result = FAIL;
  3047. char message[1000]={0};
  3048. double diff_f = 0.0;
  3049. int diff_i = 0;
  3050. struct tm tp;
  3051. DEBUG_ERROR("handle sendGetCompositeScheduleConfirmation ...\n");
  3052. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  3053. tp.tm_isdst = -1;
  3054. time_t utc = mktime(&tp);
  3055. time_t t = time(NULL);
  3056. diff_f = difftime(t, utc);
  3057. diff_i = (int)diff_f;
  3058. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3059. #if 0 //remove temporally
  3060. 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}"
  3061. ,MESSAGE_TYPE_CALLRESULT
  3062. ,uuid
  3063. ,payload
  3064. ,connectorIdInt
  3065. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3066. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3067. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3068. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3069. #endif
  3070. if(nPeriod == 0)
  3071. {
  3072. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3073. ,MESSAGE_TYPE_CALLRESULT
  3074. ,uuid
  3075. ,payload
  3076. ,connectorIdInt
  3077. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule);
  3078. }
  3079. else
  3080. {
  3081. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3082. ,MESSAGE_TYPE_CALLRESULT
  3083. ,uuid
  3084. ,payload
  3085. ,connectorIdInt
  3086. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3087. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3088. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3089. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3090. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3091. #if 1 // remove temporally
  3092. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3093. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3094. {
  3095. if (idx_sample == 0)
  3096. {
  3097. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3098. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  3099. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3100. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3101. }
  3102. else
  3103. {
  3104. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3105. , (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diff_i /*-1*/)
  3106. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3107. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3108. }
  3109. }
  3110. #endif
  3111. sprintf(message + strlen(message), "]}}]");
  3112. }
  3113. LWS_Send(message);
  3114. result = TRUE;
  3115. return result;
  3116. }
  3117. int sendGetConfigurationConfirmation(char *uuid)
  3118. {
  3119. mtrace();
  3120. int result = FAIL;
  3121. int MaxKeySupported = 0;
  3122. int sentConfigurationNumber= 0;
  3123. int sentunConfigurationNumber= 0;
  3124. char message[4000]={0};
  3125. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3126. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3127. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3128. ,MESSAGE_TYPE_CALLRESULT
  3129. ,uuid );
  3130. //configuration key
  3131. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3132. {
  3133. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3134. {
  3135. if (sentConfigurationNumber == 0)
  3136. {
  3137. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3138. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3139. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3140. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3141. }
  3142. else
  3143. {
  3144. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3145. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3146. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3147. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3148. }
  3149. sentConfigurationNumber = sentConfigurationNumber + 1;
  3150. }
  3151. }
  3152. sprintf(message + strlen(message), "]");
  3153. if(UnknownKeynum != 0)
  3154. {
  3155. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3156. //unkown key
  3157. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3158. {
  3159. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3160. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3161. if(sentunConfigurationNumber == 0)
  3162. {
  3163. sprintf(message + strlen(message), "\"%s\""
  3164. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3165. }
  3166. else
  3167. {
  3168. sprintf(message + strlen(message), ",\"%s\""
  3169. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3170. }
  3171. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3172. }
  3173. sprintf(message + strlen(message), "]");
  3174. }
  3175. sprintf(message + strlen(message), "} ]");
  3176. LWS_Send(message);
  3177. #if 0
  3178. printf("error 1-0\n");
  3179. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3180. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3181. #endif
  3182. return result;
  3183. }
  3184. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3185. {
  3186. mtrace();
  3187. int result = FAIL;
  3188. char message[400]={0};
  3189. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3190. if(strcmp(payload,"")==0)
  3191. {
  3192. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3193. }
  3194. else
  3195. {
  3196. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3197. }
  3198. LWS_Send(message);
  3199. result = TRUE;
  3200. return result;
  3201. }
  3202. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3203. {
  3204. mtrace();
  3205. int result = FAIL;
  3206. char message[80]={0};
  3207. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3208. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3209. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3210. LWS_Send(message);
  3211. result = TRUE;
  3212. return result;
  3213. }
  3214. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3215. {
  3216. mtrace();
  3217. int result = FAIL;
  3218. char message[80]={0};
  3219. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3220. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3221. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3222. LWS_Send(message);
  3223. result = TRUE;
  3224. return result;
  3225. }
  3226. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3227. {
  3228. mtrace();
  3229. int result = FAIL;
  3230. char message[80]={0};
  3231. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3232. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3233. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3234. LWS_Send(message);
  3235. result = TRUE;
  3236. return result;
  3237. }
  3238. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3239. {
  3240. mtrace();
  3241. int result = FAIL;
  3242. char message[80]={0};
  3243. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3244. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3245. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3246. LWS_Send(message);
  3247. result = TRUE;
  3248. return result;
  3249. }
  3250. int sendResetConfirmation(char *uuid,char *payload)
  3251. {
  3252. mtrace();
  3253. int result = FAIL;
  3254. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3255. char message[80]={0};
  3256. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3257. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3258. LWS_Send(message);
  3259. result = TRUE;
  3260. return result;
  3261. }
  3262. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3263. {
  3264. mtrace();
  3265. int result = FAIL;
  3266. char message[500]={0};
  3267. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3268. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3269. LWS_Send(message);
  3270. result = TRUE;
  3271. return result;
  3272. }
  3273. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3274. {
  3275. mtrace();
  3276. int result = FAIL;
  3277. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3278. char message[80]={0};
  3279. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  3280. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3281. LWS_Send(message);
  3282. result = TRUE;
  3283. return result;
  3284. }
  3285. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3286. {
  3287. mtrace();
  3288. int result = FAIL;
  3289. char message[80]={0};
  3290. DEBUG_ERROR("sendTriggerMessageConfirmation\n");
  3291. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3292. LWS_Send(message);
  3293. result = TRUE;
  3294. return result;
  3295. }
  3296. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3297. {
  3298. mtrace();
  3299. int result = FAIL;
  3300. char message[80]={0};
  3301. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3302. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  3303. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3304. LWS_Send(message);
  3305. result = TRUE;
  3306. return result;
  3307. }
  3308. int sendUpdateFirmwareConfirmation(char *uuid)
  3309. {
  3310. mtrace();
  3311. int result = FAIL;
  3312. char message[60]={0};
  3313. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3314. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3315. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3316. LWS_Send(message);
  3317. result = TRUE;
  3318. return result;
  3319. }
  3320. //==========================================
  3321. // send CallError routine
  3322. //==========================================
  3323. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3324. {
  3325. mtrace();
  3326. //int result = FAIL;
  3327. char message[220]={0};
  3328. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3329. #ifdef SystemLogMessage
  3330. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3331. uniqueId, action, errorCode, errorDescription);
  3332. #endif
  3333. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3334. LWS_Send(message);
  3335. //result = TRUE;
  3336. }
  3337. //==========================================
  3338. // Handle server request routine Start
  3339. //==========================================
  3340. #define GUN_NUM 1
  3341. int handleCancelReservationRequest(char *uuid, char *payload)
  3342. {
  3343. mtrace();
  3344. int result = FAIL;
  3345. int gunNO = 0;
  3346. int reservationIdInt =0;
  3347. char comfirmstr[20];
  3348. int c = 0;
  3349. char *loc;
  3350. char sstr[100]={0};
  3351. DEBUG_INFO("handle CancelReservationRequest\n");
  3352. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3353. c = 0;
  3354. loc = strstr(payload, "reservationId");
  3355. memset(sstr ,0, sizeof(sstr) );
  3356. while (loc[strlen("reservationId")+2+c] != '}')
  3357. {
  3358. sstr[c] = loc[strlen("reservationId")+2+c];
  3359. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3360. c++;
  3361. }
  3362. sstr[c] = '\0';
  3363. reservationIdInt = atoi(sstr);
  3364. memset(comfirmstr, 0, sizeof comfirmstr);
  3365. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3366. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3367. //check Transaction active
  3368. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3369. {
  3370. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3371. {
  3372. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3373. {
  3374. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3375. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3376. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3377. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3378. goto end;
  3379. }
  3380. }
  3381. for (int index = 0; index < CCS_QUANTITY; index++)
  3382. {
  3383. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3384. {
  3385. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3386. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3387. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3388. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3389. goto end;
  3390. }
  3391. }
  3392. for (int index = 0; index < GB_QUANTITY; index++)
  3393. {
  3394. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3395. {
  3396. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3397. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3398. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3399. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3400. goto end;
  3401. }
  3402. }
  3403. }
  3404. else
  3405. {
  3406. for (int index = 0; index < AC_QUANTITY; index++)
  3407. {
  3408. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3409. {
  3410. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3411. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3412. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3413. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3414. goto end;
  3415. }
  3416. }
  3417. }// END FOR AC ELSE
  3418. //The reservationId does NOT match the reservationId
  3419. sendCancelReservationConfirmation(uuid, comfirmstr);
  3420. end:
  3421. // Fill in ocpp packet uuid
  3422. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3423. return result;
  3424. }
  3425. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3426. {
  3427. mtrace();
  3428. int result = FAIL;
  3429. int gunIndex = 0;
  3430. char sstr[90]={0};
  3431. char typeStr[16]={0};
  3432. char comfirmstr[20];
  3433. int specificId = FALSE;
  3434. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3435. char *loc;
  3436. //int intervalInt = 0;
  3437. int c = 0;
  3438. /*** connectorId ****/
  3439. c = 0;
  3440. loc = strstr(payload, "connectorId");
  3441. memset(sstr ,0, sizeof(sstr) );
  3442. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3443. {
  3444. sstr[c] = loc[strlen("connectorId")+2+c];
  3445. c++;
  3446. }
  3447. sstr[c] = '\0';
  3448. gunIndex = atoi(sstr);
  3449. /***type ****/
  3450. loc = strstr(payload, "type");
  3451. memset(sstr ,0, sizeof(sstr) );
  3452. c = 0;
  3453. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3454. {
  3455. sstr[c] = loc[3+strlen("type")+c];
  3456. c++;
  3457. }
  3458. sstr[c] = '\0';
  3459. strcpy(typeStr, sstr);
  3460. if(gunIndex != 0)
  3461. {
  3462. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3463. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3464. }
  3465. else
  3466. {
  3467. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3468. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3469. }
  3470. memset(comfirmstr, 0, sizeof comfirmstr);
  3471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3472. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3473. {
  3474. specificId = TRUE;
  3475. }
  3476. if(specificId == FALSE)
  3477. goto end;
  3478. if(gunIndex != 0)
  3479. {
  3480. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3481. }
  3482. else
  3483. {
  3484. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3485. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3486. }
  3487. /*
  3488. enum _SYSTEM_STATUS
  3489. {
  3490. S_BOOTING = 0,
  3491. S_IDLE, = 1
  3492. S_AUTHORIZING, =2
  3493. S_REASSIGN_CHECK, =3
  3494. S_REASSIGN, =4
  3495. S_PRECHARGE, =5
  3496. S_PREPARING_FOR_EV, =6
  3497. S_PREPARING_FOR_EVSE, =7
  3498. S_CHARGING, =8
  3499. S_TERMINATING, =9
  3500. S_COMPLETE, =10
  3501. S_ALARM, =11
  3502. S_FAULT =12
  3503. }
  3504. */
  3505. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3506. {
  3507. //check Transaction active
  3508. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3509. {
  3510. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3511. {
  3512. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3513. {
  3514. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3515. {
  3516. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3517. }
  3518. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3519. {
  3520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3521. }
  3522. else
  3523. {
  3524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3525. }
  3526. goto end;
  3527. }
  3528. }//END FOR CHAdeMO_QUANTITY
  3529. for (int index = 0; index < CCS_QUANTITY; index++)
  3530. {
  3531. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3532. {
  3533. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3534. {
  3535. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3536. }
  3537. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3538. {
  3539. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3540. }
  3541. else
  3542. {
  3543. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3544. }
  3545. goto end;
  3546. }
  3547. }//END FOR CCS_QUANTITY
  3548. for (int index = 0; index < GB_QUANTITY; index++)
  3549. {
  3550. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3551. {
  3552. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3553. {
  3554. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3555. }
  3556. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3557. {
  3558. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3559. }
  3560. else
  3561. {
  3562. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3563. }
  3564. goto end;
  3565. }
  3566. }// END FOR GB_QUANTITY
  3567. }
  3568. else
  3569. {
  3570. for (int index = 0; index < AC_QUANTITY; index++)
  3571. {
  3572. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3573. {
  3574. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3575. {
  3576. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3577. }
  3578. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3579. {
  3580. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3581. }
  3582. else
  3583. {
  3584. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3585. }
  3586. goto end;
  3587. }
  3588. }//END FOR AC_QUANTITY
  3589. }// END FOR AC ELSE
  3590. }//END FOR AvailabilityTypeStr[Inoperative]
  3591. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3592. {
  3593. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3594. //check Transaction active
  3595. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3596. {
  3597. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3598. {
  3599. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3600. {
  3601. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3602. goto end;
  3603. }
  3604. }//END FOR CHAdeMO_QUANTITY
  3605. for (int index = 0; index < CCS_QUANTITY; index++)
  3606. {
  3607. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3608. {
  3609. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3610. goto end;
  3611. }
  3612. }//END FOR CCS_QUANTITY
  3613. for (int index = 0; index < GB_QUANTITY; index++)
  3614. {
  3615. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3616. {
  3617. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3618. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3619. goto end;
  3620. }
  3621. }// END FOR GB_QUANTITY
  3622. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3623. }
  3624. else
  3625. {
  3626. for (int index = 0; index < AC_QUANTITY; index++)
  3627. {
  3628. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3629. {
  3630. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3631. goto end;
  3632. }
  3633. }//END FOR CHAdeMO_QUANTITY
  3634. }//END FOR AC ELSE
  3635. }//END FOR AvailabilityTypeStr[Operative]
  3636. end:
  3637. if(gunIndex != 0)
  3638. {
  3639. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3640. }
  3641. else
  3642. {
  3643. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3644. }
  3645. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3646. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3647. return result;
  3648. }
  3649. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3650. {
  3651. mtrace();
  3652. int result = FAIL;
  3653. char sstr[100]={0};
  3654. char keystr[40]={0};
  3655. char valuestr[16]={0};
  3656. char *loc;
  3657. int c = 0;
  3658. char comfirmstr[20];
  3659. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3660. /***key ****/
  3661. loc = strstr(payload, "key");
  3662. memset(sstr ,0, sizeof(sstr) );
  3663. c = 0;
  3664. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3665. {
  3666. sstr[c] = loc[3+strlen("key")+c];
  3667. c++;
  3668. }
  3669. sstr[c] = '\0';
  3670. strcpy(keystr, sstr);
  3671. /***value ****/
  3672. loc = strstr(payload, "value");
  3673. memset(sstr ,0, sizeof(sstr) );
  3674. c = 0;
  3675. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3676. {
  3677. sstr[c] = loc[3+strlen("value")+c];
  3678. c++;
  3679. }
  3680. sstr[c] = '\0';
  3681. strcpy(valuestr, sstr);
  3682. if((uuid==NULL) || (payload ==NULL) )
  3683. {
  3684. #ifdef Debug
  3685. DEBUG_INFO("payload is null\n");
  3686. #endif
  3687. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3688. }
  3689. else
  3690. {
  3691. int status = setKeyValue(keystr, valuestr);
  3692. switch(status)
  3693. {
  3694. case ConfigurationStatus_Accepted:
  3695. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3696. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3697. break;
  3698. case ConfigurationStatus_Rejected:
  3699. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3700. break;
  3701. case RebootRequired:
  3702. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3703. break;
  3704. case NotSupported:
  3705. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3706. break;
  3707. default:
  3708. break;
  3709. }
  3710. }
  3711. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3712. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3713. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3714. return result;
  3715. }
  3716. int handleClearCacheRequest(char *uuid, char *payload)
  3717. {
  3718. mtrace();
  3719. int result = FAIL;
  3720. char comfirmstr[20];
  3721. int fd;
  3722. char rmFileCmd[100]={0};
  3723. struct stat stats;
  3724. DEBUG_ERROR("handle ClearCacheRequest\n");
  3725. stat("../Storage/OCPP", &stats);
  3726. // Check for directory existence
  3727. if (S_ISDIR(stats.st_mode) == 1)
  3728. {
  3729. //DEBUG_ERROR("\n OCPP directory exist \n");
  3730. }
  3731. else
  3732. {
  3733. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3734. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3735. system(rmFileCmd);
  3736. }
  3737. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  3738. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3739. {
  3740. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3741. }
  3742. else
  3743. {
  3744. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3745. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3746. if(log == NULL)
  3747. {
  3748. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3749. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3750. goto end;
  3751. }
  3752. else
  3753. {
  3754. fclose(log);
  3755. }
  3756. }
  3757. fd = open(AuthorizationCache_JSON,O_RDWR);
  3758. if(fd < 0)
  3759. {
  3760. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3761. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3762. }
  3763. else
  3764. {
  3765. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3766. //* 清空?�件 */
  3767. ftruncate(fd,0);
  3768. //* ?�新设置?�件?�移??*/
  3769. lseek(fd,0,SEEK_SET);
  3770. close(fd);
  3771. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3772. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3773. }
  3774. end:
  3775. sendClearCacheConfirmation(uuid, comfirmstr);
  3776. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3777. return result;
  3778. }
  3779. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3780. {
  3781. mtrace();
  3782. int result = FAIL;
  3783. int resultRename;
  3784. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3785. char chargingProfilePurposeStr[26]={0};
  3786. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3787. char tempchargingProfilePurposeStr[26]={0};
  3788. char sstr[160]={0};//sstr[200]={ 0 };
  3789. char str[100]={0};
  3790. int c = 0;
  3791. //int i = 0;
  3792. //char * pch;
  3793. char *loc;
  3794. char fname[200];
  3795. char comfirmstr[20]={0};
  3796. char word[1000]={0};
  3797. int clearflag = FALSE;
  3798. int chargingProfileIdIsNULL = FALSE;
  3799. int connectorIsNULL = FALSE;
  3800. FILE *fptr1, *fptr2;
  3801. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3802. int n_chargingProfile=0;
  3803. char sLineWord[1060]={0};
  3804. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3805. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3806. //***id ****/
  3807. c = 0;
  3808. loc = strstr(payload, "id");
  3809. memset(sstr ,0, sizeof(sstr) );
  3810. if(loc == NULL)
  3811. {
  3812. chargingProfileIdIsNULL = TRUE;
  3813. }
  3814. while ((loc != NULL) &&(loc[strlen("id")+2+c] != ',') )
  3815. {
  3816. sstr[c] = loc[strlen("id")+2+c];
  3817. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3818. c++;
  3819. }
  3820. sstr[c] = '\0';
  3821. chargingProfileIdInt = atoi(sstr);
  3822. //***connectorId ****/
  3823. c=0;
  3824. loc = strstr(payload, "connectorId");
  3825. memset(sstr ,0, sizeof(sstr) );
  3826. if(loc == NULL)
  3827. {
  3828. connectorIsNULL = TRUE;
  3829. }
  3830. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  3831. {
  3832. sstr[c] = loc[strlen("connectorId")+2+c];
  3833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3834. c++;
  3835. }
  3836. sstr[c] = '\0';
  3837. connectorIdInt = atoi(sstr);
  3838. //***chargingProfilePurpose ****/
  3839. loc = strstr(payload, "chargingProfilePurpose");
  3840. memset(sstr ,0, sizeof(sstr) );
  3841. c = 0;
  3842. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3843. {
  3844. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3845. c++;
  3846. }
  3847. sstr[c] = '\0';
  3848. strcpy(chargingProfilePurposeStr, sstr);
  3849. //***stackLevel ****/
  3850. c=0;
  3851. loc = strstr(payload, "stackLevel");
  3852. memset(sstr ,0, sizeof(sstr) );
  3853. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3854. {
  3855. sstr[c] = loc[strlen("stackLevel")+2+c];
  3856. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3857. c++;
  3858. }
  3859. sstr[c] = '\0';
  3860. stackLevelInt = atoi(sstr);
  3861. if(connectorIsNULL == FALSE)
  3862. {
  3863. switch(connectorIdInt)
  3864. {
  3865. case 0:
  3866. if(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)
  3867. {
  3868. strcpy(fname, ChargePointMaxProfile_JSON);
  3869. }
  3870. else
  3871. {
  3872. strcpy(fname, TxDefaultProfile_0_JSON);
  3873. }
  3874. break;
  3875. case 1:
  3876. if(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)
  3877. {
  3878. strcpy(fname, TxDefaultProfile_1_JSON);
  3879. }
  3880. else
  3881. {
  3882. strcpy(fname, TxProfile_1_JSON);
  3883. }
  3884. break;
  3885. case 2:
  3886. if(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)
  3887. {
  3888. strcpy(fname, TxDefaultProfile_2_JSON);
  3889. }
  3890. else
  3891. {
  3892. strcpy(fname, TxProfile_2_JSON);
  3893. }
  3894. break;
  3895. default:
  3896. strcpy(fname, ChargePointMaxProfile_JSON );
  3897. break;
  3898. }
  3899. }
  3900. else
  3901. {
  3902. strcpy(fname, ChargePointMaxProfile_JSON );
  3903. }
  3904. fptr1 = fopen(fname, "r");
  3905. if (!fptr1)
  3906. {
  3907. //file not exist
  3908. DEBUG_ERROR("Unable to open the input file!!\n");
  3909. fptr1 = fopen(fname, "w+");
  3910. }
  3911. fclose(fptr1);
  3912. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3913. {
  3914. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3915. goto end;
  3916. }
  3917. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3918. {
  3919. //clear the whole contents of a file in C
  3920. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3921. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3922. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3923. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3924. fclose(fopen(TxProfile_1_JSON, "w"));
  3925. fclose(fopen(TxProfile_2_JSON, "w"));
  3926. #if 0
  3927. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3928. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3929. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3930. #endif
  3931. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3932. }
  3933. else
  3934. {
  3935. fptr1 = fopen(fname, "r");
  3936. fptr2 = fopen(temp, "w+");
  3937. while(fscanf(fptr1, "%s", word) != EOF)
  3938. {
  3939. DEBUG_INFO("word=%s\n",word);
  3940. if(strcmp(word, "chargingProfileId") == 0)
  3941. {
  3942. n_chargingProfile = n_chargingProfile + 1;
  3943. printf("Found\n");
  3944. }
  3945. }
  3946. rewind(fptr1);
  3947. //search Charging Profile Element
  3948. //int i= 0;
  3949. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3950. {
  3951. //*************************tempconnectorIdInt*********************************/
  3952. loc = strstr(sLineWord, "connectorId");
  3953. c = 0;
  3954. memset(sstr ,0, sizeof(sstr) );
  3955. while (loc[strlen("connectorId")+2+c] != ',')
  3956. {
  3957. sstr[c] = loc[strlen("connectorId")+2+c];
  3958. c++;
  3959. }
  3960. sstr[c] = '\0';
  3961. tempconnectorIdInt = atoi(sstr);
  3962. //chargingProfileId
  3963. c = 0;
  3964. loc = strstr(sLineWord, "chargingProfileId");
  3965. memset(sstr ,0, sizeof(sstr) );
  3966. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3967. {
  3968. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3969. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3970. c++;
  3971. }
  3972. sstr[c] = '\0';
  3973. tempchargingProfileIdInt = atoi(sstr);
  3974. //stackLevel
  3975. c = 0;
  3976. loc = strstr(sLineWord, "stackLevel");
  3977. memset(sstr ,0, sizeof(sstr) );
  3978. while (loc[strlen("stackLevel")+2+c] != ',')
  3979. {
  3980. sstr[c] = loc[strlen("stackLevel")+2+c];
  3981. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3982. c++;
  3983. }
  3984. sstr[c] = '\0';
  3985. tempstackLevelInt = atoi(sstr);
  3986. c = 0;
  3987. loc = strstr(sLineWord, "chargingProfilePurpose");
  3988. memset(sstr ,0, sizeof(sstr) );
  3989. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3990. {
  3991. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3992. c++;
  3993. }
  3994. sstr[c] = '\0';
  3995. strcpy(tempchargingProfilePurposeStr, sstr);
  3996. if(chargingProfileIdIsNULL == FALSE)
  3997. {
  3998. DEBUG_INFO("\n OCPP clear 0 !!!\n");
  3999. if(tempchargingProfileIdInt == chargingProfileIdInt)
  4000. {
  4001. DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  4002. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4003. clearflag = TRUE;
  4004. break;//continue;
  4005. }
  4006. else
  4007. {
  4008. DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  4009. //json_object_array_add(newHeatMap, jsonitem);
  4010. fprintf(fptr2, sLineWord);//writing data into file
  4011. }
  4012. }
  4013. else
  4014. {
  4015. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt) && (tempstackLevelInt == stackLevelInt))
  4016. {
  4017. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4018. clearflag = TRUE;
  4019. break;//continue;
  4020. }
  4021. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4022. {
  4023. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4024. clearflag = TRUE;
  4025. break;//continue;
  4026. }
  4027. else
  4028. {
  4029. //json_object_array_add(newHeatMap, jsonitem);
  4030. fprintf(fptr2, sLineWord);//writing data into file
  4031. }
  4032. }
  4033. memset(sLineWord, 0, sizeof sLineWord);
  4034. }
  4035. if(clearflag == FALSE)
  4036. {
  4037. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4038. goto end;
  4039. }
  4040. fclose(fptr1);
  4041. fclose(fptr2);
  4042. sprintf(str,"rm -f %s",fname);
  4043. system(str);
  4044. resultRename = rename(temp, fname);
  4045. if(resultRename == 0)
  4046. {
  4047. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4048. }
  4049. else
  4050. {
  4051. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4052. }
  4053. }
  4054. end:
  4055. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4056. return result;
  4057. }
  4058. int handleDataTransferRequest(char *uuid, char *payload)
  4059. {
  4060. mtrace();
  4061. int result = FAIL;
  4062. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4063. char tempvendorId[255]={0};
  4064. char tempmessageId[50]={0};
  4065. char tempdata[50]={0};
  4066. char sstr[160]={0};//sstr[200]={ 0 };
  4067. char message[80]={0};
  4068. int c = 0;
  4069. char *loc;
  4070. DEBUG_INFO("handle DataTransferRequest\n");
  4071. if((uuid != NULL) && (payload != NULL))
  4072. {
  4073. //===============================
  4074. // vendorId
  4075. //===============================
  4076. c = 0;
  4077. loc = strstr(payload, "vendorId");
  4078. while (loc[strlen("vendorId")+3+c] != '\"')
  4079. {
  4080. sstr[c] = loc[strlen("vendorId")+3+c];
  4081. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4082. c++;
  4083. }
  4084. sstr[c] = '\0';
  4085. strcpy(tempvendorId,sstr);
  4086. //===============================
  4087. // messageId
  4088. //===============================
  4089. memset(sstr ,0, sizeof(sstr) );
  4090. c = 0;
  4091. loc = strstr(payload, "messageId");
  4092. while (loc[strlen("messageId")+3+c] != '\"')
  4093. {
  4094. sstr[c] = loc[strlen("messageId")+3+c];
  4095. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4096. c++;
  4097. }
  4098. sstr[c] = '\0';
  4099. strcpy(tempmessageId,sstr);
  4100. //===============================
  4101. // data
  4102. //===============================
  4103. memset(sstr ,0, sizeof(sstr) );
  4104. c = 0;
  4105. loc = strstr(payload, "data");
  4106. printf("loc=%s\n",loc);
  4107. while (loc[strlen("data")+3+c] != '\"')
  4108. {
  4109. sstr[c] = loc[strlen("data")+3+c];
  4110. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4111. c++;
  4112. }
  4113. sstr[c] = '\0';
  4114. strcpy(tempdata,sstr);
  4115. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4116. }
  4117. else
  4118. {
  4119. char guid[37]={0};
  4120. random_uuid(guid);
  4121. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4122. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4123. }
  4124. LWS_Send(message);
  4125. return result;
  4126. }
  4127. #if 0
  4128. long long diff_tm(struct tm *a, struct tm *b) {
  4129. return a->tm_sec - b->tm_sec
  4130. + 60LL * (a->tm_min - b->tm_min)
  4131. + 3600LL * (a->tm_hour - b->tm_hour)
  4132. + 86400LL * (a->tm_yday - b->tm_yday)
  4133. + (a->tm_year - 70) * 31536000LL
  4134. - (a->tm_year - 69) / 4 * 86400LL
  4135. + (a->tm_year - 1) / 100 * 86400LL
  4136. - (a->tm_year + 299) / 400 * 86400LL
  4137. - (b->tm_year - 70) * 31536000LL
  4138. + (b->tm_year - 69) / 4 * 86400LL
  4139. - (b->tm_year - 1) / 100 * 86400LL
  4140. + (b->tm_year + 299) /400 * 86400LL;
  4141. }
  4142. #endif
  4143. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4144. {
  4145. mtrace();
  4146. int result = FAIL;
  4147. int connectorIdInt, durationInt;
  4148. char chargingRateUnitStr[4]={0};
  4149. //int tempconnectorIdInt,
  4150. int tempdurationInt;
  4151. float tempminChargingRateFloat = 0.0;
  4152. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4153. int tempStartPeriodInt=0;
  4154. float tempLimitInt=0.0;//0.1;
  4155. int tempNumberPhasesInt=0;
  4156. char fname[200];
  4157. char comfirmstr[20];
  4158. //float totallimit =0.0;
  4159. float MinChargingRate =0.0;
  4160. double diff_t;
  4161. struct tm tp;
  4162. //int clearflag = FALSE;
  4163. FILE *fptr1;//, *fptr2;
  4164. //char temp[] = "../Storage/OCPP/temp.json";
  4165. int c = 0;
  4166. //int i = 0;
  4167. char * pch;
  4168. char *loc;
  4169. char sstr[200]={ 0 };
  4170. int n_chargingProfile = 0;
  4171. int n_SchedulePeriods = 0;
  4172. char SchedulePeriodList[10][200]={0};
  4173. char sLineWord[800]={0};
  4174. //int n_periods = 0;
  4175. char word[1000]={0};
  4176. int confirmPeriods = 0;
  4177. struct StructProfile ChargePointMaxProfile;
  4178. struct StructProfile TxDefaultProfile;
  4179. struct StructProfile TxProfile;
  4180. struct StructProfile TxDefaultProfiletemp[2]={0};
  4181. int TxDefaultProfileFileIsNull=FALSE;
  4182. int ChargePointMaxProfileIsNull=FALSE;
  4183. int TxProfileIsNull=FALSE;
  4184. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4185. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4186. memset(&TxProfile,0,sizeof(struct StructProfile));
  4187. c=0;
  4188. loc = strstr(payload, "connectorId");
  4189. memset(sstr ,0, sizeof(sstr) );
  4190. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4191. {
  4192. sstr[c] = loc[strlen("connectorId")+2+c];
  4193. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4194. c++;
  4195. }
  4196. sstr[c] = '\0';
  4197. connectorIdInt = atoi(sstr);
  4198. c=0;
  4199. loc = strstr(payload, "duration");
  4200. memset(sstr ,0, sizeof(sstr) );
  4201. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4202. {
  4203. sstr[c] = loc[strlen("duration")+2+c];
  4204. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4205. c++;
  4206. }
  4207. sstr[c] = '\0';
  4208. durationInt = atoi(sstr);
  4209. c = 0;
  4210. loc = strstr(payload, "chargingRateUnit");
  4211. memset(sstr ,0, sizeof(sstr) );
  4212. if(loc == NULL)
  4213. {
  4214. }
  4215. else
  4216. {
  4217. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4218. {
  4219. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4220. c++;
  4221. }
  4222. sstr[c] = '\0';
  4223. strcpy(chargingRateUnitStr, sstr);
  4224. }
  4225. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4226. if(connectorIdInt==0) // connectorId is 0
  4227. {
  4228. //******************************ChargePointMaxProfile*****************************************************/
  4229. strcpy(fname, ChargePointMaxProfile_JSON );
  4230. char word[30]={0};
  4231. char sLineWord[1060]={0};
  4232. int n_chargingProfile=0;
  4233. ChargePointMaxProfileIsNull=TRUE;
  4234. if((access(fname,F_OK))!=-1)
  4235. {
  4236. fptr1 = fopen(fname, "r");
  4237. int c;
  4238. c = fgetc(fptr1);
  4239. //DEBUG_INFO("c:%d\n",c);
  4240. rewind(fptr1);
  4241. if(c == EOF)
  4242. {
  4243. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4244. ChargePointMaxProfileIsNull=TRUE;
  4245. fclose(fptr1);
  4246. }
  4247. else
  4248. {
  4249. ChargePointMaxProfileIsNull=FALSE;
  4250. while(fscanf(fptr1, "%s", word) != EOF)
  4251. {
  4252. if(strcmp(word, "chargingProfileId") == 0)
  4253. {
  4254. n_chargingProfile = n_chargingProfile + 1;
  4255. printf("Found\n");
  4256. }
  4257. }
  4258. rewind(fptr1);
  4259. //search Charging Profile Element
  4260. int i= 0;
  4261. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4262. #if 0
  4263. /***********connectorId****************/
  4264. c = 0;
  4265. loc = strstr(sLineWord, "connectorId");
  4266. // printf("loc=%s\n",loc);
  4267. memset(sstr ,0, sizeof(sstr) );
  4268. while (loc[strlen("connectorId")+2+c] != ',')
  4269. {
  4270. sstr[c] = loc[strlen("connectorId")+2+c];
  4271. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4272. c++;
  4273. }
  4274. sstr[c] = '\0';
  4275. tempconnectorIdInt = atoi(sstr);
  4276. #endif
  4277. //***********validFrom**************/
  4278. c = 0;
  4279. loc = strstr(sLineWord, "validFrom");
  4280. //DEBUG_INFO("loc=%s\n",loc);
  4281. memset(sstr ,0, sizeof(sstr) );
  4282. if(loc != NULL)
  4283. {
  4284. while (loc[3+strlen("validFrom")+c] != '\"')
  4285. {
  4286. sstr[c] = loc[3+strlen("validFrom")+c];
  4287. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4288. c++;
  4289. }
  4290. sstr[c] = '\0';
  4291. DEBUG_INFO("validFrom=%s\n",sstr);
  4292. strcpy(tempvalidFromStr,sstr);
  4293. }
  4294. else
  4295. {
  4296. strcpy(tempvalidFromStr,"");
  4297. }
  4298. //**********startSchedule**********/
  4299. c = 0;
  4300. loc = strstr(sLineWord, "startSchedule");
  4301. //DEBUG_INFO("loc=%s\n",loc);
  4302. memset(sstr ,0, sizeof(sstr) );
  4303. while (loc[3+strlen("startSchedule")+c] != '\"')
  4304. {
  4305. sstr[c] = loc[3+strlen("startSchedule")+c];
  4306. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4307. c++;
  4308. }
  4309. sstr[c] = '\0';
  4310. strcpy(tempstartScheduleStr, sstr);
  4311. //**********startSchedule**********/
  4312. c = 0;
  4313. loc = strstr(sLineWord, "chargingRateUnit");
  4314. memset(sstr ,0, sizeof(sstr) );
  4315. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4316. {
  4317. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4318. c++;
  4319. }
  4320. sstr[c] = '\0';
  4321. strcpy(tempchargingRateUnitStr, sstr);
  4322. //**********minChargingRate*******/
  4323. c = 0;
  4324. loc = strstr(sLineWord, "minChargingRate");
  4325. //printf("loc=%s\n",loc);
  4326. if(loc != NULL)
  4327. {
  4328. memset(sstr ,0, sizeof(sstr) );
  4329. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4330. {
  4331. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4332. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4333. c++;
  4334. }
  4335. sstr[c] = '\0';
  4336. tempminChargingRateFloat = atof(sstr);
  4337. }
  4338. else
  4339. {
  4340. tempminChargingRateFloat = 0.0;
  4341. }
  4342. //
  4343. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4344. tp.tm_isdst = -1;
  4345. time_t utc = mktime(&tp);
  4346. // current time
  4347. time_t t = time(NULL);
  4348. diff_t = difftime(t, utc);
  4349. //parsing strings to words
  4350. i = 0;
  4351. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4352. loc = loc+3+strlen("chargingSchedulePeriod");
  4353. pch = strtok(loc ,"{");
  4354. while (pch != NULL)
  4355. {
  4356. strcpy(SchedulePeriodList[i], pch);
  4357. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4358. //printf ("%s\n",pch);
  4359. pch = strtok (NULL, "{");
  4360. i = i + 1;
  4361. }
  4362. n_SchedulePeriods = i;
  4363. for(int i=0;i<n_SchedulePeriods;i++)
  4364. {
  4365. //*************startPeriod****************/
  4366. c = 0;
  4367. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4368. memset(sstr ,0, sizeof(sstr) );
  4369. while (loc[strlen("startPeriod")+2+c] != ',')
  4370. {
  4371. sstr[c] = loc[strlen("startPeriod")+2+c];
  4372. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4373. c++;
  4374. }
  4375. sstr[c] = '\0';
  4376. tempStartPeriodInt = atoi(sstr);
  4377. //*************limit****************/
  4378. c = 0;
  4379. loc = strstr(SchedulePeriodList[i], "limit");
  4380. memset(sstr ,0, sizeof(sstr) );
  4381. while (loc[strlen("limit")+2+c] != ',')
  4382. {
  4383. sstr[c] = loc[strlen("limit")+2+c];
  4384. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4385. c++;
  4386. }
  4387. sstr[c] = '\0';
  4388. tempLimitInt = atof(sstr);
  4389. //*************numberPhases****************/
  4390. c = 0;
  4391. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4392. memset(sstr ,0, sizeof(sstr) );
  4393. while (loc[strlen("numberPhases")+2+c] != ',')
  4394. {
  4395. sstr[c] = loc[strlen("numberPhases")+2+c];
  4396. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4397. c++;
  4398. }
  4399. sstr[c] = '\0';
  4400. tempNumberPhasesInt = atoi(sstr);
  4401. ChargePointMaxProfile.Duration = durationInt;
  4402. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4403. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4404. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4405. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4406. }
  4407. if(MinChargingRate < tempminChargingRateFloat)
  4408. MinChargingRate = tempminChargingRateFloat;
  4409. }
  4410. }// End of file ChargingProfile
  4411. } //THE END OF ACCESS ChargePointMaxProfile
  4412. //******************************TxDefaultProfile***********************************************/
  4413. strcpy(fname, TxDefaultProfile_0_JSON);
  4414. memset(word, 0, 30);
  4415. memset(sLineWord, 0, 1060);
  4416. //char word[30]={0};
  4417. //char sLineWord[1060]={0};
  4418. n_chargingProfile=0;
  4419. TxDefaultProfileFileIsNull=TRUE;
  4420. if((access(fname,F_OK))!=-1)
  4421. {
  4422. fptr1 = fopen(fname, "r");
  4423. c = 0;
  4424. c = fgetc(fptr1);
  4425. //DEBUG_INFO("c:%d\n",c);
  4426. rewind(fptr1);
  4427. if(c == EOF)
  4428. {
  4429. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4430. TxDefaultProfileFileIsNull=TRUE;
  4431. fclose(fptr1);
  4432. }
  4433. else
  4434. {
  4435. TxDefaultProfileFileIsNull=FALSE;
  4436. while(fscanf(fptr1, "%s", word) != EOF)
  4437. {
  4438. if(strcmp(word, "chargingProfileId") == 0)
  4439. {
  4440. n_chargingProfile = n_chargingProfile + 1;
  4441. printf("Found\n");
  4442. }
  4443. }
  4444. rewind(fptr1);
  4445. //search Charging Profile Element
  4446. int i= 0;
  4447. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4448. #if 0
  4449. /***********connectorId****************/
  4450. c = 0;
  4451. loc = strstr(sLineWord, "connectorId");
  4452. // printf("loc=%s\n",loc);
  4453. memset(sstr ,0, sizeof(sstr) );
  4454. while (loc[strlen("connectorId")+2+c] != ',')
  4455. {
  4456. sstr[c] = loc[strlen("connectorId")+2+c];
  4457. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4458. c++;
  4459. }
  4460. sstr[c] = '\0';
  4461. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4462. tempconnectorIdInt = atoi(sstr);
  4463. #endif
  4464. //***********validFrom**************/
  4465. c = 0;
  4466. loc = strstr(sLineWord, "validFrom");
  4467. //DEBUG_INFO("loc=%s\n",loc);
  4468. memset(sstr ,0, sizeof(sstr) );
  4469. if(loc != NULL)
  4470. {
  4471. while (loc[3+strlen("validFrom")+c] != '\"')
  4472. {
  4473. sstr[c] = loc[3+strlen("validFrom")+c];
  4474. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4475. c++;
  4476. }
  4477. sstr[c] = '\0';
  4478. DEBUG_INFO("validFrom=%s\n",sstr);
  4479. strcpy(tempvalidFromStr,sstr);
  4480. }
  4481. else
  4482. {
  4483. strcpy(tempvalidFromStr,"");
  4484. }
  4485. //**********startSchedule**********/
  4486. c = 0;
  4487. loc = strstr(sLineWord, "startSchedule");
  4488. //DEBUG_INFO("loc=%s\n",loc);
  4489. memset(sstr ,0, sizeof(sstr) );
  4490. while (loc[3+strlen("startSchedule")+c] != '\"')
  4491. {
  4492. sstr[c] = loc[3+strlen("startSchedule")+c];
  4493. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4494. c++;
  4495. }
  4496. sstr[c] = '\0';
  4497. strcpy(tempstartScheduleStr, sstr);
  4498. DEBUG_INFO(" debug 3-1\n");
  4499. //**********startSchedule**********/
  4500. c = 0;
  4501. loc = strstr(sLineWord, "chargingRateUnit");
  4502. memset(sstr ,0, sizeof(sstr) );
  4503. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4504. {
  4505. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4506. c++;
  4507. }
  4508. sstr[c] = '\0';
  4509. strcpy(tempchargingRateUnitStr, sstr);
  4510. //**********minChargingRate*******/
  4511. c = 0;
  4512. loc = strstr(sLineWord, "minChargingRate");
  4513. //printf("loc=%s\n",loc);
  4514. if(loc != NULL)
  4515. {
  4516. memset(sstr ,0, sizeof(sstr) );
  4517. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4518. {
  4519. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4521. c++;
  4522. }
  4523. sstr[c] = '\0';
  4524. tempminChargingRateFloat = atof(sstr);
  4525. }
  4526. else
  4527. {
  4528. tempminChargingRateFloat = 0.0;
  4529. }
  4530. //
  4531. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4532. tp.tm_isdst = -1;
  4533. time_t utc = mktime(&tp);
  4534. // current time
  4535. time_t t = time(NULL);
  4536. diff_t = difftime(t, utc);
  4537. //parsing strings to words
  4538. i = 0;
  4539. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4540. loc = loc+3+strlen("chargingSchedulePeriod");
  4541. pch = strtok(loc ,"{");
  4542. while (pch != NULL)
  4543. {
  4544. strcpy(SchedulePeriodList[i], pch);
  4545. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4546. //printf ("%s\n",pch);
  4547. pch = strtok (NULL, "{");
  4548. i = i + 1;
  4549. }
  4550. n_SchedulePeriods = i;
  4551. for(int i=0;i<n_SchedulePeriods;i++)
  4552. {
  4553. //*************startPeriod****************/
  4554. c = 0;
  4555. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4556. memset(sstr ,0, sizeof(sstr) );
  4557. while (loc[strlen("startPeriod")+2+c] != ',')
  4558. {
  4559. sstr[c] = loc[strlen("startPeriod")+2+c];
  4560. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4561. c++;
  4562. }
  4563. sstr[c] = '\0';
  4564. tempStartPeriodInt = atoi(sstr);
  4565. //*************limit****************/
  4566. c = 0;
  4567. loc = strstr(SchedulePeriodList[i], "limit");
  4568. memset(sstr ,0, sizeof(sstr) );
  4569. while (loc[strlen("limit")+2+c] != ',')
  4570. {
  4571. sstr[c] = loc[strlen("limit")+2+c];
  4572. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4573. c++;
  4574. }
  4575. sstr[c] = '\0';
  4576. tempLimitInt = atof(sstr);
  4577. //*************numberPhases****************/
  4578. c = 0;
  4579. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4580. memset(sstr ,0, sizeof(sstr) );
  4581. while (loc[strlen("numberPhases")+2+c] != ',')
  4582. {
  4583. sstr[c] = loc[strlen("numberPhases")+2+c];
  4584. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4585. c++;
  4586. }
  4587. sstr[c] = '\0';
  4588. tempNumberPhasesInt = atoi(sstr);
  4589. TxDefaultProfile.Duration = durationInt;
  4590. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4591. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4592. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4593. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4594. }
  4595. if(MinChargingRate < tempminChargingRateFloat)
  4596. MinChargingRate = tempminChargingRateFloat;
  4597. }
  4598. }
  4599. }// the end of ACCESS TxDefaultProfile
  4600. // Composite Schedule
  4601. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4602. {
  4603. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4604. {
  4605. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4606. {
  4607. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4608. }
  4609. else
  4610. {
  4611. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4612. }
  4613. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4614. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4615. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4616. }
  4617. }
  4618. //* Define temporary variables */
  4619. struct tm *gtime;
  4620. time_t now;
  4621. char buf[28];
  4622. /* Read the current system time */
  4623. time(&now);
  4624. /* Convert the system time to GMT (now UTC) */
  4625. gtime = gmtime(&now);
  4626. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4627. // make .conf
  4628. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  4629. //MaxChargingProfilesInstalled is 10
  4630. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4631. memset(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4632. //nPeriod = 1;
  4633. if(chargingRateUnitStr[0] != 0)
  4634. {
  4635. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4636. }
  4637. else
  4638. {
  4639. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, "" );
  4640. }
  4641. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4642. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4643. confirmPeriods = 1;
  4644. }
  4645. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4646. {
  4647. //*****************************ChargePointMaxProfile******************************************/
  4648. strcpy(fname, ChargePointMaxProfile_JSON);
  4649. ChargePointMaxProfileIsNull=TRUE;
  4650. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4651. {
  4652. fptr1 = fopen(fname, "r");
  4653. int c;
  4654. c = fgetc(fptr1);
  4655. //DEBUG_INFO("c:%d\n",c);
  4656. rewind(fptr1);
  4657. if(c == EOF)
  4658. {
  4659. DEBUG_INFO("\n End of file reached.");
  4660. ChargePointMaxProfileIsNull=TRUE;
  4661. fclose(fptr1);
  4662. }
  4663. else
  4664. {
  4665. ChargePointMaxProfileIsNull=FALSE;
  4666. while(fscanf(fptr1, "%s", word) != EOF)
  4667. {
  4668. if(strcmp(word, "chargingProfileId") == 0)
  4669. {
  4670. n_chargingProfile = n_chargingProfile + 1;
  4671. }
  4672. }
  4673. rewind(fptr1);
  4674. //search Charging Profile Element
  4675. int i = 0;
  4676. int j = 0;
  4677. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4678. #if 0
  4679. /***********connectorId****************/
  4680. c = 0;
  4681. loc = strstr(sLineWord, "connectorId");
  4682. memset(sstr ,0, sizeof(sstr) );
  4683. while (loc[strlen("connectorId")+2+c] != ',')
  4684. {
  4685. sstr[c] = loc[strlen("connectorId")+2+c];
  4686. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4687. c++;
  4688. }
  4689. sstr[c] = '\0';
  4690. tempconnectorIdInt = atoi(sstr);
  4691. #endif
  4692. //***********validFrom**************/
  4693. c = 0;
  4694. loc = strstr(sLineWord, "validFrom");
  4695. if(loc != NULL)
  4696. {
  4697. memset(sstr ,0, sizeof(sstr) );
  4698. while (loc[3+strlen("validFrom")+c] != '\"')
  4699. {
  4700. sstr[c] = loc[3+strlen("validFrom")+c];
  4701. c++;
  4702. }
  4703. sstr[c] = '\0';
  4704. strcpy(tempvalidFromStr,sstr);
  4705. }
  4706. else
  4707. {
  4708. strcpy(tempvalidFromStr,"");
  4709. }
  4710. //***********validFrom**************/
  4711. c = 0;
  4712. loc = strstr(sLineWord, "duration");
  4713. if(loc != NULL)
  4714. {
  4715. memset(sstr ,0, sizeof(sstr) );
  4716. while (loc[2+strlen("duration")+c] != ',')
  4717. {
  4718. sstr[c] = loc[2+strlen("duration")+c];
  4719. c++;
  4720. }
  4721. sstr[c] = '\0';
  4722. tempdurationInt = atoi(sstr);
  4723. }
  4724. else
  4725. {
  4726. tempdurationInt = 0;
  4727. }
  4728. //**********startSchedule**********/
  4729. c = 0;
  4730. loc = strstr(sLineWord, "startSchedule");
  4731. memset(sstr ,0, sizeof(sstr) );
  4732. while (loc[3+strlen("startSchedule")+c] != '\"')
  4733. {
  4734. sstr[c] = loc[3+strlen("startSchedule")+c];
  4735. c++;
  4736. }
  4737. sstr[c] = '\0';
  4738. strcpy(tempstartScheduleStr, sstr);
  4739. //**********startSchedule**********/
  4740. c = 0;
  4741. loc = strstr(sLineWord, "chargingRateUnit");
  4742. memset(sstr ,0, sizeof(sstr) );
  4743. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4744. {
  4745. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4746. c++;
  4747. }
  4748. sstr[c] = '\0';
  4749. strcpy(tempchargingRateUnitStr, sstr);
  4750. //**********minChargingRate*******/
  4751. c = 0;
  4752. loc = strstr(sLineWord, "minChargingRate");
  4753. if(loc != NULL)
  4754. {
  4755. memset(sstr ,0, sizeof(sstr) );
  4756. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4757. {
  4758. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4759. c++;
  4760. }
  4761. sstr[c] = '\0';
  4762. tempminChargingRateFloat = atof(sstr);
  4763. }
  4764. else
  4765. {
  4766. tempminChargingRateFloat = 0.0;
  4767. }
  4768. //
  4769. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4770. tp.tm_isdst = -1;
  4771. time_t utc = mktime(&tp);
  4772. time_t t = time(NULL);
  4773. diff_t = difftime(t, utc);
  4774. DEBUG_INFO("diff_t=%f\n",diff_t);
  4775. DEBUG_INFO(" debug 5 -1\n");
  4776. //parsing strings to words
  4777. i = 0;
  4778. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4779. loc = loc+3+strlen("chargingSchedulePeriod");
  4780. pch = strtok(loc ,"{");
  4781. while (pch != NULL)
  4782. {
  4783. strcpy(SchedulePeriodList[i], pch);
  4784. pch = strtok (NULL, "{");
  4785. i = i + 1;
  4786. }
  4787. n_SchedulePeriods = i;
  4788. for(int i=0;i<n_SchedulePeriods;i++)
  4789. {
  4790. //*************startPeriod****************/
  4791. c = 0;
  4792. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4793. memset(sstr ,0, sizeof(sstr) );
  4794. while (loc[strlen("startPeriod")+2+c] != ',')
  4795. {
  4796. sstr[c] = loc[strlen("startPeriod")+2+c];
  4797. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4798. c++;
  4799. }
  4800. sstr[c] = '\0';
  4801. tempStartPeriodInt = atoi(sstr);
  4802. //*************limit****************/
  4803. c = 0;
  4804. loc = strstr(SchedulePeriodList[i], "limit");
  4805. memset(sstr ,0, sizeof(sstr) );
  4806. while (loc[strlen("limit")+2+c] != ',')
  4807. {
  4808. sstr[c] = loc[strlen("limit")+2+c];
  4809. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4810. c++;
  4811. }
  4812. sstr[c] = '\0';
  4813. tempLimitInt = atof(sstr);
  4814. //*************numberPhases****************/
  4815. c = 0;
  4816. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4817. memset(sstr ,0, sizeof(sstr) );
  4818. while (loc[strlen("numberPhases")+2+c] != '}')
  4819. {
  4820. sstr[c] = loc[strlen("numberPhases")+2+c];
  4821. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4822. c++;
  4823. }
  4824. sstr[c] = '\0';
  4825. tempNumberPhasesInt = atoi(sstr);
  4826. if(j == 0)
  4827. {
  4828. ChargePointMaxProfile.Duration = tempdurationInt;
  4829. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4830. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4831. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4832. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4833. }
  4834. }
  4835. if(MinChargingRate < tempminChargingRateFloat)
  4836. {
  4837. MinChargingRate = tempminChargingRateFloat;
  4838. }
  4839. if(confirmPeriods < n_SchedulePeriods)
  4840. {
  4841. confirmPeriods = n_SchedulePeriods;
  4842. }
  4843. j = j + 1;
  4844. }
  4845. fclose(fptr1);
  4846. }
  4847. }// the end of access file ChargePointMaxProfile
  4848. //****************************TxDefaultProfile************************************************/
  4849. switch(connectorIdInt)
  4850. {
  4851. case 0:
  4852. break;
  4853. case 1:
  4854. strcpy(fname, TxDefaultProfile_1_JSON );
  4855. break;
  4856. case 2:
  4857. strcpy(fname, TxDefaultProfile_2_JSON );
  4858. break;
  4859. default:
  4860. strcpy(fname, TxDefaultProfile_1_JSON );
  4861. break;
  4862. }
  4863. TxDefaultProfileFileIsNull=TRUE;
  4864. if((access(fname,F_OK))!=-1)
  4865. {
  4866. fptr1 = fopen(fname, "r");
  4867. c = 0;
  4868. c = fgetc(fptr1);
  4869. //DEBUG_INFO("c:%d\n",c);
  4870. rewind(fptr1);
  4871. if(c == EOF)
  4872. {
  4873. DEBUG_INFO("\n End of file reached.");
  4874. TxDefaultProfileFileIsNull=TRUE;
  4875. fclose(fptr1);
  4876. }
  4877. else
  4878. {
  4879. TxDefaultProfileFileIsNull=FALSE;
  4880. while(fscanf(fptr1, "%s", word) != EOF)
  4881. {
  4882. if(strcmp(word, "chargingProfileId") == 0)
  4883. {
  4884. n_chargingProfile = n_chargingProfile + 1;
  4885. }
  4886. }
  4887. rewind(fptr1);
  4888. //search Charging Profile Element
  4889. int i = 0;
  4890. int j = 0;
  4891. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4892. #if 0
  4893. /***********connectorId****************/
  4894. c = 0;
  4895. loc = strstr(sLineWord, "connectorId");
  4896. memset(sstr ,0, sizeof(sstr) );
  4897. while (loc[strlen("connectorId")+2+c] != ',')
  4898. {
  4899. sstr[c] = loc[strlen("connectorId")+2+c];
  4900. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4901. c++;
  4902. }
  4903. sstr[c] = '\0';
  4904. tempconnectorIdInt = atoi(sstr);
  4905. #endif
  4906. //***********validFrom**************/
  4907. c = 0;
  4908. loc = strstr(sLineWord, "validFrom");
  4909. if(loc != NULL)
  4910. {
  4911. memset(sstr ,0, sizeof(sstr) );
  4912. while (loc[3+strlen("validFrom")+c] != '\"')
  4913. {
  4914. sstr[c] = loc[3+strlen("validFrom")+c];
  4915. c++;
  4916. }
  4917. sstr[c] = '\0';
  4918. strcpy(tempvalidFromStr,sstr);
  4919. }
  4920. else
  4921. {
  4922. strcpy(tempvalidFromStr,"");
  4923. }
  4924. //***********validFrom**************/
  4925. c = 0;
  4926. loc = strstr(sLineWord, "duration");
  4927. if(loc != NULL)
  4928. {
  4929. memset(sstr ,0, sizeof(sstr) );
  4930. while (loc[2+strlen("duration")+c] != ',')
  4931. {
  4932. sstr[c] = loc[2+strlen("duration")+c];
  4933. c++;
  4934. }
  4935. sstr[c] = '\0';
  4936. tempdurationInt = atoi(sstr);
  4937. }
  4938. else
  4939. {
  4940. tempdurationInt = 0;
  4941. }
  4942. //**********startSchedule**********/
  4943. c = 0;
  4944. loc = strstr(sLineWord, "startSchedule");
  4945. memset(sstr ,0, sizeof(sstr) );
  4946. while (loc[3+strlen("startSchedule")+c] != '\"')
  4947. {
  4948. sstr[c] = loc[3+strlen("startSchedule")+c];
  4949. c++;
  4950. }
  4951. sstr[c] = '\0';
  4952. strcpy(tempstartScheduleStr, sstr);
  4953. //**********startSchedule**********/
  4954. c = 0;
  4955. loc = strstr(sLineWord, "chargingRateUnit");
  4956. memset(sstr ,0, sizeof(sstr) );
  4957. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4958. {
  4959. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4960. c++;
  4961. }
  4962. sstr[c] = '\0';
  4963. strcpy(tempchargingRateUnitStr, sstr);
  4964. //**********minChargingRate*******/
  4965. c = 0;
  4966. loc = strstr(sLineWord, "minChargingRate");
  4967. if(loc != NULL)
  4968. {
  4969. memset(sstr ,0, sizeof(sstr) );
  4970. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4971. {
  4972. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4973. c++;
  4974. }
  4975. sstr[c] = '\0';
  4976. tempminChargingRateFloat = atof(sstr);
  4977. }
  4978. else
  4979. {
  4980. tempminChargingRateFloat = 0.0;
  4981. }
  4982. //
  4983. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4984. tp.tm_isdst = -1;
  4985. time_t utc = mktime(&tp);
  4986. time_t t = time(NULL);
  4987. diff_t = difftime(t, utc);
  4988. DEBUG_INFO("diff_t=%f\n",diff_t);
  4989. DEBUG_INFO(" debug 5 -1\n");
  4990. //parsing strings to words
  4991. i = 0;
  4992. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4993. loc = loc+3+strlen("chargingSchedulePeriod");
  4994. pch = strtok(loc ,"{");
  4995. while (pch != NULL)
  4996. {
  4997. strcpy(SchedulePeriodList[i], pch);
  4998. pch = strtok (NULL, "{");
  4999. i = i + 1;
  5000. }
  5001. n_SchedulePeriods = i;
  5002. for(int i=0;i<n_SchedulePeriods;i++)
  5003. {
  5004. //*************startPeriod****************/
  5005. c = 0;
  5006. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5007. memset(sstr ,0, sizeof(sstr) );
  5008. while (loc[strlen("startPeriod")+2+c] != ',')
  5009. {
  5010. sstr[c] = loc[strlen("startPeriod")+2+c];
  5011. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5012. c++;
  5013. }
  5014. sstr[c] = '\0';
  5015. tempStartPeriodInt = atoi(sstr);
  5016. //*************limit****************/
  5017. c = 0;
  5018. loc = strstr(SchedulePeriodList[i], "limit");
  5019. memset(sstr ,0, sizeof(sstr) );
  5020. while (loc[strlen("limit")+2+c] != ',')
  5021. {
  5022. sstr[c] = loc[strlen("limit")+2+c];
  5023. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5024. c++;
  5025. }
  5026. sstr[c] = '\0';
  5027. tempLimitInt = atof(sstr);
  5028. //*************numberPhases****************/
  5029. c = 0;
  5030. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5031. memset(sstr ,0, sizeof(sstr) );
  5032. while (loc[strlen("numberPhases")+2+c] != '}')
  5033. {
  5034. sstr[c] = loc[strlen("numberPhases")+2+c];
  5035. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5036. c++;
  5037. }
  5038. sstr[c] = '\0';
  5039. tempNumberPhasesInt = atoi(sstr);
  5040. if(j == 0)
  5041. {
  5042. TxDefaultProfile.Duration = tempdurationInt;
  5043. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5044. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5045. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5046. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5047. }
  5048. else
  5049. {
  5050. //other stack level charging Profile
  5051. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5052. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5053. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5054. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5055. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5056. }
  5057. }
  5058. if(MinChargingRate < tempminChargingRateFloat)
  5059. MinChargingRate = tempminChargingRateFloat;
  5060. if(confirmPeriods < n_SchedulePeriods)
  5061. confirmPeriods = n_SchedulePeriods;
  5062. j = j + 1;
  5063. }
  5064. fclose(fptr1);
  5065. //Stacking Charging Profiles
  5066. for(int l=0; l <(j-1) ;l++)
  5067. {
  5068. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5069. {
  5070. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5071. {
  5072. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5073. {
  5074. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5075. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5076. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5077. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5078. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  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. else
  5086. {
  5087. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5088. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5089. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5090. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5091. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5092. }
  5093. }
  5094. }
  5095. }
  5096. //end of Stacking Charging Profiles
  5097. }
  5098. }// the end of ACCESS TxDefaultProfile
  5099. //****************************TxProfile************************************************/
  5100. switch(connectorIdInt)
  5101. {
  5102. case 0:
  5103. break;
  5104. case 1:
  5105. strcpy(fname, TxProfile_1_JSON );
  5106. break;
  5107. case 2:
  5108. strcpy(fname, TxProfile_2_JSON );
  5109. break;
  5110. default:
  5111. strcpy(fname, TxProfile_1_JSON );
  5112. break;
  5113. }
  5114. TxProfileIsNull=TRUE;
  5115. if((access(fname,F_OK))!=-1)
  5116. {
  5117. fptr1 = fopen(fname, "r");
  5118. c = 0;
  5119. c = fgetc(fptr1);
  5120. //DEBUG_INFO("c:%d\n",c);
  5121. rewind(fptr1);
  5122. if(c == EOF)
  5123. {
  5124. DEBUG_INFO("\n End of file reached.");
  5125. TxProfileIsNull=TRUE;
  5126. fclose(fptr1);
  5127. }
  5128. else
  5129. {
  5130. TxProfileIsNull=FALSE;
  5131. while(fscanf(fptr1, "%s", word) != EOF)
  5132. {
  5133. if(strcmp(word, "chargingProfileId") == 0)
  5134. {
  5135. n_chargingProfile = n_chargingProfile + 1;
  5136. }
  5137. }
  5138. rewind(fptr1);
  5139. //search Charging Profile Element
  5140. int i= 0;
  5141. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5142. #if 0
  5143. /***********connectorId****************/
  5144. c = 0;
  5145. loc = strstr(sLineWord, "connectorId");
  5146. memset(sstr ,0, sizeof(sstr) );
  5147. while (loc[strlen("connectorId")+2+c] != ',')
  5148. {
  5149. sstr[c] = loc[strlen("connectorId")+2+c];
  5150. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5151. c++;
  5152. }
  5153. sstr[c] = '\0';
  5154. tempconnectorIdInt = atoi(sstr);
  5155. #endif
  5156. //***********validFrom**************/
  5157. c = 0;
  5158. loc = strstr(sLineWord, "validFrom");
  5159. if(loc != NULL)
  5160. {
  5161. memset(sstr ,0, sizeof(sstr) );
  5162. while (loc[3+strlen("validFrom")+c] != '\"')
  5163. {
  5164. sstr[c] = loc[3+strlen("validFrom")+c];
  5165. c++;
  5166. }
  5167. sstr[c] = '\0';
  5168. strcpy(tempvalidFromStr,sstr);
  5169. }
  5170. else
  5171. {
  5172. strcpy(tempvalidFromStr,"");
  5173. }
  5174. //**********startSchedule**********/
  5175. c = 0;
  5176. loc = strstr(sLineWord, "startSchedule");
  5177. memset(sstr ,0, sizeof(sstr) );
  5178. while (loc[3+strlen("startSchedule")+c] != '\"')
  5179. {
  5180. sstr[c] = loc[3+strlen("startSchedule")+c];
  5181. c++;
  5182. }
  5183. sstr[c] = '\0';
  5184. strcpy(tempstartScheduleStr, sstr);
  5185. //**********startSchedule**********/
  5186. c = 0;
  5187. loc = strstr(sLineWord, "chargingRateUnit");
  5188. memset(sstr ,0, sizeof(sstr) );
  5189. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5190. {
  5191. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5192. c++;
  5193. }
  5194. sstr[c] = '\0';
  5195. strcpy(tempchargingRateUnitStr, sstr);
  5196. //**********minChargingRate*******/
  5197. c = 0;
  5198. loc = strstr(sLineWord, "minChargingRate");
  5199. if(loc != NULL)
  5200. {
  5201. memset(sstr ,0, sizeof(sstr) );
  5202. while (loc[3+strlen("minChargingRate")+c] != '\"')
  5203. {
  5204. sstr[c] = loc[3+strlen("minChargingRate")+c];
  5205. c++;
  5206. }
  5207. sstr[c] = '\0';
  5208. tempminChargingRateFloat = atof(sstr);
  5209. }
  5210. else
  5211. {
  5212. tempminChargingRateFloat = 0.0;
  5213. }
  5214. //
  5215. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5216. tp.tm_isdst = -1;
  5217. time_t utc = mktime(&tp);
  5218. time_t t = time(NULL);
  5219. diff_t = difftime(t, utc);
  5220. DEBUG_INFO("diff_t=%f\n",diff_t);
  5221. //parsing strings to words
  5222. i = 0;
  5223. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5224. loc = loc+3+strlen("chargingSchedulePeriod");
  5225. pch = strtok(loc ,"{");
  5226. while (pch != NULL)
  5227. {
  5228. strcpy(SchedulePeriodList[i], pch);
  5229. pch = strtok (NULL, "{");
  5230. i = i + 1;
  5231. }
  5232. n_SchedulePeriods = i;
  5233. for(int i=0;i<n_SchedulePeriods;i++)
  5234. {
  5235. //*************startPeriod****************/
  5236. c = 0;
  5237. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5238. memset(sstr ,0, sizeof(sstr) );
  5239. while (loc[strlen("startPeriod")+2+c] != ',')
  5240. {
  5241. sstr[c] = loc[strlen("startPeriod")+2+c];
  5242. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5243. c++;
  5244. }
  5245. sstr[c] = '\0';
  5246. tempStartPeriodInt = atoi(sstr);
  5247. //*************limit****************/
  5248. c = 0;
  5249. loc = strstr(SchedulePeriodList[i], "limit");
  5250. memset(sstr ,0, sizeof(sstr) );
  5251. while (loc[strlen("limit")+2+c] != ',')
  5252. {
  5253. sstr[c] = loc[strlen("limit")+2+c];
  5254. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5255. c++;
  5256. }
  5257. sstr[c] = '\0';
  5258. tempLimitInt = atof(sstr);
  5259. //*************numberPhases****************/
  5260. c = 0;
  5261. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5262. memset(sstr ,0, sizeof(sstr) );
  5263. while (loc[strlen("numberPhases")+2+c] != '}')
  5264. {
  5265. sstr[c] = loc[strlen("numberPhases")+2+c];
  5266. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5267. c++;
  5268. }
  5269. sstr[c] = '\0';
  5270. tempNumberPhasesInt = atoi(sstr);
  5271. TxProfile.Duration = durationInt;
  5272. TxProfile.TotalPeriod = n_SchedulePeriods;
  5273. TxProfile.Period[i].Limit = tempLimitInt;
  5274. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5275. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5276. }
  5277. if(MinChargingRate < tempminChargingRateFloat)
  5278. MinChargingRate = tempminChargingRateFloat;
  5279. if(confirmPeriods < n_SchedulePeriods)
  5280. confirmPeriods = n_SchedulePeriods;
  5281. }
  5282. fclose(fptr1);
  5283. }
  5284. }// the end of ACCESS TxProfile
  5285. //CompositeSchedule
  5286. int period=0;
  5287. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5288. {
  5289. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5290. {
  5291. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5292. {
  5293. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5294. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5295. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5296. period = period + 1;
  5297. }
  5298. else
  5299. {
  5300. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5301. {
  5302. }
  5303. else
  5304. {
  5305. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5306. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5307. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5308. period = period + 1;
  5309. }
  5310. }
  5311. }
  5312. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5313. {
  5314. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5315. {
  5316. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5317. {
  5318. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5319. }
  5320. else
  5321. {
  5322. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5323. }
  5324. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5325. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5326. period = period + 1;
  5327. }
  5328. }
  5329. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5330. {
  5331. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5332. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5333. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5334. period = period + 1;
  5335. }
  5336. }
  5337. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5338. {
  5339. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5340. {
  5341. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5342. {
  5343. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5344. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5345. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5346. period = period + 1;
  5347. }
  5348. else
  5349. {
  5350. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5351. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5352. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5353. period = period + 1;
  5354. }
  5355. }
  5356. }
  5357. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5358. {
  5359. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5360. {
  5361. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5362. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5363. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5364. period = period + 1;
  5365. }
  5366. }
  5367. confirmPeriods = period;
  5368. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5369. //* Define temporary variables */
  5370. struct tm *gtime;
  5371. time_t now;
  5372. char buf[28];
  5373. //* Read the current system time */
  5374. time(&now);
  5375. //* Convert the system time to GMT (now UTC) */
  5376. gtime = gmtime(&now);
  5377. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5378. // make .conf
  5379. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  5380. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = durationInt;
  5381. //DEBUG_INFO(" debug 11\n");
  5382. // if(chargingRateUnitStr[0] != 0)
  5383. // {
  5384. // strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  5385. // }
  5386. // else
  5387. {
  5388. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5389. }
  5390. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5391. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5392. }
  5393. else
  5394. {
  5395. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5396. }
  5397. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5398. return result;
  5399. }
  5400. int handleGetConfigurationRequest(char *uuid, char *payload)
  5401. {
  5402. mtrace();
  5403. int result = FAIL;
  5404. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5405. //struct json_object *jsonitem;
  5406. int MaxKeySupported = 0;
  5407. int n_keys = 0;
  5408. char requestKey[43][50]={0};
  5409. char search[]="[";
  5410. char sstr[500]={ 0 };
  5411. //int pos;
  5412. int l, c = 0;
  5413. int i = 0;
  5414. char *delim = "\",\"";
  5415. char * pch;
  5416. char *loc = strstr(payload, search);
  5417. //********************* Parsing String ***********************************/
  5418. if(loc == NULL) {
  5419. DEBUG_INFO("no key match in Configuration \n");
  5420. }
  5421. else {
  5422. //pos = loc - payload;
  5423. l = strlen(loc)-4;
  5424. while (c < l)
  5425. {
  5426. sstr[c] = loc[c+2];
  5427. c++;
  5428. }
  5429. sstr[c] = '\0';
  5430. //parsing strings to words
  5431. pch = strtok(sstr,delim);
  5432. if(pch == NULL)
  5433. {
  5434. strcpy(requestKey[0], sstr);
  5435. }
  5436. else
  5437. {
  5438. while (pch != NULL)
  5439. {
  5440. strcpy(requestKey[i], pch);
  5441. pch = strtok (NULL, delim);
  5442. i = i + 1;
  5443. }
  5444. n_keys = i;
  5445. }
  5446. }
  5447. UnknownKeynum = 0;
  5448. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5449. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5450. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5451. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5452. if(n_keys != 0)
  5453. {
  5454. for(int i=0;i<n_keys;i++)
  5455. {
  5456. getKeyValue(requestKey[i]);
  5457. //json_object_put(jsonitem);
  5458. }
  5459. }
  5460. else
  5461. {
  5462. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5463. getKeyValue("");
  5464. }
  5465. processUnkownKey();
  5466. sendGetConfigurationConfirmation(uuid);
  5467. return result;
  5468. }
  5469. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5470. {
  5471. mtrace();
  5472. int result = FAIL;
  5473. //void *ret; //
  5474. char fnamePlusPath[50]="";
  5475. char fname[16]="";
  5476. pthread_t t; // pthread 變數
  5477. time_t rawtime;
  5478. struct tm * timeinfo;
  5479. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5480. system("exec /root/logPackTools 'log' 6");
  5481. //char buffer [128];
  5482. time (&rawtime);
  5483. //printf("%ld\n", rawtime);
  5484. timeinfo = localtime (&rawtime);
  5485. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5486. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5487. if((access(fnamePlusPath,F_OK))!=-1)
  5488. {
  5489. DEBUG_INFO("fnamePlusPath exist.\n");
  5490. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5491. }
  5492. else
  5493. {
  5494. DEBUG_INFO("fnamePlusPath not exist!\n");
  5495. }
  5496. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5497. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5498. pthread_join(t, NULL/*&ret*/);
  5499. return result;
  5500. }
  5501. void* GetDiagnosticsProcess(void* data)
  5502. {
  5503. mtrace();
  5504. int retriesInt=0, retryIntervalInt=0;
  5505. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5506. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5507. char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
  5508. int port=0;
  5509. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5510. char fname[16]="";
  5511. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5512. int c = 0;
  5513. char *loc;
  5514. int isSuccess = FALSE;
  5515. char ftpbuf[200]={0};
  5516. //char temp[100]={0};
  5517. char * pch;
  5518. // [2,"137d88c7-a403-4ead-bb2d-fc6ec90531c1","GetDiagnostics",{"location":"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/","retries":0,"retryInterval":0,"startTime":"0001-01-01T00:00:00.000Z","stopTime":"0001-01-01T00:00:00.000Z"}]
  5519. char *str = (char*) data; // ?��?輸入資�?
  5520. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5521. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5522. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5523. //****************location*******************/
  5524. c = 0;
  5525. memset(sstr ,0, sizeof(sstr) );
  5526. loc = strstr(str, "location");
  5527. while (loc[3+strlen("location")+c] != '\"')
  5528. {
  5529. sstr[c] = loc[3+strlen("location")+c];
  5530. c++;
  5531. }
  5532. sstr[c] = '\0';
  5533. strcpy(locationstr,sstr);
  5534. if(strcmp(locationstr,"")==0)
  5535. {
  5536. DEBUG_INFO("location is <Empty>!\n");
  5537. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5538. goto end;
  5539. }
  5540. //****************retries*******************/
  5541. c = 0;
  5542. loc = strstr(str, "retries");
  5543. if(loc == NULL)
  5544. {
  5545. retriesIsNULL = TRUE;
  5546. }
  5547. else
  5548. {
  5549. while (loc[strlen("retries")+2+c] != ',')
  5550. {
  5551. sstr[c] = loc[strlen("retries")+2+c];
  5552. c++;
  5553. }
  5554. sstr[c] = '\0';
  5555. retriesInt = atoi(sstr);
  5556. }
  5557. if(retriesIsNULL == TRUE)
  5558. {
  5559. retriesInt = 0;
  5560. }
  5561. //****************retryInterval*******************/
  5562. c = 0;
  5563. loc = strstr(str, "retryInterval");
  5564. if(loc == NULL)
  5565. {
  5566. retryIntervalIsNULL = TRUE;
  5567. }
  5568. else
  5569. {
  5570. while (loc[strlen("retryInterval")+2+c] != ',')
  5571. {
  5572. sstr[c] = loc[strlen("retryInterval")+2+c];
  5573. c++;
  5574. }
  5575. sstr[c] = '\0';
  5576. retryIntervalInt = atoi(sstr);
  5577. }
  5578. //****************startTime*******************/
  5579. c = 0;
  5580. memset(sstr ,0, sizeof(sstr) );
  5581. loc = strstr(str, "startTime");
  5582. if(loc == NULL)
  5583. {
  5584. startTimeIsNULL = TRUE;
  5585. }
  5586. else
  5587. {
  5588. while (loc[3+strlen("startTime")+c] != '\"')
  5589. {
  5590. sstr[c] = loc[3+strlen("startTime")+c];
  5591. c++;
  5592. }
  5593. sstr[c] = '\0';
  5594. strcpy(startTimestr,sstr);
  5595. }
  5596. //****************stopTime*******************/
  5597. c = 0;
  5598. memset(sstr ,0, sizeof(sstr) );
  5599. loc = strstr(str, "stopTime");
  5600. if(loc == NULL)
  5601. {
  5602. stopTimeIsNULL = TRUE;
  5603. }
  5604. else
  5605. {
  5606. while (loc[3+strlen("stopTime")+c] != '\"')
  5607. {
  5608. sstr[c] = loc[3+strlen("stopTime")+c];
  5609. c++;
  5610. }
  5611. sstr[c] = '\0';
  5612. strcpy(stopTimestr,sstr);
  5613. }
  5614. memset(protocol, 0, sizeof(protocol));
  5615. memset(user, 0, sizeof(user) );
  5616. memset(password, 0, sizeof(password));
  5617. memset(host, 0, sizeof(host));
  5618. memset(path, 0, sizeof(path));
  5619. memset(ftppath, 0, sizeof(ftppath));
  5620. memset(host1, 0, sizeof(host1));
  5621. memset(path1, 0, sizeof(path1));
  5622. /*location: ftp://user:password@host:port/path*/
  5623. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5624. // protocol, user, password, host, &port, path);
  5625. #if 0 // remove for temporally
  5626. //zip files in /Storage
  5627. system("exec /root/logPackTools 'log' 6");
  5628. #endif
  5629. // system("exec /root/Module_WebService 'log' 6");
  5630. time_t rawtime;
  5631. struct tm * timeinfo;
  5632. //char buffer [128];
  5633. time (&rawtime);
  5634. //printf("%ld\n", rawtime);
  5635. timeinfo = localtime (&rawtime);
  5636. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5637. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5638. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5639. if((access(fnamePlusPath,F_OK))!=-1)
  5640. {
  5641. DEBUG_INFO("fnamePlusPath exist.\n");
  5642. }
  5643. else
  5644. {
  5645. DEBUG_INFO("fnamePlusPath not exist!\n");
  5646. goto end;
  5647. }
  5648. pch=strchr(locationstr,'@');
  5649. if(pch==NULL)
  5650. {
  5651. sscanf(locationstr,
  5652. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5653. protocol, host, &port, path);
  5654. strcpy(user,"anonymous");
  5655. strcpy(password,"");
  5656. }
  5657. else
  5658. {
  5659. DEBUG_INFO("pch=%s\n", pch);
  5660. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5661. protocol, user, password, host, &port, path);
  5662. }
  5663. if(strcmp(protocol,"ftp")!=0)
  5664. {
  5665. DEBUG_INFO("protocol is not ftp!\n");
  5666. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5667. goto end;
  5668. }
  5669. sscanf(host,"%[^/]%s",host1, path1);
  5670. sprintf(ftppath,"%s", path1);
  5671. DEBUG_INFO("protocol =%s\n",protocol);
  5672. DEBUG_INFO("user =%s\n",user);
  5673. DEBUG_INFO("password =%s\n",password);
  5674. DEBUG_INFO("host1 =%s\n",host1);
  5675. DEBUG_INFO("port =%d\n",port);
  5676. DEBUG_INFO("path1 =%s\n",path1);
  5677. DEBUG_INFO("ftppath=%s\n",ftppath);
  5678. int ftppathlen=strlen(ftppath);
  5679. int i=1;
  5680. char filenametemp[50];
  5681. while(i < ftppathlen)
  5682. {
  5683. int len=ftppathlen-i;
  5684. if(ftppath[len]== 47) // '/' ascll code: 47
  5685. {
  5686. DEBUG_INFO("find '/' all right\n");
  5687. break;
  5688. }
  5689. i=i+1;
  5690. }
  5691. memset(filenametemp, 0, sizeof(filenametemp));
  5692. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5693. filenametemp[i+1] = 0;
  5694. //httpDownLoadFile(host, ftppath, fname);
  5695. memset(ftpbuf, 0, sizeof(ftpbuf));
  5696. if(port == 0)
  5697. port = 21;
  5698. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5699. do{
  5700. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5701. sleep(retryIntervalInt);
  5702. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5703. if(!isSuccess)
  5704. {
  5705. //BulldogUtil.sleepMs(interval*1000);
  5706. DEBUG_INFO("Diagnostics fail.\n");
  5707. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5708. }
  5709. else
  5710. {
  5711. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5712. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5713. //isUpdateRequest = TRUE;
  5714. }
  5715. end:
  5716. // json_object_put(obj);
  5717. DiagnosticsStatusNotificationStatus = 0; //Idle
  5718. pthread_exit(NULL/*(void *) fname*/); // ?��?子執行�?
  5719. }
  5720. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5721. {
  5722. mtrace();
  5723. int result = FAIL;
  5724. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5725. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5726. {
  5727. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5728. localversion = -1;
  5729. }
  5730. else
  5731. {
  5732. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5733. OCPP_getListVerion();
  5734. }
  5735. //from db.OCPP_getListVerion
  5736. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5737. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5738. sendGetLocalListVersionConfirmation(uuid,"");
  5739. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5740. return result;
  5741. }
  5742. int handleRemoteStartRequest(char *uuid, char *payload)
  5743. {
  5744. mtrace();
  5745. int result = FAIL;
  5746. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5747. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5748. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5749. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5750. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5751. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5752. int chargingSchedulePeriodCount = 0;
  5753. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5754. int c = 0;
  5755. char *loc;
  5756. char comfirmstr[20]={0};
  5757. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5758. if(server_pending == TRUE)
  5759. {
  5760. return 0;
  5761. }
  5762. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5763. //**********connectorId****************/
  5764. c = 0;
  5765. memset(sstr ,0, sizeof(sstr) );
  5766. loc = strstr(payload, "connectorId");
  5767. if(loc == NULL)
  5768. {
  5769. connectorIdIsNULL = TRUE;
  5770. }
  5771. else
  5772. {
  5773. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5774. {
  5775. sstr[c] = loc[strlen("connectorId")+2+c];
  5776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5777. c++;
  5778. }
  5779. sstr[c] = '\0';
  5780. connectorIdInt = atoi(sstr);
  5781. }
  5782. if(connectorIdIsNULL == TRUE) // need to discussion
  5783. {
  5784. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5785. goto end;
  5786. }
  5787. //****************idTag*******************/
  5788. c = 0;
  5789. memset(sstr ,0, sizeof(sstr) );
  5790. loc = strstr(payload, "idTag");
  5791. while (loc[3+strlen("idTag")+c] != '\"')
  5792. {
  5793. sstr[c] = loc[3+strlen("idTag")+c];
  5794. c++;
  5795. }
  5796. sstr[c] = '\0';
  5797. strcpy(idTagstr,sstr);
  5798. //****************chargingProfile*******************/
  5799. c = 0;
  5800. memset(sstr ,0, sizeof(sstr) );
  5801. loc = strstr(payload, "chargingProfile");
  5802. if(loc == NULL)
  5803. {
  5804. chargingProfileIsNULL = TRUE;
  5805. }
  5806. else
  5807. {
  5808. //****************chargingProfileId*******************/
  5809. c=0;
  5810. loc = strstr(payload, "chargingProfileId");
  5811. memset(sstr ,0, sizeof(sstr) );
  5812. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5813. {
  5814. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5815. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5816. c++;
  5817. }
  5818. sstr[c] = '\0';
  5819. chargingProfileIdInt = atoi(sstr);
  5820. //****************transactionId*******************/
  5821. loc = strstr(payload, "transactionId");
  5822. if(loc == NULL)
  5823. {
  5824. transactionIdIsNULL = TRUE;
  5825. }
  5826. else
  5827. {
  5828. c=0;
  5829. memset(sstr ,0, sizeof(sstr) );
  5830. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5831. {
  5832. sstr[c] = loc[strlen("transactionId")+2+c];
  5833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5834. c++;
  5835. }
  5836. sstr[c] = '\0';
  5837. transactionIdInt = atoi(sstr);
  5838. }
  5839. //****************stackLevel*******************/
  5840. c=0;
  5841. loc = strstr(payload, "stackLevel");
  5842. memset(sstr ,0, sizeof(sstr) );
  5843. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5844. {
  5845. sstr[c] = loc[strlen("stackLevel")+2+c];
  5846. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5847. c++;
  5848. }
  5849. sstr[c] = '\0';
  5850. stackLevelInt = atoi(sstr);
  5851. //****************chargingProfilePurpose*******************/
  5852. c = 0;
  5853. memset(sstr ,0, sizeof(sstr) );
  5854. loc = strstr(payload, "chargingProfilePurpose");
  5855. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5856. {
  5857. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5858. c++;
  5859. }
  5860. sstr[c] = '\0';
  5861. strcpy(chargingProfilePurposestr,sstr);
  5862. //****************chargingProfileKind*******************/
  5863. c = 0;
  5864. memset(sstr ,0, sizeof(sstr) );
  5865. loc = strstr(payload, "chargingProfileKind");
  5866. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5867. {
  5868. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5869. c++;
  5870. }
  5871. sstr[c] = '\0';
  5872. strcpy(chargingProfileKindstr,sstr);
  5873. //****************recurrencyKind*******************/
  5874. loc = strstr(payload, "recurrencyKind");
  5875. if(loc == NULL)
  5876. {
  5877. recurrencyKindIsNULL = TRUE;
  5878. }
  5879. else
  5880. {
  5881. c = 0;
  5882. memset(sstr ,0, sizeof(sstr) );
  5883. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5884. {
  5885. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5886. c++;
  5887. }
  5888. sstr[c] = '\0';
  5889. strcpy(recurrencyKindstr,sstr);
  5890. }
  5891. //****************validFrom*******************/
  5892. loc = strstr(payload, "validFrom");
  5893. if(loc == NULL)
  5894. {
  5895. validFromIsNULL = TRUE;
  5896. }
  5897. else
  5898. {
  5899. c = 0;
  5900. memset(sstr ,0, sizeof(sstr) );
  5901. while (loc[3+strlen("validFrom")+c] != '\"')
  5902. {
  5903. sstr[c] = loc[3+strlen("validFrom")+c];
  5904. c++;
  5905. }
  5906. sstr[c] = '\0';
  5907. strcpy(validFromstr,sstr);
  5908. }
  5909. //****************validTo*******************/
  5910. loc = strstr(payload, "validTo");
  5911. if(loc == NULL)
  5912. {
  5913. validToIsNULL = TRUE;
  5914. }
  5915. else
  5916. {
  5917. c = 0;
  5918. memset(sstr ,0, sizeof(sstr) );
  5919. while (loc[3+strlen("validTo")+c] != '\"')
  5920. {
  5921. sstr[c] = loc[3+strlen("validTo")+c];
  5922. c++;
  5923. }
  5924. sstr[c] = '\0';
  5925. strcpy(validTostr,sstr);
  5926. }
  5927. //****************chargingSchedule*******************/
  5928. loc = strstr(payload, "chargingSchedule");
  5929. if(loc != NULL)
  5930. {
  5931. //****************duration*******************/
  5932. loc = strstr(payload, "duration");
  5933. if(loc == NULL)
  5934. {
  5935. durationIsNULL = TRUE;
  5936. }
  5937. else
  5938. {
  5939. c=0;
  5940. memset(sstr ,0, sizeof(sstr) );
  5941. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5942. {
  5943. sstr[c] = loc[strlen("duration")+2+c];
  5944. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5945. c++;
  5946. }
  5947. sstr[c] = '\0';
  5948. durationInt = atoi(sstr);
  5949. }
  5950. //****************startSchedule******************/
  5951. loc = strstr(payload, "startSchedule");
  5952. if(loc == NULL)
  5953. {
  5954. startScheduleIsNULL = TRUE;
  5955. }
  5956. else
  5957. {
  5958. c = 0;
  5959. memset(sstr ,0, sizeof(sstr) );
  5960. while (loc[3+strlen("startSchedule")+c] != '\"')
  5961. {
  5962. sstr[c] = loc[3+strlen("startSchedule")+c];
  5963. c++;
  5964. }
  5965. sstr[c] = '\0';
  5966. strcpy(startSchedulestr,sstr);
  5967. }
  5968. //****************chargingRateUnit*******************/
  5969. c = 0;
  5970. memset(sstr ,0, sizeof(sstr) );
  5971. loc = strstr(payload, "chargingRateUnit");
  5972. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5973. {
  5974. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5975. c++;
  5976. }
  5977. sstr[c] = '\0';
  5978. strcpy(chargingRateUnitstr,sstr);
  5979. //****************minChargingRate*******************/
  5980. loc = strstr(payload, "minChargingRate");
  5981. if(loc == NULL)
  5982. {
  5983. minChargingRateIsNULL = TRUE;
  5984. }
  5985. else
  5986. {
  5987. c=0;
  5988. memset(sstr ,0, sizeof(sstr) );
  5989. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5990. {
  5991. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5992. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5993. c++;
  5994. }
  5995. sstr[c] = '\0';
  5996. minChargingRateflaot = atof(sstr);
  5997. }
  5998. //****************chargingSchedulePeriod count*******************/
  5999. int what_len = strlen("startPeriod");
  6000. char *where = payload;
  6001. while ((where = strstr(where, "startPeriod"))) {
  6002. where += what_len;
  6003. chargingSchedulePeriodCount++;
  6004. }
  6005. where = payload;
  6006. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6007. {
  6008. //****************startPeriod*******************/
  6009. c=0;
  6010. loc = strstr(where, "startPeriod");
  6011. memset(sstr ,0, sizeof(sstr) );
  6012. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6013. {
  6014. sstr[c] = loc[strlen("startPeriod")+2+c];
  6015. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6016. c++;
  6017. }
  6018. sstr[c] = '\0';
  6019. startPeriodInt[periodNums] = atoi(sstr);
  6020. //****************limit*******************/
  6021. c=0;
  6022. loc = strstr(where, "limit");
  6023. memset(sstr ,0, sizeof(sstr) );
  6024. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6025. {
  6026. sstr[c] = loc[strlen("limit")+2+c];
  6027. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6028. c++;
  6029. }
  6030. sstr[c] = '\0';
  6031. limitflaot[periodNums] = atof(sstr);
  6032. //****************numberPhases*******************/
  6033. loc = strstr(where, "numberPhases");
  6034. if(loc == NULL)
  6035. {
  6036. numberPhasesIsNULL = TRUE;
  6037. }
  6038. else
  6039. {
  6040. c=0;
  6041. memset(sstr ,0, sizeof(sstr) );
  6042. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6043. {
  6044. sstr[c] = loc[strlen("numberPhases")+2+c];
  6045. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6046. c++;
  6047. }
  6048. sstr[c] = '\0';
  6049. numberPhasesInt[periodNums] = atoi(sstr);
  6050. }
  6051. where = loc;
  6052. }
  6053. }
  6054. }
  6055. /*
  6056. enum _SYSTEM_STATUS
  6057. {
  6058. S_BOOTING = 0,
  6059. S_IDLE, = 1
  6060. S_AUTHORIZING, =2
  6061. S_REASSIGN_CHECK, =3
  6062. S_REASSIGN, =4
  6063. S_PRECHARGE, =5
  6064. S_PREPARING_FOR_EV, =6
  6065. S_PREPARING_FOR_EVSE, =7
  6066. S_CHARGING, =8
  6067. S_TERMINATING, =9
  6068. S_COMPLETE, =10
  6069. S_ALARM, =11
  6070. S_FAULT =12
  6071. }
  6072. */
  6073. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6074. {
  6075. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6076. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6077. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6078. //check Transaction active
  6079. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6080. {
  6081. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6082. {
  6083. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6084. {
  6085. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6086. {
  6087. //Reserved
  6088. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6089. }
  6090. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6091. {
  6092. //Reserved
  6093. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6094. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6095. goto end;
  6096. }
  6097. else
  6098. {
  6099. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6100. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6101. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6102. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6103. {
  6104. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6105. goto end;
  6106. }
  6107. }//END FOR ELSE
  6108. }
  6109. }// END FOR CHAdeMO_QUANTITY
  6110. for (int index = 0; index < CCS_QUANTITY; index++)
  6111. {
  6112. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6113. {
  6114. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6115. {
  6116. //Reserved
  6117. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6118. }
  6119. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6120. {
  6121. //Reserved
  6122. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6123. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6124. goto end;
  6125. }
  6126. else
  6127. {
  6128. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6129. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6130. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6131. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6132. {
  6133. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6134. goto end;
  6135. }
  6136. }// END FOR ELSE
  6137. }
  6138. }// END FOR CCS_QUANTITY
  6139. for (int index = 0; index < GB_QUANTITY; index++)
  6140. {
  6141. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6142. {
  6143. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6144. {
  6145. //Reserved
  6146. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6147. }
  6148. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6149. {
  6150. //Reserved
  6151. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6152. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6153. goto end;
  6154. }
  6155. else
  6156. {
  6157. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6158. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6159. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6160. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6161. {
  6162. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6163. goto end;
  6164. }
  6165. }// END FOR ELSE
  6166. }
  6167. } // END FOR GB_QUANTITY
  6168. }
  6169. else
  6170. {
  6171. for (int index = 0; index < AC_QUANTITY; index++)
  6172. {
  6173. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6174. {
  6175. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6176. {
  6177. //Reserved
  6178. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6179. }
  6180. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6181. {
  6182. //Reserved
  6183. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6184. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6185. goto end;
  6186. }
  6187. else
  6188. {
  6189. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6190. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6191. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6192. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6193. {
  6194. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6195. goto end;
  6196. }
  6197. }//END FOR ELSE
  6198. }
  6199. }// END FOR AC_QUANTITY
  6200. }
  6201. if(chargingProfileIsNULL == FALSE)
  6202. {
  6203. //ChargingProfile
  6204. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6205. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6206. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6207. if(recurrencyKindIsNULL == FALSE) //OPTION
  6208. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6209. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6210. if(transactionIdIsNULL == FALSE) // OPTION
  6211. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6212. if(validFromIsNULL == FALSE) // OPTION
  6213. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6214. if(validToIsNULL == FALSE) //OPTION
  6215. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6216. //ChargingSchedule
  6217. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6218. if(durationIsNULL == FALSE) //OPTION
  6219. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6220. if(minChargingRateIsNULL == FALSE) //OPTION
  6221. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6222. if(startScheduleIsNULL == FALSE) //OPTION
  6223. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6224. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6225. {
  6226. //ChargingSchedulePeriod
  6227. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6228. if(numberPhasesIsNULL == FALSE)
  6229. {
  6230. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6231. }
  6232. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6233. }
  6234. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6235. {
  6236. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6237. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6238. }
  6239. else
  6240. {
  6241. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6242. }
  6243. }
  6244. else
  6245. {
  6246. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6247. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6248. }
  6249. }
  6250. else
  6251. {
  6252. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6253. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6254. }
  6255. end:
  6256. if(connectorIdIsNULL == FALSE)
  6257. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6258. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6259. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6260. //OCPP send RemoteStartConfirmation by first.
  6261. sendRemoteStartConfirmation(uuid, comfirmstr);
  6262. return result;
  6263. }
  6264. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6265. {
  6266. mtrace();
  6267. int result = FAIL;
  6268. int match = FALSE;
  6269. int GunNO = 0;
  6270. int transactionIdInt=0;
  6271. int transactionIdIsNULL= FALSE;
  6272. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6273. int c = 0;
  6274. char *loc;
  6275. char comfirmstr[20];
  6276. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6277. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6278. if(server_pending == TRUE)
  6279. {
  6280. return 0;
  6281. }
  6282. c=0;
  6283. loc = strstr(payload, "transactionId");
  6284. if(loc == NULL)
  6285. {
  6286. transactionIdIsNULL= TRUE;
  6287. }
  6288. else
  6289. {
  6290. memset(sstr ,0, sizeof(sstr) );
  6291. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6292. {
  6293. sstr[c] = loc[strlen("transactionId")+2+c];
  6294. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6295. c++;
  6296. }
  6297. sstr[c] = '\0';
  6298. transactionIdInt = atoi(sstr);
  6299. }
  6300. if(transactionIdIsNULL == FALSE)
  6301. {
  6302. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6303. {
  6304. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6305. {
  6306. //check Transaction active
  6307. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6308. {
  6309. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6310. {
  6311. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6312. {
  6313. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6314. {
  6315. match = TRUE;
  6316. GunNO = gun_index;
  6317. }
  6318. }
  6319. }// END FOR CHAdeMO_QUANTITY
  6320. for (int index = 0; index < CCS_QUANTITY; index++)
  6321. {
  6322. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6323. {
  6324. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6325. {
  6326. match = TRUE;
  6327. GunNO = gun_index;
  6328. }
  6329. }
  6330. }// END FOR CCS_QUANTITY
  6331. for (int index = 0; index < GB_QUANTITY; index++)
  6332. {
  6333. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6334. {
  6335. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6336. {
  6337. match = TRUE;
  6338. GunNO = gun_index;
  6339. }
  6340. }
  6341. }// END FOR GB_QUANTITY
  6342. }
  6343. else
  6344. {
  6345. for (int index = 0; index < AC_QUANTITY; index++)
  6346. {
  6347. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6348. {
  6349. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6350. {
  6351. match = TRUE;
  6352. GunNO = gun_index;
  6353. }
  6354. }
  6355. }// END FOR CHAdeMO_QUANTITY
  6356. }// END FOR AC ELSE
  6357. }// CHECK IF ResponseTransactionId == transactionIdInt
  6358. }//END FOR
  6359. if( match == TRUE)
  6360. {
  6361. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6362. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6363. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6364. }
  6365. else
  6366. {
  6367. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6368. }
  6369. }
  6370. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6371. return result;
  6372. }
  6373. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6374. {
  6375. mtrace();
  6376. int result = FAIL;
  6377. int connectorIdInt=0, reservationIdInt=0;
  6378. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6379. char comfirmstr[20]={0};
  6380. char sstr[180]={ 0 };
  6381. int c = 0;
  6382. char *loc;
  6383. //char *ptr;
  6384. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6385. //***(1)connectorId ****/
  6386. c=0;
  6387. loc = strstr(payload, "connectorId");
  6388. memset(sstr ,0, sizeof(sstr) );
  6389. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6390. {
  6391. sstr[c] = loc[strlen("connectorId")+2+c];
  6392. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6393. c++;
  6394. }
  6395. sstr[c] = '\0';
  6396. connectorIdInt = atoi(sstr);
  6397. //***(2)expiryDate ****/
  6398. loc = strstr(payload, "expiryDate");
  6399. memset(sstr ,0, sizeof(sstr) );
  6400. c = 0;
  6401. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6402. {
  6403. sstr[c] = loc[3+strlen("expiryDate")+c];
  6404. c++;
  6405. }
  6406. sstr[c] = '\0';
  6407. strcpy(expiryDatestr, sstr);
  6408. //***(3)idTag ****/
  6409. loc = strstr(payload, "idTag");
  6410. memset(sstr ,0, sizeof(sstr) );
  6411. c = 0;
  6412. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6413. {
  6414. sstr[c] = loc[3+strlen("idTag")+c];
  6415. c++;
  6416. }
  6417. sstr[c] = '\0';
  6418. strcpy(idTagstr, sstr);
  6419. //***(4)parentIdTag ****/
  6420. loc = strstr(payload, "parentIdTag");
  6421. memset(sstr ,0, sizeof(sstr) );
  6422. c = 0;
  6423. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6424. {
  6425. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6426. c++;
  6427. }
  6428. sstr[c] = '\0';
  6429. strcpy(parentIdTagstr, sstr);
  6430. //***(5)reservationId ****/
  6431. c=0;
  6432. loc = strstr(payload, "reservationId");
  6433. memset(sstr ,0, sizeof(sstr) );
  6434. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6435. {
  6436. sstr[c] = loc[strlen("reservationId")+2+c];
  6437. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6438. c++;
  6439. }
  6440. sstr[c] = '\0';
  6441. reservationIdInt = atoi(sstr);
  6442. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6443. /*
  6444. enum _SYSTEM_STATUS
  6445. {
  6446. S_BOOTING = 0,
  6447. S_IDLE, = 1
  6448. S_AUTHORIZING, =2
  6449. S_REASSIGN_CHECK, =3
  6450. S_REASSIGN, =4
  6451. S_PRECHARGE, =5
  6452. S_PREPARING_FOR_EV, =6
  6453. S_PREPARING_FOR_EVSE, =7
  6454. S_CHARGING, =8
  6455. S_TERMINATING, =9
  6456. S_COMPLETE, =10
  6457. S_ALARM, =11
  6458. S_FAULT =12
  6459. }
  6460. */
  6461. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6462. {
  6463. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6464. goto end;
  6465. }
  6466. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6467. {
  6468. //check Transaction active
  6469. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6470. {
  6471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6472. {
  6473. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6474. {
  6475. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6476. {
  6477. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6478. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6479. {
  6480. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6481. {
  6482. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6483. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6484. }
  6485. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6486. {
  6487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6488. }
  6489. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6490. {
  6491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6492. }
  6493. else
  6494. {
  6495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6496. }
  6497. }
  6498. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6499. {
  6500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6501. }
  6502. }
  6503. else
  6504. {
  6505. //replace reservation
  6506. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6507. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6508. }
  6509. }
  6510. } // END FOR CHAdeMO_QUANTITY
  6511. for (int index = 0; index < CCS_QUANTITY; index++)
  6512. {
  6513. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6514. {
  6515. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6516. {
  6517. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6518. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6519. {
  6520. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6521. {
  6522. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6523. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6524. }
  6525. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6526. {
  6527. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6528. }
  6529. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6530. {
  6531. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6532. }
  6533. else
  6534. {
  6535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6536. }
  6537. }
  6538. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6539. {
  6540. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6541. }
  6542. }
  6543. else
  6544. {
  6545. //replace reservation
  6546. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6547. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6548. }
  6549. }
  6550. } // END FOR CCS_QUANTITY
  6551. for (int index = 0; index < GB_QUANTITY; index++)
  6552. {
  6553. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6554. {
  6555. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6556. {
  6557. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6558. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6559. {
  6560. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6561. {
  6562. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6563. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6564. }
  6565. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6566. {
  6567. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6568. }
  6569. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6570. {
  6571. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6572. }
  6573. else
  6574. {
  6575. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6576. }
  6577. }
  6578. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6579. {
  6580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6581. }
  6582. }
  6583. else
  6584. {
  6585. //replace reservation
  6586. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6587. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6588. }
  6589. }
  6590. }// END FOR GB_QUANTITY
  6591. }
  6592. else
  6593. {
  6594. for (int index = 0; index < AC_QUANTITY; index++)
  6595. {
  6596. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6597. {
  6598. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6599. {
  6600. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6601. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6602. {
  6603. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6604. {
  6605. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6606. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6607. }
  6608. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6609. {
  6610. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6611. }
  6612. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6613. {
  6614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6615. }
  6616. else
  6617. {
  6618. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6619. }
  6620. }
  6621. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6622. {
  6623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6624. }
  6625. }
  6626. else
  6627. {
  6628. //replace reservation
  6629. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6630. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6631. }
  6632. }
  6633. } // END FOR AC_QUANTITY
  6634. }//END FOR AC ELSE
  6635. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6636. }
  6637. else if(connectorIdInt == 0)
  6638. {
  6639. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6640. {
  6641. //check Transaction active
  6642. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6643. {
  6644. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6645. {
  6646. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6647. {
  6648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6649. goto end;
  6650. }
  6651. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6652. {
  6653. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6654. goto end;
  6655. }
  6656. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6657. {
  6658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6659. goto end;
  6660. }
  6661. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6662. {
  6663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6664. goto end;
  6665. }
  6666. }
  6667. }// END FOR CHAdeMO_QUANTITY
  6668. for (int index = 0; index < CCS_QUANTITY; index++)
  6669. {
  6670. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6671. {
  6672. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  6673. {
  6674. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6675. }
  6676. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6677. {
  6678. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6679. }
  6680. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6681. {
  6682. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6683. }
  6684. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6685. {
  6686. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6687. }
  6688. }
  6689. } // END FOR CCS_QUANTITY
  6690. for (int index = 0; index < GB_QUANTITY; index++)
  6691. {
  6692. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6693. {
  6694. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  6695. {
  6696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6697. }
  6698. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6699. {
  6700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6701. }
  6702. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6703. {
  6704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6705. }
  6706. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6707. {
  6708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6709. }
  6710. }
  6711. } // END FOR GB_QUANTITY
  6712. }
  6713. else
  6714. {
  6715. for (int index = 0; index < AC_QUANTITY; index++)
  6716. {
  6717. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6718. {
  6719. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  6720. {
  6721. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6722. goto end;
  6723. }
  6724. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6725. {
  6726. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6727. goto end;
  6728. }
  6729. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6730. {
  6731. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6732. goto end;
  6733. }
  6734. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6735. {
  6736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6737. goto end;
  6738. }
  6739. }
  6740. }// END FOR AC_QUANTITY
  6741. }
  6742. //The connectorId is 0
  6743. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6745. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6746. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6747. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6748. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6749. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6750. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6751. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6752. result = TRUE;
  6753. return result;
  6754. }
  6755. else
  6756. {
  6757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6758. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6759. }
  6760. if(strcmp(comfirmstr,"Accepted") == 0)
  6761. {
  6762. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6763. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6764. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6765. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6766. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6767. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6768. result = TRUE;
  6769. return result;
  6770. }
  6771. end:
  6772. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6773. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6774. return result;
  6775. }
  6776. int handleResetRequest(char *uuid, char *payload)
  6777. {
  6778. mtrace();
  6779. int result = FAIL;
  6780. char sstr[10]={0};
  6781. char typestr[10]={0};
  6782. char comfirmstr[20]={0};
  6783. int c = 0;
  6784. char *loc;
  6785. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6786. DEBUG_INFO("handleResetRequest ...\n");
  6787. loc = strstr(payload, "type");
  6788. memset(sstr ,0, sizeof(sstr) );
  6789. c = 0;
  6790. while (loc[3+strlen("type")+c] != '\"')
  6791. {
  6792. sstr[c] = loc[3+strlen("type")+c];
  6793. c++;
  6794. }
  6795. sstr[c] = '\0';
  6796. strcpy(typestr,sstr);
  6797. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6798. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6799. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6800. {
  6801. //check Transaction active
  6802. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6803. {
  6804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6805. {
  6806. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6807. {
  6808. //0: unplug, 1: Plug-in
  6809. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6810. }
  6811. }
  6812. for (int index = 0; index < CCS_QUANTITY; index++)
  6813. {
  6814. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6815. {
  6816. //0: unplug, 1: Plug-in
  6817. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6818. }
  6819. }
  6820. for (int index = 0; index < GB_QUANTITY; index++)
  6821. {
  6822. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6823. {
  6824. //0: unplug, 1: Plug-in
  6825. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6826. }
  6827. }
  6828. }
  6829. else
  6830. {
  6831. for (int index = 0; index < AC_QUANTITY; index++)
  6832. {
  6833. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6834. {
  6835. //0: unplug, 1: Plug-in
  6836. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6837. }
  6838. }
  6839. }// END FOR AC ELSE
  6840. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6841. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6842. result = TRUE;
  6843. return result;
  6844. }
  6845. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6846. {
  6847. //check Transaction active
  6848. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6849. {
  6850. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6851. {
  6852. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6853. {
  6854. //0: unplug, 1: Plug-in
  6855. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6856. }
  6857. }
  6858. for (int index = 0; index < CCS_QUANTITY; index++)
  6859. {
  6860. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6861. {
  6862. //0: unplug, 1: Plug-in
  6863. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6864. }
  6865. }
  6866. for (int index = 0; index < GB_QUANTITY; index++)
  6867. {
  6868. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6869. {
  6870. //0: unplug, 1: Plug-in
  6871. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6872. }
  6873. }
  6874. }
  6875. else
  6876. {
  6877. for (int index = 0; index < AC_QUANTITY; index++)
  6878. {
  6879. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6880. {
  6881. //0: unplug, 1: Plug-in
  6882. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6883. }
  6884. }
  6885. }// END FOR AC ELSE
  6886. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6887. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6888. result = TRUE;
  6889. return result;
  6890. }
  6891. else
  6892. {
  6893. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6894. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6895. goto errorend;
  6896. }
  6897. errorend:
  6898. sendResetConfirmation(uuid, comfirmstr);
  6899. return result;
  6900. }
  6901. int handleSendLocalListRequest(char *uuid, char *payload)
  6902. {
  6903. mtrace();
  6904. int result = FAIL;
  6905. int listVersionInt;
  6906. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6907. char listsearch[]="listVersion";
  6908. char updateTypesearch[]="updateType";
  6909. char localAuthorizationListsearch[]="localAuthorizationList";
  6910. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6911. char CardList[500][160]={0};
  6912. char updateTypestr[15]={0};
  6913. char idTagstr[20]={0};
  6914. char parentIdTag[20]={0};
  6915. char expiryDate[30]={0};
  6916. char idTagstatus[16]={0};
  6917. int c = 0;
  6918. int i = 0;
  6919. char *delim1 = "}";
  6920. char * pch;
  6921. char *loc;
  6922. //char *ptr;
  6923. char comfirmstr[20];
  6924. //int n_localAuthorizations = 0;
  6925. int checkState_Faulted = FALSE;
  6926. DEBUG_INFO("handleSendLocalListRequest\n");
  6927. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6928. {
  6929. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6930. goto end;
  6931. }
  6932. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6933. {
  6934. //check Charge Point state
  6935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6936. {
  6937. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6938. {
  6939. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6940. }
  6941. }
  6942. for (int index = 0; index < CCS_QUANTITY; index++)
  6943. {
  6944. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6945. {
  6946. checkState_Faulted = TRUE; //OCPP Status
  6947. }
  6948. }
  6949. for (int index = 0; index < GB_QUANTITY; index++)
  6950. {
  6951. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6952. {
  6953. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6954. }
  6955. }
  6956. }
  6957. else
  6958. {
  6959. //check Charge Point state
  6960. for (int index = 0; index < AC_QUANTITY; index++)
  6961. {
  6962. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6963. {
  6964. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6965. }
  6966. }
  6967. }// END FOR AC ELSE
  6968. if(checkState_Faulted == TRUE)
  6969. {
  6970. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6971. goto end;
  6972. }
  6973. //listVersion
  6974. c = 0;
  6975. loc = strstr(payload, listsearch);
  6976. while (loc[strlen("listVersion")+2+c] != ',')
  6977. {
  6978. sstr[c] = loc[strlen("listVersion")+2+c];
  6979. c++;
  6980. }
  6981. sstr[c] = '\0';
  6982. listVersionInt = atoi(sstr);
  6983. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6984. //updateType
  6985. loc = strstr(payload, updateTypesearch);
  6986. c = 0;
  6987. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6988. {
  6989. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6990. c++;
  6991. }
  6992. sstr[c] = '\0';
  6993. strcpy(updateTypestr, sstr);
  6994. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6995. //localAuthorizationList
  6996. memset(sstr ,0, sizeof(sstr) );
  6997. loc = strstr(payload, localAuthorizationListsearch);
  6998. if(loc != NULL) // localAuthorizationList is not NULL
  6999. {
  7000. //Check UpdateType
  7001. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7002. {
  7003. //Local list full update
  7004. printf("Local list full update.\n");
  7005. OCPP_cleanLocalList();
  7006. }
  7007. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7008. {
  7009. //Local list different update
  7010. printf("Local list different update.\n");
  7011. OCPP_getListVerion();
  7012. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7013. {
  7014. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7015. goto end;
  7016. }
  7017. }
  7018. else
  7019. {
  7020. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7021. goto end;
  7022. }
  7023. c = 0;
  7024. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7025. {
  7026. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7027. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7028. c++;
  7029. }
  7030. sstr[c] = '\0';
  7031. //parsing strings to words
  7032. i = 0;
  7033. pch = strtok(sstr,delim1);
  7034. while (pch != NULL)
  7035. {
  7036. strcpy(CardList[i], pch);
  7037. pch = strtok (NULL, delim1);
  7038. i = i + 1;
  7039. }
  7040. //local Authorizations List Numbers
  7041. //n_localAuthorizations = i;
  7042. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7043. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7044. c= 0;
  7045. while(c < i)
  7046. {
  7047. //Search "IdToken"
  7048. memset(sstr ,0, sizeof(sstr) );
  7049. loc = strstr(CardList[c], "idTag");
  7050. int j = 0;
  7051. while (loc[3+strlen("idTag")+j] != '\"')
  7052. {
  7053. sstr[j] = loc[3+strlen("idTag")+j];
  7054. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7055. j++;
  7056. }
  7057. sstr[j] = '\0';
  7058. strcpy(idTagstr, sstr);
  7059. //Search "expiryDate"
  7060. memset(sstr ,0, sizeof(sstr) );
  7061. loc = strstr(CardList[c], "expiryDate");
  7062. j = 0;
  7063. while (loc[3+strlen("expiryDate")+j] != '\"')
  7064. {
  7065. sstr[j] = loc[3+strlen("expiryDate")+j];
  7066. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7067. j++;
  7068. }
  7069. sstr[j] = '\0';
  7070. strcpy(expiryDate, sstr);
  7071. //Search "parentIdTag"
  7072. memset(sstr ,0, sizeof(sstr) );
  7073. loc = strstr(CardList[c], "parentIdTag");
  7074. j = 0;
  7075. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7076. {
  7077. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7078. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7079. j++;
  7080. }
  7081. sstr[j] = '\0';
  7082. strcpy(parentIdTag, sstr);
  7083. //Search "status"
  7084. memset(sstr ,0, sizeof(sstr) );
  7085. loc = strstr(CardList[c], "status");
  7086. j = 0;
  7087. while (loc[3+strlen("status")+j] != '\"')
  7088. {
  7089. sstr[j] = loc[3+strlen("status")+j];
  7090. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7091. j++;
  7092. }
  7093. sstr[j] = '\0';
  7094. strcpy(idTagstatus, sstr);
  7095. OCPP_getIdTag(idTagstr);
  7096. //OCPP_getIdTag("test"); For Test
  7097. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7098. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7099. {
  7100. //Local list full update
  7101. DEBUG_INFO("Local list full update.\n");
  7102. // update list
  7103. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7104. OCPP_get_TableAuthlocalAllData();
  7105. }
  7106. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7107. {
  7108. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7109. {
  7110. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7111. }
  7112. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7113. {
  7114. OCPP_deleteIdTag(idTagstr);
  7115. }
  7116. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7117. {
  7118. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7119. }
  7120. }
  7121. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7122. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7123. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7124. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7125. c++;
  7126. }
  7127. }
  7128. else
  7129. {
  7130. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7131. {
  7132. //Local list different update
  7133. DEBUG_INFO("Local list different update.\n");
  7134. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7135. goto end;
  7136. }
  7137. }
  7138. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7139. end:
  7140. sendSendLocalListConfirmation(uuid, comfirmstr);
  7141. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7142. #if 0
  7143. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7144. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7145. #endif
  7146. return result;
  7147. }
  7148. /*
  7149. enum _SYSTEM_STATUS
  7150. {
  7151. S_BOOTING = 0,
  7152. S_IDLE, =1
  7153. S_AUTHORIZING, =2
  7154. S_REASSIGN_CHECK, =3
  7155. S_REASSIGN, =4
  7156. S_PRECHARGE, =5
  7157. S_PREPARING_FOR_EV, =6
  7158. S_PREPARING_FOR_EVSE, =7
  7159. S_CHARGING, =8
  7160. S_TERMINATING, =9
  7161. S_COMPLETE, =10
  7162. S_ALARM, =11
  7163. S_FAULT =12
  7164. };
  7165. */
  7166. #define MAX 200
  7167. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7168. {
  7169. mtrace();
  7170. int result = FAIL;
  7171. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7172. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7173. char chargingProfilePurposeStr[30]={0};
  7174. char chargingProfileKindStr[16]={0};
  7175. char recurrencyKindStr[10]={0};
  7176. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7177. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7178. int chargingSchedulePeriodCount = 0;
  7179. //int updateflag = FALSE;
  7180. char comfirmstr[20]={0};
  7181. int meet= FALSE;
  7182. char sstr[10]={0};
  7183. int c = 0;
  7184. char *loc;
  7185. FILE *fptr1;//, *fptr2;
  7186. //int lno=0;//, linectr = 0;
  7187. //int modifyflag = FALSE;
  7188. char filename[MAX]={0};
  7189. char tempfile[] = "../Storage/OCPP/temp.json";
  7190. int resultRename=0;
  7191. char rmFileCmd[50]={0};
  7192. char tempchargingProfilePurposeStr[30]={0};
  7193. //[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}}}]
  7194. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7195. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7196. //*********************connectorId***************************/
  7197. loc = strstr(payload, "connectorId");
  7198. c = 0;
  7199. memset(sstr ,0, sizeof(sstr) );
  7200. while (loc[strlen("connectorId")+2+c] != ',')
  7201. {
  7202. sstr[c] = loc[strlen("connectorId")+2+c];
  7203. c++;
  7204. }
  7205. sstr[c] = '\0';
  7206. connectorIdInt = atoi(sstr);
  7207. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7208. {
  7209. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7210. }
  7211. else
  7212. {
  7213. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7214. }
  7215. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7216. //*********************chargingProfileId***************************/
  7217. loc = strstr(payload, "chargingProfileId");
  7218. c = 0;
  7219. memset(sstr ,0, sizeof(sstr) );
  7220. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7221. {
  7222. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7223. c++;
  7224. }
  7225. sstr[c] = '\0';
  7226. chargingProfileIdInt = atoi(sstr);
  7227. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7228. {
  7229. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7230. }
  7231. else
  7232. {
  7233. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7234. }
  7235. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7236. //*********************transactionId***************************/
  7237. loc = strstr(payload, "transactionId");
  7238. if(loc != NULL)
  7239. {
  7240. c = 0;
  7241. memset(sstr ,0, sizeof(sstr) );
  7242. while (loc[strlen("transactionId")+2+c] != ',')
  7243. {
  7244. sstr[c] = loc[strlen("transactionId")+2+c];
  7245. c++;
  7246. }
  7247. sstr[c] = '\0';
  7248. transactionIdInt = atoi(sstr);
  7249. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7250. {
  7251. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7252. }
  7253. else
  7254. {
  7255. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7256. }
  7257. }
  7258. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7259. //*********************stackLevel***************************/
  7260. loc = strstr(payload, "stackLevel");
  7261. c = 0;
  7262. memset(sstr ,0, sizeof(sstr) );
  7263. while (loc[strlen("stackLevel")+2+c] != ',')
  7264. {
  7265. sstr[c] = loc[strlen("stackLevel")+2+c];
  7266. c++;
  7267. }
  7268. sstr[c] = '\0';
  7269. stackLevelInt = atoi(sstr);
  7270. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7271. {
  7272. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7273. }
  7274. else
  7275. {
  7276. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7277. }
  7278. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7279. //*********************chargingProfilePurpose***************************/
  7280. loc = strstr(payload, "chargingProfilePurpose");
  7281. c = 0;
  7282. memset(sstr ,0, sizeof(sstr) );
  7283. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7284. {
  7285. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7286. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7287. c++;
  7288. }
  7289. sstr[c] = '\0';
  7290. strcpy(chargingProfilePurposeStr,sstr);
  7291. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7292. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7293. {
  7294. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7295. }
  7296. else
  7297. {
  7298. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7299. }
  7300. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7301. //*********************chargingProfileKind***************************/
  7302. loc = strstr(payload, "chargingProfileKind");
  7303. c = 0;
  7304. memset(sstr ,0, sizeof(sstr) );
  7305. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7306. {
  7307. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7308. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7309. c++;
  7310. }
  7311. sstr[c] = '\0';
  7312. strcpy(chargingProfileKindStr,sstr);
  7313. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7314. {
  7315. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7316. }
  7317. else
  7318. {
  7319. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7320. }
  7321. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7322. //*********************recurrencyKind***************************/
  7323. loc = strstr(payload, "recurrencyKind");
  7324. if(loc != NULL)
  7325. {
  7326. c = 0;
  7327. memset(sstr ,0, sizeof(sstr) );
  7328. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7329. {
  7330. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7331. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7332. c++;
  7333. }
  7334. sstr[c] = '\0';
  7335. strcpy(recurrencyKindStr,sstr);
  7336. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7337. {
  7338. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7339. }
  7340. else
  7341. {
  7342. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7343. }
  7344. }
  7345. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7346. //*********************validFrom***************************/
  7347. loc = strstr(payload, "validFrom");
  7348. if(loc != NULL)
  7349. {
  7350. c = 0;
  7351. memset(sstr ,0, sizeof(sstr) );
  7352. while (loc[3+strlen("validFrom")+c] != '\"')
  7353. {
  7354. sstr[c] = loc[3+strlen("validFrom")+c];
  7355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7356. c++;
  7357. }
  7358. sstr[c] = '\0';
  7359. strcpy(validFromStr,sstr);
  7360. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7361. {
  7362. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7363. }
  7364. else
  7365. {
  7366. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7367. }
  7368. }
  7369. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7370. //*********************validTo***************************/
  7371. loc = strstr(payload, "validTo");
  7372. if(loc != NULL)
  7373. {
  7374. c = 0;
  7375. memset(sstr ,0, sizeof(sstr) );
  7376. while (loc[3+strlen("validTo")+c] != '\"')
  7377. {
  7378. sstr[c] = loc[3+strlen("validTo")+c];
  7379. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7380. c++;
  7381. }
  7382. sstr[c] = '\0';
  7383. strcpy(validToStr,sstr);
  7384. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7385. {
  7386. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7387. }
  7388. else
  7389. {
  7390. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7391. }
  7392. }
  7393. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7394. //*********************duration***************************/
  7395. loc = strstr(payload, "duration");
  7396. if(loc != NULL)
  7397. {
  7398. c = 0;
  7399. memset(sstr ,0, sizeof(sstr) );
  7400. while (loc[strlen("duration")+2+c] != ',')
  7401. {
  7402. sstr[c] = loc[strlen("duration")+2+c];
  7403. c++;
  7404. }
  7405. sstr[c] = '\0';
  7406. durationInt = atoi(sstr);
  7407. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7408. {
  7409. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7410. }
  7411. else
  7412. {
  7413. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7414. }
  7415. }
  7416. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7417. //*********************startSchedule***************************/
  7418. loc = strstr(payload, "startSchedule");
  7419. if(loc != NULL)
  7420. {
  7421. c = 0;
  7422. memset(sstr ,0, sizeof(sstr) );
  7423. while (loc[3+strlen("startSchedule")+c] != '\"')
  7424. {
  7425. sstr[c] = loc[3+strlen("startSchedule")+c];
  7426. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7427. c++;
  7428. }
  7429. sstr[c] = '\0';
  7430. strcpy(startScheduleStr,sstr);
  7431. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7432. {
  7433. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7434. }
  7435. else
  7436. {
  7437. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7438. }
  7439. }
  7440. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7441. //*********************chargingRateUnit***************************/
  7442. loc = strstr(payload, "chargingRateUnit");
  7443. if(loc != NULL)
  7444. {
  7445. c = 0;
  7446. memset(sstr ,0, sizeof(sstr) );
  7447. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7448. {
  7449. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7450. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7451. c++;
  7452. }
  7453. sstr[c] = '\0';
  7454. strcpy(chargingRateUnitStr,sstr);
  7455. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7456. {
  7457. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7458. }
  7459. else
  7460. {
  7461. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7462. }
  7463. }
  7464. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7465. //****************chargingSchedulePeriod count start*******************/
  7466. int what_len = strlen("startPeriod");
  7467. char *where = payload;
  7468. if (what_len)
  7469. while ((where = strstr(where, "startPeriod"))) {
  7470. where += what_len;
  7471. chargingSchedulePeriodCount++;
  7472. }
  7473. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7474. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7475. where = payload;
  7476. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7477. {
  7478. //****************startPeriod*******************/
  7479. c=0;
  7480. loc = strstr(where, "startPeriod");
  7481. memset(sstr ,0, sizeof(sstr) );
  7482. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7483. {
  7484. sstr[c] = loc[strlen("startPeriod")+2+c];
  7485. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7486. c++;
  7487. }
  7488. sstr[c] = '\0';
  7489. startPeriodInt[periodNums] = atoi(sstr);
  7490. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7491. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7492. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7493. {
  7494. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7495. }
  7496. else
  7497. {
  7498. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7499. }
  7500. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7501. //****************limit*******************/
  7502. c=0;
  7503. loc = strstr(where, "limit");
  7504. memset(sstr ,0, sizeof(sstr) );
  7505. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7506. {
  7507. sstr[c] = loc[strlen("limit")+2+c];
  7508. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7509. c++;
  7510. }
  7511. sstr[c] = '\0';
  7512. limitflaot[periodNums] = atof(sstr);
  7513. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7514. {
  7515. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7516. }
  7517. else
  7518. {
  7519. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7520. }
  7521. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7522. //****************numberPhases*******************/
  7523. loc = strstr(where, "numberPhases");
  7524. if(loc != NULL)
  7525. {
  7526. c=0;
  7527. memset(sstr ,0, sizeof(sstr) );
  7528. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7529. {
  7530. sstr[c] = loc[strlen("numberPhases")+2+c];
  7531. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7532. c++;
  7533. }
  7534. sstr[c] = '\0';
  7535. numberPhasesInt[periodNums] = atoi(sstr);
  7536. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7537. {
  7538. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7539. }
  7540. else
  7541. {
  7542. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7543. }
  7544. }
  7545. where = loc;
  7546. }
  7547. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7548. //****************chargingSchedulePeriod count end*******************/
  7549. //*********************minChargingRate***************************/
  7550. loc = strstr(payload, "minChargingRate");
  7551. if(loc != NULL)
  7552. {
  7553. c = 0;
  7554. memset(sstr ,0, sizeof(sstr) );
  7555. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7556. {
  7557. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7558. c++;
  7559. }
  7560. sstr[c] = '\0';
  7561. minChargingRateFloat = atof(sstr);
  7562. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7563. {
  7564. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7565. }
  7566. else
  7567. {
  7568. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7569. }
  7570. }
  7571. DEBUG_INFO("\n\n Replace a specific line in a text file with a new text :\n");
  7572. DEBUG_INFO("-------------------------------------------------------------\n");
  7573. DEBUG_INFO(" Input the file name to be opened : ");
  7574. //fgets(fname, MAX, stdin);
  7575. //fname[strlen(fname) - 1] = '\0';
  7576. #if 0
  7577. switch(connectorIdInt)
  7578. {
  7579. case 0:
  7580. strcpy(filename, ChargingProfile_0_JSON );
  7581. break;
  7582. case 1:
  7583. strcpy(filename, ChargingProfile_1_JSON );
  7584. break;
  7585. case 2:
  7586. strcpy(filename, ChargingProfile_2_JSON );
  7587. break;
  7588. default:
  7589. strcpy(filename, ChargingProfile_0_JSON );
  7590. break;
  7591. }
  7592. fptr1 = fopen(filename, "r");
  7593. if (!fptr1)
  7594. {
  7595. //file not exist
  7596. DEBUG_INFO("Unable to open the input file!!\n");
  7597. fptr1 = fopen(filename, "w+");
  7598. }
  7599. fclose(fptr1);
  7600. #endif
  7601. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7602. //DEBUG_INFO(" ChargingProfilePurposeTypeStr[TxProfile]=%s\n", ChargingProfilePurposeTypeStr[TxProfile]);
  7603. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7604. {
  7605. //printf("set chargingProfile 1-2\n");
  7606. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7607. if(connectorIdInt != 0)
  7608. {
  7609. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7610. goto end;
  7611. }
  7612. strcpy(filename, ChargePointMaxProfile_JSON );
  7613. fptr1 = fopen(filename, "r");
  7614. if (!fptr1)
  7615. {
  7616. //file not exist
  7617. DEBUG_INFO("Unable to open the input file!!\n");
  7618. fptr1 = fopen(filename, "w+");
  7619. }
  7620. fclose(fptr1);
  7621. }
  7622. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7623. {
  7624. //printf("set chargingProfile 1-3\n");
  7625. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7626. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7627. {
  7628. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7629. goto end;
  7630. }
  7631. switch(connectorIdInt)
  7632. {
  7633. case 0:
  7634. strcpy(filename, TxDefaultProfile_0_JSON );
  7635. break;
  7636. case 1:
  7637. strcpy(filename, TxDefaultProfile_1_JSON );
  7638. break;
  7639. case 2:
  7640. strcpy(filename, TxDefaultProfile_2_JSON );
  7641. break;
  7642. default:
  7643. strcpy(filename, TxDefaultProfile_0_JSON );
  7644. break;
  7645. }
  7646. fptr1 = fopen(filename, "r");
  7647. if (!fptr1)
  7648. {
  7649. //file not exist
  7650. DEBUG_INFO("Unable to open the input file!!\n");
  7651. fptr1 = fopen(filename, "w+");
  7652. }
  7653. fclose(fptr1);
  7654. }
  7655. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7656. {
  7657. //printf("set chargingProfile 1-4\n");
  7658. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7659. //check Transaction active
  7660. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7661. {
  7662. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7663. {
  7664. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7665. {
  7666. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7667. {
  7668. meet = TRUE;
  7669. break;
  7670. }
  7671. }
  7672. }
  7673. }
  7674. for (int index = 0; index < CCS_QUANTITY; index++)
  7675. {
  7676. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7677. {
  7678. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7679. {
  7680. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7681. {
  7682. meet = TRUE;
  7683. break;
  7684. }
  7685. }
  7686. }
  7687. }
  7688. for (int index = 0; index < GB_QUANTITY; index++)
  7689. {
  7690. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7691. {
  7692. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7693. {
  7694. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7695. {
  7696. meet = TRUE;
  7697. break;
  7698. }
  7699. }
  7700. }
  7701. }
  7702. if(meet == FALSE)
  7703. {
  7704. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7705. goto end;
  7706. }
  7707. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7708. {
  7709. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7710. goto end;
  7711. }
  7712. switch(connectorIdInt)
  7713. {
  7714. case 0:
  7715. break;
  7716. case 1:
  7717. strcpy(filename, TxProfile_1_JSON);
  7718. break;
  7719. case 2:
  7720. strcpy(filename, TxProfile_2_JSON);
  7721. break;
  7722. default:
  7723. strcpy(filename, TxProfile_1_JSON);
  7724. break;
  7725. }
  7726. fptr1 = fopen(filename, "r");
  7727. if (!fptr1)
  7728. {
  7729. //file not exist
  7730. DEBUG_INFO("Unable to open the input file!!\n");
  7731. fptr1 = fopen(filename, "w+");
  7732. }
  7733. fclose(fptr1);
  7734. }
  7735. //**********************************Write to File********************************************************/
  7736. FILE *infile;
  7737. FILE *outfile;
  7738. // open file for writing
  7739. infile = fopen (filename, "r");
  7740. outfile = fopen (tempfile, "w");
  7741. int d =0;
  7742. d = fgetc(infile);
  7743. DEBUG_INFO("d:%d\n",d);
  7744. rewind(infile);
  7745. //*检测到文件结束标识返回1,否则返回0。*/
  7746. if(d == EOF)
  7747. {
  7748. DEBUG_INFO("ChargingProfile content is NULL\n");
  7749. fprintf(outfile,"[%s]\n",payload);
  7750. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7751. fclose(infile);
  7752. fclose(outfile);
  7753. sprintf(rmFileCmd,"rm -f %s",filename);
  7754. system(rmFileCmd);
  7755. resultRename = rename(tempfile, filename);
  7756. if(resultRename == 0)
  7757. {
  7758. DEBUG_INFO("File chargingProfile renamed successfully");
  7759. }
  7760. else
  7761. {
  7762. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7763. }
  7764. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7765. //system(rmFileCmd);
  7766. }
  7767. else
  7768. {
  7769. char buf[1000]={0};
  7770. while (fgets(buf, sizeof(buf), infile) != NULL)
  7771. {
  7772. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7773. //*************************tempconnectorIdInt*********************************/
  7774. loc = strstr(buf, "connectorId");
  7775. c = 0;
  7776. memset(sstr ,0, sizeof(sstr) );
  7777. while (loc[strlen("connectorId")+2+c] != ',')
  7778. {
  7779. sstr[c] = loc[strlen("connectorId")+2+c];
  7780. c++;
  7781. }
  7782. sstr[c] = '\0';
  7783. tempconnectorIdInt = atoi(sstr);
  7784. //*************************tempchargingProfileIdInt*********************************/
  7785. loc = strstr(buf, "chargingProfileId");
  7786. c = 0;
  7787. memset(sstr ,0, sizeof(sstr) );
  7788. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7789. {
  7790. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7791. c++;
  7792. }
  7793. sstr[c] = '\0';
  7794. tempchargingProfileIdInt = atoi(sstr);
  7795. //*************************tempstackLevelInt*********************************/
  7796. loc = strstr(buf, "stackLevel");
  7797. c = 0;
  7798. memset(sstr ,0, sizeof(sstr) );
  7799. while (loc[strlen("stackLevel")+2+c] != ',')
  7800. {
  7801. sstr[c] = loc[strlen("stackLevel")+2+c];
  7802. c++;
  7803. }
  7804. sstr[c] = '\0';
  7805. tempstackLevelInt = atoi(sstr);
  7806. //*************************tempchargingProfilePurposeStr*********************************/
  7807. loc = strstr(payload, "chargingProfilePurpose");
  7808. c = 0;
  7809. memset(sstr ,0, sizeof(sstr) );
  7810. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7811. {
  7812. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7813. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7814. c++;
  7815. }
  7816. sstr[c] = '\0';
  7817. strcpy(tempchargingProfilePurposeStr,sstr);
  7818. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7819. {
  7820. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7821. {
  7822. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7823. fprintf(outfile,"[%s]\n",payload);
  7824. }
  7825. else
  7826. {
  7827. //DEBUG_INFO("update set chargingProfile to file -1\n");
  7828. if(tempstackLevelInt < stackLevelInt)
  7829. {
  7830. //DEBUG_INFO("update set chargingProfile to file -2\n");
  7831. fprintf(outfile,"[%s]\n",payload);
  7832. fprintf(outfile,"[%s]\n",buf);
  7833. }
  7834. else
  7835. {
  7836. fprintf(outfile,"[%s]\n",buf);
  7837. fprintf(outfile,"[%s]\n",payload);
  7838. }
  7839. }
  7840. DEBUG_INFO("update set chargingProfile to file\n");
  7841. }
  7842. else
  7843. {
  7844. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7845. {
  7846. fprintf(outfile,"[%s]\n",payload);
  7847. fprintf(outfile,"[%s]\n",buf);
  7848. }
  7849. else if(tempstackLevelInt < stackLevelInt)
  7850. {
  7851. fprintf(outfile,"[%s]\n",payload);
  7852. fprintf(outfile,"[%s]\n",buf);
  7853. }
  7854. else
  7855. {
  7856. fprintf(outfile,"[%s]\n",buf);
  7857. fprintf(outfile,"[%s]\n",payload);
  7858. }
  7859. fprintf(outfile,"[%s]\n",buf);
  7860. DEBUG_INFO("add set chargingProfile to file\n");
  7861. }
  7862. } // end of while loop
  7863. fclose(infile);
  7864. fclose(outfile);
  7865. sprintf(rmFileCmd,"rm -f %s",filename);
  7866. system(rmFileCmd);
  7867. resultRename = rename(tempfile, filename);
  7868. if(resultRename == 0)
  7869. {
  7870. DEBUG_INFO("File chargingProfile renamed successfully");
  7871. }
  7872. else
  7873. {
  7874. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7875. }
  7876. result = TRUE;
  7877. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7878. }
  7879. end:
  7880. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7881. return result;
  7882. return result;
  7883. }
  7884. int handleTriggerMessageRequest(char *uuid, char *payload)
  7885. {
  7886. mtrace();
  7887. int result = FAIL;
  7888. int connectorIdIsNULL = FALSE;
  7889. int connectorIdInt =0;
  7890. char sstr[40]={0};
  7891. char requestedMessagestr[40]={0};
  7892. char comfirmstr[20]={0};
  7893. int c = 0;
  7894. char *loc;
  7895. DEBUG_INFO("handleTriggerMessageRequest\n");
  7896. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7897. c = 0;
  7898. loc = strstr(payload, "requestedMessage");
  7899. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7900. {
  7901. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7902. c++;
  7903. }
  7904. sstr[c] = '\0';
  7905. strcpy(requestedMessagestr, sstr);
  7906. c = 0;
  7907. loc = strstr(payload, "connectorId");
  7908. if(loc == NULL)
  7909. {
  7910. connectorIdIsNULL = TRUE;
  7911. }
  7912. else
  7913. {
  7914. memset(sstr ,0, sizeof(sstr) );
  7915. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7916. {
  7917. sstr[c] = loc[strlen("connectorId")+2+c];
  7918. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7919. c++;
  7920. }
  7921. sstr[c] = '\0';
  7922. connectorIdInt = atoi(sstr);
  7923. }
  7924. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7925. {
  7926. //connectorIdInt = json_object_get_int(connectorId);
  7927. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7928. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7929. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7930. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7931. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7932. }
  7933. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7934. {
  7935. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7936. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7937. return TRUE;
  7938. }
  7939. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7940. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7941. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7942. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7943. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7944. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7945. {
  7946. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7947. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7948. return TRUE;
  7949. }
  7950. else
  7951. {
  7952. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7953. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7954. }
  7955. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7956. {
  7957. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7958. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7959. }
  7960. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7961. {
  7962. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7963. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7964. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7965. }
  7966. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7967. {
  7968. sendBootNotificationRequest();
  7969. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7970. }
  7971. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7972. {
  7973. sendHeartbeatRequest(connectorIdInt);
  7974. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7975. }
  7976. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7977. {
  7978. if(connectorIdIsNULL == FALSE)
  7979. {
  7980. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7981. {
  7982. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7983. sendMeterValuesRequest(connectorIdInt -1);
  7984. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7985. }
  7986. }
  7987. else
  7988. {
  7989. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7990. {
  7991. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  7992. sendMeterValuesRequest(idx);
  7993. }
  7994. }
  7995. }
  7996. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  7997. {
  7998. if(connectorIdIsNULL == FALSE)
  7999. {
  8000. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8001. {
  8002. sendStatusNotificationRequest(connectorIdInt -1);
  8003. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8004. }
  8005. }
  8006. else
  8007. {
  8008. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8009. sendStatusNotificationRequest(idx);
  8010. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8011. }
  8012. }
  8013. return result;
  8014. }
  8015. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8016. {
  8017. mtrace();
  8018. int result = FAIL;
  8019. char sstr[6]={0};
  8020. int connectorIdInt =0;
  8021. char comfirmstr[20]={0};
  8022. int c = 0;
  8023. char *loc;
  8024. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8025. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8026. c = 0;
  8027. loc = strstr(payload, "connectorId");
  8028. memset(sstr ,0, sizeof(sstr) );
  8029. while (loc[strlen("connectorId")+2+c] != '}')
  8030. {
  8031. sstr[c] = loc[strlen("connectorId")+2+c];
  8032. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8033. c++;
  8034. }
  8035. sstr[c] = '\0';
  8036. connectorIdInt = atoi(sstr);
  8037. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8038. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8039. {
  8040. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8041. goto end;
  8042. }
  8043. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8044. {
  8045. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8046. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8047. goto end;
  8048. }
  8049. else
  8050. {
  8051. //check Transaction active
  8052. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  8053. {
  8054. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8055. {
  8056. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8057. {
  8058. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8059. }
  8060. }
  8061. for (int index = 0; index < CCS_QUANTITY; index++)
  8062. {
  8063. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8064. {
  8065. //stop Transaction
  8066. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8067. }
  8068. }
  8069. for (int index = 0; index < GB_QUANTITY; index++)
  8070. {
  8071. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8072. {
  8073. //stop Transaction
  8074. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8075. }
  8076. }
  8077. }
  8078. else
  8079. {
  8080. for (int index = 0; index < AC_QUANTITY; index++)
  8081. {
  8082. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8083. {
  8084. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8085. }
  8086. }
  8087. }// END FOR AC ELSE
  8088. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8089. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8090. result = TRUE;
  8091. return result;
  8092. }
  8093. end:
  8094. //json_object_put(obj); --- remove temporally
  8095. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8096. return result;
  8097. }
  8098. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8099. {
  8100. mtrace();
  8101. int result = FAIL;
  8102. pthread_t t;
  8103. sendUpdateFirmwareConfirmation(uuid);
  8104. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8105. pthread_join(t, NULL); // 等�?子執行�??��?完�?
  8106. //sendUpdateFirmwareConfirmation(uuid);
  8107. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8108. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8109. return result;
  8110. }
  8111. void *UpdateFirmwareProcess(void *data)
  8112. {
  8113. mtrace();
  8114. int retriesInt =0, retryIntervalInt=0;
  8115. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8116. int port=0;
  8117. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8118. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8119. //char comfirmstr[20];
  8120. int isSuccess = 0;
  8121. char ftpbuf[200];
  8122. char temp[100];
  8123. char * pch;
  8124. int retriesISNULL=FALSE;
  8125. int retryInterval=FALSE;
  8126. int c = 0;
  8127. //int i = 0;
  8128. char *loc;
  8129. char sstr[300]={ 0 };
  8130. char *str = (char*) data; // ?��?輸入資�?
  8131. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8132. //***************location **************/
  8133. loc = strstr(str, "location");
  8134. memset(sstr ,0, sizeof(sstr) );
  8135. c = 0;
  8136. while (loc[3+strlen("location")+c] != '\"')
  8137. {
  8138. sstr[c] = loc[3+strlen("location")+c];
  8139. c++;
  8140. }
  8141. sstr[c] = '\0';
  8142. strcpy(locationstr, sstr);
  8143. //***************retries**************/
  8144. c = 0;
  8145. loc = strstr(str, "retries");
  8146. if(loc == NULL)
  8147. {
  8148. retriesISNULL=TRUE;
  8149. }
  8150. else
  8151. {
  8152. memset(sstr ,0, sizeof(sstr) );
  8153. while (loc[strlen("retries")+2+c] != ',')
  8154. {
  8155. sstr[c] = loc[strlen("retries")+2+c];
  8156. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8157. c++;
  8158. }
  8159. sstr[c] = '\0';
  8160. }
  8161. if(retriesISNULL == FALSE)
  8162. {
  8163. retriesInt = atoi(sstr);
  8164. }
  8165. //***************retrieveDate **************/
  8166. loc = strstr(str, "retrieveDate");
  8167. memset(sstr ,0, sizeof(sstr) );
  8168. c = 0;
  8169. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8170. {
  8171. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8172. c++;
  8173. }
  8174. sstr[c] = '\0';
  8175. strcpy(retrieveDatestr, sstr);
  8176. //***************retryInterval **************/
  8177. c = 0;
  8178. loc = strstr(str, "retryInterval");
  8179. memset(sstr ,0, sizeof(sstr) );
  8180. if(loc == NULL)
  8181. {
  8182. retryInterval=TRUE;
  8183. }
  8184. else
  8185. {
  8186. while (loc[strlen("retryInterval")+2+c] != ',')
  8187. {
  8188. sstr[c] = loc[strlen("retryInterval")+2+c];
  8189. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8190. c++;
  8191. }
  8192. sstr[c] = '\0';
  8193. }
  8194. if(retryInterval==FALSE)
  8195. {
  8196. retryIntervalInt = atoi(sstr);
  8197. }
  8198. memset(ftppath, 0, sizeof(ftppath));
  8199. memset(path, 0, sizeof(path));
  8200. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8201. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8202. if(strncmp(locationstr,"http", 4) == 0)
  8203. {
  8204. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8205. protocol, host, path);
  8206. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8207. // protocol, user, password, host, path);
  8208. sprintf(ftppath,"/%s", path);
  8209. DEBUG_INFO("protocol =%s\n",protocol);
  8210. DEBUG_INFO("host =%s\n",host);
  8211. DEBUG_INFO("path =%s\n",path);
  8212. DEBUG_INFO("ftppath=%s\n",ftppath);
  8213. int ftppathlen=strlen(ftppath);
  8214. int i=1;
  8215. char filenametemp[50];
  8216. while(i < ftppathlen)
  8217. {
  8218. int len=ftppathlen-i;
  8219. if(ftppath[len]== 47) // '/' ascll code: 47
  8220. {
  8221. DEBUG_INFO("compare '/' all right\n");
  8222. break;
  8223. }
  8224. i=i+1;
  8225. }
  8226. memset(filenametemp, 0, sizeof(filenametemp));
  8227. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8228. filenametemp[i+1] = 0;
  8229. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8230. do{
  8231. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8232. sleep(retryIntervalInt);
  8233. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8234. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8235. if(!isSuccess)
  8236. {
  8237. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8238. }
  8239. else
  8240. {
  8241. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8242. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8243. isUpdateRequest = TRUE;
  8244. }
  8245. }
  8246. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8247. {
  8248. memset(ftpbuf, 0, sizeof(ftpbuf));
  8249. memset(temp, 0, sizeof(temp));
  8250. DEBUG_INFO("locationstr=%s\n",locationstr);
  8251. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8252. int ftppathlen=strlen(ftpbuf);
  8253. int i=1;
  8254. char filenametemp[50];
  8255. while(i < ftppathlen)
  8256. {
  8257. int len=ftppathlen-i;
  8258. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8259. {
  8260. DEBUG_INFO(" compare '/' all right\n");
  8261. break;
  8262. }
  8263. i=i+1;
  8264. }
  8265. memset(filenametemp, 0, sizeof(filenametemp));
  8266. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8267. filenametemp[i+1] = 0;
  8268. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8269. pch=strchr(temp,'@');
  8270. if(pch==NULL)
  8271. {
  8272. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8273. protocol, host, &port, path);
  8274. strcpy(user,"anonymous");
  8275. strcpy(password,"");
  8276. }
  8277. else
  8278. {
  8279. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8280. protocol, user, password, host, &port, path);
  8281. }
  8282. sscanf(host,"%[^/]%s",host1, path1);
  8283. sprintf(ftppath,"%s", path1);
  8284. DEBUG_INFO("protocol =%s\n",protocol);
  8285. DEBUG_INFO("user =%s\n",user);
  8286. DEBUG_INFO("password =%s\n",password);
  8287. DEBUG_INFO("host1 =%s\n",host1);
  8288. DEBUG_INFO("port =%d\n",port);
  8289. DEBUG_INFO("path1 =%s\n",path1);
  8290. DEBUG_INFO("ftppath=%s\n",ftppath);
  8291. //ftpFile(host, user, password, port, ftppath, fname);
  8292. //download firmware pthred
  8293. if(port == 0)
  8294. {
  8295. port = 21;
  8296. }
  8297. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8298. do{
  8299. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8300. sleep(retryIntervalInt);
  8301. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8302. if(!isSuccess)
  8303. {
  8304. //BulldogUtil.sleepMs(interval*1000);
  8305. DEBUG_INFO("Update firmware request and download file fail.\n");
  8306. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8307. }
  8308. else
  8309. {
  8310. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8311. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8312. isUpdateRequest = TRUE;
  8313. }
  8314. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8315. }
  8316. else
  8317. {
  8318. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8319. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8320. }
  8321. pthread_exit(NULL);
  8322. }
  8323. //==========================================
  8324. // Handle server response routine
  8325. //==========================================
  8326. void handleAuthorizeResponse(char *payload, int gun_index)
  8327. {
  8328. mtrace();
  8329. char expiryDatestr[30]={0};
  8330. char parentIdTagstr[20]={0};
  8331. char statusstr[20]={0};
  8332. char expiryDatestrtemp[30]={0};
  8333. char parentIdTagstrtemp[20]={0};
  8334. char IdTagstrtemp[20]={0};
  8335. char statusstrtemp[20]={0};
  8336. int expiryDateISNULL=FALSE;
  8337. int parentIdTagISNULL=FALSE;
  8338. char sstr[160]={ 0 };
  8339. char* filename = AuthorizationCache_JSON;
  8340. char tempfile[] = "../Storage/OCPP/temp.json";
  8341. int c = 0;
  8342. char *loc;
  8343. int resultRename=0;
  8344. int responseIdTagInfoAsZero= 0;
  8345. char rmFileCmd[50]={0};
  8346. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8347. //***********expiryDate*************/
  8348. loc = strstr(payload, "expiryDate");
  8349. memset(sstr ,0, sizeof(sstr) );
  8350. c = 0;
  8351. if(loc == NULL)
  8352. {
  8353. expiryDateISNULL = TRUE;
  8354. }
  8355. else
  8356. {
  8357. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8358. {
  8359. sstr[c] = loc[3+strlen("expiryDate")+c];
  8360. c++;
  8361. }
  8362. sstr[c] = '\0';
  8363. strcpy(expiryDatestr, sstr);
  8364. }
  8365. //***********parentIdTag*************/
  8366. loc = strstr(payload, "parentIdTag");
  8367. memset(sstr ,0, sizeof(sstr) );
  8368. c = 0;
  8369. if(loc == NULL)
  8370. {
  8371. parentIdTagISNULL = TRUE;
  8372. }
  8373. else
  8374. {
  8375. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8376. {
  8377. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8378. c++;
  8379. }
  8380. sstr[c] = '\0';
  8381. strcpy(parentIdTagstr, sstr);
  8382. }
  8383. //***********status*************/
  8384. loc = strstr(payload, "status");
  8385. memset(sstr ,0, sizeof(sstr) );
  8386. c = 0;
  8387. while (loc[3+strlen("status")+c] != '\"')
  8388. {
  8389. sstr[c] = loc[3+strlen("status")+c];
  8390. c++;
  8391. }
  8392. sstr[c] = '\0';
  8393. strcpy(statusstr, sstr);
  8394. //#ifdef SystemLogMessage
  8395. // if(expiryDateISNULL == FALSE)
  8396. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8397. // if(parentIdTagISNULL == FALSE)
  8398. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8399. // DEBUG_INFO("status: %s\n", statusstr);
  8400. //#endif
  8401. if(expiryDateISNULL == FALSE)
  8402. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8403. if(parentIdTagISNULL == FALSE)
  8404. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8405. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8406. //Update idTag information to authorization cache if supproted
  8407. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8408. {
  8409. if((access(filename,F_OK))!=-1)
  8410. {
  8411. DEBUG_INFO("AuthorizationCache exist.\n");
  8412. }
  8413. else
  8414. {
  8415. DEBUG_INFO("AuthorizationCache not exist\n");
  8416. FILE *log = fopen(filename, "w+");
  8417. if(log == NULL)
  8418. {
  8419. DEBUG_INFO("log is NULL\n");
  8420. goto out;
  8421. }
  8422. else
  8423. {
  8424. fclose(log);
  8425. }
  8426. }
  8427. FILE *infile;
  8428. FILE *outfile;
  8429. // open file for writing
  8430. infile = fopen (filename, "r");
  8431. outfile = fopen (tempfile, "w");
  8432. //*检测到文件结束标识返回1,否则返回0。*/
  8433. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8434. int c;
  8435. c = fgetc(infile);
  8436. //DEBUG_INFO("c:%d\n",c);
  8437. rewind(infile);
  8438. if(c == EOF)
  8439. {
  8440. DEBUG_INFO("Orignal File is NULL\n");
  8441. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8442. {
  8443. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8444. }
  8445. else
  8446. {
  8447. strcpy(expiryDatestrtemp, "");
  8448. }
  8449. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8450. {
  8451. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8452. }
  8453. else
  8454. {
  8455. //write Authorize IdTag
  8456. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8457. }
  8458. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8459. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8460. fclose(infile);
  8461. fclose(outfile);
  8462. sprintf(rmFileCmd,"rm -f %s",filename);
  8463. system(rmFileCmd);
  8464. resultRename = rename(tempfile, filename);
  8465. if(resultRename == 0)
  8466. {
  8467. DEBUG_INFO("File renamed successfully");
  8468. }
  8469. else
  8470. {
  8471. DEBUG_INFO("Error: unable to rename the file");
  8472. }
  8473. }
  8474. else
  8475. {
  8476. char buf[160]={0};
  8477. //DEBUG_INFO("Orignal File is not NULL\n");
  8478. while (fgets(buf, sizeof(buf), infile) != NULL)
  8479. {
  8480. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8481. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8482. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8483. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8484. memset(statusstr, 0, sizeof(statusstrtemp));
  8485. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8486. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8487. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8488. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8489. //------------------IdTag-----------------------
  8490. loc = strstr(buf, "idTag");
  8491. memset(sstr ,0, sizeof(sstr) );
  8492. c = 0;
  8493. while (loc[3+strlen("idTag")+c] != '\"')
  8494. {
  8495. sstr[c] = loc[3+strlen("idTag")+c];
  8496. c++;
  8497. }
  8498. sstr[c] = '\0';
  8499. strcpy(IdTagstrtemp,sstr);
  8500. //*********************expiryDate***************/
  8501. loc = strstr(buf, "expiryDate");
  8502. memset(sstr ,0, sizeof(sstr) );
  8503. c = 0;
  8504. while (loc[3+strlen("expiryDate")+c] != '\"')
  8505. {
  8506. sstr[c] = loc[3+strlen("expiryDate")+c];
  8507. c++;
  8508. }
  8509. sstr[c] = '\0';
  8510. strcpy(expiryDatestr,sstr);
  8511. //*********************parentIdTag***************/
  8512. loc = strstr(buf, "parentIdTag");
  8513. memset(sstr ,0, sizeof(sstr) );
  8514. c = 0;
  8515. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8516. {
  8517. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8518. c++;
  8519. }
  8520. sstr[c] = '\0';
  8521. strcpy(parentIdTagstr,sstr);
  8522. //*********************status***************/
  8523. loc = strstr(buf, "status");
  8524. memset(sstr ,0, sizeof(sstr) );
  8525. c = 0;
  8526. while (loc[3+strlen("status")+c] != '\"')
  8527. {
  8528. sstr[c] = loc[3+strlen("status")+c];
  8529. c++;
  8530. }
  8531. sstr[c] = '\0';
  8532. strcpy(statusstr,sstr);
  8533. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8534. {
  8535. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8536. responseIdTagInfoAsZero = 1;
  8537. }
  8538. else
  8539. {
  8540. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8541. }
  8542. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8543. {
  8544. //modify item
  8545. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8546. {
  8547. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8548. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8549. }
  8550. else
  8551. {
  8552. strcpy(expiryDatestrtemp, "");
  8553. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8554. }
  8555. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8556. {
  8557. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8558. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8559. }
  8560. else
  8561. {
  8562. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8563. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8564. }
  8565. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8566. }
  8567. else
  8568. {
  8569. //wrie original item
  8570. strcpy(expiryDatestrtemp, expiryDatestr);
  8571. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8572. strcpy(statusstrtemp, statusstr);
  8573. }
  8574. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8575. }
  8576. fclose(infile);
  8577. fclose(outfile);
  8578. sprintf(rmFileCmd,"rm -f %s",filename);
  8579. system(rmFileCmd);
  8580. resultRename = rename(tempfile, filename);
  8581. if(resultRename == 0)
  8582. {
  8583. DEBUG_INFO("File renamed successfully");
  8584. }
  8585. else
  8586. {
  8587. DEBUG_INFO("Error: unable to rename the file");
  8588. }
  8589. }
  8590. }
  8591. out:
  8592. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8593. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8594. authorizeRetryTimes = 0;
  8595. }
  8596. void handleBootNotificationResponse(char *payload, int gun_index)
  8597. {
  8598. mtrace();
  8599. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8600. char statusStr[12]={0};
  8601. char currentTimeStr[30]={0};
  8602. char *loc;
  8603. int intervalInt = 0;
  8604. int c = 0;
  8605. //double diff_t;
  8606. struct tm tp;
  8607. char buf[28]={0};
  8608. char timebuf[50]={0};
  8609. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8610. //*** interval ****/
  8611. c = 0;
  8612. loc = strstr(payload, "interval");
  8613. printf("loc=%s\n",loc);
  8614. memset(sstr ,0, sizeof(sstr) );
  8615. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8616. {
  8617. sstr[c] = loc[strlen("interval")+2+c];
  8618. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8619. c++;
  8620. }
  8621. sstr[c] = '\0';
  8622. DEBUG_INFO("id=%d\n",atoi(sstr));
  8623. intervalInt = atoi(sstr);
  8624. //***status ****/
  8625. loc = strstr(payload, "status");
  8626. memset(sstr ,0, sizeof(sstr) );
  8627. c = 0;
  8628. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8629. {
  8630. sstr[c] = loc[3+strlen("status")+c];
  8631. c++;
  8632. }
  8633. sstr[c] = '\0';
  8634. strcpy(statusStr, sstr);
  8635. //***currentTime ****/
  8636. loc = strstr(payload, "currentTime");
  8637. //printf("loc=%s\n",loc);
  8638. memset(sstr ,0, sizeof(sstr) );
  8639. c = 0;
  8640. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8641. {
  8642. sstr[c] = loc[3+strlen("currentTime")+c];
  8643. c++;
  8644. }
  8645. sstr[c] = '\0';
  8646. strcpy(currentTimeStr, sstr);
  8647. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8648. HeartBeatWaitTime = BootNotificationInterval;
  8649. //#ifdef SystemLogMessage
  8650. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8651. // DEBUG_INFO("interval: %d\n", intervalInt);
  8652. // DEBUG_INFO("status: %s\n", statusStr);
  8653. //#endif
  8654. //write back to ShmOCPP16Data->BootNotification
  8655. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8656. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8657. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8658. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8659. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8660. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8661. {
  8662. server_sign = TRUE;
  8663. server_pending =FALSE;
  8664. }
  8665. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8666. {
  8667. server_pending = TRUE;
  8668. }
  8669. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8670. tp.tm_isdst = -1;
  8671. //time_t utc = mktime(&tp);
  8672. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8673. memset(timebuf, 0, sizeof timebuf);
  8674. sprintf(timebuf,"date -s '%s'",buf);
  8675. DEBUG_INFO("timebuf=%s\n",timebuf);
  8676. system(timebuf);
  8677. //==============================================
  8678. // RTC sync
  8679. //==============================================
  8680. system("/sbin/hwclock -w --systohc");
  8681. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8682. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8683. }
  8684. void handleDataTransferResponse(char *payload, int gun_index)
  8685. {
  8686. char sstr[160]={0};//sstr[200]={ 0 };
  8687. int c = 0;
  8688. char *loc;
  8689. DEBUG_INFO("handleDataTransferResponse ...\n");
  8690. loc = strstr(payload, "status");
  8691. printf("loc=%s\n",loc);
  8692. c = 0;
  8693. while (loc[3+strlen("status")+c] != '\"')
  8694. {
  8695. sstr[c] = loc[3+strlen("status")+c];
  8696. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8697. c++;
  8698. }
  8699. sstr[c] = '\0';
  8700. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8701. //#ifdef SystemLogMessage
  8702. //DEBUG_INFO("data: %s\n", payload);
  8703. //#endif
  8704. }
  8705. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8706. {
  8707. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8708. //struct json_object *obj;
  8709. // obj = json_tokener_parse(payload);
  8710. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8711. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8712. //No fields are defined.
  8713. }
  8714. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8715. {
  8716. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8717. //struct json_object *obj;
  8718. // obj = json_tokener_parse(payload);
  8719. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8720. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8721. //No fields are defined.
  8722. }
  8723. void handleHeartbeatResponse(char *payload, int gun_index)
  8724. {
  8725. mtrace();
  8726. //double diff_t;
  8727. struct tm tp;
  8728. char buf[28]={0};
  8729. char timebuf[50]={0};
  8730. char sstr[30]={ 0 };
  8731. int c = 0;
  8732. char *loc;
  8733. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8734. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8735. c = 0;
  8736. loc = strstr(payload, "currentTime");
  8737. memset(sstr ,0, sizeof(sstr) );
  8738. while (loc[3+strlen("currentTime")+c] != '\"')
  8739. {
  8740. sstr[c] = loc[3+strlen("currentTime")+c];
  8741. c++;
  8742. }
  8743. sstr[c] = '\0';
  8744. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8745. #ifdef SystemLogMessage
  8746. DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8747. #endif
  8748. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8749. tp.tm_isdst = -1;
  8750. //time_t utc = mktime(&tp);
  8751. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8752. memset(timebuf, 0, sizeof timebuf);
  8753. sprintf(timebuf,"date -s '%s'",buf);
  8754. system(timebuf);
  8755. //==============================================
  8756. // RTC sync
  8757. //==============================================
  8758. system("/sbin/hwclock -w --systohc");
  8759. if(FirstHeartBeat == 0)
  8760. {
  8761. FirstHeartBeat = 1;
  8762. }
  8763. }
  8764. void handleMeterValuesResponse(char *payload, int gun_index)
  8765. {
  8766. mtrace();
  8767. //struct json_object *obj;
  8768. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8769. //No fields are defined.
  8770. }
  8771. void handleStartTransactionResponse(char *payload, int gun_index)
  8772. {
  8773. mtrace();
  8774. char sstr[30]={ 0 };
  8775. int c = 0;
  8776. char *loc;
  8777. int transactionIdInt = 0;
  8778. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8779. DEBUG_INFO("handleStartTransactionResponse\n");
  8780. //****************expiryDate********************/
  8781. loc = strstr(payload, "expiryDate");
  8782. if(loc == NULL)
  8783. {
  8784. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8785. }
  8786. else
  8787. {
  8788. c = 0;
  8789. memset(sstr ,0, sizeof(sstr) );
  8790. while (loc[3+strlen("expiryDate")+c] != '\"')
  8791. {
  8792. sstr[c] = loc[3+strlen("expiryDate")+c];
  8793. c++;
  8794. }
  8795. sstr[c] = '\0';
  8796. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8797. }
  8798. //****************parentIdTag********************/
  8799. loc = strstr(payload, "parentIdTag");
  8800. if(loc == NULL)
  8801. {
  8802. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8803. }
  8804. else
  8805. {
  8806. c = 0;
  8807. memset(sstr ,0, sizeof(sstr) );
  8808. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8809. {
  8810. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8811. c++;
  8812. }
  8813. sstr[c] = '\0';
  8814. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8815. }
  8816. //****************status********************/
  8817. loc = strstr(payload, "status");
  8818. if(loc == NULL)
  8819. {
  8820. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8821. }
  8822. else
  8823. {
  8824. c = 0;
  8825. memset(sstr ,0, sizeof(sstr) );
  8826. while (loc[3+strlen("status")+c] != '\"')
  8827. {
  8828. sstr[c] = loc[3+strlen("status")+c];
  8829. c++;
  8830. }
  8831. sstr[c] = '\0';
  8832. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8833. }
  8834. //****************transactionId********************/
  8835. c=0;
  8836. loc = strstr(payload, "transactionId");
  8837. memset(sstr ,0, sizeof(sstr) );
  8838. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8839. {
  8840. sstr[c] = loc[strlen("transactionId")+2+c];
  8841. c++;
  8842. }
  8843. sstr[c] = '\0';
  8844. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8845. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8846. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8847. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8848. #ifdef SystemLogMessage
  8849. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8850. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8851. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8852. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8853. #endif
  8854. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8855. {
  8856. //add Charging Record
  8857. SettingChargingRecord(gun_index, transactionIdInt);
  8858. }
  8859. }
  8860. void handleStatusNotificationResponse(char *payload, int gun_index)
  8861. {
  8862. mtrace();
  8863. printf("handleStatusNotificationResponse\n");
  8864. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8865. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8866. }
  8867. void handleStopTransactionnResponse(char *payload, int gun_index)
  8868. {
  8869. mtrace();
  8870. char sstr[30]={ 0 };
  8871. int c = 0;
  8872. char *loc;
  8873. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8874. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8875. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8876. loc = strstr(payload, "idTagInfo");
  8877. //***********************idTagInfo************************/
  8878. if(loc != NULL)
  8879. {
  8880. //***********************expiryDate************************/
  8881. loc = strstr(payload, "expiryDate");
  8882. if(loc != NULL)
  8883. {
  8884. memset(sstr ,0, sizeof(sstr) );
  8885. c = 0;
  8886. while (loc[3+strlen("expiryDate")+c] != '\"')
  8887. {
  8888. sstr[c] = loc[3+strlen("expiryDate")+c];
  8889. c++;
  8890. }
  8891. sstr[c] = '\0';
  8892. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8893. }
  8894. //***********************parentIdTag************************/
  8895. loc = strstr(payload, "parentIdTag");
  8896. if(loc != NULL)
  8897. {
  8898. memset(sstr ,0, sizeof(sstr) );
  8899. c = 0;
  8900. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8901. {
  8902. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8903. c++;
  8904. }
  8905. sstr[c] = '\0';
  8906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8907. }
  8908. //***********************status************************/
  8909. loc = strstr(payload, "status");
  8910. memset(sstr ,0, sizeof(sstr) );
  8911. c = 0;
  8912. while (loc[3+strlen("status")+c] != '\"')
  8913. {
  8914. sstr[c] = loc[3+strlen("status")+c];
  8915. c++;
  8916. }
  8917. sstr[c] = '\0';
  8918. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8919. }
  8920. #ifdef SystemLogMessage
  8921. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8922. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8923. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8924. #endif
  8925. }
  8926. //==========================================
  8927. // Handle Error routine
  8928. //==========================================
  8929. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8930. {
  8931. mtrace();
  8932. #ifdef SystemLogMessage
  8933. DEBUG_INFO("errorCode: %s\n", errorCode);
  8934. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8935. DEBUG_INFO("errorDetails: %s\n", payload);
  8936. #endif
  8937. }
  8938. //===============================================
  8939. // Common routine
  8940. //===============================================
  8941. int initialConfigurationTable(void)
  8942. {
  8943. printf("initialConfigurationTable \n");
  8944. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8945. /*Core Profile*/
  8946. //AllowOfflineTxForUnknownId
  8947. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8948. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8951. //AuthorizationCacheEnabled
  8952. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8955. //AuthorizeRemoteTxRequests
  8956. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8959. //BlinkRepeat
  8960. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8963. //ClockAlignedDataInterval
  8964. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8967. //ConnectionTimeOut
  8968. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8971. //GetConfigurationMaxKeys
  8972. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  8975. // HeartbeatInterval
  8976. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  8977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  8978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  8979. // LightIntensity
  8980. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  8981. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  8982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  8983. // LocalAuthorizeOffline
  8984. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  8985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  8986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  8987. // LocalPreAuthorize
  8988. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  8989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  8990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  8991. // MaxEnergyOnInvalidId
  8992. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  8993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  8994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  8995. // MeterValuesAlignedData
  8996. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  8997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  8998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export(A),Energy.Active.Export.Interval(KWh),Power.Active.Export(KW),Voltage(V),SOC(Percent)" );
  8999. // MeterValuesAlignedDataMaxLength
  9000. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9003. // MeterValuesSampledData
  9004. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export(A),Energy.Active.Export.Interval(KWh),Power.Active.Export(KW),Voltage(V),SOC(Percent)" );
  9007. // MeterValuesSampledDataMaxLength
  9008. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9011. // MeterValueSampleInterval
  9012. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9015. // MinimumStatusDuration
  9016. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9019. // NumberOfConnectors
  9020. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  9023. // ResetRetries
  9024. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9027. // ConnectorPhaseRotation
  9028. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  9031. // ConnectorPhaseRotationMaxLength
  9032. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9035. // StopTransactionOnEVSideDisconnect
  9036. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9039. // StopTransactionOnInvalidId
  9040. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9043. // StopTxnAlignedData
  9044. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9047. // StopTxnAlignedDataMaxLength
  9048. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9051. // StopTxnSampledData
  9052. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9055. // StopTxnSampledDataMaxLength
  9056. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9059. // SupportedFeatureProfiles
  9060. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9063. // SupportedFeatureProfilesMaxLength
  9064. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9067. // TransactionMessageAttempts
  9068. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9071. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9072. // TransactionMessageRetryInterval
  9073. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9076. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9077. // UnlockConnectorOnEVSideDisconnect
  9078. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9081. // WebSocketPingInterval
  9082. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9085. //* Local Auth List Management Profile*/
  9086. #if 0
  9087. //For OCTT Test Case
  9088. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9091. #endif
  9092. #if 1
  9093. //LocalAuthListEnabled
  9094. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9097. #endif
  9098. //LocalAuthListMaxLength
  9099. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9102. //SendLocalListMaxLength
  9103. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9106. //ReserveConnectorZeroSupported
  9107. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9110. //* Smart Charging Profile */
  9111. //ChargeProfileMaxStackLevel
  9112. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9115. // ChargingScheduleAllowedChargingRateUnit
  9116. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9119. // ChargingScheduleMaxPeriods
  9120. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9123. // ConnectorSwitch3to1PhaseSupported
  9124. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9127. // MaxChargingProfilesInstalled
  9128. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9131. return 0;
  9132. }
  9133. void getKeyValue(char *keyReq)
  9134. {
  9135. int isEmpty = FALSE;
  9136. int isKnowKey = FALSE;
  9137. //int unKnowIndex = 0;
  9138. DEBUG_INFO("getKeyValue \n");
  9139. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9140. isEmpty = TRUE;
  9141. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9142. {
  9143. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9146. {
  9147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9148. }
  9149. else
  9150. {
  9151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9152. }
  9153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9154. isKnowKey = TRUE;
  9155. }
  9156. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9157. {
  9158. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9160. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9161. {
  9162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9163. }
  9164. else
  9165. {
  9166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9167. }
  9168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9169. isKnowKey = TRUE;
  9170. }
  9171. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9172. {
  9173. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9175. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9176. {
  9177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9178. }
  9179. else
  9180. {
  9181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9182. }
  9183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9184. isKnowKey = TRUE;
  9185. }
  9186. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9187. {
  9188. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9191. {
  9192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9193. }
  9194. else
  9195. {
  9196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9197. }
  9198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9199. isKnowKey = TRUE;
  9200. }
  9201. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9202. {
  9203. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9206. {
  9207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9208. }
  9209. else
  9210. {
  9211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9212. }
  9213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9214. isKnowKey = TRUE;
  9215. }
  9216. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9217. {
  9218. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9221. {
  9222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9223. }
  9224. else
  9225. {
  9226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9227. }
  9228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9229. isKnowKey = TRUE;
  9230. }
  9231. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9232. {
  9233. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9235. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9236. {
  9237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9238. }
  9239. else
  9240. {
  9241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9242. }
  9243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9244. isKnowKey = TRUE;
  9245. }
  9246. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9247. {
  9248. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9251. {
  9252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9253. }
  9254. else
  9255. {
  9256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9257. }
  9258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9259. isKnowKey = TRUE;
  9260. }
  9261. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9262. {
  9263. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9265. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9266. {
  9267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9268. }
  9269. else
  9270. {
  9271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9272. }
  9273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9274. isKnowKey = TRUE;
  9275. }
  9276. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9277. {
  9278. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9280. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9281. {
  9282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9283. }
  9284. else
  9285. {
  9286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9287. }
  9288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9289. isKnowKey = TRUE;
  9290. }
  9291. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9292. {
  9293. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9296. {
  9297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9298. }
  9299. else
  9300. {
  9301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9302. }
  9303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9304. isKnowKey = TRUE;
  9305. }
  9306. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9307. {
  9308. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9311. {
  9312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9313. }
  9314. else
  9315. {
  9316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9317. }
  9318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9319. isKnowKey = TRUE;
  9320. }
  9321. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9322. {
  9323. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9325. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9326. {
  9327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9328. }
  9329. else
  9330. {
  9331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9332. }
  9333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9334. isKnowKey = TRUE;
  9335. }
  9336. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9337. {
  9338. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9341. {
  9342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9343. }
  9344. else
  9345. {
  9346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9347. }
  9348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9349. isKnowKey = TRUE;
  9350. }
  9351. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9352. {
  9353. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9355. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9356. {
  9357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9358. }
  9359. else
  9360. {
  9361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9362. }
  9363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9364. isKnowKey = TRUE;
  9365. }
  9366. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9367. {
  9368. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9370. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9371. {
  9372. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9373. }
  9374. else
  9375. {
  9376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9377. }
  9378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9379. isKnowKey = TRUE;
  9380. }
  9381. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9382. {
  9383. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9386. {
  9387. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9388. }
  9389. else
  9390. {
  9391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9392. }
  9393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9394. isKnowKey = TRUE;
  9395. }
  9396. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9397. {
  9398. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9401. {
  9402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9403. }
  9404. else
  9405. {
  9406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9407. }
  9408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9409. isKnowKey = TRUE;
  9410. }
  9411. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9412. {
  9413. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9416. {
  9417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9418. }
  9419. else
  9420. {
  9421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9422. }
  9423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9424. isKnowKey = TRUE;
  9425. }
  9426. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9427. {
  9428. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9430. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9431. {
  9432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9433. }
  9434. else
  9435. {
  9436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9437. }
  9438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9439. isKnowKey = TRUE;
  9440. }
  9441. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9442. {
  9443. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9445. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9446. {
  9447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9448. }
  9449. else
  9450. {
  9451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9452. }
  9453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9454. isKnowKey = TRUE;
  9455. }
  9456. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9457. {
  9458. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9461. {
  9462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9463. }
  9464. else
  9465. {
  9466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9467. }
  9468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9469. isKnowKey = TRUE;
  9470. }
  9471. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9472. {
  9473. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9476. {
  9477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9478. }
  9479. else
  9480. {
  9481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9482. }
  9483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9484. isKnowKey = TRUE;
  9485. }
  9486. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9487. {
  9488. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9491. {
  9492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9493. }
  9494. else
  9495. {
  9496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9497. }
  9498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9499. isKnowKey = TRUE;
  9500. }
  9501. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9502. {
  9503. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9505. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9506. {
  9507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9508. }
  9509. else
  9510. {
  9511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9512. }
  9513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9514. isKnowKey = TRUE;
  9515. }
  9516. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9517. {
  9518. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9521. {
  9522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9523. }
  9524. else
  9525. {
  9526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9527. }
  9528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9529. isKnowKey = TRUE;
  9530. }
  9531. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9532. {
  9533. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9536. {
  9537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9538. }
  9539. else
  9540. {
  9541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9542. }
  9543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9544. isKnowKey = TRUE;
  9545. }
  9546. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9547. {
  9548. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9551. {
  9552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9553. }
  9554. else
  9555. {
  9556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9557. }
  9558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9559. isKnowKey = TRUE;
  9560. }
  9561. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9562. {
  9563. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9566. {
  9567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9568. }
  9569. else
  9570. {
  9571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9572. }
  9573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9574. isKnowKey = TRUE;
  9575. }
  9576. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9577. {
  9578. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9581. {
  9582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9583. }
  9584. else
  9585. {
  9586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9587. }
  9588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9589. isKnowKey = TRUE;
  9590. }
  9591. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9592. {
  9593. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9596. {
  9597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9598. }
  9599. else
  9600. {
  9601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9602. }
  9603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9604. isKnowKey = TRUE;
  9605. }
  9606. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9607. {
  9608. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9611. {
  9612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9613. }
  9614. else
  9615. {
  9616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9617. }
  9618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9619. isKnowKey = TRUE;
  9620. }
  9621. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9622. {
  9623. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9626. {
  9627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9628. }
  9629. else
  9630. {
  9631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9632. }
  9633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9634. isKnowKey = TRUE;
  9635. }
  9636. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9637. {
  9638. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9641. {
  9642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9643. }
  9644. else
  9645. {
  9646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9647. }
  9648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9649. isKnowKey = TRUE;
  9650. }
  9651. #if 0
  9652. //For OCTT Test Case
  9653. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9654. {
  9655. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9657. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9658. {
  9659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9660. }
  9661. else
  9662. {
  9663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9664. }
  9665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9666. isKnowKey = TRUE;
  9667. }
  9668. #endif
  9669. #if 1
  9670. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9671. {
  9672. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9674. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9675. {
  9676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9677. }
  9678. else
  9679. {
  9680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9681. }
  9682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9683. isKnowKey = TRUE;
  9684. }
  9685. #endif
  9686. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9687. {
  9688. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9690. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9691. {
  9692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9693. }
  9694. else
  9695. {
  9696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9697. }
  9698. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9699. isKnowKey = TRUE;
  9700. }
  9701. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9702. {
  9703. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9705. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9706. {
  9707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9708. }
  9709. else
  9710. {
  9711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9712. }
  9713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9714. isKnowKey = TRUE;
  9715. }
  9716. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9717. {
  9718. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9720. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9721. {
  9722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9723. }
  9724. else
  9725. {
  9726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9727. }
  9728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9729. isKnowKey = TRUE;
  9730. }
  9731. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9732. {
  9733. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9735. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9736. {
  9737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9738. }
  9739. else
  9740. {
  9741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9742. }
  9743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9744. isKnowKey = TRUE;
  9745. }
  9746. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9747. {
  9748. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9750. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9751. {
  9752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9753. }
  9754. else
  9755. {
  9756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9757. }
  9758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9759. isKnowKey = TRUE;
  9760. }
  9761. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9762. {
  9763. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9765. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9766. {
  9767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9768. }
  9769. else
  9770. {
  9771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9772. }
  9773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9774. isKnowKey = TRUE;
  9775. }
  9776. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9777. {
  9778. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9780. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9781. {
  9782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9783. }
  9784. else
  9785. {
  9786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9787. }
  9788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9789. isKnowKey = TRUE;
  9790. }
  9791. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9792. {
  9793. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9795. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9796. {
  9797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9798. }
  9799. else
  9800. {
  9801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9802. }
  9803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9804. isKnowKey = TRUE;
  9805. }
  9806. //=========================================================
  9807. if(!isEmpty && !isKnowKey)
  9808. {
  9809. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9810. strcpy(unknownkey[UnknownKeynum], keyReq);
  9811. UnknownKeynum = UnknownKeynum + 1;
  9812. }
  9813. }
  9814. void processUnkownKey(void)
  9815. {
  9816. DEBUG_INFO("processUnkownKey\n");
  9817. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9818. for(int index=0; index < UnknownKeynum; index++)
  9819. {
  9820. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9821. {
  9822. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9823. }
  9824. }
  9825. }
  9826. int setKeyValue(char *key, char *value)
  9827. {
  9828. int isSuccess = NotSupported;
  9829. int check_ascii=0;
  9830. #ifdef Debug
  9831. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9832. #endif
  9833. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9834. {
  9835. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9837. {
  9838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9839. isSuccess = ConfigurationStatus_Accepted;
  9840. }
  9841. else
  9842. {
  9843. isSuccess = ConfigurationStatus_Rejected;
  9844. }
  9845. }
  9846. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9847. {
  9848. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9850. {
  9851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9852. isSuccess = ConfigurationStatus_Accepted;
  9853. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9854. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9855. }
  9856. else
  9857. {
  9858. isSuccess = ConfigurationStatus_Rejected;
  9859. }
  9860. }
  9861. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9862. {
  9863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9864. {
  9865. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9867. isSuccess = ConfigurationStatus_Accepted;
  9868. }
  9869. else
  9870. {
  9871. isSuccess = ConfigurationStatus_Rejected;
  9872. }
  9873. }
  9874. if(strcmp(key, "BlinkRepeat") == 0)
  9875. {
  9876. //Charger.BlinkRepeat = Integer.parseInt(value);
  9877. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9878. {
  9879. check_ascii = value[0];
  9880. if( (check_ascii < 48) || (check_ascii > 57) )
  9881. {
  9882. isSuccess = ConfigurationStatus_Rejected;
  9883. }
  9884. else
  9885. {
  9886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9887. isSuccess = ConfigurationStatus_Accepted;
  9888. }
  9889. }
  9890. else
  9891. {
  9892. isSuccess = ConfigurationStatus_Rejected;
  9893. }
  9894. }
  9895. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9896. {
  9897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9898. {
  9899. check_ascii = value[0];
  9900. if( (check_ascii < 48) || (check_ascii > 57) )
  9901. {
  9902. isSuccess = ConfigurationStatus_Rejected;
  9903. }
  9904. else
  9905. {
  9906. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9908. isSuccess = ConfigurationStatus_Accepted;
  9909. }
  9910. }
  9911. else
  9912. {
  9913. isSuccess = ConfigurationStatus_Rejected;
  9914. }
  9915. }
  9916. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9917. {
  9918. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9919. {
  9920. check_ascii = value[0];
  9921. if( (check_ascii < 48) || (check_ascii > 57) )
  9922. {
  9923. isSuccess = ConfigurationStatus_Rejected;
  9924. }
  9925. else
  9926. {
  9927. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9929. isSuccess = ConfigurationStatus_Accepted;
  9930. }
  9931. }
  9932. else
  9933. {
  9934. isSuccess = ConfigurationStatus_Rejected;
  9935. }
  9936. }
  9937. if(strcmp(key, "HeartbeatInterval") == 0)
  9938. {
  9939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9940. {
  9941. check_ascii = value[0];
  9942. if( (check_ascii < 48) || (check_ascii > 57) )
  9943. {
  9944. isSuccess = ConfigurationStatus_Rejected;
  9945. }
  9946. else
  9947. {
  9948. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9950. HeartBeatWaitTime = atoi(value);
  9951. isSuccess = ConfigurationStatus_Accepted;
  9952. }
  9953. }
  9954. else
  9955. {
  9956. isSuccess = ConfigurationStatus_Rejected;
  9957. }
  9958. }
  9959. if(strcmp(key, "LightIntensity") == 0)
  9960. {
  9961. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9962. {
  9963. check_ascii = value[0];
  9964. if( (check_ascii < 48) || (check_ascii > 57) )
  9965. {
  9966. isSuccess = ConfigurationStatus_Rejected;
  9967. }
  9968. else
  9969. {
  9970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9971. isSuccess = ConfigurationStatus_Accepted;
  9972. }
  9973. }
  9974. else
  9975. {
  9976. isSuccess = ConfigurationStatus_Rejected;
  9977. }
  9978. }
  9979. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  9980. {
  9981. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9982. {
  9983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9984. isSuccess = ConfigurationStatus_Accepted;
  9985. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9986. }
  9987. else
  9988. {
  9989. isSuccess = ConfigurationStatus_Rejected;
  9990. }
  9991. }
  9992. if(strcmp(key, "LocalPreAuthorize") == 0)
  9993. {
  9994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9995. {
  9996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9997. isSuccess = ConfigurationStatus_Accepted;
  9998. }
  9999. else
  10000. {
  10001. isSuccess = ConfigurationStatus_Rejected;
  10002. }
  10003. }
  10004. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10005. {
  10006. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10007. {
  10008. check_ascii = value[0];
  10009. if( (check_ascii < 48) || (check_ascii > 57) )
  10010. {
  10011. isSuccess = ConfigurationStatus_Rejected;
  10012. }
  10013. else
  10014. {
  10015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10016. isSuccess = ConfigurationStatus_Accepted;
  10017. }
  10018. }
  10019. else
  10020. {
  10021. isSuccess = ConfigurationStatus_Rejected;
  10022. }
  10023. }
  10024. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10025. {
  10026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10027. {
  10028. //int valueLength = strlen(value);
  10029. for(int i = 0; value[i]; i++){
  10030. value[i] = tolower(value[i]);
  10031. }
  10032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10033. isSuccess = ConfigurationStatus_Accepted;
  10034. }
  10035. else
  10036. {
  10037. isSuccess = ConfigurationStatus_Rejected;
  10038. }
  10039. }
  10040. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10041. {
  10042. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10043. {
  10044. //int valueLength = strlen(value);
  10045. for(int i = 0; value[i]; i++){
  10046. value[i] = tolower(value[i]);
  10047. }
  10048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10049. isSuccess = ConfigurationStatus_Accepted;
  10050. }
  10051. else
  10052. {
  10053. isSuccess = ConfigurationStatus_Rejected;
  10054. }
  10055. }
  10056. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10057. {
  10058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10059. {
  10060. check_ascii = value[0];
  10061. if( (check_ascii < 48) || (check_ascii > 57) )
  10062. {
  10063. isSuccess = ConfigurationStatus_Rejected;
  10064. }
  10065. else
  10066. {
  10067. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10069. isSuccess = ConfigurationStatus_Accepted;
  10070. }
  10071. #ifdef Debug
  10072. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10073. #endif
  10074. }
  10075. else
  10076. {
  10077. isSuccess = ConfigurationStatus_Rejected;
  10078. #ifdef Debug
  10079. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10080. #endif
  10081. }
  10082. }
  10083. if(strcmp(key, "MinimumStatusDuration") == 0)
  10084. {
  10085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10086. {
  10087. check_ascii = value[0];
  10088. if( (check_ascii < 48) || (check_ascii > 57) )
  10089. {
  10090. isSuccess = ConfigurationStatus_Rejected;
  10091. }
  10092. else
  10093. {
  10094. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10095. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10096. isSuccess = ConfigurationStatus_Accepted;
  10097. }
  10098. }
  10099. else
  10100. {
  10101. isSuccess = ConfigurationStatus_Rejected;
  10102. }
  10103. }
  10104. if(strcmp(key, "ResetRetries") == 0)
  10105. {
  10106. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10107. {
  10108. check_ascii = value[0];
  10109. if( (check_ascii < 48) || (check_ascii > 57) )
  10110. {
  10111. isSuccess = ConfigurationStatus_Rejected;
  10112. }
  10113. else
  10114. {
  10115. //Charger.ResetRetries = Integer.parseInt(value);
  10116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10117. isSuccess = ConfigurationStatus_Accepted;
  10118. }
  10119. }
  10120. else
  10121. {
  10122. isSuccess = ConfigurationStatus_Rejected;
  10123. }
  10124. }
  10125. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10126. {
  10127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10128. {
  10129. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10130. //int valueLength = strlen(value);
  10131. for(int i = 0; value[i]; i++){
  10132. value[i] = tolower(value[i]);
  10133. }
  10134. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10135. isSuccess = ConfigurationStatus_Accepted;
  10136. }
  10137. else
  10138. {
  10139. isSuccess = ConfigurationStatus_Rejected;
  10140. }
  10141. }
  10142. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10143. {
  10144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10145. {
  10146. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10148. isSuccess = ConfigurationStatus_Accepted;
  10149. }
  10150. else
  10151. {
  10152. isSuccess = ConfigurationStatus_Rejected;
  10153. }
  10154. }
  10155. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10156. {
  10157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10158. {
  10159. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10161. isSuccess = ConfigurationStatus_Accepted;
  10162. }
  10163. else
  10164. {
  10165. isSuccess = ConfigurationStatus_Rejected;
  10166. }
  10167. }
  10168. if(strcmp(key, "StopTxnAlignedData") == 0)
  10169. {
  10170. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10171. {
  10172. //Charger.StopTxnAlignedData = value.toLowerCase();
  10173. //int valueLength = strlen(value);
  10174. for(int i = 0; value[i]; i++){
  10175. value[i] = tolower(value[i]);
  10176. }
  10177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10178. isSuccess = ConfigurationStatus_Accepted;
  10179. }
  10180. else
  10181. {
  10182. isSuccess = ConfigurationStatus_Rejected;
  10183. }
  10184. }
  10185. if(strcmp(key, "StopTxnSampledData") == 0)
  10186. {
  10187. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10188. {
  10189. //Charger.StopTxnSampledData = value.toLowerCase();
  10190. //int valueLength = strlen(value);
  10191. for(int i = 0; value[i]; i++){
  10192. value[i] = tolower(value[i]);
  10193. }
  10194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10195. isSuccess = ConfigurationStatus_Accepted;
  10196. }
  10197. else
  10198. {
  10199. isSuccess = ConfigurationStatus_Rejected;
  10200. }
  10201. }
  10202. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10203. {
  10204. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10205. {
  10206. check_ascii = value[0];
  10207. if( (check_ascii < 48) || (check_ascii > 57) )
  10208. {
  10209. isSuccess = ConfigurationStatus_Rejected;
  10210. }
  10211. else
  10212. {
  10213. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10215. TransactionMessageAttemptsValue = atoi(value);
  10216. isSuccess = ConfigurationStatus_Accepted;
  10217. }
  10218. }
  10219. else
  10220. {
  10221. isSuccess = ConfigurationStatus_Rejected;
  10222. }
  10223. }
  10224. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10225. {
  10226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10227. {
  10228. check_ascii = value[0];
  10229. if( (check_ascii < 48) || (check_ascii > 57) )
  10230. {
  10231. isSuccess = ConfigurationStatus_Rejected;
  10232. }
  10233. else
  10234. {
  10235. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10237. TransactionMessageRetryIntervalValue = atoi(value);
  10238. isSuccess = ConfigurationStatus_Accepted;
  10239. }
  10240. }
  10241. else
  10242. {
  10243. isSuccess = ConfigurationStatus_Rejected;
  10244. }
  10245. }
  10246. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10247. {
  10248. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10249. {
  10250. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10252. isSuccess = ConfigurationStatus_Accepted;
  10253. }
  10254. else
  10255. {
  10256. isSuccess = ConfigurationStatus_Rejected;
  10257. }
  10258. }
  10259. if(strcmp(key, "WebSocketPingInterval") == 0)
  10260. {
  10261. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10262. {
  10263. check_ascii = value[0];
  10264. if( (check_ascii < 48) || (check_ascii > 57) )
  10265. {
  10266. isSuccess = ConfigurationStatus_Rejected;
  10267. }
  10268. else
  10269. {
  10270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10271. isSuccess = ConfigurationStatus_Accepted;
  10272. }
  10273. }
  10274. else
  10275. {
  10276. isSuccess = ConfigurationStatus_Rejected;
  10277. }
  10278. }
  10279. #if 0
  10280. //For OCPP Test Case
  10281. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10282. {
  10283. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10284. {
  10285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10286. isSuccess = ConfigurationStatus_Accepted;
  10287. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10288. }
  10289. else
  10290. {
  10291. isSuccess = ConfigurationStatus_Rejected;
  10292. }
  10293. }
  10294. #endif
  10295. #if 1
  10296. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10297. {
  10298. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10299. {
  10300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10301. isSuccess = ConfigurationStatus_Accepted;
  10302. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10303. }
  10304. else
  10305. {
  10306. isSuccess = ConfigurationStatus_Rejected;
  10307. }
  10308. }
  10309. #endif
  10310. return isSuccess;
  10311. }
  10312. int updateSetting(char *key, char *value)
  10313. {
  10314. mtrace();
  10315. int isSuccess = FALSE;
  10316. char string[1000]={0}, buffer[1000]={0};
  10317. char strtemp[50]={0};
  10318. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10319. int pos, c = 0;
  10320. char *loc;
  10321. int pos1=0;
  10322. FILE *f = fopen("/var/www/settings1", "r");
  10323. if(f == NULL)
  10324. {
  10325. #ifdef Debug
  10326. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10327. #endif
  10328. return isSuccess;
  10329. }
  10330. fseek(f, 0, SEEK_END);
  10331. long fsize = ftell(f);
  10332. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10333. fread(string, 1, fsize, f);
  10334. fclose(f);
  10335. string[fsize] = 0;
  10336. loc = strstr(string, key);
  10337. if(loc != NULL)
  10338. {
  10339. DEBUG_INFO("key exist!\n");
  10340. pos = loc - string-1;
  10341. f = fopen("/var/www/settings1", "w");
  10342. strncpy(buffer, string, pos);
  10343. fprintf(f, "%s", buffer);
  10344. memset(sstr ,0, sizeof(sstr) );
  10345. c = 0;
  10346. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10347. {
  10348. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10349. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10350. c++;
  10351. }
  10352. sstr[c] = '\0';
  10353. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10354. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10355. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10356. memset(buffer ,0, sizeof(buffer) );
  10357. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10358. //printf("buffer=%s",buffer);
  10359. fprintf(f, "%s", buffer);
  10360. fclose(f);
  10361. }
  10362. else
  10363. {
  10364. printf("key not exist!\n");
  10365. f = fopen("/var/www/settings1", "w+");
  10366. fputs(string, f);
  10367. fseek(f, -1, SEEK_CUR);
  10368. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10369. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10370. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10371. fclose(f);
  10372. }
  10373. isSuccess = TRUE;
  10374. return isSuccess;
  10375. }
  10376. int TransactionMessageAttemptsGet(void)
  10377. {
  10378. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10379. }
  10380. int FirstHeartBeatResponse(void)
  10381. {
  10382. return FirstHeartBeat;
  10383. }
  10384. int TransactionMessageRetryIntervalGet(void)
  10385. {
  10386. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10387. }
  10388. #define SA struct sockaddr
  10389. #define MAXBUF 1024
  10390. //static int m_socket_data;
  10391. //static int sockfd;
  10392. int ReadHttpStatus(int sock){
  10393. //char c;
  10394. char buff[1024]="",*ptr=buff+1;
  10395. int bytes_received, status;
  10396. DEBUG_INFO("Begin Response ..\n");
  10397. while((bytes_received = recv(sock, ptr, 1, 0))){
  10398. if(bytes_received==-1){
  10399. perror("ReadHttpStatus");
  10400. exit(1);
  10401. }
  10402. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10403. ptr++;
  10404. }
  10405. *ptr=0;
  10406. ptr=buff+1;
  10407. sscanf(ptr,"%*s %d ", &status);
  10408. DEBUG_INFO("%s\n",ptr);
  10409. DEBUG_INFO("status=%d\n",status);
  10410. DEBUG_INFO("End Response ..\n");
  10411. return (bytes_received>0)?status:0;
  10412. }
  10413. //the only filed that it parsed is 'Content-Length'
  10414. int ParseHeader(int sock){
  10415. //char c;
  10416. char buff[1024]="",*ptr=buff+4;
  10417. int bytes_received;
  10418. DEBUG_INFO("Begin HEADER ..\n");
  10419. while((bytes_received = recv(sock, ptr, 1, 0))){
  10420. if(bytes_received==-1){
  10421. perror("Parse Header");
  10422. exit(1);
  10423. }
  10424. if(
  10425. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10426. (ptr[-1]=='\r') && (*ptr=='\n' )
  10427. ) break;
  10428. ptr++;
  10429. }
  10430. *ptr=0;
  10431. ptr=buff+4;
  10432. //printf("%s",ptr);
  10433. if(bytes_received){
  10434. ptr=strstr(ptr,"Content-Length:");
  10435. if(ptr){
  10436. sscanf(ptr,"%*s %d",&bytes_received);
  10437. }else
  10438. bytes_received=-1; //unknown size
  10439. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10440. }
  10441. DEBUG_INFO("End HEADER ..\n");
  10442. return bytes_received ;
  10443. }
  10444. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10445. {
  10446. char ftpbuf[200];
  10447. int systemresult;
  10448. DEBUG_INFO("filename=%s\n",filename);
  10449. DEBUG_INFO("url=%s\n",url);
  10450. memset(ftpbuf, 0, sizeof(ftpbuf));
  10451. sprintf(ftpbuf, "wget --tries=3 -O %s -c %s",filename, url);
  10452. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10453. systemresult = system(ftpbuf);
  10454. DEBUG_INFO("systemresult=%d\n",systemresult);
  10455. if(systemresult != 0)
  10456. {
  10457. DEBUG_INFO("http DownLoad error!\n");
  10458. return FALSE;
  10459. }
  10460. return TRUE;
  10461. }
  10462. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10463. {
  10464. char ftpbuf[200];
  10465. int systemresult;
  10466. //char temp[100];
  10467. #if 0
  10468. struct hostent* server;
  10469. char *IPbuffer;
  10470. server = gethostbyname(location);
  10471. // To convert an Internet network
  10472. // address into ASCII string
  10473. IPbuffer = inet_ntoa(*((struct in_addr*)
  10474. server->h_addr_list[0]));
  10475. #endif
  10476. memset(ftpbuf, 0, sizeof(ftpbuf));
  10477. sprintf(ftpbuf, "wget --tries=3 -O %s -c %s",filename, url);
  10478. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10479. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10480. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10481. systemresult = system(ftpbuf);
  10482. DEBUG_INFO("systemresult=%d\n",systemresult);
  10483. if(systemresult != 0)
  10484. {
  10485. printf("ftpget error!\n");
  10486. return FALSE;
  10487. }
  10488. return TRUE;
  10489. }
  10490. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10491. {
  10492. struct hostent* server;
  10493. char *IPbuffer;
  10494. char ftpbuf[200];
  10495. int systemresult;
  10496. // To retrieve host information
  10497. server = gethostbyname(location);
  10498. // To convert an Internet network
  10499. // address into ASCII string
  10500. IPbuffer = inet_ntoa(*((struct in_addr*)
  10501. server->h_addr_list[0]));
  10502. memset(ftpbuf, 0, sizeof(ftpbuf));
  10503. /* format : ftpput -u username -p passwd IP target source*/
  10504. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10505. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10506. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10507. systemresult = system(ftpbuf);
  10508. DEBUG_INFO("systemresult=%d\n",systemresult);
  10509. if(systemresult != 0)
  10510. {
  10511. DEBUG_INFO("ftpput error!\n");
  10512. return FALSE;
  10513. }
  10514. return TRUE;
  10515. }
  10516. int SettingChargingRecord(int target, int transactionId)
  10517. {
  10518. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  10519. {
  10520. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10521. {
  10522. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10523. {
  10524. addBuff(target, transactionId, 0);
  10525. return TRUE;
  10526. }
  10527. }
  10528. for (int index = 0; index < CCS_QUANTITY; index++)
  10529. {
  10530. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10531. {
  10532. addBuff(target, transactionId, 0);
  10533. return TRUE;
  10534. }
  10535. }
  10536. for (int index = 0; index < GB_QUANTITY; index++)
  10537. {
  10538. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10539. {
  10540. addBuff(target, transactionId, 0);
  10541. return TRUE;
  10542. }
  10543. }
  10544. }
  10545. else
  10546. {
  10547. for (int index = 0; index < AC_QUANTITY; index++)
  10548. {
  10549. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10550. {
  10551. addBuff(target, transactionId, 0);
  10552. return TRUE;
  10553. }
  10554. }
  10555. }
  10556. return FALSE;
  10557. }
  10558. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10559. {
  10560. int isSuccess = FALSE;
  10561. //char *query = NULL;
  10562. sqlite3_stmt *stmt;
  10563. int rc; // return code
  10564. char str[20];
  10565. sprintf(str,"%d",user_id);
  10566. 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 */
  10567. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10568. rc = sqlite3_step(stmt); /* 3 */
  10569. if (rc != SQLITE_DONE) {
  10570. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10571. goto out;
  10572. }
  10573. sqlite3_finalize(stmt);
  10574. // free(query);
  10575. out:
  10576. //----------------------
  10577. // close SQLite database
  10578. //----------------------
  10579. sqlite3_close(db);
  10580. printf("database closed.\n");
  10581. return isSuccess;
  10582. }
  10583. /**
  10584. * Place the contents of the specified file into a memory buffer
  10585. *
  10586. * @param[in] filename The path and name of the file to read
  10587. * @param[out] filebuffer A pointer to the contents in memory
  10588. * @return status 0 success, 1 on failure
  10589. */
  10590. int get_file_contents(const char* filename, char** outbuffer) {
  10591. FILE* file = NULL;
  10592. long filesize;
  10593. const int blocksize = 1;
  10594. size_t readsize;
  10595. char* filebuffer;
  10596. // Open the file
  10597. file = fopen(filename, "r");
  10598. if (NULL == file)
  10599. {
  10600. printf("'%s' not opened\n", filename);
  10601. exit(EXIT_FAILURE);
  10602. }
  10603. // Determine the file size
  10604. fseek(file, 0, SEEK_END);
  10605. filesize = ftell(file);
  10606. rewind (file);
  10607. // Allocate memory for the file contents
  10608. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10609. *outbuffer = filebuffer;
  10610. if (filebuffer == NULL)
  10611. {
  10612. fputs ("malloc out-of-memory", stderr);
  10613. exit(EXIT_FAILURE);
  10614. }
  10615. // Read in the file
  10616. readsize = fread(filebuffer, blocksize, filesize, file);
  10617. if (readsize != filesize)
  10618. {
  10619. fputs ("didn't read file completely",stderr);
  10620. exit(EXIT_FAILURE);
  10621. }
  10622. // Clean exit
  10623. fclose(file);
  10624. return EXIT_SUCCESS;
  10625. }
  10626. static int selectSqlCount = 0;
  10627. static int callback(void *data, int argc, char **argv, char **azColName){
  10628. int i;
  10629. printf("%s: ", (const char*)data);
  10630. selectSqlCount = argc;
  10631. for(i = 0; i<argc; i++){
  10632. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10633. }
  10634. printf("\n");
  10635. return 0;
  10636. }
  10637. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10638. //int i;
  10639. //printf("%s:\n", (const char*)data);
  10640. localversion = argv[5] ? atoi(argv[5]) : 0;
  10641. printf("localversion=%d\n", localversion);
  10642. return 0;
  10643. }
  10644. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10645. //int i;
  10646. //printf("%s:\n", (const char*)data);
  10647. //idTag
  10648. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10649. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10650. //parentIdTag
  10651. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10652. //expir_date
  10653. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10654. //status
  10655. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10656. //version
  10657. idTagQuery.listVersionInt = atoi(argv[5]);
  10658. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10659. return 0;
  10660. }
  10661. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10662. int i;
  10663. //printf("%s:\n", (const char*)data);
  10664. #if 1
  10665. for(i=0; i<argc; i++){
  10666. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10667. }
  10668. //printf("");
  10669. #endif
  10670. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10671. // printf("localversion=%d\n", localversion);
  10672. return 0;
  10673. }
  10674. /** sqlite3_exec的回调。
  10675. *
  10676. * 向控制台打印查询的结果。
  10677. *
  10678. * @param in data 传递给回调函数的数据。
  10679. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10680. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10681. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10682. * @return 状态码。
  10683. */
  10684. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10685. {
  10686. for (int i = 0; i < n_columns; i++)
  10687. {
  10688. DEBUG_INFO("%s/t", col_values[i]);
  10689. }
  10690. DEBUG_INFO("/n");
  10691. return 0;
  10692. }
  10693. void OCPP_getListVerion()
  10694. {
  10695. int rc = 0;
  10696. // const char* data = "Callback function called";
  10697. char sql[100];
  10698. char zErrMsg[100];
  10699. memset(sql, 0, 100);
  10700. memset(zErrMsg, 0, 100);
  10701. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10702. /* Execute SQL statement */
  10703. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10704. DEBUG_INFO("rc=%d\n",rc);
  10705. if( rc != SQLITE_OK ){
  10706. DEBUG_INFO("SQL error: %s", zErrMsg);
  10707. //sqlite3_free(zErrMsg);
  10708. }else{
  10709. DEBUG_INFO("Operation done successfully");
  10710. }
  10711. }
  10712. void OCPP_getIdTag(char *idTag)
  10713. {
  10714. int rc = 0;
  10715. // const char* data = "Callback function called";
  10716. char sql[100];
  10717. char zErrMsg[100];
  10718. memset(sql, 0, 100);
  10719. memset(zErrMsg, 0, 100);
  10720. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10721. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10722. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10723. /* Execute SQL statement */
  10724. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10725. if( rc != SQLITE_OK ){
  10726. DEBUG_INFO("SQL error: %s", zErrMsg);
  10727. //sqlite3_free(zErrMsg);
  10728. }else{
  10729. printf("Operation done successfully");
  10730. }
  10731. //return ver;
  10732. }
  10733. void OCPP_get_TableAuthlocalAllData(void)
  10734. {
  10735. int rc = 0;
  10736. // const char* data = "Callback function called";
  10737. char sql[100];
  10738. char zErrMsg[100];
  10739. memset(sql, 0, 100);
  10740. memset(zErrMsg, 0, 100);
  10741. sprintf(sql,"select * from ocpp_auth_local ");
  10742. /* Execute SQL statement */
  10743. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10744. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10745. if( rc != SQLITE_OK ){
  10746. DEBUG_INFO("SQL error: %s", zErrMsg);
  10747. //sqlite3_free(zErrMsg);
  10748. }else{
  10749. DEBUG_INFO("Operation done successfully");
  10750. }
  10751. //return ver;
  10752. }
  10753. int OCPP_cleanLocalList()
  10754. {
  10755. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10756. char *errMsg = 0;
  10757. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10758. if (SQLITE_OK != rc)
  10759. {
  10760. DEBUG_INFO("%s\n",errMsg);
  10761. return FALSE;
  10762. }
  10763. else
  10764. {
  10765. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10766. }
  10767. return TRUE;
  10768. }
  10769. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10770. {
  10771. int isSuccess = FALSE;
  10772. int ret = 0;
  10773. //const char* data = "Callback function called";
  10774. char sql[200];
  10775. char zErrMsg[100];
  10776. memset(sql, 0, 200);
  10777. memset(zErrMsg, 0, 100);
  10778. 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);
  10779. //* Execute SQL statement */
  10780. //zErrMsg = 0;
  10781. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10782. if( ret != SQLITE_OK ){
  10783. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10784. // free(zErrMsg);
  10785. // free(sql);
  10786. return isSuccess;
  10787. }
  10788. DEBUG_INFO("successfully Insert records created\n");
  10789. isSuccess = TRUE;
  10790. return isSuccess;
  10791. }
  10792. void OCPP_deleteIdTag(char *idTag)
  10793. {
  10794. //int ver = 0;
  10795. //int isSuccess = FALSE;
  10796. int rc = 0;
  10797. char sql[100];
  10798. char zErrMsg[100];
  10799. memset(sql, 0, 100);
  10800. memset(zErrMsg, 0, 100);
  10801. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10802. //* Execute SQL statement */
  10803. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10804. if( rc != SQLITE_OK ){
  10805. DEBUG_INFO("SQL error: %s", zErrMsg);
  10806. //sqlite3_free(zErrMsg);
  10807. }else{
  10808. DEBUG_INFO("Operation done successfully");
  10809. }
  10810. }
  10811. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10812. {
  10813. int isSuccess = FALSE;
  10814. int ret = 0;
  10815. const char* data = "Callback function called";
  10816. char sql[200];
  10817. char zErrMsg[100];
  10818. memset(sql, 0, 200);
  10819. memset(zErrMsg, 0, 100);
  10820. //* selectFromTable */
  10821. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10822. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10823. //* Execute SQL statement */
  10824. selectSqlCount = 0;
  10825. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10826. if( ret != SQLITE_OK ){
  10827. printf("Error SQL: %s\n", zErrMsg);
  10828. }
  10829. printf("successfully select operation done\n");
  10830. memset(sql, 0, 200);
  10831. memset(zErrMsg, 0, 100);
  10832. if(selectSqlCount == 0)
  10833. {
  10834. //Insert
  10835. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
  10836. 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);
  10837. DEBUG_INFO("sql:%s\n", sql);
  10838. //* Execute SQL statement */
  10839. //zErrMsg = 0;
  10840. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10841. if( ret != SQLITE_OK ){
  10842. printf("SQL error: %s\n", zErrMsg);
  10843. return isSuccess;
  10844. }
  10845. DEBUG_INFO("successfully Insert records created\n");
  10846. isSuccess = TRUE;
  10847. }
  10848. else
  10849. {
  10850. //Update
  10851. //* Create merged SQL statement */
  10852. 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);
  10853. /* Execute SQL statement */
  10854. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10855. if( ret != SQLITE_OK ){
  10856. printf("SQL error: %s\n", zErrMsg);
  10857. //sqlite3_free(zErrMsg);
  10858. //sqlite3_free(sql);
  10859. return isSuccess;
  10860. }
  10861. DEBUG_INFO("Successfully operation done \n");
  10862. isSuccess = TRUE;
  10863. }
  10864. return isSuccess;
  10865. }
  10866. char *GetOcppServerURL()
  10867. {
  10868. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10869. memset(OcppHost, 0, sizeof(OcppHost));
  10870. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10871. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10872. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10873. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10874. DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10875. DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10876. DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10877. DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10878. return OcppHost;
  10879. }
  10880. char *GetOcppPath()
  10881. {
  10882. if(OcppTempPath == NULL)
  10883. {
  10884. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10885. }
  10886. else
  10887. {
  10888. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10889. }
  10890. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10891. return OcppPath;
  10892. }
  10893. int GetOcppPort()
  10894. {
  10895. return OcppPort;
  10896. }
  10897. int GetOcppConnStatus(void)
  10898. {
  10899. return ShmOCPP16Data->OcppConnStatus;
  10900. }
  10901. #if 0
  10902. void Send(struct json_object *message)
  10903. {
  10904. printf("Send -1 \n");
  10905. printf("message=%s\n",json_object_to_json_string(message));
  10906. LWS_Send(json_object_to_json_string(message));
  10907. }
  10908. #endif
  10909. void LWS_Send(char * str)
  10910. {
  10911. #if 1
  10912. //=====================================================
  10913. // Check InternetConn 0: disconnected, 1: connected
  10914. //====================================================
  10915. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  10916. {
  10917. DEBUG_INFO("\n offline now !!!\n");
  10918. return;
  10919. }
  10920. #endif
  10921. pthread_mutex_lock(&lock);
  10922. memset(SendBuffer,0,SendBufLen);
  10923. sprintf((char *)SendBuffer, "%s", str);
  10924. pthread_mutex_unlock(&lock);
  10925. lws_callback_on_writable(wsi_client);
  10926. lws_service(context, 10000);//timeout_ms
  10927. //usleep(10000); // 等�??��?微�?
  10928. //DEBUG_INFO("Send message end\n");
  10929. }