MessageHandler.c 453 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872
  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. void SetOcppConnStatus(uint8_t status);
  160. int updateSetting(char *key, char *value);
  161. int setKeyValue(char *key, char *value);
  162. void OCPP_get_TableAuthlocalAllData(void);
  163. void processUnkownKey(void);
  164. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  165. struct StructOCPPMeterValue
  166. {
  167. unsigned char TimeStamp[28];
  168. struct StructSampledValue SampledValue[10];
  169. };
  170. struct ClientTime
  171. {
  172. unsigned int Heartbeat;
  173. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  174. unsigned int StartTransaction;
  175. unsigned int StopTransaction;
  176. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  177. }clientTime;
  178. typedef union
  179. {
  180. //Operations Initiated by Central System
  181. unsigned char CsMsgValue[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  182. struct
  183. {
  184. //CsMsgValue[0]
  185. unsigned char StatusNotificationReq :1; //bit 0,
  186. unsigned char StatusNotificationConf :1; //bit 0,
  187. unsigned char :6; //bit 2~7
  188. }bits[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  189. }CpinitiateMsg;
  190. CpinitiateMsg cpinitateMsg;
  191. //==========================================
  192. // Init all Enumeration & Mapping String
  193. //==========================================
  194. /*ChargePointErrorCode*/
  195. typedef enum {
  196. ConnectorLockFailure,
  197. EVCommunicationError,
  198. GroundFailure,
  199. HighTemperature,
  200. InternalError,
  201. LocalListConflict,
  202. NoError,
  203. OtherError,
  204. OverCurrentFailure,
  205. OverVoltage,
  206. PowerMeterFailure,
  207. PowerSwitchFailure,
  208. ReaderFailure,
  209. ResetFailure,
  210. UnderVoltage,
  211. WeakSignal
  212. } ChargePointErrorCode;
  213. #if 0
  214. static char *ChargePointErrorCodeStr[] = {
  215. MACROSTR(ConnectorLockFailure),
  216. MACROSTR(EVCommunicationError),
  217. MACROSTR(GroundFailure),
  218. MACROSTR(HighTemperature),
  219. MACROSTR(InternalError),
  220. MACROSTR(LocalListConflict),
  221. MACROSTR(NoError),
  222. MACROSTR(OtherError),
  223. MACROSTR(OverCurrentFailure),
  224. MACROSTR(OverVoltage),
  225. MACROSTR(PowerMeterFailure),
  226. MACROSTR(PowerSwitchFailure),
  227. MACROSTR(ReaderFailure),
  228. MACROSTR(ResetFailure),
  229. MACROSTR(UnderVoltage),
  230. MACROSTR(WeakSignal)
  231. };
  232. #endif
  233. /*ChargePointStatus*/
  234. typedef enum {
  235. Available =0,
  236. Preparing,
  237. Charging,
  238. SuspendedEVSE,
  239. SuspendedEV,
  240. Finishing,
  241. Reserved,
  242. Unavailable,
  243. Faulted
  244. } ChargePointStatus;
  245. static char * ChargePointStatusStr[] = {
  246. MACROSTR(Available),
  247. MACROSTR(Preparing),
  248. MACROSTR(Charging),
  249. MACROSTR(SuspendedEVSE),
  250. MACROSTR(SuspendedEV),
  251. MACROSTR(Finishing),
  252. MACROSTR(Reserved),
  253. MACROSTR(Unavailable),
  254. MACROSTR(Faulted)
  255. };
  256. /*AvailabilityType*/
  257. typedef enum {
  258. RegistrationStatus_Accepted,
  259. RegistrationStatus_Pending,
  260. RegistrationStatus_Rejected
  261. } RegistrationStatus;
  262. static char *RegistrationStatusStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Pending),
  265. MACROSTR(Rejected)
  266. };
  267. /*AvailabilityType*/
  268. typedef enum {
  269. Inoperative,
  270. Operative
  271. } AvailabilityType;
  272. static char *AvailabilityTypeStr[] = {
  273. MACROSTR(Inoperative),
  274. MACROSTR(Operative)
  275. };
  276. /*AvailabilityStatus*/
  277. typedef enum {
  278. Accepted,
  279. Rejected,
  280. Scheduled
  281. } AvailabilityStatus;
  282. static char *AvailabilityStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Rejected),
  285. MACROSTR(Scheduled)
  286. };
  287. /*ConfigurationStatus*/
  288. typedef enum {
  289. ConfigurationStatus_Accepted,
  290. ConfigurationStatus_Rejected,
  291. RebootRequired,
  292. NotSupported
  293. } ConfigurationStatus;
  294. static char *ConfigurationStatusStr[] = {
  295. MACROSTR(Accepted),
  296. MACROSTR(Rejected),
  297. MACROSTR(RebootRequired),
  298. MACROSTR(NotSupported)
  299. };
  300. /*ClearCacheStatus*/
  301. typedef enum {
  302. ClearCacheStatus_Accepted,
  303. ClearCacheStatus_Rejected
  304. } ClearCacheStatus;
  305. static char *ClearCacheStatusStr[] = {
  306. MACROSTR(Accepted),
  307. MACROSTR(Rejected)
  308. };
  309. /*ChargingProfilePurposeType*/
  310. typedef enum {
  311. ChargePointMaxProfile,
  312. TxDefaultProfile,
  313. TxProfile
  314. } ChargingProfilePurposeType;
  315. static char *ChargingProfilePurposeTypeStr[] = {
  316. MACROSTR(ChargePointMaxProfile),
  317. MACROSTR(TxDefaultProfile),
  318. MACROSTR(TxProfile)
  319. };
  320. /*ChargingProfileStatus*/
  321. typedef enum {
  322. ChargingProfileStatus_Accepted,
  323. ChargingProfileStatus_Rejected,
  324. ChargingProfileStatus_NotSupported
  325. } ChargingProfileStatus;
  326. static char *ChargingProfileStatusStr[] = {
  327. MACROSTR(Accepted),
  328. MACROSTR(Rejected),
  329. MACROSTR(NotSupported)
  330. };
  331. /*ClearChargingProfileStatus*/
  332. typedef enum {
  333. ClearChargingProfileStatus_Accepted,
  334. ClearChargingProfileStatus_Unknown
  335. } ClearChargingProfileStatus;
  336. static char *ClearChargingProfileStatusStr[] = {
  337. MACROSTR(Accepted),
  338. MACROSTR(Unknown)
  339. };
  340. /*GetCompositeScheduleStatus*/
  341. typedef enum {
  342. GetCompositeScheduleStatus_Accepted,
  343. GetCompositeScheduleStatus_Rejected
  344. } GetCompositeScheduleStatus;
  345. static char *GetCompositeScheduleStatusStr[] = {
  346. MACROSTR(Accepted),
  347. MACROSTR(Rejected)
  348. };
  349. /*ChargingRateUnitType*/
  350. typedef enum {
  351. ChargingRateUnitType_W,
  352. ChargingRateUnitType_A
  353. } ChargingRateUnitType;
  354. /*AuthorizationStatus*/
  355. typedef enum {
  356. AuthorizationStatus_Accepted ,
  357. AuthorizationStatus_Blocked ,
  358. AuthorizationStatus_Expired ,
  359. AuthorizationStatus_Invalid ,
  360. AuthorizationStatus_ConcurrentTx
  361. } AuthorizationStatus;
  362. /*UpdateType*/
  363. typedef enum {
  364. Differential ,
  365. Full
  366. } UpdateType;
  367. static char *UpdateTypeStr[] = {
  368. MACROSTR(Differential),
  369. MACROSTR(Full)
  370. };
  371. /*UpdateStatus*/
  372. typedef enum {
  373. UpdateStatus_Accepted ,
  374. UpdateStatus_Failed ,
  375. UpdateStatus_NotSupported ,
  376. UpdateStatus_VersionMismatch
  377. } UpdateStatus;
  378. static char *UpdateStatusStr[] = {
  379. MACROSTR(Accepted),
  380. MACROSTR(Failed),
  381. MACROSTR(NotSupported),
  382. MACROSTR(VersionMismatch)
  383. };
  384. /*RemoteStartStopStatus*/
  385. typedef enum {
  386. RemoteStartStopStatus_Accepted,
  387. RemoteStartStopStatus_Rejected
  388. } RemoteStartStopStatus;
  389. static char *RemoteStartStopStatusStr[] = {
  390. MACROSTR(Accepted),
  391. MACROSTR(Rejected)
  392. };
  393. /*ReservationStatus*/
  394. typedef enum {
  395. ReservationStatus_Accepted,
  396. ReservationStatus_Faulted,
  397. ReservationStatus_Occupied,
  398. ReservationStatus_Rejected,
  399. ReservationStatus_Unavailable
  400. } ReservationStatus;
  401. static char *ReservationStatusStr[] = {
  402. MACROSTR(Accepted),
  403. MACROSTR(Faulted),
  404. MACROSTR(Occupied),
  405. MACROSTR(Rejected),
  406. MACROSTR(Unavailable)
  407. };
  408. /*ResetType*/
  409. typedef enum {
  410. Hard,
  411. Soft
  412. } ResetType;
  413. static char *ResetTypeStr[] = {
  414. MACROSTR(Hard),
  415. MACROSTR(Soft)
  416. };
  417. /*ResetStatus*/
  418. typedef enum {
  419. ResetStatus_Accepted,
  420. ResetStatus_Rejected
  421. } ResetStatus;
  422. static char *ResetStatusStr[] = {
  423. MACROSTR(Accepted),
  424. MACROSTR(Rejected)
  425. };
  426. /*DiagnosticsStatus*/
  427. typedef enum {
  428. DiagnosticsStatus_Idle,
  429. DiagnosticsStatus_Uploaded,
  430. DiagnosticsStatus_UploadFailed,
  431. DiagnosticsStatus_Uploading
  432. } DiagnosticsStatus;
  433. static char * DiagnosticsStatusStr[] = {
  434. MACROSTR(Idle),
  435. MACROSTR(Uploaded),
  436. MACROSTR(UploadFailed),
  437. MACROSTR(Uploading)
  438. };
  439. /*FirmwareStatus*/
  440. typedef enum {
  441. FirmwareStatus_Downloaded,
  442. FirmwareStatus_DownloadFailed,
  443. FirmwareStatus_Downloading,
  444. FirmwareStatus_Idle,
  445. FirmwareStatus_InstallationFailed,
  446. FirmwareStatus_Installing,
  447. FirmwareStatus_Installed
  448. } FirmwareStatus;
  449. static char * FirmwareStatusStr[] = {
  450. MACROSTR(Downloaded),
  451. MACROSTR(DownloadFailed),
  452. MACROSTR(Downloading),
  453. MACROSTR(Idle),
  454. MACROSTR(InstallationFailed),
  455. MACROSTR(Installing),
  456. MACROSTR(Installed)
  457. };
  458. /*MessageTrigger*/
  459. typedef enum {
  460. BootNotification,
  461. DiagnosticsStatusNotification,
  462. FirmwareStatusNotification,
  463. Heartbeat,
  464. MeterValues,
  465. StatusNotification
  466. } MessageTrigger;
  467. static char * MessageTriggerStr[] = {
  468. MACROSTR(BootNotification),
  469. MACROSTR(DiagnosticsStatusNotification),
  470. MACROSTR(FirmwareStatusNotification),
  471. MACROSTR(Heartbeat),
  472. MACROSTR(MeterValues),
  473. MACROSTR(StatusNotification)
  474. };
  475. /*TriggerMessageStatus*/
  476. typedef enum {
  477. TriggerMessageStatus_Accepted ,
  478. TriggerMessageStatus_Rejected ,
  479. TriggerMessageStatus_NotImplemented
  480. } TriggerMessageStatus;
  481. static char * TriggerMessageStatusStr[] = {
  482. MACROSTR(Accepted),
  483. MACROSTR(Rejected),
  484. MACROSTR(NotImplemented)
  485. };
  486. /*UnlockStatus*/
  487. typedef enum {
  488. Unlocked,
  489. UnlockFailed,
  490. UnlockStatus_NotSupported
  491. } UnlockStatus;
  492. static char * UnlockStatusStr[] = {
  493. MACROSTR(Unlocked),
  494. MACROSTR(UnlockFailed),
  495. MACROSTR(NotSupported)
  496. };
  497. /*StopTransactionReason*/
  498. typedef enum {
  499. EmergencyStop,
  500. EVDisconnected,
  501. HardReset,
  502. Local,
  503. Other,
  504. PowerLoss,
  505. Reboot,
  506. Remote,
  507. SoftReset,
  508. UnlockCommand,
  509. DeAuthorized
  510. } StopTransactionReason;
  511. static char * StopTransactionReasonStr[] = {
  512. MACROSTR(EmergencyStop),
  513. MACROSTR(EVDisconnected),
  514. MACROSTR(HardReset),
  515. MACROSTR(Local),
  516. MACROSTR(Other),
  517. MACROSTR(PowerLoss),
  518. MACROSTR(Reboot),
  519. MACROSTR(Remote),
  520. MACROSTR(SoftReset),
  521. MACROSTR(UnlockCommand),
  522. MACROSTR(DeAuthorized)
  523. };
  524. /*CancelReservationStatus*/
  525. typedef enum {
  526. CancelReservationStatus_Accepted,
  527. CancelReservationStatus_Rejected
  528. } CancelReservationStatus;
  529. static char * CancelReservationStatusStr[] = {
  530. MACROSTR(Accepted),
  531. MACROSTR(Rejected)
  532. };
  533. /*ReadingContext*/
  534. typedef enum {
  535. ReadingContext_Interruption_Begin,
  536. ReadingContext_Interruption_End,
  537. ReadingContext_Other,
  538. ReadingContext_Sample_Clock,
  539. ReadingContext_Sample_Periodic ,
  540. ReadingContext_Transaction_Begin ,
  541. ReadingContext_Transaction_End,
  542. ReadingContext_Trigger
  543. } ReadingContext;
  544. static char * ReadingContextStr[] = {
  545. MACROSTR(Interruption.Begin),
  546. MACROSTR(Interruption.End),
  547. MACROSTR(Other),
  548. MACROSTR(Sample.Clock),
  549. MACROSTR(Sample.Periodic),
  550. MACROSTR(Transaction.Begin),
  551. MACROSTR(Transaction.End),
  552. MACROSTR(Trigger)
  553. };
  554. /*ValueFormat*/
  555. typedef enum {
  556. Raw,
  557. SignedData
  558. } ValueFormat;
  559. static char * ValueFormatStr[] = {
  560. MACROSTR(Raw),
  561. MACROSTR(SignedData)
  562. };
  563. /*Measurand*/
  564. typedef enum {
  565. Current_Export ,
  566. Current_Import,
  567. Current_Offered,
  568. Energy_Active_Export_Register,
  569. Energy_Active_Import_Register,
  570. Energy_Reactive_Export_Register,
  571. Energy_Reactive_Import_Register,
  572. Energy_Active_Export_Interval,
  573. Energy_Active_Import_Interval,
  574. Energy_Reactive_Export_Interval,
  575. Energy_Reactive_Import_Interval,
  576. Frequency,
  577. Power_Active_Export ,
  578. Power_Active_Import,
  579. Power_Factor,
  580. Power_Offered,
  581. Power_Reactive_Export,
  582. Power_Reactive_Import,
  583. RPM,
  584. SoC,
  585. Temperature ,
  586. Voltage
  587. } Measurand;
  588. static char * MeasurandStr[] = {
  589. MACROSTR(Current.Export),
  590. MACROSTR(Current.Import),
  591. MACROSTR(Current.Offered),
  592. MACROSTR(Energy.Active.Export.Register),
  593. MACROSTR(Energy.Active.Import.Register),
  594. MACROSTR(Energy.Reactive.Export.Register),
  595. MACROSTR(Energy.Reactive.Import.Register),
  596. MACROSTR(Energy.Active.Export.Interval),
  597. MACROSTR(Energy.Active.Import.Interval),
  598. MACROSTR(Energy.Reactive.Export.Interval),
  599. MACROSTR(Energy.Reactive.Import.Interval),
  600. MACROSTR(Frequency),
  601. MACROSTR(Power.Active.Export),
  602. MACROSTR(Power.Active.Import),
  603. MACROSTR(Power.Factor),
  604. MACROSTR(Power.Offered),
  605. MACROSTR(Power.Reactive.ExportMACROSTR),
  606. MACROSTR(Power.Reactive.Import),
  607. MACROSTR(RPM),
  608. MACROSTR(SoC),
  609. MACROSTR(Temperature),
  610. MACROSTR(Voltage)
  611. };
  612. /*Location*/
  613. typedef enum {
  614. Location_Body,
  615. Location_Cable,
  616. Location_EV,
  617. Location_Inlet ,
  618. Location_Outlet
  619. } Location;
  620. static char * LocationStr[] = {
  621. MACROSTR(Body),
  622. MACROSTR(Cable),
  623. MACROSTR(EV),
  624. MACROSTR(Inlet),
  625. MACROSTR(Outlet)
  626. };
  627. /*Phase*/
  628. typedef enum {
  629. L1,
  630. L2,
  631. L3,
  632. N,
  633. L1_N,
  634. L2_N,
  635. L3_N,
  636. L1_L2,
  637. L2_L3,
  638. L3_L1
  639. } Phase;
  640. static char * PhaseStr[] = {
  641. MACROSTR(L1),
  642. MACROSTR(L2),
  643. MACROSTR(L3),
  644. MACROSTR(N),
  645. MACROSTR(L1-N),
  646. MACROSTR(L2-N),
  647. MACROSTR(L3-N),
  648. MACROSTR(L1-L2),
  649. MACROSTR(L2-L3),
  650. MACROSTR(L3-L1)
  651. };
  652. /*UnitOfMeasure*/
  653. typedef enum {
  654. UnitOfMeasure_Wh,
  655. UnitOfMeasure_kWh ,
  656. UnitOfMeasure_varh ,
  657. UnitOfMeasure_kvarh ,
  658. UnitOfMeasure_W ,
  659. UnitOfMeasure_kW ,
  660. UnitOfMeasure_VA ,
  661. UnitOfMeasure_kVA ,
  662. UnitOfMeasure_var ,
  663. UnitOfMeasure_kvar ,
  664. UnitOfMeasure_A ,
  665. UnitOfMeasure_V ,
  666. UnitOfMeasure_Celsius ,
  667. UnitOfMeasure_Fahrenheit ,
  668. UnitOfMeasure_K ,
  669. UnitOfMeasure_Percent
  670. } UnitOfMeasure;
  671. static char * UnitOfMeasureStr[] = {
  672. MACROSTR(Wh),
  673. MACROSTR(kWh),
  674. MACROSTR(varh),
  675. MACROSTR(kvarh),
  676. MACROSTR(W),
  677. MACROSTR(kW),
  678. MACROSTR(VA),
  679. MACROSTR(kVA),
  680. MACROSTR(var),
  681. MACROSTR(kvar),
  682. MACROSTR(A),
  683. MACROSTR(V),
  684. MACROSTR(Celsius),
  685. MACROSTR(Fahrenheit),
  686. MACROSTR(K),
  687. MACROSTR(Percent)
  688. };
  689. /*Configuration enum*/
  690. enum CoreProfile {
  691. AllowOfflineTxForUnknownId=0,
  692. AuthorizationCacheEnabled,
  693. AuthorizeRemoteTxRequests,
  694. BlinkRepeat,
  695. ClockAlignedDataInterval,
  696. ConnectionTimeOut,
  697. GetConfigurationMaxKeys,
  698. HeartbeatInterval,
  699. LightIntensity,
  700. LocalAuthorizeOffline,
  701. LocalPreAuthorize,
  702. MaxEnergyOnInvalidId,
  703. MeterValuesAlignedData,
  704. MeterValuesAlignedDataMaxLength,
  705. MeterValuesSampledData,
  706. MeterValuesSampledDataMaxLength,
  707. MeterValueSampleInterval,
  708. MinimumStatusDuration,
  709. NumberOfConnectors,
  710. ResetRetries,
  711. ConnectorPhaseRotation,
  712. ConnectorPhaseRotationMaxLength,
  713. StopTransactionOnEVSideDisconnect,
  714. StopTransactionOnInvalidId,
  715. StopTxnAlignedData,
  716. StopTxnAlignedDataMaxLength,
  717. StopTxnSampledData,
  718. StopTxnSampledDataMaxLength,
  719. SupportedFeatureProfiles,
  720. SupportedFeatureProfilesMaxLength,
  721. TransactionMessageAttempts,
  722. TransactionMessageRetryInterval,
  723. UnlockConnectorOnEVSideDisconnect,
  724. WebSocketPingInterval,
  725. _CoreProfile_CNT
  726. };
  727. enum LocalAuthListManagementProfile{
  728. LocalAuthListEnabled=0,
  729. LocalAuthListMaxLength,
  730. SendLocalListMaxLength,
  731. _LocalAuthListManagementProfile_CNT
  732. };
  733. enum ReservationProfile{
  734. ReserveConnectorZeroSupported
  735. };
  736. enum SmartChargingProfile{
  737. ChargeProfileMaxStackLevel,
  738. ChargingScheduleAllowedChargingRateUnit,
  739. ChargingScheduleMaxPeriods,
  740. ConnectorSwitch3to1PhaseSupported,
  741. MaxChargingProfilesInstalled
  742. };
  743. enum ChargerSystemStatus{
  744. ChargerSystemStatus_Booting,
  745. ChargerSystemStatus_Idle,
  746. ChargerSystemStatus_Authorizing,
  747. ChargerSystemStatus_Preparing,
  748. ChargerSystemStatus_Charging,
  749. ChargerSystemStatus_Terminating,
  750. ChargerSystemStatus_Alarm,
  751. ChargerSystemStatus_Fault
  752. };
  753. enum GetConfigurationKey {
  754. GetConfiguration_AllowOfflineTxForUnknownId=0,
  755. GetConfiguration_AuthorizationCacheEnabled,
  756. GetConfiguration_AuthorizeRemoteTxRequests,
  757. GetConfiguration_BlinkRepeat,
  758. GetConfiguration_ClockAlignedDataInterval,
  759. GetConfiguration_ConnectionTimeOut,
  760. GetConfiguration_GetConfigurationMaxKeys,
  761. GetConfiguration_HeartbeatInterval,
  762. GetConfiguration_LightIntensity,
  763. GetConfiguration_LocalAuthorizeOffline,
  764. GetConfiguration_LocalPreAuthorize,
  765. GetConfiguration_MaxEnergyOnInvalidId,
  766. GetConfiguration_MeterValuesAlignedData,
  767. GetConfiguration_MeterValuesAlignedDataMaxLength,
  768. GetConfiguration_MeterValuesSampledData,
  769. GetConfiguration_MeterValuesSampledDataMaxLength,
  770. GetConfiguration_MeterValueSampleInterval,
  771. GetConfiguration_MinimumStatusDuration,
  772. GetConfiguration_NumberOfConnectors,
  773. GetConfiguration_ResetRetries,
  774. GetConfiguration_ConnectorPhaseRotation,
  775. GetConfiguration_ConnectorPhaseRotationMaxLength,
  776. GetConfiguration_StopTransactionOnEVSideDisconnect,
  777. GetConfiguration_StopTransactionOnInvalidId,
  778. GetConfiguration_StopTxnAlignedData,
  779. GetConfiguration_StopTxnAlignedDataMaxLength,
  780. GetConfiguration_StopTxnSampledData,
  781. GetConfiguration_StopTxnSampledDataMaxLength,
  782. GetConfiguration_SupportedFeatureProfiles,
  783. GetConfiguration_SupportedFeatureProfilesMaxLength,
  784. GetConfiguration_TransactionMessageAttempts,
  785. GetConfiguration_TransactionMessageRetryInterval,
  786. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  787. GetConfiguration_WebSocketPingInterval,
  788. GetConfiguration_LocalAuthListEnabled,
  789. GetConfiguration_LocalAuthListMaxLength,
  790. GetConfiguration_SendLocalListMaxLength,
  791. GetConfiguration_ReserveConnectorZeroSupported,
  792. GetConfiguration_ChargeProfileMaxStackLevel,
  793. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  794. GetConfiguration_ChargingScheduleMaxPeriods,
  795. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  796. GetConfiguration_MaxChargingProfilesInstalled,
  797. };
  798. //GetConfiguration Array
  799. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  800. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  801. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  802. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  803. struct StructChargingSchedulePeriod staticCHAdeMOChargingSchedulePeriod[10]={0};
  804. struct StructChargingSchedulePeriod staticCCSChargingSchedulePeriod[10]={0};
  805. struct StructChargingSchedulePeriod staticGBChargingSchedulePeriod[10]={0};
  806. struct StructChargingSchedulePeriod staticACChargingSchedulePeriod[10]={0};
  807. struct StructChargingSchedulePeriod staticCHAdeMOCompositeChargingSchedulePeriod[10]={0};
  808. struct StructChargingSchedulePeriod staticCCSCompositeChargingSchedulePeriod[10]={0};
  809. struct StructChargingSchedulePeriod staticGBCompositeChargingSchedulePeriod[10]={0};
  810. struct StructChargingSchedulePeriod staticACCompositeChargingSchedulePeriod[10]={0};
  811. struct StructChargingSchedulePeriod staticCHAdeMORemoteStartTransactionChargingSchedulePeriod[10]={0};
  812. struct StructChargingSchedulePeriod staticCCSRemoteStartTransactionChargingSchedulePeriod[10]={0};
  813. struct StructChargingSchedulePeriod staticGBRemoteStartTransactionChargingSchedulePeriod[10]={0};
  814. struct StructChargingSchedulePeriod staticACRemoteStartTransactionChargingSchedulePeriod[10]={0};
  815. struct StructOCPPMeterValue staticCHAdeMOTransactionDataForMeterValueRequest={0};
  816. struct StructOCPPMeterValue staticCCSTransactionDataForMeterValueRequest={0};
  817. struct StructOCPPMeterValue staticGBTransactionDataForMeterValueRequest={0};
  818. struct StructOCPPMeterValue staticACTransactionDataForMeterValueRequest={0};
  819. struct StructOCPPMeterValue staticCHAdeMOTransactionDataForStopTransactionRequest[0];
  820. struct StructOCPPMeterValue staticCCSTransactionDataForStopTransactionRequest[0];
  821. struct StructOCPPMeterValue staticGBTransactionDataForStopTransactionRequest[0];
  822. struct StructOCPPMeterValue staticACTransactionDataForStopTransactionRequest[0];
  823. //==========================================
  824. // Init all share memory
  825. //==========================================
  826. int InitShareMemory()
  827. {
  828. int result = PASS;
  829. int MeterSMId;
  830. //printf("1\n");
  831. //creat ShmSysConfigAndInfo
  832. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  833. {
  834. #ifdef SystemLogMessage
  835. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  836. #endif
  837. result = FAIL;
  838. }
  839. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  840. {
  841. #ifdef SystemLogMessage
  842. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  843. #endif
  844. result = FAIL;
  845. }
  846. else
  847. {}
  848. //printf("2\n");
  849. //creat ShmStatusCodeData
  850. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  851. {
  852. #ifdef SystemLogMessage
  853. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  854. #endif
  855. result = FAIL;
  856. }
  857. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  858. {
  859. #ifdef SystemLogMessage
  860. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  861. #endif
  862. result = FAIL;
  863. }
  864. else
  865. {}
  866. //printf("3\n");
  867. //creat ShmPsuData
  868. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmget ShmPsuData NG\n");
  872. #endif
  873. result = FAIL;
  874. }
  875. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  876. {
  877. #ifdef SystemLogMessage
  878. DEBUG_ERROR("shmat ShmPsuData NG\n");
  879. #endif
  880. result = FAIL;
  881. }
  882. else
  883. {}
  884. //creat ShmOCPP16Data
  885. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  886. {
  887. #ifdef SystemLogMessage
  888. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  889. #endif
  890. result = FAIL;
  891. }
  892. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  893. {
  894. #ifdef SystemLogMessage
  895. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  896. #endif
  897. result = FAIL;
  898. }
  899. else
  900. {}
  901. /****************************** For TEST ************************************************/
  902. //inital settings
  903. gunTotalNumber = (strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL) ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  904. memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/);
  905. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  906. {
  907. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  908. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  909. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  910. }
  911. // Charger PRE_SYS_MODE
  912. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  913. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  914. clientTime.Heartbeat=time((time_t*)NULL);
  915. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  916. {
  917. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  918. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  919. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  920. }
  921. //HeartBeatWaitTime = 10;
  922. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  923. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  924. // allocate Configuration memory address
  925. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  926. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  927. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  928. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  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. // Update firmware request
  1075. //==============================================
  1076. if(isUpdateRequest == TRUE )
  1077. {
  1078. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1079. {
  1080. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1081. {
  1082. //check SystemStatus
  1083. /*************************DC*******************************/
  1084. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1085. {
  1086. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1087. {
  1088. IdleModeCnt = IdleModeCnt + 1;
  1089. }
  1090. }
  1091. for (int index = 0; index < CCS_QUANTITY; index++)
  1092. {
  1093. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1094. {
  1095. IdleModeCnt = IdleModeCnt + 1;
  1096. }
  1097. }
  1098. for (int index = 0; index < GB_QUANTITY; index++)
  1099. {
  1100. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1101. {
  1102. IdleModeCnt = IdleModeCnt + 1;
  1103. }
  1104. }
  1105. }
  1106. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1107. {
  1108. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1109. isUpdateRequest = FALSE;
  1110. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1111. }
  1112. }
  1113. else
  1114. {
  1115. /*************************AC*******************************/
  1116. for (int index = 0; index < AC_QUANTITY; index++)
  1117. {
  1118. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1119. {
  1120. IdleModeCnt = IdleModeCnt + 1;
  1121. }
  1122. }
  1123. if(IdleModeCnt == AC_QUANTITY)
  1124. {
  1125. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1126. isUpdateRequest = FALSE;
  1127. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1128. }
  1129. }
  1130. }
  1131. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1132. for(int gun_index=0;gun_index < gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY )*/ ;gun_index++)
  1133. {
  1134. //===============================
  1135. // CSU Trigger Reset Conf
  1136. //===============================
  1137. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1138. {
  1139. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1140. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1141. {
  1142. server_sign = FALSE;
  1143. }
  1144. }
  1145. //===============================
  1146. // CSU Trigger Authorize Request
  1147. //===============================
  1148. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1149. {
  1150. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1151. {
  1152. sendAuthorizeRequest(0);
  1153. authorizeRetryTimes = authorizeRetryTimes + 1;
  1154. // authenrequest = TRUE
  1155. if(authorizeRetryTimes < 3)
  1156. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1157. }
  1158. }
  1159. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1160. {
  1161. authorizeRetryTimes = 0;
  1162. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1163. server_sign = FALSE;
  1164. }
  1165. //==============================================
  1166. // Charger start transaction
  1167. //==============================================
  1168. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1169. {
  1170. sendStartTransactionRequest(gun_index);
  1171. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1172. clientTime.StartTransaction = time((time_t*)NULL);
  1173. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1174. }
  1175. //==============================================
  1176. // Charger stop transaction
  1177. //==============================================
  1178. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1179. {
  1180. sendStopTransactionRequest(gun_index);
  1181. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1182. clientTime.StopTransaction = time((time_t*)NULL);
  1183. }
  1184. //==============================================
  1185. // Charger status report
  1186. //==============================================
  1187. /* Check Mode Change */
  1188. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1189. {
  1190. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1191. {
  1192. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1193. {
  1194. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1195. {
  1196. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1197. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1198. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1199. statusModeChage[gun_index] = TRUE;
  1200. }
  1201. }
  1202. }
  1203. for (int index = 0; index < CCS_QUANTITY; index++)
  1204. {
  1205. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1206. {
  1207. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1208. {
  1209. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1210. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1211. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1212. statusModeChage[gun_index] = TRUE;
  1213. }
  1214. }
  1215. }
  1216. for (int index = 0; index < GB_QUANTITY; index++)
  1217. {
  1218. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1219. {
  1220. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1221. {
  1222. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1223. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1224. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1225. statusModeChage[gun_index] = TRUE;
  1226. }
  1227. }
  1228. }
  1229. }
  1230. else //AC
  1231. {
  1232. for (int index = 0; index < AC_QUANTITY; index++)
  1233. {
  1234. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1235. {
  1236. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1237. {
  1238. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1239. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1240. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1241. statusModeChage[gun_index] = TRUE;
  1242. }
  1243. }
  1244. }// END OF FOR
  1245. }// END OF ELSE
  1246. if((SystemInitial != 0)||
  1247. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1248. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1249. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1250. {
  1251. if(SystemInitial != 0)
  1252. SystemInitial = SystemInitial -1;
  1253. //GunStatusInterval= GunStatusInterval* gun_index;
  1254. sendStatusNotificationRequest(gun_index);
  1255. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1256. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1257. statusModeChage[gun_index] = FALSE;
  1258. //sleep(30); // sleep for 30 seconds
  1259. }
  1260. //==============================================
  1261. // Meter report
  1262. //==============================================
  1263. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1264. {
  1265. //check Transaction active
  1266. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1267. {
  1268. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1269. {
  1270. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1271. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1272. {
  1273. meterValueSend[gun_index] =1;
  1274. }
  1275. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1276. {
  1277. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1278. if((access(filenmae,F_OK))!=-1)
  1279. {
  1280. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1281. sprintf(str,"rm -f %s",filenmae);
  1282. system(str);
  1283. }
  1284. }
  1285. }// End for CHAdeMO
  1286. for (int index = 0; index < CCS_QUANTITY; index++)
  1287. {
  1288. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1289. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1290. {
  1291. meterValueSend[gun_index] =1;
  1292. }
  1293. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1294. {
  1295. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1296. if((access(filenmae,F_OK))!=-1)
  1297. {
  1298. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1299. sprintf(str,"rm -f %s",filenmae);
  1300. system(str);
  1301. }
  1302. }
  1303. } // End for CCS
  1304. for (int index = 0; index < GB_QUANTITY; index++)
  1305. {
  1306. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1307. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1308. {
  1309. meterValueSend[gun_index] =1;
  1310. }
  1311. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1312. {
  1313. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1314. if((access(filenmae,F_OK))!=-1)
  1315. {
  1316. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1317. sprintf(str,"rm -f %s",filenmae);
  1318. system(str);
  1319. }
  1320. }
  1321. }// End for GB
  1322. }
  1323. else
  1324. {
  1325. for (int index = 0; index < AC_QUANTITY; index++)
  1326. {
  1327. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1328. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1329. {
  1330. meterValueSend[gun_index] =1;
  1331. }
  1332. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1333. {
  1334. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1335. if((access(filenmae,F_OK))!=-1)
  1336. {
  1337. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1338. sprintf(str,"rm -f %s",filenmae);
  1339. system(str);
  1340. }
  1341. }
  1342. }//End for AC
  1343. }//END OF ELSE
  1344. // sleep(1);
  1345. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1346. if(meterValueSend[gun_index] == 1)
  1347. sendMeterValuesRequest(gun_index);
  1348. }
  1349. //==============================================
  1350. // Check Connector reserved
  1351. //==============================================
  1352. //===============================
  1353. // Check if Reserve is expired
  1354. //===============================
  1355. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1356. {
  1357. double diff_t;
  1358. struct tm tp;
  1359. // current time
  1360. time_t t = time(NULL);
  1361. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1362. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1363. tp.tm_isdst = -1;
  1364. time_t utc = mktime(&tp);
  1365. diff_t = difftime(utc, t);
  1366. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1367. if(diff_t <= 0)
  1368. {
  1369. DEBUG_INFO("reserve expired !!! \n");
  1370. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1371. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1372. }
  1373. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1374. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1375. (strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,(const char *)ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1376. {
  1377. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1378. }
  1379. else
  1380. {
  1381. //check Transaction active
  1382. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1383. {
  1384. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1385. {
  1386. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1387. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId !=0))
  1388. {
  1389. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1390. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1391. {
  1392. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1393. }
  1394. }
  1395. }
  1396. for (int index = 0; index < CCS_QUANTITY; index++)
  1397. {
  1398. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1399. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId !=0))
  1400. {
  1401. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1402. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1403. {
  1404. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1405. }
  1406. }
  1407. }
  1408. for (int index = 0; index < GB_QUANTITY; index++)
  1409. {
  1410. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1411. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId !=0) )
  1412. {
  1413. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1414. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1415. {
  1416. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1417. }
  1418. }
  1419. }
  1420. }
  1421. else //AC
  1422. {
  1423. for (int index = 0; index < AC_QUANTITY; index++)
  1424. {
  1425. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1426. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId !=0))
  1427. {
  1428. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1429. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ) // S_ALARM, S_FAULT
  1430. {
  1431. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1432. }
  1433. }
  1434. }
  1435. }// END OF ELSE
  1436. }// END OF check Transaction active
  1437. }//END OF Check if Reserve is expired
  1438. //==========================================
  1439. // csu trigger FirmwareStatusNotificationReq
  1440. //==========================================
  1441. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1442. {
  1443. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1444. }
  1445. //==========================================
  1446. // csu trigger CancelReservationConf
  1447. //==========================================
  1448. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1449. {
  1450. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1451. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1452. }
  1453. //==========================================
  1454. // csu trigger ChangeAvailabilityConf
  1455. //==========================================
  1456. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1457. {
  1458. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1459. }
  1460. //==========================================
  1461. // csu trigger UnlockConnectorConf
  1462. //==========================================
  1463. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1464. {
  1465. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1466. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1467. }
  1468. //==========================================
  1469. // csu trigger ReserveNowConf
  1470. //==========================================
  1471. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1472. {
  1473. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1474. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1475. }
  1476. //==========================================
  1477. // csu trigger DataTransferReq
  1478. //==========================================
  1479. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1480. {
  1481. sendDataTransferRequest(gun_index);
  1482. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1483. }
  1484. }
  1485. }
  1486. //==========================================
  1487. // send request routine
  1488. //==========================================
  1489. int sendAuthorizeRequest(int gun_index)
  1490. {
  1491. mtrace();
  1492. int result = FAIL;
  1493. char message[100]={0};
  1494. char guid[37];
  1495. char tempdata[65]={0};
  1496. DEBUG_INFO("sendAuthorizeRequest \n");
  1497. //Local Authorize
  1498. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1499. {
  1500. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1501. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1502. {
  1503. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1504. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1505. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1506. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1507. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1508. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1509. authorizeRetryTimes = 0;
  1510. return result;
  1511. }
  1512. else
  1513. {
  1514. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1515. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1516. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1517. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1518. result = PASS;
  1519. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1520. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1521. authorizeRetryTimes = 0;
  1522. return result;
  1523. }
  1524. }
  1525. //initailize struct Authorize
  1526. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1527. //get data from shared memory
  1528. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1529. random_uuid(guid);
  1530. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1531. LWS_Send(message);
  1532. sprintf(tempdata, "Authorize,%d", gun_index);
  1533. if(hashmap_operation(0, guid, tempdata) == 1)
  1534. {
  1535. result = PASS;
  1536. DEBUG_ERROR("Authorize mapItem pass\n");
  1537. }
  1538. //#ifdef SystemLogMessage
  1539. //DEBUG_INFO(">>>>>Authorize request\n");
  1540. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1541. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1542. //#endif
  1543. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1544. return result;
  1545. }
  1546. int sendBootNotificationRequest(void)
  1547. {
  1548. mtrace();
  1549. int result = FAIL;
  1550. char message[500]={0}, payload[700]={0};
  1551. char guid[37]={0};
  1552. char tempdata[65]={0};
  1553. int IsGunCharging = FALSE;
  1554. //check Transaction active
  1555. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1556. {
  1557. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1558. {
  1559. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1560. {
  1561. IsGunCharging = TRUE;
  1562. }
  1563. }
  1564. for (int index = 0; index < CCS_QUANTITY; index++)
  1565. {
  1566. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1567. {
  1568. IsGunCharging = TRUE;
  1569. }
  1570. }
  1571. for (int index = 0; index < GB_QUANTITY; index++)
  1572. {
  1573. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1574. {
  1575. IsGunCharging = TRUE;
  1576. }
  1577. }
  1578. }
  1579. else
  1580. {
  1581. for (int index = 0; index < AC_QUANTITY; index++)
  1582. {
  1583. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1584. {
  1585. IsGunCharging = TRUE;
  1586. }
  1587. }
  1588. }
  1589. if(IsGunCharging == TRUE)
  1590. {
  1591. server_sign = TRUE;
  1592. return result;
  1593. }
  1594. // Fill BootNotification fields
  1595. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1596. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1597. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1598. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1599. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1600. ShmOCPP16Data->ChargeBoxId
  1601. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1602. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1603. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1604. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1605. ,ShmOCPP16Data->BootNotification.CpIccid
  1606. ,ShmOCPP16Data->BootNotification.CpImsi
  1607. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1608. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1609. random_uuid(guid);
  1610. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1611. LWS_Send(message);
  1612. sprintf(tempdata, "BootNotification,0");
  1613. 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*/)
  1614. {
  1615. result = PASS;
  1616. }
  1617. memset(queuedata, 0, sizeof(queuedata));
  1618. strcpy(queuedata,message);
  1619. //#ifdef SystemLogMessage
  1620. //DEBUG_INFO(">>>>>BootNotification request\n");
  1621. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1622. //#endif
  1623. return result;
  1624. }
  1625. int sendDataTransferRequest(int gun_index)
  1626. {
  1627. mtrace();
  1628. char message[1000]={0};
  1629. char guid[37]={0};
  1630. char tempdata[65]={0};
  1631. int result = FAIL;
  1632. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1633. random_uuid(guid);
  1634. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1635. MESSAGE_TYPE_CALL,
  1636. guid,
  1637. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1638. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1639. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1640. LWS_Send(message);
  1641. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1642. 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*/)
  1643. {
  1644. result = PASS;
  1645. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1646. }
  1647. //#ifdef SystemLogMessage
  1648. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1649. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1650. //#endif
  1651. return result;
  1652. }
  1653. int sendDiagnosticsStatusNotificationRequest(char *status)
  1654. {
  1655. mtrace();
  1656. int result = FAIL;
  1657. char message[110]={0};
  1658. char guid[37]={0};
  1659. char tempdata[65]={0};
  1660. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1661. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1662. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1663. random_uuid(guid);
  1664. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1665. LWS_Send(message);
  1666. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1667. if(hashmap_operation(0, guid, tempdata) == 1)
  1668. {
  1669. result = PASS;
  1670. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1671. }
  1672. //#ifdef SystemLogMessage
  1673. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1674. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1675. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1676. //#endif
  1677. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1678. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1679. //record status
  1680. if(strcmp(status,"Idle")==0)
  1681. {
  1682. DiagnosticsStatusNotificationStatus = 0;
  1683. }
  1684. else if(strcmp(status,"Uploaded")==0)
  1685. {
  1686. DiagnosticsStatusNotificationStatus = 1;
  1687. }
  1688. else if(strcmp(status,"UploadFailed")==0)
  1689. {
  1690. DiagnosticsStatusNotificationStatus = 2;
  1691. }
  1692. else if(strcmp(status,"Uploading")==0)
  1693. {
  1694. DiagnosticsStatusNotificationStatus = 3;
  1695. }
  1696. return result;
  1697. }
  1698. int sendFirmwareStatusNotificationRequest(char *status)
  1699. {
  1700. mtrace();
  1701. int result = FAIL;
  1702. char message[110]={0};
  1703. char guid[37]={0};
  1704. char tempdata[65]={0};
  1705. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1706. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1707. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1708. random_uuid(guid);
  1709. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1710. LWS_Send(message);
  1711. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1712. 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*/)
  1713. {
  1714. result = PASS;
  1715. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1716. }
  1717. //#ifdef SystemLogMessage
  1718. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1719. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1720. //#endif
  1721. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1722. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1723. //record status
  1724. if(strcmp(status,"Downloaded")==0)
  1725. {
  1726. FirmwareStatusNotificationStatus = 0;
  1727. }
  1728. else if(strcmp(status,"DownloadFailed")==0)
  1729. {
  1730. FirmwareStatusNotificationStatus = 1;
  1731. }
  1732. else if(strcmp(status,"Downloading")==0)
  1733. {
  1734. FirmwareStatusNotificationStatus = 2;
  1735. }
  1736. else if(strcmp(status,"Idle")==0)
  1737. {
  1738. FirmwareStatusNotificationStatus = 3;
  1739. }
  1740. else if(strcmp(status,"InstallationFailed")==0)
  1741. {
  1742. FirmwareStatusNotificationStatus = 4;
  1743. }
  1744. else if(strcmp(status,"Installing")==0)
  1745. {
  1746. FirmwareStatusNotificationStatus = 5;
  1747. }
  1748. else if(strcmp(status,"Installed")==0)
  1749. {
  1750. FirmwareStatusNotificationStatus = 6;
  1751. }
  1752. return result;
  1753. }
  1754. int sendHeartbeatRequest(int gun_index)
  1755. {
  1756. mtrace();
  1757. int result = FAIL;
  1758. char message[80]={0};
  1759. char guid[37]={0};
  1760. char tempdata[65]={0};
  1761. random_uuid(guid);
  1762. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1763. , MESSAGE_TYPE_CALL
  1764. , guid );
  1765. LWS_Send(message);
  1766. sprintf(tempdata, "Heartbeat,%d", 0);
  1767. 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*/)
  1768. {
  1769. result = PASS;
  1770. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1771. }
  1772. //#ifdef SystemLogMessage
  1773. //DEBUG_INFO(">>>>>Heartbeat request\n");
  1774. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1775. //#endif
  1776. return result;
  1777. }
  1778. int sendStartTransactionRequest(int gun_index)
  1779. {
  1780. mtrace();
  1781. int result = FAIL;
  1782. char message[250]={0};
  1783. char guid[37]={0};
  1784. struct timeval tmnow;
  1785. struct tm *tm;
  1786. char buf[30];//, usec_buf[6];
  1787. char tempdata[65]={0};
  1788. DEBUG_INFO("sendStartTransactionRequest...");
  1789. gettimeofday(&tmnow, NULL);
  1790. time_t t;
  1791. t = time(NULL);
  1792. /*UTC time and date*/
  1793. tm = gmtime(&t);
  1794. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1795. #if 0 // remove temporally
  1796. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1797. strcat(buf,".");
  1798. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1799. strcat(buf,usec_buf);
  1800. #endif
  1801. //printf("Start Charging Time :%s",buf);
  1802. // set value
  1803. if(ShmOCPP16Data->OcppConnStatus == 1 )
  1804. {
  1805. memset(&ShmOCPP16Data->StartTransaction[gun_index], 0, sizeof(ShmOCPP16Data->StartTransaction[gun_index])); // Clear StartTransaction Value
  1806. }
  1807. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1808. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1809. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1810. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1811. {
  1812. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1813. {
  1814. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1815. {
  1816. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1817. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1818. }
  1819. }
  1820. for (int index = 0; index < CCS_QUANTITY; index++)
  1821. {
  1822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1823. {
  1824. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1825. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1826. }
  1827. }
  1828. for (int index = 0; index < GB_QUANTITY; index++)
  1829. {
  1830. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1831. {
  1832. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1833. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1834. }
  1835. }
  1836. }
  1837. else
  1838. {
  1839. for (int index = 0; index < AC_QUANTITY; index++)
  1840. {
  1841. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1842. {
  1843. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1844. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1845. }
  1846. }
  1847. }//END OF ELSE
  1848. random_uuid(guid);
  1849. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1850. , MESSAGE_TYPE_CALL
  1851. , guid
  1852. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1853. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1854. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1855. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1856. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1857. LWS_Send(message);
  1858. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1859. 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*/)
  1860. {
  1861. result = PASS;
  1862. }
  1863. strcpy(queuedata, message);
  1864. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1865. //#ifdef SystemLogMessage
  1866. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1867. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1868. //#endif
  1869. return result;
  1870. }
  1871. int sendStatusNotificationRequest(int gun_index)
  1872. {
  1873. mtrace();
  1874. int result = FAIL;
  1875. char message[600]={0};
  1876. char guid[37];
  1877. int currentStatus = 0;
  1878. struct timeval tmnow;
  1879. struct tm *tm;
  1880. char buf[30];//, usec_buf[6];
  1881. char tempdata[65]={0};
  1882. gettimeofday(&tmnow, NULL);
  1883. time_t t;
  1884. t = time(NULL);
  1885. /*UTC time and date*/
  1886. tm = gmtime(&t);
  1887. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  1888. #if 0 // remove temporally
  1889. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1890. strcat(buf,".");
  1891. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1892. strcat(buf,usec_buf);
  1893. #endif
  1894. printf("%s",buf);
  1895. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1896. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1897. // it's option
  1898. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1899. /*
  1900. enum _SYSTEM_STATUS
  1901. {
  1902. S_BOOTING = 0,
  1903. S_IDLE, = 1
  1904. S_AUTHORIZING, =2
  1905. S_REASSIGN_CHECK, =3
  1906. S_REASSIGN, =4
  1907. S_PRECHARGE, =5
  1908. S_PREPARING_FOR_EV, =6
  1909. S_PREPARING_FOR_EVSE, =7
  1910. S_CHARGING, =8
  1911. S_TERMINATING, =9
  1912. S_COMPLETE, =10
  1913. S_ALARM, =11
  1914. S_FAULT =12
  1915. }
  1916. */
  1917. //check Transaction active
  1918. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  1919. {
  1920. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1921. {
  1922. //printf("gun_index=%d\n",gun_index);
  1923. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1924. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1925. {
  1926. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1927. currentStatus = 0; //OCPP Status
  1928. }
  1929. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1930. {
  1931. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1932. currentStatus = 1; //OCPP Status
  1933. }
  1934. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1935. {
  1936. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1937. currentStatus = 2; //OCPP Status
  1938. }
  1939. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1940. {
  1941. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1942. currentStatus = 5; //OCPP Status
  1943. }
  1944. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1945. {
  1946. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1947. currentStatus = 4; //OCPP Status
  1948. }
  1949. 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
  1950. {
  1951. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1952. currentStatus = 7; //OCPP Status: Unavailable
  1953. }
  1954. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1955. {
  1956. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1957. currentStatus = 8; //OCPP Status: Faulted
  1958. }
  1959. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1960. {
  1961. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1962. currentStatus = 6; //OCPP Status: Reserved
  1963. }
  1964. }//end of for CHAdeMO_QUANTITY
  1965. for (int index = 0; index < CCS_QUANTITY; index++)
  1966. {
  1967. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1968. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1969. {
  1970. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1971. currentStatus = 0; //OCPP Status
  1972. }
  1973. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1974. {
  1975. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1976. currentStatus = 1; //OCPP Status
  1977. }
  1978. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1979. {
  1980. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1981. currentStatus = 2; //OCPP Status
  1982. }
  1983. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1984. {
  1985. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1986. currentStatus = 5; //OCPP Status
  1987. }
  1988. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1989. {
  1990. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1991. currentStatus = 4; //OCPP Status
  1992. }
  1993. 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
  1994. {
  1995. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1996. currentStatus = 7; //OCPP Status
  1997. }
  1998. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1999. {
  2000. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2001. currentStatus = 8; //OCPP Status
  2002. }
  2003. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2004. {
  2005. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2006. currentStatus = 6; //OCPP Status
  2007. }
  2008. }
  2009. for (int index = 0; index < GB_QUANTITY; index++)
  2010. {
  2011. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  2012. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2013. {
  2014. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2015. currentStatus = 0; //OCPP Status
  2016. }
  2017. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2018. {
  2019. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2020. currentStatus = 1; //OCPP Status
  2021. }
  2022. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2023. {
  2024. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2025. currentStatus = 2; //OCPP Status
  2026. }
  2027. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2028. {
  2029. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2030. currentStatus = 5; //OCPP Status
  2031. }
  2032. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2033. {
  2034. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2035. currentStatus = 4; //OCPP Status
  2036. }
  2037. 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
  2038. {
  2039. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2040. currentStatus = 7; //OCPP Status: Unavailable
  2041. }
  2042. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2043. {
  2044. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2045. currentStatus = 8; //OCPP Status: Faulted
  2046. }
  2047. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2048. {
  2049. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2050. currentStatus = 6; //OCPP Status: Faulted
  2051. }
  2052. }
  2053. }
  2054. else
  2055. {
  2056. for (int index = 0; index < AC_QUANTITY; index++)
  2057. {
  2058. //printf("gun_index=%d\n",gun_index);
  2059. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  2060. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  2061. {
  2062. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  2063. currentStatus = 0; //OCPP Status
  2064. }
  2065. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  2066. {
  2067. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  2068. currentStatus = 1; //OCPP Status
  2069. }
  2070. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  2071. {
  2072. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  2073. currentStatus = 2; //OCPP Status
  2074. }
  2075. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  2076. {
  2077. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  2078. currentStatus = 5; //OCPP Status
  2079. }
  2080. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  2081. {
  2082. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2083. currentStatus = 4; //OCPP Status
  2084. }
  2085. 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
  2086. {
  2087. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2088. currentStatus = 7; //OCPP Status: Unavailable
  2089. }
  2090. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  2091. {
  2092. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2093. currentStatus = 8; //OCPP Status: Faulted
  2094. }
  2095. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  2096. {
  2097. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  2098. currentStatus = 6; //OCPP Status: Reserved
  2099. }
  2100. }//end of for AC_QUANTITY
  2101. }//END OF ELSE
  2102. //it's option
  2103. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2104. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2105. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  2106. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2107. random_uuid(guid);
  2108. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2109. , MESSAGE_TYPE_CALL
  2110. , guid
  2111. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2112. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2113. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2114. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2115. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2116. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2117. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2118. LWS_Send(message);
  2119. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2120. 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*/)
  2121. {
  2122. DEBUG_ERROR("statusNotification mapitem pass");
  2123. result = PASS;
  2124. }
  2125. //#ifdef SystemLogMessage
  2126. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2127. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2128. //#endif
  2129. return result;
  2130. }
  2131. int sendStopTransactionRequest(int gun_index)
  2132. {
  2133. mtrace();
  2134. int result = FAIL;
  2135. char message[1500]={0};
  2136. char guid[37]={0};
  2137. char tempdata[65]={0};
  2138. int idx_sample=0;
  2139. DEBUG_ERROR("sendStopTransactionRequest \n");
  2140. //memset(&(ShmOCPP16Data->StopTransaction[gun_index].TransactionData), 0, sizeof(struct StructMeterValue));
  2141. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId/*ShmOCPP16Data->Authorize.IdTag*/);
  2142. //ENERGY_ACTIVE_IMPORT_REGISTER
  2143. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2144. {
  2145. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2146. {
  2147. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2148. {
  2149. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2150. //Check Status
  2151. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2152. {
  2153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2154. }
  2155. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2156. }
  2157. }// END OF CHAdeMO_QUANTITY
  2158. for (int index = 0; index < CCS_QUANTITY; index++)
  2159. {
  2160. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2161. {
  2162. //for test
  2163. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2164. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2165. //Check Status
  2166. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2167. {
  2168. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2169. }
  2170. else
  2171. {
  2172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2173. }
  2174. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2175. }
  2176. }// END OF CCS_QUANTITY
  2177. for (int index = 0; index < GB_QUANTITY; index++)
  2178. {
  2179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2180. {
  2181. // for test
  2182. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2183. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2184. //Check Status
  2185. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2186. {
  2187. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2188. }
  2189. else
  2190. {
  2191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2192. }
  2193. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2194. }
  2195. }// END OF GB_QUANTITY
  2196. }
  2197. else
  2198. {
  2199. for (int index = 0; index < AC_QUANTITY; index++)
  2200. {
  2201. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2202. {
  2203. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2204. //Check Status
  2205. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2206. {
  2207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2208. }
  2209. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2210. }
  2211. }// END OF AC_QUANTITY
  2212. }//END OF ELSE
  2213. //Stop Transaction Time
  2214. struct timeval tmnow;
  2215. struct tm *tm;
  2216. char buf[30];//, usec_buf[6];
  2217. gettimeofday(&tmnow, NULL);
  2218. time_t t;
  2219. t = time(NULL);
  2220. /*UTC time and date*/
  2221. tm = gmtime(&t);
  2222. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2223. #if 0 // remove temporally
  2224. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2225. strcat(buf,".");
  2226. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2227. strcat(buf,usec_buf);
  2228. #endif
  2229. printf("StopTransaction Time %s\n",buf);
  2230. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2232. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2233. random_uuid(guid);
  2234. sprintf(message,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":"
  2235. ,MESSAGE_TYPE_CALL
  2236. ,guid
  2237. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2238. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2239. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2240. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2241. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason);
  2242. /***********************************transactionData******************************************************/
  2243. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2244. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2245. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2246. {
  2247. //transactionData = json_object_new_object();
  2248. //json_object_object_add(transactionData, "timestamp", json_object_new_string("2019-05-04T18:15:33Z"));
  2249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp, buf/*"2019-05-04T18:15:33Z"*/);
  2250. sprintf(message + strlen(message), "[{\"timestamp\":\"%s\",\"sampledValue\":[", (const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp);
  2251. //=================================
  2252. // Transaction_Begin
  2253. //=================================
  2254. // Energy.Active.Export.Interval
  2255. idx_sample=0;
  2256. 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
  2257. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2263. sprintf(message + strlen(message), "{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2264. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2265. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2266. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2267. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2268. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2269. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2270. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2271. );
  2272. //=================================
  2273. // Transaction_End
  2274. //=================================
  2275. //Current.Export
  2276. idx_sample=1;
  2277. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2278. {
  2279. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2280. {
  2281. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2282. {
  2283. 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
  2284. }
  2285. }
  2286. for (int index = 0; index < CCS_QUANTITY; index++)
  2287. {
  2288. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2289. {
  2290. 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
  2291. }
  2292. }
  2293. for (int index = 0; index < GB_QUANTITY; index++)
  2294. {
  2295. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2296. {
  2297. 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
  2298. }
  2299. }
  2300. }
  2301. else
  2302. {
  2303. for (int index = 0; index < AC_QUANTITY; index++)
  2304. {
  2305. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2306. {
  2307. 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
  2308. }
  2309. }
  2310. }// END FOR AC ELSE
  2311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Current_Export/*Energy_Reactive_Export_Register*/]);
  2314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A/*UnitOfMeasure_kWh*/]);
  2317. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2318. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2319. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2320. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2321. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2322. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2323. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2324. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2325. );
  2326. //Energy.Active.Export.Interval
  2327. idx_sample=2;
  2328. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2329. {
  2330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2331. {
  2332. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2333. {
  2334. 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
  2335. }
  2336. }
  2337. for (int index = 0; index < CCS_QUANTITY; index++)
  2338. {
  2339. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2340. {
  2341. 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
  2342. }
  2343. }
  2344. for (int index = 0; index < GB_QUANTITY; index++)
  2345. {
  2346. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2347. {
  2348. 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
  2349. }
  2350. }
  2351. }
  2352. else
  2353. {
  2354. for (int index = 0; index < AC_QUANTITY; index++)
  2355. {
  2356. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2357. {
  2358. 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
  2359. }
  2360. }
  2361. }// END FOR AC ELSE
  2362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2363. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2365. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2368. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2369. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2370. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2371. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2372. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2373. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2374. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2375. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2376. );
  2377. //Power.Active.Export
  2378. idx_sample=3;
  2379. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2380. {
  2381. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2382. {
  2383. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2384. {
  2385. 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
  2386. }
  2387. }
  2388. for (int index = 0; index < CCS_QUANTITY; index++)
  2389. {
  2390. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2391. {
  2392. 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
  2393. }
  2394. }
  2395. for (int index = 0; index < GB_QUANTITY; index++)
  2396. {
  2397. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2398. {
  2399. 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
  2400. }
  2401. }
  2402. }
  2403. else
  2404. {
  2405. for (int index = 0; index < AC_QUANTITY; index++)
  2406. {
  2407. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2408. {
  2409. 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
  2410. }
  2411. }
  2412. }// END FOR AC ELSE
  2413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2416. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2419. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2420. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2421. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2422. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2423. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2424. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2425. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2426. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2427. );
  2428. //Voltage
  2429. idx_sample=4;
  2430. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2431. {
  2432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2433. {
  2434. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2435. {
  2436. 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
  2437. }
  2438. }
  2439. for (int index = 0; index < CCS_QUANTITY; index++)
  2440. {
  2441. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2442. {
  2443. 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
  2444. }
  2445. }
  2446. for (int index = 0; index < GB_QUANTITY; index++)
  2447. {
  2448. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2449. {
  2450. 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
  2451. }
  2452. }
  2453. }
  2454. else
  2455. {
  2456. for (int index = 0; index < AC_QUANTITY; index++)
  2457. {
  2458. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2459. {
  2460. 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
  2461. }
  2462. }
  2463. }// END FOR AC ELSE
  2464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2469. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2470. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2471. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2472. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2473. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2474. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2475. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2476. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2477. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2478. );
  2479. //SoC
  2480. idx_sample=5;
  2481. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2482. {
  2483. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2484. {
  2485. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2486. {
  2487. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2488. }
  2489. }
  2490. for (int index = 0; index < CCS_QUANTITY; index++)
  2491. {
  2492. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2493. {
  2494. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2495. }
  2496. }
  2497. for (int index = 0; index < GB_QUANTITY; index++)
  2498. {
  2499. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2500. {
  2501. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2502. }
  2503. }
  2504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  2506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  2508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  2509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2510. sprintf(message + strlen(message), ",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\" }",
  2511. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value,
  2512. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,
  2513. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,
  2514. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,
  2515. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,
  2516. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,
  2517. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit
  2518. );
  2519. } // END FOR DC CASE
  2520. sprintf(message + strlen(message)," ] } ] } ]");
  2521. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue);
  2522. //free(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);
  2523. }
  2524. LWS_Send(message);
  2525. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2526. if(hashmap_operation(0, guid, tempdata) == 1)
  2527. {
  2528. result = PASS;
  2529. DEBUG_INFO("StopTransaction mapitem pass\n");
  2530. }
  2531. strcpy(queuedata, message);
  2532. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2533. //#ifdef SystemLogMessage
  2534. //DEBUG_INFO(">>>>>StopTransaction request\n");
  2535. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2536. //#endif
  2537. //for test
  2538. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2539. return result;
  2540. }
  2541. int sendMeterValuesRequest(int gun_index)
  2542. {
  2543. mtrace();
  2544. int result = FAIL;
  2545. char message[1500]={0};
  2546. char guid[37]={0};
  2547. int idx_sample=0;
  2548. //int length = 0;
  2549. char tempdata[65]={0};
  2550. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2551. DEBUG_ERROR("gun_index =%d\n",gun_index);
  2552. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2553. {
  2554. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2555. DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2556. DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2557. return result;
  2558. }
  2559. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2560. {
  2561. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2562. }
  2563. //set value
  2564. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2565. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2566. random_uuid(guid);
  2567. sprintf(message,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":"
  2568. ,MESSAGE_TYPE_CALL
  2569. ,guid
  2570. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2571. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId);
  2572. //,comfirmpayload);
  2573. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2574. {
  2575. //allocate memory space
  2576. //ShmOCPP16Data->MeterValues[gun_index].MeterValue = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2577. //UTC Date time
  2578. struct timeval tmnow;
  2579. struct tm *tm;
  2580. char buf[30];//, usec_buf[6];
  2581. gettimeofday(&tmnow, NULL);
  2582. time_t t;
  2583. t = time(NULL);
  2584. /*UTC time and date*/
  2585. tm = gmtime(&t);
  2586. strftime(buf,30,"%Y-%m-%dT%H:%M:%SZ", tm);
  2587. #if 0 // remove temporally
  2588. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2589. strcat(buf,".");
  2590. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2591. strcat(buf,usec_buf);
  2592. #endif
  2593. // printf("%s",buf);
  2594. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp, buf);
  2595. //allocate memory space
  2596. //ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*6);
  2597. sprintf(message + strlen(message),"[{\"timestamp\":\"%s\",\"sampledValue\":[",(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp);
  2598. idx_sample=0;
  2599. //********************************(1)Current.Export************************************************/
  2600. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2601. {
  2602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2603. {
  2604. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2605. {
  2606. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2607. }
  2608. }
  2609. for (int index = 0; index < CCS_QUANTITY; index++)
  2610. {
  2611. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2612. {
  2613. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2614. }
  2615. }
  2616. for (int index = 0; index < GB_QUANTITY; index++)
  2617. {
  2618. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2619. {
  2620. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2621. }
  2622. }
  2623. }
  2624. else
  2625. {
  2626. for (int index = 0; index < AC_QUANTITY; index++)
  2627. {
  2628. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2629. {
  2630. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2631. }
  2632. }
  2633. }// END FOR AC ELSE
  2634. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2635. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2636. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Current_Export]);
  2637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2640. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2641. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2642. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2643. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2644. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2645. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2646. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2647. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2648. );
  2649. #if 0
  2650. idx_sample=1;
  2651. //****************************************************(2)Energy.Active.Export.Register*********************************************/
  2652. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2653. {
  2654. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2655. {
  2656. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2657. {
  2658. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2659. }
  2660. }
  2661. for (int index = 0; index < CCS_QUANTITY; index++)
  2662. {
  2663. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2664. {
  2665. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2666. }
  2667. }
  2668. for (int index = 0; index < GB_QUANTITY; index++)
  2669. {
  2670. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2671. {
  2672. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2673. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2674. }
  2675. }
  2676. }
  2677. else
  2678. {
  2679. for (int index = 0; index < AC_QUANTITY; index++)
  2680. {
  2681. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2682. {
  2683. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2684. }
  2685. }
  2686. }// END FOR AC ELSE
  2687. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2688. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2689. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Register]);
  2690. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2691. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2692. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2693. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2694. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2695. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2696. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2697. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2698. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2699. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2700. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2701. );
  2702. #endif
  2703. idx_sample=1;
  2704. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2705. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2706. {
  2707. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2708. {
  2709. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2710. {
  2711. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2712. }
  2713. }
  2714. for (int index = 0; index < CCS_QUANTITY; index++)
  2715. {
  2716. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2718. {
  2719. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2720. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2721. }
  2722. }
  2723. for (int index = 0; index < GB_QUANTITY; index++)
  2724. {
  2725. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2726. {
  2727. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2728. }
  2729. }
  2730. }
  2731. else
  2732. {
  2733. for (int index = 0; index < AC_QUANTITY; index++)
  2734. {
  2735. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2736. {
  2737. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2738. }
  2739. }
  2740. }//END FOR AC ELSE
  2741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2743. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2744. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2745. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2746. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2747. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2748. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2749. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2750. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2751. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2752. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2753. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2754. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2755. );
  2756. idx_sample=2;
  2757. //********************************(4)Power.Active.Export************************************************/
  2758. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2759. {
  2760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2761. {
  2762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2763. {
  2764. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2765. }
  2766. }
  2767. for (int index = 0; index < CCS_QUANTITY; index++)
  2768. {
  2769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2770. {
  2771. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2772. }
  2773. }
  2774. for (int index = 0; index < GB_QUANTITY; index++)
  2775. {
  2776. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2777. {
  2778. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2779. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2780. }
  2781. }
  2782. }
  2783. else
  2784. {
  2785. for (int index = 0; index < AC_QUANTITY; index++)
  2786. {
  2787. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2788. {
  2789. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2790. }
  2791. }
  2792. }// END FOR AC ELSE
  2793. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Power_Active_Export]);
  2796. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2797. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2798. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2799. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},",
  2800. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2801. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2802. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2803. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2804. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2805. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2806. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2807. );
  2808. idx_sample=3;
  2809. //***********************************************(5)VOLTAGE******************************************************/
  2810. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2811. {
  2812. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2813. {
  2814. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2815. {
  2816. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2817. }
  2818. }
  2819. for (int index = 0; index < CCS_QUANTITY; index++)
  2820. {
  2821. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2822. {
  2823. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2824. }
  2825. }
  2826. for (int index = 0; index < GB_QUANTITY; index++)
  2827. {
  2828. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2829. {
  2830. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2831. }
  2832. }
  2833. }
  2834. else
  2835. {
  2836. for (int index = 0; index < AC_QUANTITY; index++)
  2837. {
  2838. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2839. {
  2840. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2841. }
  2842. }
  2843. }//END FOR AC ELSE
  2844. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2845. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Voltage]);
  2847. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2848. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2849. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2850. sprintf(message + strlen(message),"{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2851. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2852. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2853. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2854. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2855. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2856. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2857. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2858. );
  2859. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2860. {
  2861. idx_sample=4;
  2862. //sampledValue = NULL;
  2863. //***********************************************(6)SOC******************************************************/
  2864. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  2865. {
  2866. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2867. {
  2868. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2869. {
  2870. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2871. }
  2872. }
  2873. for (int index = 0; index < CCS_QUANTITY; index++)
  2874. {
  2875. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2876. {
  2877. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2878. }
  2879. }
  2880. for (int index = 0; index < GB_QUANTITY; index++)
  2881. {
  2882. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2883. {
  2884. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2885. }
  2886. }
  2887. }
  2888. else
  2889. {
  2890. for (int index = 0; index < AC_QUANTITY; index++)
  2891. {
  2892. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2893. {
  2894. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2895. }
  2896. }
  2897. }//END FOR AC ELSE
  2898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2899. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2900. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[SoC]);
  2901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2902. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2904. sprintf(message + strlen(message),",{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}",
  2905. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value,
  2906. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context,
  2907. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format,
  2908. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand,
  2909. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase,
  2910. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location,
  2911. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit
  2912. );
  2913. }
  2914. //}
  2915. sprintf(message + strlen(message)," ] } ] } ]");
  2916. //free(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue);
  2917. }
  2918. LWS_Send(message);
  2919. //memset(mapItem, 0, sizeof(data_struct_t));
  2920. // Put request guid to hash map
  2921. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2922. 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*/)
  2923. {
  2924. result = PASS;
  2925. DEBUG_INFO("MeterValues mapitem pass\n");
  2926. }
  2927. strcpy(queuedata, message);
  2928. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2929. //#ifdef SystemLogMessage
  2930. //DEBUG_INFO(">>>>>MeerValues request\n");
  2931. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2932. //#endif
  2933. return result;
  2934. }
  2935. //==========================================
  2936. // send confirm routine
  2937. //==========================================
  2938. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2939. {
  2940. mtrace();
  2941. int result = FAIL;
  2942. char message[100]={0};
  2943. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2944. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2945. LWS_Send(message);
  2946. result = TRUE;
  2947. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2948. return result;
  2949. }
  2950. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2951. {
  2952. mtrace();
  2953. int result = FAIL;
  2954. char message[100]={0};
  2955. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2956. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2957. LWS_Send(message);
  2958. result = TRUE;
  2959. return result;
  2960. }
  2961. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2962. {
  2963. mtrace();
  2964. int result = FAIL;
  2965. char message[100]={0};
  2966. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\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 sendClearCacheConfirmation(char *uuid,char *payload)
  2973. {
  2974. mtrace();
  2975. int result = FAIL;
  2976. char message[500]={0};
  2977. // int count = 0;
  2978. // int gun_index = 0;
  2979. // char guid[37];
  2980. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2981. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2982. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2983. LWS_Send(message);
  2984. return result;
  2985. }
  2986. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2987. {
  2988. mtrace();
  2989. int result = FAIL;
  2990. char message[500]={0};
  2991. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2992. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2993. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2994. LWS_Send(message);
  2995. return result;
  2996. }
  2997. int sendDataTransferConfirmation(char *uuid,char *payload)
  2998. {
  2999. mtrace();
  3000. char statusStr[20]={0};
  3001. char dataStr[10]={0};
  3002. char sstr[20]={0};
  3003. int c = 0;
  3004. char *loc;
  3005. int result = FAIL;
  3006. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  3007. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  3008. /**********************status**************************/
  3009. loc = strstr(payload, "status");
  3010. memset(sstr ,0, sizeof(sstr) );
  3011. c = 0;
  3012. while (loc[3+strlen("status")+c] != '\"')
  3013. {
  3014. sstr[c] = loc[3+strlen("status")+c];
  3015. c++;
  3016. }
  3017. sstr[c] = '\0';
  3018. strcpy(statusStr, sstr);
  3019. /**********************data**************************/
  3020. loc = strstr(payload, "data");
  3021. memset(sstr ,0, sizeof(sstr) );
  3022. c = 0;
  3023. while (loc[3+strlen("data")+c] != '\"')
  3024. {
  3025. sstr[c] = loc[3+strlen("data")+c];
  3026. c++;
  3027. }
  3028. sstr[c] = '\0';
  3029. strcpy(dataStr, sstr);
  3030. return result;
  3031. }
  3032. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  3033. {
  3034. mtrace();
  3035. int result = FAIL;
  3036. char message[1000]={0};
  3037. double diff_f = 0.0;
  3038. int diff_i = 0;
  3039. struct tm tp;
  3040. DEBUG_ERROR("handle sendGetCompositeScheduleConfirmation ...\n");
  3041. strptime((const char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule, "%Y-%m-%dT%H:%M:%S", &tp);
  3042. tp.tm_isdst = -1;
  3043. time_t utc = mktime(&tp);
  3044. time_t t = time(NULL);
  3045. diff_f = difftime(t, utc);
  3046. diff_i = (int)diff_f;
  3047. DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3048. #if 0 //remove temporally
  3049. 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}"
  3050. ,MESSAGE_TYPE_CALLRESULT
  3051. ,uuid
  3052. ,payload
  3053. ,connectorIdInt
  3054. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3055. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3056. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3057. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3058. #endif
  3059. if(nPeriod == 0)
  3060. {
  3061. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3062. ,MESSAGE_TYPE_CALLRESULT
  3063. ,uuid
  3064. ,payload
  3065. ,connectorIdInt
  3066. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule);
  3067. }
  3068. else
  3069. {
  3070. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3071. ,MESSAGE_TYPE_CALLRESULT
  3072. ,uuid
  3073. ,payload
  3074. ,connectorIdInt
  3075. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3076. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3077. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3078. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3079. //int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3080. #if 1 // remove temporally
  3081. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  3082. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3083. {
  3084. if (idx_sample == 0)
  3085. {
  3086. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3087. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  3088. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3089. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3090. }
  3091. else
  3092. {
  3093. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3094. , (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diff_i /*-1*/)
  3095. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3096. , ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3097. }
  3098. }
  3099. #endif
  3100. sprintf(message + strlen(message), "]}}]");
  3101. }
  3102. LWS_Send(message);
  3103. result = TRUE;
  3104. return result;
  3105. }
  3106. int sendGetConfigurationConfirmation(char *uuid)
  3107. {
  3108. mtrace();
  3109. int result = FAIL;
  3110. int MaxKeySupported = 0;
  3111. int sentConfigurationNumber= 0;
  3112. int sentunConfigurationNumber= 0;
  3113. char message[4000]={0};
  3114. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3115. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3116. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3117. ,MESSAGE_TYPE_CALLRESULT
  3118. ,uuid );
  3119. //configuration key
  3120. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3121. {
  3122. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3123. {
  3124. if (sentConfigurationNumber == 0)
  3125. {
  3126. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3127. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3128. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3129. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3130. }
  3131. else
  3132. {
  3133. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3134. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3135. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3136. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3137. }
  3138. sentConfigurationNumber = sentConfigurationNumber + 1;
  3139. }
  3140. }
  3141. sprintf(message + strlen(message), "]");
  3142. if(UnknownKeynum != 0)
  3143. {
  3144. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3145. //unkown key
  3146. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3147. {
  3148. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3149. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3150. if(sentunConfigurationNumber == 0)
  3151. {
  3152. sprintf(message + strlen(message), "\"%s\""
  3153. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3154. }
  3155. else
  3156. {
  3157. sprintf(message + strlen(message), ",\"%s\""
  3158. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3159. }
  3160. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3161. }
  3162. sprintf(message + strlen(message), "]");
  3163. }
  3164. sprintf(message + strlen(message), "} ]");
  3165. LWS_Send(message);
  3166. #if 0
  3167. printf("error 1-0\n");
  3168. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  3169. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  3170. #endif
  3171. return result;
  3172. }
  3173. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3174. {
  3175. mtrace();
  3176. int result = FAIL;
  3177. char message[400]={0};
  3178. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3179. if(strcmp(payload,"")==0)
  3180. {
  3181. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3182. }
  3183. else
  3184. {
  3185. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3186. }
  3187. LWS_Send(message);
  3188. result = TRUE;
  3189. return result;
  3190. }
  3191. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3192. {
  3193. mtrace();
  3194. int result = FAIL;
  3195. char message[80]={0};
  3196. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3197. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3198. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3199. LWS_Send(message);
  3200. result = TRUE;
  3201. return result;
  3202. }
  3203. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3204. {
  3205. mtrace();
  3206. int result = FAIL;
  3207. char message[80]={0};
  3208. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3209. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3210. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3211. LWS_Send(message);
  3212. result = TRUE;
  3213. return result;
  3214. }
  3215. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3216. {
  3217. mtrace();
  3218. int result = FAIL;
  3219. char message[80]={0};
  3220. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3221. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3222. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3223. LWS_Send(message);
  3224. result = TRUE;
  3225. return result;
  3226. }
  3227. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3228. {
  3229. mtrace();
  3230. int result = FAIL;
  3231. char message[80]={0};
  3232. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3233. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3234. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3235. LWS_Send(message);
  3236. result = TRUE;
  3237. return result;
  3238. }
  3239. int sendResetConfirmation(char *uuid,char *payload)
  3240. {
  3241. mtrace();
  3242. int result = FAIL;
  3243. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3244. char message[80]={0};
  3245. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3246. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3247. LWS_Send(message);
  3248. result = TRUE;
  3249. return result;
  3250. }
  3251. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3252. {
  3253. mtrace();
  3254. int result = FAIL;
  3255. char message[500]={0};
  3256. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3257. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3258. LWS_Send(message);
  3259. result = TRUE;
  3260. return result;
  3261. }
  3262. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3263. {
  3264. mtrace();
  3265. int result = FAIL;
  3266. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3267. char message[80]={0};
  3268. DEBUG_ERROR("handleSetChargingProfileRequest\n");
  3269. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3270. LWS_Send(message);
  3271. result = TRUE;
  3272. return result;
  3273. }
  3274. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3275. {
  3276. mtrace();
  3277. int result = FAIL;
  3278. char message[80]={0};
  3279. DEBUG_ERROR("sendTriggerMessageConfirmation\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 sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3286. {
  3287. mtrace();
  3288. int result = FAIL;
  3289. char message[80]={0};
  3290. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3291. DEBUG_ERROR("sendUnlockConnectorConfirmation\n");
  3292. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3293. LWS_Send(message);
  3294. result = TRUE;
  3295. return result;
  3296. }
  3297. int sendUpdateFirmwareConfirmation(char *uuid)
  3298. {
  3299. mtrace();
  3300. int result = FAIL;
  3301. char message[60]={0};
  3302. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3303. DEBUG_ERROR("sendUpdateFirmwareConfirmation\n");
  3304. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3305. LWS_Send(message);
  3306. result = TRUE;
  3307. return result;
  3308. }
  3309. //==========================================
  3310. // send CallError routine
  3311. //==========================================
  3312. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3313. {
  3314. mtrace();
  3315. //int result = FAIL;
  3316. char message[220]={0};
  3317. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3318. #ifdef SystemLogMessage
  3319. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3320. uniqueId, action, errorCode, errorDescription);
  3321. #endif
  3322. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3323. LWS_Send(message);
  3324. //result = TRUE;
  3325. }
  3326. //==========================================
  3327. // Handle server request routine Start
  3328. //==========================================
  3329. #define GUN_NUM 1
  3330. int handleCancelReservationRequest(char *uuid, char *payload)
  3331. {
  3332. mtrace();
  3333. int result = FAIL;
  3334. int gunNO = 0;
  3335. int reservationIdInt =0;
  3336. char comfirmstr[20];
  3337. int c = 0;
  3338. char *loc;
  3339. char sstr[100]={0};
  3340. DEBUG_INFO("handle CancelReservationRequest\n");
  3341. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3342. c = 0;
  3343. loc = strstr(payload, "reservationId");
  3344. memset(sstr ,0, sizeof(sstr) );
  3345. while (loc[strlen("reservationId")+2+c] != '}')
  3346. {
  3347. sstr[c] = loc[strlen("reservationId")+2+c];
  3348. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3349. c++;
  3350. }
  3351. sstr[c] = '\0';
  3352. reservationIdInt = atoi(sstr);
  3353. memset(comfirmstr, 0, sizeof comfirmstr);
  3354. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3355. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3356. //check Transaction active
  3357. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3358. {
  3359. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3360. {
  3361. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3362. {
  3363. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3364. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3365. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3366. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3367. goto end;
  3368. }
  3369. }
  3370. for (int index = 0; index < CCS_QUANTITY; index++)
  3371. {
  3372. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3373. {
  3374. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3375. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3376. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3377. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3378. goto end;
  3379. }
  3380. }
  3381. for (int index = 0; index < GB_QUANTITY; index++)
  3382. {
  3383. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3384. {
  3385. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3386. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3387. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3388. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3389. goto end;
  3390. }
  3391. }
  3392. }
  3393. else
  3394. {
  3395. for (int index = 0; index < AC_QUANTITY; index++)
  3396. {
  3397. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3398. {
  3399. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3400. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3401. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3402. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3403. goto end;
  3404. }
  3405. }
  3406. }// END FOR AC ELSE
  3407. //The reservationId does NOT match the reservationId
  3408. sendCancelReservationConfirmation(uuid, comfirmstr);
  3409. end:
  3410. // Fill in ocpp packet uuid
  3411. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3412. return result;
  3413. }
  3414. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3415. {
  3416. mtrace();
  3417. int result = FAIL;
  3418. int gunIndex = 0;
  3419. char sstr[90]={0};
  3420. char typeStr[16]={0};
  3421. char comfirmstr[20];
  3422. int specificId = FALSE;
  3423. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3424. char *loc;
  3425. //int intervalInt = 0;
  3426. int c = 0;
  3427. /*** connectorId ****/
  3428. c = 0;
  3429. loc = strstr(payload, "connectorId");
  3430. memset(sstr ,0, sizeof(sstr) );
  3431. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3432. {
  3433. sstr[c] = loc[strlen("connectorId")+2+c];
  3434. c++;
  3435. }
  3436. sstr[c] = '\0';
  3437. gunIndex = atoi(sstr);
  3438. /***type ****/
  3439. loc = strstr(payload, "type");
  3440. memset(sstr ,0, sizeof(sstr) );
  3441. c = 0;
  3442. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3443. {
  3444. sstr[c] = loc[3+strlen("type")+c];
  3445. c++;
  3446. }
  3447. sstr[c] = '\0';
  3448. strcpy(typeStr, sstr);
  3449. if(gunIndex != 0)
  3450. {
  3451. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3452. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3453. }
  3454. else
  3455. {
  3456. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3457. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3458. }
  3459. memset(comfirmstr, 0, sizeof comfirmstr);
  3460. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3461. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3462. {
  3463. specificId = TRUE;
  3464. }
  3465. if(specificId == FALSE)
  3466. goto end;
  3467. if(gunIndex != 0)
  3468. {
  3469. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3470. }
  3471. else
  3472. {
  3473. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3474. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3475. }
  3476. /*
  3477. enum _SYSTEM_STATUS
  3478. {
  3479. S_BOOTING = 0,
  3480. S_IDLE, = 1
  3481. S_AUTHORIZING, =2
  3482. S_REASSIGN_CHECK, =3
  3483. S_REASSIGN, =4
  3484. S_PRECHARGE, =5
  3485. S_PREPARING_FOR_EV, =6
  3486. S_PREPARING_FOR_EVSE, =7
  3487. S_CHARGING, =8
  3488. S_TERMINATING, =9
  3489. S_COMPLETE, =10
  3490. S_ALARM, =11
  3491. S_FAULT =12
  3492. }
  3493. */
  3494. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3495. {
  3496. //check Transaction active
  3497. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3498. {
  3499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3500. {
  3501. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3502. {
  3503. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3504. {
  3505. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3506. }
  3507. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3508. {
  3509. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3510. }
  3511. else
  3512. {
  3513. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3514. }
  3515. goto end;
  3516. }
  3517. }//END FOR CHAdeMO_QUANTITY
  3518. for (int index = 0; index < CCS_QUANTITY; index++)
  3519. {
  3520. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3521. {
  3522. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3523. {
  3524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3525. }
  3526. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3527. {
  3528. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3529. }
  3530. else
  3531. {
  3532. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3533. }
  3534. goto end;
  3535. }
  3536. }//END FOR CCS_QUANTITY
  3537. for (int index = 0; index < GB_QUANTITY; index++)
  3538. {
  3539. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3540. {
  3541. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3542. {
  3543. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3544. }
  3545. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3546. {
  3547. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3548. }
  3549. else
  3550. {
  3551. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3552. }
  3553. goto end;
  3554. }
  3555. }// END FOR GB_QUANTITY
  3556. }
  3557. else
  3558. {
  3559. for (int index = 0; index < AC_QUANTITY; index++)
  3560. {
  3561. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3562. {
  3563. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3564. {
  3565. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3566. }
  3567. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3568. {
  3569. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3570. }
  3571. else
  3572. {
  3573. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3574. }
  3575. goto end;
  3576. }
  3577. }//END FOR AC_QUANTITY
  3578. }// END FOR AC ELSE
  3579. }//END FOR AvailabilityTypeStr[Inoperative]
  3580. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3581. {
  3582. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3583. //check Transaction active
  3584. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  3585. {
  3586. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3587. {
  3588. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3589. {
  3590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3591. goto end;
  3592. }
  3593. }//END FOR CHAdeMO_QUANTITY
  3594. for (int index = 0; index < CCS_QUANTITY; index++)
  3595. {
  3596. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3597. {
  3598. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3599. goto end;
  3600. }
  3601. }//END FOR CCS_QUANTITY
  3602. for (int index = 0; index < GB_QUANTITY; index++)
  3603. {
  3604. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3605. {
  3606. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3607. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3608. goto end;
  3609. }
  3610. }// END FOR GB_QUANTITY
  3611. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3612. }
  3613. else
  3614. {
  3615. for (int index = 0; index < AC_QUANTITY; index++)
  3616. {
  3617. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3618. {
  3619. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3620. goto end;
  3621. }
  3622. }//END FOR CHAdeMO_QUANTITY
  3623. }//END FOR AC ELSE
  3624. }//END FOR AvailabilityTypeStr[Operative]
  3625. end:
  3626. if(gunIndex != 0)
  3627. {
  3628. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3629. }
  3630. else
  3631. {
  3632. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3633. }
  3634. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3635. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3636. return result;
  3637. }
  3638. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3639. {
  3640. mtrace();
  3641. int result = FAIL;
  3642. char sstr[100]={0};
  3643. char keystr[40]={0};
  3644. char valuestr[16]={0};
  3645. char *loc;
  3646. int c = 0;
  3647. char comfirmstr[20];
  3648. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3649. /***key ****/
  3650. loc = strstr(payload, "key");
  3651. memset(sstr ,0, sizeof(sstr) );
  3652. c = 0;
  3653. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3654. {
  3655. sstr[c] = loc[3+strlen("key")+c];
  3656. c++;
  3657. }
  3658. sstr[c] = '\0';
  3659. strcpy(keystr, sstr);
  3660. /***value ****/
  3661. loc = strstr(payload, "value");
  3662. memset(sstr ,0, sizeof(sstr) );
  3663. c = 0;
  3664. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3665. {
  3666. sstr[c] = loc[3+strlen("value")+c];
  3667. c++;
  3668. }
  3669. sstr[c] = '\0';
  3670. strcpy(valuestr, sstr);
  3671. if((uuid==NULL) || (payload ==NULL) )
  3672. {
  3673. #ifdef Debug
  3674. DEBUG_INFO("payload is null\n");
  3675. #endif
  3676. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3677. }
  3678. else
  3679. {
  3680. int status = setKeyValue(keystr, valuestr);
  3681. switch(status)
  3682. {
  3683. case ConfigurationStatus_Accepted:
  3684. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3685. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3686. break;
  3687. case ConfigurationStatus_Rejected:
  3688. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3689. break;
  3690. case RebootRequired:
  3691. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3692. break;
  3693. case NotSupported:
  3694. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3695. break;
  3696. default:
  3697. break;
  3698. }
  3699. }
  3700. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3701. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3702. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3703. return result;
  3704. }
  3705. int handleClearCacheRequest(char *uuid, char *payload)
  3706. {
  3707. mtrace();
  3708. int result = FAIL;
  3709. char comfirmstr[20];
  3710. int fd;
  3711. char rmFileCmd[100]={0};
  3712. struct stat stats;
  3713. DEBUG_ERROR("handle ClearCacheRequest\n");
  3714. stat("../Storage/OCPP", &stats);
  3715. // Check for directory existence
  3716. if (S_ISDIR(stats.st_mode) == 1)
  3717. {
  3718. //DEBUG_ERROR("\n OCPP directory exist \n");
  3719. }
  3720. else
  3721. {
  3722. DEBUG_ERROR("\n OCPP directory not exist, create dir \n");
  3723. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3724. system(rmFileCmd);
  3725. }
  3726. memset(&rmFileCmd, 0, sizeof rmFileCmd);
  3727. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3728. {
  3729. DEBUG_ERROR("AuthorizationCache file exist.\n");
  3730. }
  3731. else
  3732. {
  3733. DEBUG_ERROR("AuthorizationCache file not exist\n");
  3734. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3735. if(log == NULL)
  3736. {
  3737. DEBUG_ERROR("AuthorizationCache file is NULL\n");
  3738. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3739. goto end;
  3740. }
  3741. else
  3742. {
  3743. fclose(log);
  3744. }
  3745. }
  3746. fd = open(AuthorizationCache_JSON,O_RDWR);
  3747. if(fd < 0)
  3748. {
  3749. DEBUG_ERROR("open AuthorizationCache file failed\n");
  3750. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3751. }
  3752. else
  3753. {
  3754. DEBUG_ERROR("open AuthorizationCache file successful\n");
  3755. //* 清空?�件 */
  3756. ftruncate(fd,0);
  3757. //* ?�新设置?�件?�移??*/
  3758. lseek(fd,0,SEEK_SET);
  3759. close(fd);
  3760. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3761. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3762. }
  3763. end:
  3764. sendClearCacheConfirmation(uuid, comfirmstr);
  3765. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3766. return result;
  3767. }
  3768. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3769. {
  3770. mtrace();
  3771. int result = FAIL;
  3772. int resultRename;
  3773. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3774. char chargingProfilePurposeStr[26]={0};
  3775. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3776. char tempchargingProfilePurposeStr[26]={0};
  3777. char sstr[160]={0};//sstr[200]={ 0 };
  3778. char str[100]={0};
  3779. int c = 0;
  3780. //int i = 0;
  3781. //char * pch;
  3782. char *loc;
  3783. char fname[200];
  3784. char comfirmstr[20]={0};
  3785. char word[1000]={0};
  3786. int clearflag = FALSE;
  3787. int chargingProfileIdIsNULL = FALSE;
  3788. int connectorIsNULL = FALSE;
  3789. FILE *fptr1, *fptr2;
  3790. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3791. int n_chargingProfile=0;
  3792. char sLineWord[1060]={0};
  3793. DEBUG_ERROR("handle ClearChargingProfileRequest\n");
  3794. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3795. //***id ****/
  3796. c = 0;
  3797. loc = strstr(payload, "id");
  3798. memset(sstr ,0, sizeof(sstr) );
  3799. if(loc == NULL)
  3800. {
  3801. chargingProfileIdIsNULL = TRUE;
  3802. }
  3803. while ((loc != NULL) &&(loc[strlen("id")+2+c] != ',') )
  3804. {
  3805. sstr[c] = loc[strlen("id")+2+c];
  3806. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3807. c++;
  3808. }
  3809. sstr[c] = '\0';
  3810. chargingProfileIdInt = atoi(sstr);
  3811. //***connectorId ****/
  3812. c=0;
  3813. loc = strstr(payload, "connectorId");
  3814. memset(sstr ,0, sizeof(sstr) );
  3815. if(loc == NULL)
  3816. {
  3817. connectorIsNULL = TRUE;
  3818. }
  3819. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  3820. {
  3821. sstr[c] = loc[strlen("connectorId")+2+c];
  3822. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3823. c++;
  3824. }
  3825. sstr[c] = '\0';
  3826. connectorIdInt = atoi(sstr);
  3827. //***chargingProfilePurpose ****/
  3828. loc = strstr(payload, "chargingProfilePurpose");
  3829. memset(sstr ,0, sizeof(sstr) );
  3830. c = 0;
  3831. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3832. {
  3833. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3834. c++;
  3835. }
  3836. sstr[c] = '\0';
  3837. strcpy(chargingProfilePurposeStr, sstr);
  3838. //***stackLevel ****/
  3839. c=0;
  3840. loc = strstr(payload, "stackLevel");
  3841. memset(sstr ,0, sizeof(sstr) );
  3842. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3843. {
  3844. sstr[c] = loc[strlen("stackLevel")+2+c];
  3845. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3846. c++;
  3847. }
  3848. sstr[c] = '\0';
  3849. stackLevelInt = atoi(sstr);
  3850. if(connectorIsNULL == FALSE)
  3851. {
  3852. switch(connectorIdInt)
  3853. {
  3854. case 0:
  3855. if(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)
  3856. {
  3857. strcpy(fname, ChargePointMaxProfile_JSON);
  3858. }
  3859. else
  3860. {
  3861. strcpy(fname, TxDefaultProfile_0_JSON);
  3862. }
  3863. break;
  3864. case 1:
  3865. if(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)
  3866. {
  3867. strcpy(fname, TxDefaultProfile_1_JSON);
  3868. }
  3869. else
  3870. {
  3871. strcpy(fname, TxProfile_1_JSON);
  3872. }
  3873. break;
  3874. case 2:
  3875. if(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)
  3876. {
  3877. strcpy(fname, TxDefaultProfile_2_JSON);
  3878. }
  3879. else
  3880. {
  3881. strcpy(fname, TxProfile_2_JSON);
  3882. }
  3883. break;
  3884. default:
  3885. strcpy(fname, ChargePointMaxProfile_JSON );
  3886. break;
  3887. }
  3888. }
  3889. else
  3890. {
  3891. strcpy(fname, ChargePointMaxProfile_JSON );
  3892. }
  3893. fptr1 = fopen(fname, "r");
  3894. if (!fptr1)
  3895. {
  3896. //file not exist
  3897. DEBUG_ERROR("Unable to open the input file!!\n");
  3898. fptr1 = fopen(fname, "w+");
  3899. }
  3900. fclose(fptr1);
  3901. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3902. {
  3903. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3904. goto end;
  3905. }
  3906. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3907. {
  3908. //clear the whole contents of a file in C
  3909. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3910. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3911. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3912. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3913. fclose(fopen(TxProfile_1_JSON, "w"));
  3914. fclose(fopen(TxProfile_2_JSON, "w"));
  3915. #if 0
  3916. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3917. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3918. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3919. #endif
  3920. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3921. }
  3922. else
  3923. {
  3924. fptr1 = fopen(fname, "r");
  3925. fptr2 = fopen(temp, "w+");
  3926. while(fscanf(fptr1, "%s", word) != EOF)
  3927. {
  3928. DEBUG_INFO("word=%s\n",word);
  3929. if(strcmp(word, "chargingProfileId") == 0)
  3930. {
  3931. n_chargingProfile = n_chargingProfile + 1;
  3932. printf("Found\n");
  3933. }
  3934. }
  3935. rewind(fptr1);
  3936. //search Charging Profile Element
  3937. //int i= 0;
  3938. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3939. {
  3940. //*************************tempconnectorIdInt*********************************/
  3941. loc = strstr(sLineWord, "connectorId");
  3942. c = 0;
  3943. memset(sstr ,0, sizeof(sstr) );
  3944. while (loc[strlen("connectorId")+2+c] != ',')
  3945. {
  3946. sstr[c] = loc[strlen("connectorId")+2+c];
  3947. c++;
  3948. }
  3949. sstr[c] = '\0';
  3950. tempconnectorIdInt = atoi(sstr);
  3951. //chargingProfileId
  3952. c = 0;
  3953. loc = strstr(sLineWord, "chargingProfileId");
  3954. memset(sstr ,0, sizeof(sstr) );
  3955. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3956. {
  3957. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3958. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3959. c++;
  3960. }
  3961. sstr[c] = '\0';
  3962. tempchargingProfileIdInt = atoi(sstr);
  3963. //stackLevel
  3964. c = 0;
  3965. loc = strstr(sLineWord, "stackLevel");
  3966. memset(sstr ,0, sizeof(sstr) );
  3967. while (loc[strlen("stackLevel")+2+c] != ',')
  3968. {
  3969. sstr[c] = loc[strlen("stackLevel")+2+c];
  3970. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3971. c++;
  3972. }
  3973. sstr[c] = '\0';
  3974. tempstackLevelInt = atoi(sstr);
  3975. c = 0;
  3976. loc = strstr(sLineWord, "chargingProfilePurpose");
  3977. memset(sstr ,0, sizeof(sstr) );
  3978. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3979. {
  3980. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3981. c++;
  3982. }
  3983. sstr[c] = '\0';
  3984. strcpy(tempchargingProfilePurposeStr, sstr);
  3985. if(chargingProfileIdIsNULL == FALSE)
  3986. {
  3987. DEBUG_INFO("\n OCPP clear 0 !!!\n");
  3988. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3989. {
  3990. DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3991. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3992. clearflag = TRUE;
  3993. break;//continue;
  3994. }
  3995. else
  3996. {
  3997. DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3998. //json_object_array_add(newHeatMap, jsonitem);
  3999. fprintf(fptr2, sLineWord);//writing data into file
  4000. }
  4001. }
  4002. else
  4003. {
  4004. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt) && (tempstackLevelInt == stackLevelInt))
  4005. {
  4006. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4007. clearflag = TRUE;
  4008. break;//continue;
  4009. }
  4010. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4011. {
  4012. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4013. clearflag = TRUE;
  4014. break;//continue;
  4015. }
  4016. else
  4017. {
  4018. //json_object_array_add(newHeatMap, jsonitem);
  4019. fprintf(fptr2, sLineWord);//writing data into file
  4020. }
  4021. }
  4022. memset(sLineWord, 0, sizeof sLineWord);
  4023. }
  4024. if(clearflag == FALSE)
  4025. {
  4026. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4027. goto end;
  4028. }
  4029. fclose(fptr1);
  4030. fclose(fptr2);
  4031. sprintf(str,"rm -f %s",fname);
  4032. system(str);
  4033. resultRename = rename(temp, fname);
  4034. if(resultRename == 0)
  4035. {
  4036. DEBUG_ERROR("File ChargingProfile renamed successfully");
  4037. }
  4038. else
  4039. {
  4040. DEBUG_ERROR("Error: unable to rename the ChargingProfile file");
  4041. }
  4042. }
  4043. end:
  4044. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4045. return result;
  4046. }
  4047. int handleDataTransferRequest(char *uuid, char *payload)
  4048. {
  4049. mtrace();
  4050. int result = FAIL;
  4051. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4052. char tempvendorId[255]={0};
  4053. char tempmessageId[50]={0};
  4054. char tempdata[50]={0};
  4055. char sstr[160]={0};//sstr[200]={ 0 };
  4056. char message[80]={0};
  4057. int c = 0;
  4058. char *loc;
  4059. DEBUG_INFO("handle DataTransferRequest\n");
  4060. if((uuid != NULL) && (payload != NULL))
  4061. {
  4062. //===============================
  4063. // vendorId
  4064. //===============================
  4065. c = 0;
  4066. loc = strstr(payload, "vendorId");
  4067. while (loc[strlen("vendorId")+3+c] != '\"')
  4068. {
  4069. sstr[c] = loc[strlen("vendorId")+3+c];
  4070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4071. c++;
  4072. }
  4073. sstr[c] = '\0';
  4074. strcpy(tempvendorId,sstr);
  4075. //===============================
  4076. // messageId
  4077. //===============================
  4078. memset(sstr ,0, sizeof(sstr) );
  4079. c = 0;
  4080. loc = strstr(payload, "messageId");
  4081. while (loc[strlen("messageId")+3+c] != '\"')
  4082. {
  4083. sstr[c] = loc[strlen("messageId")+3+c];
  4084. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4085. c++;
  4086. }
  4087. sstr[c] = '\0';
  4088. strcpy(tempmessageId,sstr);
  4089. //===============================
  4090. // data
  4091. //===============================
  4092. memset(sstr ,0, sizeof(sstr) );
  4093. c = 0;
  4094. loc = strstr(payload, "data");
  4095. printf("loc=%s\n",loc);
  4096. while (loc[strlen("data")+3+c] != '\"')
  4097. {
  4098. sstr[c] = loc[strlen("data")+3+c];
  4099. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4100. c++;
  4101. }
  4102. sstr[c] = '\0';
  4103. strcpy(tempdata,sstr);
  4104. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4105. }
  4106. else
  4107. {
  4108. char guid[37]={0};
  4109. random_uuid(guid);
  4110. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4111. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4112. }
  4113. LWS_Send(message);
  4114. return result;
  4115. }
  4116. #if 0
  4117. long long diff_tm(struct tm *a, struct tm *b) {
  4118. return a->tm_sec - b->tm_sec
  4119. + 60LL * (a->tm_min - b->tm_min)
  4120. + 3600LL * (a->tm_hour - b->tm_hour)
  4121. + 86400LL * (a->tm_yday - b->tm_yday)
  4122. + (a->tm_year - 70) * 31536000LL
  4123. - (a->tm_year - 69) / 4 * 86400LL
  4124. + (a->tm_year - 1) / 100 * 86400LL
  4125. - (a->tm_year + 299) / 400 * 86400LL
  4126. - (b->tm_year - 70) * 31536000LL
  4127. + (b->tm_year - 69) / 4 * 86400LL
  4128. - (b->tm_year - 1) / 100 * 86400LL
  4129. + (b->tm_year + 299) /400 * 86400LL;
  4130. }
  4131. #endif
  4132. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4133. {
  4134. mtrace();
  4135. int result = FAIL;
  4136. int connectorIdInt, durationInt;
  4137. char chargingRateUnitStr[4]={0};
  4138. //int tempconnectorIdInt,
  4139. int tempdurationInt;
  4140. float tempminChargingRateFloat = 0.0;
  4141. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4142. int tempStartPeriodInt=0;
  4143. float tempLimitInt=0.0;//0.1;
  4144. int tempNumberPhasesInt=0;
  4145. char fname[200];
  4146. char comfirmstr[20];
  4147. //float totallimit =0.0;
  4148. float MinChargingRate =0.0;
  4149. double diff_t;
  4150. struct tm tp;
  4151. //int clearflag = FALSE;
  4152. FILE *fptr1;//, *fptr2;
  4153. //char temp[] = "../Storage/OCPP/temp.json";
  4154. int c = 0;
  4155. //int i = 0;
  4156. char * pch;
  4157. char *loc;
  4158. char sstr[200]={ 0 };
  4159. int n_chargingProfile = 0;
  4160. int n_SchedulePeriods = 0;
  4161. char SchedulePeriodList[10][200]={0};
  4162. char sLineWord[800]={0};
  4163. //int n_periods = 0;
  4164. char word[1000]={0};
  4165. int confirmPeriods = 0;
  4166. struct StructProfile ChargePointMaxProfile;
  4167. struct StructProfile TxDefaultProfile;
  4168. struct StructProfile TxProfile;
  4169. struct StructProfile TxDefaultProfiletemp[2]={0};
  4170. int TxDefaultProfileFileIsNull=FALSE;
  4171. int ChargePointMaxProfileIsNull=FALSE;
  4172. int TxProfileIsNull=FALSE;
  4173. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4174. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4175. memset(&TxProfile,0,sizeof(struct StructProfile));
  4176. c=0;
  4177. loc = strstr(payload, "connectorId");
  4178. memset(sstr ,0, sizeof(sstr) );
  4179. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4180. {
  4181. sstr[c] = loc[strlen("connectorId")+2+c];
  4182. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4183. c++;
  4184. }
  4185. sstr[c] = '\0';
  4186. connectorIdInt = atoi(sstr);
  4187. c=0;
  4188. loc = strstr(payload, "duration");
  4189. memset(sstr ,0, sizeof(sstr) );
  4190. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4191. {
  4192. sstr[c] = loc[strlen("duration")+2+c];
  4193. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4194. c++;
  4195. }
  4196. sstr[c] = '\0';
  4197. durationInt = atoi(sstr);
  4198. c = 0;
  4199. loc = strstr(payload, "chargingRateUnit");
  4200. memset(sstr ,0, sizeof(sstr) );
  4201. if(loc == NULL)
  4202. {
  4203. }
  4204. else
  4205. {
  4206. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4207. {
  4208. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4209. c++;
  4210. }
  4211. sstr[c] = '\0';
  4212. strcpy(chargingRateUnitStr, sstr);
  4213. }
  4214. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4215. if(connectorIdInt==0) // connectorId is 0
  4216. {
  4217. //******************************ChargePointMaxProfile*****************************************************/
  4218. strcpy(fname, ChargePointMaxProfile_JSON );
  4219. char word[30]={0};
  4220. char sLineWord[1060]={0};
  4221. int n_chargingProfile=0;
  4222. ChargePointMaxProfileIsNull=TRUE;
  4223. if((access(fname,F_OK))!=-1)
  4224. {
  4225. fptr1 = fopen(fname, "r");
  4226. int c;
  4227. c = fgetc(fptr1);
  4228. //DEBUG_INFO("c:%d\n",c);
  4229. rewind(fptr1);
  4230. if(c == EOF)
  4231. {
  4232. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4233. ChargePointMaxProfileIsNull=TRUE;
  4234. fclose(fptr1);
  4235. }
  4236. else
  4237. {
  4238. ChargePointMaxProfileIsNull=FALSE;
  4239. while(fscanf(fptr1, "%s", word) != EOF)
  4240. {
  4241. if(strcmp(word, "chargingProfileId") == 0)
  4242. {
  4243. n_chargingProfile = n_chargingProfile + 1;
  4244. printf("Found\n");
  4245. }
  4246. }
  4247. rewind(fptr1);
  4248. //search Charging Profile Element
  4249. int i= 0;
  4250. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4251. #if 0
  4252. /***********connectorId****************/
  4253. c = 0;
  4254. loc = strstr(sLineWord, "connectorId");
  4255. // printf("loc=%s\n",loc);
  4256. memset(sstr ,0, sizeof(sstr) );
  4257. while (loc[strlen("connectorId")+2+c] != ',')
  4258. {
  4259. sstr[c] = loc[strlen("connectorId")+2+c];
  4260. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4261. c++;
  4262. }
  4263. sstr[c] = '\0';
  4264. tempconnectorIdInt = atoi(sstr);
  4265. #endif
  4266. //***********validFrom**************/
  4267. c = 0;
  4268. loc = strstr(sLineWord, "validFrom");
  4269. //DEBUG_INFO("loc=%s\n",loc);
  4270. memset(sstr ,0, sizeof(sstr) );
  4271. if(loc != NULL)
  4272. {
  4273. while (loc[3+strlen("validFrom")+c] != '\"')
  4274. {
  4275. sstr[c] = loc[3+strlen("validFrom")+c];
  4276. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4277. c++;
  4278. }
  4279. sstr[c] = '\0';
  4280. DEBUG_INFO("validFrom=%s\n",sstr);
  4281. strcpy(tempvalidFromStr,sstr);
  4282. }
  4283. else
  4284. {
  4285. strcpy(tempvalidFromStr,"");
  4286. }
  4287. //**********startSchedule**********/
  4288. c = 0;
  4289. loc = strstr(sLineWord, "startSchedule");
  4290. //DEBUG_INFO("loc=%s\n",loc);
  4291. memset(sstr ,0, sizeof(sstr) );
  4292. while (loc[3+strlen("startSchedule")+c] != '\"')
  4293. {
  4294. sstr[c] = loc[3+strlen("startSchedule")+c];
  4295. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4296. c++;
  4297. }
  4298. sstr[c] = '\0';
  4299. strcpy(tempstartScheduleStr, sstr);
  4300. //**********startSchedule**********/
  4301. c = 0;
  4302. loc = strstr(sLineWord, "chargingRateUnit");
  4303. memset(sstr ,0, sizeof(sstr) );
  4304. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4305. {
  4306. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4307. c++;
  4308. }
  4309. sstr[c] = '\0';
  4310. strcpy(tempchargingRateUnitStr, sstr);
  4311. //**********minChargingRate*******/
  4312. c = 0;
  4313. loc = strstr(sLineWord, "minChargingRate");
  4314. //printf("loc=%s\n",loc);
  4315. if(loc != NULL)
  4316. {
  4317. memset(sstr ,0, sizeof(sstr) );
  4318. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4319. {
  4320. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4321. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4322. c++;
  4323. }
  4324. sstr[c] = '\0';
  4325. tempminChargingRateFloat = atof(sstr);
  4326. }
  4327. else
  4328. {
  4329. tempminChargingRateFloat = 0.0;
  4330. }
  4331. //
  4332. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4333. tp.tm_isdst = -1;
  4334. time_t utc = mktime(&tp);
  4335. // current time
  4336. time_t t = time(NULL);
  4337. diff_t = difftime(t, utc);
  4338. //parsing strings to words
  4339. i = 0;
  4340. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4341. loc = loc+3+strlen("chargingSchedulePeriod");
  4342. pch = strtok(loc ,"{");
  4343. while (pch != NULL)
  4344. {
  4345. strcpy(SchedulePeriodList[i], pch);
  4346. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4347. //printf ("%s\n",pch);
  4348. pch = strtok (NULL, "{");
  4349. i = i + 1;
  4350. }
  4351. n_SchedulePeriods = i;
  4352. for(int i=0;i<n_SchedulePeriods;i++)
  4353. {
  4354. //*************startPeriod****************/
  4355. c = 0;
  4356. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4357. memset(sstr ,0, sizeof(sstr) );
  4358. while (loc[strlen("startPeriod")+2+c] != ',')
  4359. {
  4360. sstr[c] = loc[strlen("startPeriod")+2+c];
  4361. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4362. c++;
  4363. }
  4364. sstr[c] = '\0';
  4365. tempStartPeriodInt = atoi(sstr);
  4366. //*************limit****************/
  4367. c = 0;
  4368. loc = strstr(SchedulePeriodList[i], "limit");
  4369. memset(sstr ,0, sizeof(sstr) );
  4370. while (loc[strlen("limit")+2+c] != ',')
  4371. {
  4372. sstr[c] = loc[strlen("limit")+2+c];
  4373. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4374. c++;
  4375. }
  4376. sstr[c] = '\0';
  4377. tempLimitInt = atof(sstr);
  4378. //*************numberPhases****************/
  4379. c = 0;
  4380. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4381. memset(sstr ,0, sizeof(sstr) );
  4382. while (loc[strlen("numberPhases")+2+c] != ',')
  4383. {
  4384. sstr[c] = loc[strlen("numberPhases")+2+c];
  4385. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4386. c++;
  4387. }
  4388. sstr[c] = '\0';
  4389. tempNumberPhasesInt = atoi(sstr);
  4390. ChargePointMaxProfile.Duration = durationInt;
  4391. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4392. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4393. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4394. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4395. }
  4396. if(MinChargingRate < tempminChargingRateFloat)
  4397. MinChargingRate = tempminChargingRateFloat;
  4398. }
  4399. }// End of file ChargingProfile
  4400. } //THE END OF ACCESS ChargePointMaxProfile
  4401. //******************************TxDefaultProfile***********************************************/
  4402. strcpy(fname, TxDefaultProfile_0_JSON);
  4403. memset(word, 0, 30);
  4404. memset(sLineWord, 0, 1060);
  4405. //char word[30]={0};
  4406. //char sLineWord[1060]={0};
  4407. n_chargingProfile=0;
  4408. TxDefaultProfileFileIsNull=TRUE;
  4409. if((access(fname,F_OK))!=-1)
  4410. {
  4411. fptr1 = fopen(fname, "r");
  4412. c = 0;
  4413. c = fgetc(fptr1);
  4414. //DEBUG_INFO("c:%d\n",c);
  4415. rewind(fptr1);
  4416. if(c == EOF)
  4417. {
  4418. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4419. TxDefaultProfileFileIsNull=TRUE;
  4420. fclose(fptr1);
  4421. }
  4422. else
  4423. {
  4424. TxDefaultProfileFileIsNull=FALSE;
  4425. while(fscanf(fptr1, "%s", word) != EOF)
  4426. {
  4427. if(strcmp(word, "chargingProfileId") == 0)
  4428. {
  4429. n_chargingProfile = n_chargingProfile + 1;
  4430. printf("Found\n");
  4431. }
  4432. }
  4433. rewind(fptr1);
  4434. //search Charging Profile Element
  4435. int i= 0;
  4436. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4437. #if 0
  4438. /***********connectorId****************/
  4439. c = 0;
  4440. loc = strstr(sLineWord, "connectorId");
  4441. // printf("loc=%s\n",loc);
  4442. memset(sstr ,0, sizeof(sstr) );
  4443. while (loc[strlen("connectorId")+2+c] != ',')
  4444. {
  4445. sstr[c] = loc[strlen("connectorId")+2+c];
  4446. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4447. c++;
  4448. }
  4449. sstr[c] = '\0';
  4450. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4451. tempconnectorIdInt = atoi(sstr);
  4452. #endif
  4453. //***********validFrom**************/
  4454. c = 0;
  4455. loc = strstr(sLineWord, "validFrom");
  4456. //DEBUG_INFO("loc=%s\n",loc);
  4457. memset(sstr ,0, sizeof(sstr) );
  4458. if(loc != NULL)
  4459. {
  4460. while (loc[3+strlen("validFrom")+c] != '\"')
  4461. {
  4462. sstr[c] = loc[3+strlen("validFrom")+c];
  4463. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4464. c++;
  4465. }
  4466. sstr[c] = '\0';
  4467. DEBUG_INFO("validFrom=%s\n",sstr);
  4468. strcpy(tempvalidFromStr,sstr);
  4469. }
  4470. else
  4471. {
  4472. strcpy(tempvalidFromStr,"");
  4473. }
  4474. //**********startSchedule**********/
  4475. c = 0;
  4476. loc = strstr(sLineWord, "startSchedule");
  4477. //DEBUG_INFO("loc=%s\n",loc);
  4478. memset(sstr ,0, sizeof(sstr) );
  4479. while (loc[3+strlen("startSchedule")+c] != '\"')
  4480. {
  4481. sstr[c] = loc[3+strlen("startSchedule")+c];
  4482. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4483. c++;
  4484. }
  4485. sstr[c] = '\0';
  4486. strcpy(tempstartScheduleStr, sstr);
  4487. DEBUG_INFO(" debug 3-1\n");
  4488. //**********startSchedule**********/
  4489. c = 0;
  4490. loc = strstr(sLineWord, "chargingRateUnit");
  4491. memset(sstr ,0, sizeof(sstr) );
  4492. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4493. {
  4494. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4495. c++;
  4496. }
  4497. sstr[c] = '\0';
  4498. strcpy(tempchargingRateUnitStr, sstr);
  4499. //**********minChargingRate*******/
  4500. c = 0;
  4501. loc = strstr(sLineWord, "minChargingRate");
  4502. //printf("loc=%s\n",loc);
  4503. if(loc != NULL)
  4504. {
  4505. memset(sstr ,0, sizeof(sstr) );
  4506. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4507. {
  4508. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4509. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4510. c++;
  4511. }
  4512. sstr[c] = '\0';
  4513. tempminChargingRateFloat = atof(sstr);
  4514. }
  4515. else
  4516. {
  4517. tempminChargingRateFloat = 0.0;
  4518. }
  4519. //
  4520. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4521. tp.tm_isdst = -1;
  4522. time_t utc = mktime(&tp);
  4523. // current time
  4524. time_t t = time(NULL);
  4525. diff_t = difftime(t, utc);
  4526. //parsing strings to words
  4527. i = 0;
  4528. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4529. loc = loc+3+strlen("chargingSchedulePeriod");
  4530. pch = strtok(loc ,"{");
  4531. while (pch != NULL)
  4532. {
  4533. strcpy(SchedulePeriodList[i], pch);
  4534. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4535. //printf ("%s\n",pch);
  4536. pch = strtok (NULL, "{");
  4537. i = i + 1;
  4538. }
  4539. n_SchedulePeriods = i;
  4540. for(int i=0;i<n_SchedulePeriods;i++)
  4541. {
  4542. //*************startPeriod****************/
  4543. c = 0;
  4544. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4545. memset(sstr ,0, sizeof(sstr) );
  4546. while (loc[strlen("startPeriod")+2+c] != ',')
  4547. {
  4548. sstr[c] = loc[strlen("startPeriod")+2+c];
  4549. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4550. c++;
  4551. }
  4552. sstr[c] = '\0';
  4553. tempStartPeriodInt = atoi(sstr);
  4554. //*************limit****************/
  4555. c = 0;
  4556. loc = strstr(SchedulePeriodList[i], "limit");
  4557. memset(sstr ,0, sizeof(sstr) );
  4558. while (loc[strlen("limit")+2+c] != ',')
  4559. {
  4560. sstr[c] = loc[strlen("limit")+2+c];
  4561. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4562. c++;
  4563. }
  4564. sstr[c] = '\0';
  4565. tempLimitInt = atof(sstr);
  4566. //*************numberPhases****************/
  4567. c = 0;
  4568. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4569. memset(sstr ,0, sizeof(sstr) );
  4570. while (loc[strlen("numberPhases")+2+c] != ',')
  4571. {
  4572. sstr[c] = loc[strlen("numberPhases")+2+c];
  4573. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4574. c++;
  4575. }
  4576. sstr[c] = '\0';
  4577. tempNumberPhasesInt = atoi(sstr);
  4578. TxDefaultProfile.Duration = durationInt;
  4579. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4580. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4581. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4582. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4583. }
  4584. if(MinChargingRate < tempminChargingRateFloat)
  4585. MinChargingRate = tempminChargingRateFloat;
  4586. }
  4587. }
  4588. }// the end of ACCESS TxDefaultProfile
  4589. // Composite Schedule
  4590. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4591. {
  4592. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4593. {
  4594. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4595. {
  4596. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4597. }
  4598. else
  4599. {
  4600. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4601. }
  4602. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4603. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4604. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4605. }
  4606. }
  4607. //* Define temporary variables */
  4608. struct tm *gtime;
  4609. time_t now;
  4610. char buf[28];
  4611. /* Read the current system time */
  4612. time(&now);
  4613. /* Convert the system time to GMT (now UTC) */
  4614. gtime = gmtime(&now);
  4615. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4616. // make .conf
  4617. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  4618. //MaxChargingProfilesInstalled is 10
  4619. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4620. memset(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4621. //nPeriod = 1;
  4622. if(chargingRateUnitStr[0] != 0)
  4623. {
  4624. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4625. }
  4626. else
  4627. {
  4628. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, "" );
  4629. }
  4630. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4631. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4632. confirmPeriods = 1;
  4633. }
  4634. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4635. {
  4636. //*****************************ChargePointMaxProfile******************************************/
  4637. strcpy(fname, ChargePointMaxProfile_JSON);
  4638. ChargePointMaxProfileIsNull=TRUE;
  4639. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4640. {
  4641. fptr1 = fopen(fname, "r");
  4642. int c;
  4643. c = fgetc(fptr1);
  4644. //DEBUG_INFO("c:%d\n",c);
  4645. rewind(fptr1);
  4646. if(c == EOF)
  4647. {
  4648. DEBUG_INFO("\n End of file reached.");
  4649. ChargePointMaxProfileIsNull=TRUE;
  4650. fclose(fptr1);
  4651. }
  4652. else
  4653. {
  4654. ChargePointMaxProfileIsNull=FALSE;
  4655. while(fscanf(fptr1, "%s", word) != EOF)
  4656. {
  4657. if(strcmp(word, "chargingProfileId") == 0)
  4658. {
  4659. n_chargingProfile = n_chargingProfile + 1;
  4660. }
  4661. }
  4662. rewind(fptr1);
  4663. //search Charging Profile Element
  4664. int i = 0;
  4665. int j = 0;
  4666. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4667. #if 0
  4668. /***********connectorId****************/
  4669. c = 0;
  4670. loc = strstr(sLineWord, "connectorId");
  4671. memset(sstr ,0, sizeof(sstr) );
  4672. while (loc[strlen("connectorId")+2+c] != ',')
  4673. {
  4674. sstr[c] = loc[strlen("connectorId")+2+c];
  4675. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4676. c++;
  4677. }
  4678. sstr[c] = '\0';
  4679. tempconnectorIdInt = atoi(sstr);
  4680. #endif
  4681. //***********validFrom**************/
  4682. c = 0;
  4683. loc = strstr(sLineWord, "validFrom");
  4684. if(loc != NULL)
  4685. {
  4686. memset(sstr ,0, sizeof(sstr) );
  4687. while (loc[3+strlen("validFrom")+c] != '\"')
  4688. {
  4689. sstr[c] = loc[3+strlen("validFrom")+c];
  4690. c++;
  4691. }
  4692. sstr[c] = '\0';
  4693. strcpy(tempvalidFromStr,sstr);
  4694. }
  4695. else
  4696. {
  4697. strcpy(tempvalidFromStr,"");
  4698. }
  4699. //***********validFrom**************/
  4700. c = 0;
  4701. loc = strstr(sLineWord, "duration");
  4702. if(loc != NULL)
  4703. {
  4704. memset(sstr ,0, sizeof(sstr) );
  4705. while (loc[2+strlen("duration")+c] != ',')
  4706. {
  4707. sstr[c] = loc[2+strlen("duration")+c];
  4708. c++;
  4709. }
  4710. sstr[c] = '\0';
  4711. tempdurationInt = atoi(sstr);
  4712. }
  4713. else
  4714. {
  4715. tempdurationInt = 0;
  4716. }
  4717. //**********startSchedule**********/
  4718. c = 0;
  4719. loc = strstr(sLineWord, "startSchedule");
  4720. memset(sstr ,0, sizeof(sstr) );
  4721. while (loc[3+strlen("startSchedule")+c] != '\"')
  4722. {
  4723. sstr[c] = loc[3+strlen("startSchedule")+c];
  4724. c++;
  4725. }
  4726. sstr[c] = '\0';
  4727. strcpy(tempstartScheduleStr, sstr);
  4728. //**********startSchedule**********/
  4729. c = 0;
  4730. loc = strstr(sLineWord, "chargingRateUnit");
  4731. memset(sstr ,0, sizeof(sstr) );
  4732. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4733. {
  4734. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4735. c++;
  4736. }
  4737. sstr[c] = '\0';
  4738. strcpy(tempchargingRateUnitStr, sstr);
  4739. //**********minChargingRate*******/
  4740. c = 0;
  4741. loc = strstr(sLineWord, "minChargingRate");
  4742. if(loc != NULL)
  4743. {
  4744. memset(sstr ,0, sizeof(sstr) );
  4745. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4746. {
  4747. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4748. c++;
  4749. }
  4750. sstr[c] = '\0';
  4751. tempminChargingRateFloat = atof(sstr);
  4752. }
  4753. else
  4754. {
  4755. tempminChargingRateFloat = 0.0;
  4756. }
  4757. //
  4758. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4759. tp.tm_isdst = -1;
  4760. time_t utc = mktime(&tp);
  4761. time_t t = time(NULL);
  4762. diff_t = difftime(t, utc);
  4763. DEBUG_INFO("diff_t=%f\n",diff_t);
  4764. DEBUG_INFO(" debug 5 -1\n");
  4765. //parsing strings to words
  4766. i = 0;
  4767. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4768. loc = loc+3+strlen("chargingSchedulePeriod");
  4769. pch = strtok(loc ,"{");
  4770. while (pch != NULL)
  4771. {
  4772. strcpy(SchedulePeriodList[i], pch);
  4773. pch = strtok (NULL, "{");
  4774. i = i + 1;
  4775. }
  4776. n_SchedulePeriods = i;
  4777. for(int i=0;i<n_SchedulePeriods;i++)
  4778. {
  4779. //*************startPeriod****************/
  4780. c = 0;
  4781. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4782. memset(sstr ,0, sizeof(sstr) );
  4783. while (loc[strlen("startPeriod")+2+c] != ',')
  4784. {
  4785. sstr[c] = loc[strlen("startPeriod")+2+c];
  4786. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4787. c++;
  4788. }
  4789. sstr[c] = '\0';
  4790. tempStartPeriodInt = atoi(sstr);
  4791. //*************limit****************/
  4792. c = 0;
  4793. loc = strstr(SchedulePeriodList[i], "limit");
  4794. memset(sstr ,0, sizeof(sstr) );
  4795. while (loc[strlen("limit")+2+c] != ',')
  4796. {
  4797. sstr[c] = loc[strlen("limit")+2+c];
  4798. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4799. c++;
  4800. }
  4801. sstr[c] = '\0';
  4802. tempLimitInt = atof(sstr);
  4803. //*************numberPhases****************/
  4804. c = 0;
  4805. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4806. memset(sstr ,0, sizeof(sstr) );
  4807. while (loc[strlen("numberPhases")+2+c] != '}')
  4808. {
  4809. sstr[c] = loc[strlen("numberPhases")+2+c];
  4810. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4811. c++;
  4812. }
  4813. sstr[c] = '\0';
  4814. tempNumberPhasesInt = atoi(sstr);
  4815. if(j == 0)
  4816. {
  4817. ChargePointMaxProfile.Duration = tempdurationInt;
  4818. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4819. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4820. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4821. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4822. }
  4823. }
  4824. if(MinChargingRate < tempminChargingRateFloat)
  4825. {
  4826. MinChargingRate = tempminChargingRateFloat;
  4827. }
  4828. if(confirmPeriods < n_SchedulePeriods)
  4829. {
  4830. confirmPeriods = n_SchedulePeriods;
  4831. }
  4832. j = j + 1;
  4833. }
  4834. fclose(fptr1);
  4835. }
  4836. }// the end of access file ChargePointMaxProfile
  4837. //****************************TxDefaultProfile************************************************/
  4838. switch(connectorIdInt)
  4839. {
  4840. case 0:
  4841. break;
  4842. case 1:
  4843. strcpy(fname, TxDefaultProfile_1_JSON );
  4844. break;
  4845. case 2:
  4846. strcpy(fname, TxDefaultProfile_2_JSON );
  4847. break;
  4848. default:
  4849. strcpy(fname, TxDefaultProfile_1_JSON );
  4850. break;
  4851. }
  4852. TxDefaultProfileFileIsNull=TRUE;
  4853. if((access(fname,F_OK))!=-1)
  4854. {
  4855. fptr1 = fopen(fname, "r");
  4856. c = 0;
  4857. c = fgetc(fptr1);
  4858. //DEBUG_INFO("c:%d\n",c);
  4859. rewind(fptr1);
  4860. if(c == EOF)
  4861. {
  4862. DEBUG_INFO("\n End of file reached.");
  4863. TxDefaultProfileFileIsNull=TRUE;
  4864. fclose(fptr1);
  4865. }
  4866. else
  4867. {
  4868. TxDefaultProfileFileIsNull=FALSE;
  4869. while(fscanf(fptr1, "%s", word) != EOF)
  4870. {
  4871. if(strcmp(word, "chargingProfileId") == 0)
  4872. {
  4873. n_chargingProfile = n_chargingProfile + 1;
  4874. }
  4875. }
  4876. rewind(fptr1);
  4877. //search Charging Profile Element
  4878. int i = 0;
  4879. int j = 0;
  4880. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4881. #if 0
  4882. /***********connectorId****************/
  4883. c = 0;
  4884. loc = strstr(sLineWord, "connectorId");
  4885. memset(sstr ,0, sizeof(sstr) );
  4886. while (loc[strlen("connectorId")+2+c] != ',')
  4887. {
  4888. sstr[c] = loc[strlen("connectorId")+2+c];
  4889. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4890. c++;
  4891. }
  4892. sstr[c] = '\0';
  4893. tempconnectorIdInt = atoi(sstr);
  4894. #endif
  4895. //***********validFrom**************/
  4896. c = 0;
  4897. loc = strstr(sLineWord, "validFrom");
  4898. if(loc != NULL)
  4899. {
  4900. memset(sstr ,0, sizeof(sstr) );
  4901. while (loc[3+strlen("validFrom")+c] != '\"')
  4902. {
  4903. sstr[c] = loc[3+strlen("validFrom")+c];
  4904. c++;
  4905. }
  4906. sstr[c] = '\0';
  4907. strcpy(tempvalidFromStr,sstr);
  4908. }
  4909. else
  4910. {
  4911. strcpy(tempvalidFromStr,"");
  4912. }
  4913. //***********validFrom**************/
  4914. c = 0;
  4915. loc = strstr(sLineWord, "duration");
  4916. if(loc != NULL)
  4917. {
  4918. memset(sstr ,0, sizeof(sstr) );
  4919. while (loc[2+strlen("duration")+c] != ',')
  4920. {
  4921. sstr[c] = loc[2+strlen("duration")+c];
  4922. c++;
  4923. }
  4924. sstr[c] = '\0';
  4925. tempdurationInt = atoi(sstr);
  4926. }
  4927. else
  4928. {
  4929. tempdurationInt = 0;
  4930. }
  4931. //**********startSchedule**********/
  4932. c = 0;
  4933. loc = strstr(sLineWord, "startSchedule");
  4934. memset(sstr ,0, sizeof(sstr) );
  4935. while (loc[3+strlen("startSchedule")+c] != '\"')
  4936. {
  4937. sstr[c] = loc[3+strlen("startSchedule")+c];
  4938. c++;
  4939. }
  4940. sstr[c] = '\0';
  4941. strcpy(tempstartScheduleStr, sstr);
  4942. //**********startSchedule**********/
  4943. c = 0;
  4944. loc = strstr(sLineWord, "chargingRateUnit");
  4945. memset(sstr ,0, sizeof(sstr) );
  4946. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4947. {
  4948. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4949. c++;
  4950. }
  4951. sstr[c] = '\0';
  4952. strcpy(tempchargingRateUnitStr, sstr);
  4953. //**********minChargingRate*******/
  4954. c = 0;
  4955. loc = strstr(sLineWord, "minChargingRate");
  4956. if(loc != NULL)
  4957. {
  4958. memset(sstr ,0, sizeof(sstr) );
  4959. while (loc[3+strlen("minChargingRate")+c] != '\"')
  4960. {
  4961. sstr[c] = loc[3+strlen("minChargingRate")+c];
  4962. c++;
  4963. }
  4964. sstr[c] = '\0';
  4965. tempminChargingRateFloat = atof(sstr);
  4966. }
  4967. else
  4968. {
  4969. tempminChargingRateFloat = 0.0;
  4970. }
  4971. //
  4972. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4973. tp.tm_isdst = -1;
  4974. time_t utc = mktime(&tp);
  4975. time_t t = time(NULL);
  4976. diff_t = difftime(t, utc);
  4977. DEBUG_INFO("diff_t=%f\n",diff_t);
  4978. DEBUG_INFO(" debug 5 -1\n");
  4979. //parsing strings to words
  4980. i = 0;
  4981. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4982. loc = loc+3+strlen("chargingSchedulePeriod");
  4983. pch = strtok(loc ,"{");
  4984. while (pch != NULL)
  4985. {
  4986. strcpy(SchedulePeriodList[i], pch);
  4987. pch = strtok (NULL, "{");
  4988. i = i + 1;
  4989. }
  4990. n_SchedulePeriods = i;
  4991. for(int i=0;i<n_SchedulePeriods;i++)
  4992. {
  4993. //*************startPeriod****************/
  4994. c = 0;
  4995. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4996. memset(sstr ,0, sizeof(sstr) );
  4997. while (loc[strlen("startPeriod")+2+c] != ',')
  4998. {
  4999. sstr[c] = loc[strlen("startPeriod")+2+c];
  5000. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5001. c++;
  5002. }
  5003. sstr[c] = '\0';
  5004. tempStartPeriodInt = atoi(sstr);
  5005. //*************limit****************/
  5006. c = 0;
  5007. loc = strstr(SchedulePeriodList[i], "limit");
  5008. memset(sstr ,0, sizeof(sstr) );
  5009. while (loc[strlen("limit")+2+c] != ',')
  5010. {
  5011. sstr[c] = loc[strlen("limit")+2+c];
  5012. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5013. c++;
  5014. }
  5015. sstr[c] = '\0';
  5016. tempLimitInt = atof(sstr);
  5017. //*************numberPhases****************/
  5018. c = 0;
  5019. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5020. memset(sstr ,0, sizeof(sstr) );
  5021. while (loc[strlen("numberPhases")+2+c] != '}')
  5022. {
  5023. sstr[c] = loc[strlen("numberPhases")+2+c];
  5024. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5025. c++;
  5026. }
  5027. sstr[c] = '\0';
  5028. tempNumberPhasesInt = atoi(sstr);
  5029. if(j == 0)
  5030. {
  5031. TxDefaultProfile.Duration = tempdurationInt;
  5032. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5033. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5034. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5035. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5036. }
  5037. else
  5038. {
  5039. //other stack level charging Profile
  5040. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5041. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5042. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5043. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5044. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5045. }
  5046. }
  5047. if(MinChargingRate < tempminChargingRateFloat)
  5048. MinChargingRate = tempminChargingRateFloat;
  5049. if(confirmPeriods < n_SchedulePeriods)
  5050. confirmPeriods = n_SchedulePeriods;
  5051. j = j + 1;
  5052. }
  5053. fclose(fptr1);
  5054. //Stacking Charging Profiles
  5055. for(int l=0; l <(j-1) ;l++)
  5056. {
  5057. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5058. {
  5059. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5060. {
  5061. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5062. {
  5063. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5064. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5065. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5066. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5067. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5068. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5069. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5070. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5071. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5072. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5073. }
  5074. else
  5075. {
  5076. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5077. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5078. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5079. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5080. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5081. }
  5082. }
  5083. }
  5084. }
  5085. //end of Stacking Charging Profiles
  5086. }
  5087. }// the end of ACCESS TxDefaultProfile
  5088. //****************************TxProfile************************************************/
  5089. switch(connectorIdInt)
  5090. {
  5091. case 0:
  5092. break;
  5093. case 1:
  5094. strcpy(fname, TxProfile_1_JSON );
  5095. break;
  5096. case 2:
  5097. strcpy(fname, TxProfile_2_JSON );
  5098. break;
  5099. default:
  5100. strcpy(fname, TxProfile_1_JSON );
  5101. break;
  5102. }
  5103. TxProfileIsNull=TRUE;
  5104. if((access(fname,F_OK))!=-1)
  5105. {
  5106. fptr1 = fopen(fname, "r");
  5107. c = 0;
  5108. c = fgetc(fptr1);
  5109. //DEBUG_INFO("c:%d\n",c);
  5110. rewind(fptr1);
  5111. if(c == EOF)
  5112. {
  5113. DEBUG_INFO("\n End of file reached.");
  5114. TxProfileIsNull=TRUE;
  5115. fclose(fptr1);
  5116. }
  5117. else
  5118. {
  5119. TxProfileIsNull=FALSE;
  5120. while(fscanf(fptr1, "%s", word) != EOF)
  5121. {
  5122. if(strcmp(word, "chargingProfileId") == 0)
  5123. {
  5124. n_chargingProfile = n_chargingProfile + 1;
  5125. }
  5126. }
  5127. rewind(fptr1);
  5128. //search Charging Profile Element
  5129. int i= 0;
  5130. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5131. #if 0
  5132. /***********connectorId****************/
  5133. c = 0;
  5134. loc = strstr(sLineWord, "connectorId");
  5135. memset(sstr ,0, sizeof(sstr) );
  5136. while (loc[strlen("connectorId")+2+c] != ',')
  5137. {
  5138. sstr[c] = loc[strlen("connectorId")+2+c];
  5139. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5140. c++;
  5141. }
  5142. sstr[c] = '\0';
  5143. tempconnectorIdInt = atoi(sstr);
  5144. #endif
  5145. //***********validFrom**************/
  5146. c = 0;
  5147. loc = strstr(sLineWord, "validFrom");
  5148. if(loc != NULL)
  5149. {
  5150. memset(sstr ,0, sizeof(sstr) );
  5151. while (loc[3+strlen("validFrom")+c] != '\"')
  5152. {
  5153. sstr[c] = loc[3+strlen("validFrom")+c];
  5154. c++;
  5155. }
  5156. sstr[c] = '\0';
  5157. strcpy(tempvalidFromStr,sstr);
  5158. }
  5159. else
  5160. {
  5161. strcpy(tempvalidFromStr,"");
  5162. }
  5163. //**********startSchedule**********/
  5164. c = 0;
  5165. loc = strstr(sLineWord, "startSchedule");
  5166. memset(sstr ,0, sizeof(sstr) );
  5167. while (loc[3+strlen("startSchedule")+c] != '\"')
  5168. {
  5169. sstr[c] = loc[3+strlen("startSchedule")+c];
  5170. c++;
  5171. }
  5172. sstr[c] = '\0';
  5173. strcpy(tempstartScheduleStr, sstr);
  5174. //**********startSchedule**********/
  5175. c = 0;
  5176. loc = strstr(sLineWord, "chargingRateUnit");
  5177. memset(sstr ,0, sizeof(sstr) );
  5178. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5179. {
  5180. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5181. c++;
  5182. }
  5183. sstr[c] = '\0';
  5184. strcpy(tempchargingRateUnitStr, sstr);
  5185. //**********minChargingRate*******/
  5186. c = 0;
  5187. loc = strstr(sLineWord, "minChargingRate");
  5188. if(loc != NULL)
  5189. {
  5190. memset(sstr ,0, sizeof(sstr) );
  5191. while (loc[3+strlen("minChargingRate")+c] != '\"')
  5192. {
  5193. sstr[c] = loc[3+strlen("minChargingRate")+c];
  5194. c++;
  5195. }
  5196. sstr[c] = '\0';
  5197. tempminChargingRateFloat = atof(sstr);
  5198. }
  5199. else
  5200. {
  5201. tempminChargingRateFloat = 0.0;
  5202. }
  5203. //
  5204. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5205. tp.tm_isdst = -1;
  5206. time_t utc = mktime(&tp);
  5207. time_t t = time(NULL);
  5208. diff_t = difftime(t, utc);
  5209. DEBUG_INFO("diff_t=%f\n",diff_t);
  5210. //parsing strings to words
  5211. i = 0;
  5212. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5213. loc = loc+3+strlen("chargingSchedulePeriod");
  5214. pch = strtok(loc ,"{");
  5215. while (pch != NULL)
  5216. {
  5217. strcpy(SchedulePeriodList[i], pch);
  5218. pch = strtok (NULL, "{");
  5219. i = i + 1;
  5220. }
  5221. n_SchedulePeriods = i;
  5222. for(int i=0;i<n_SchedulePeriods;i++)
  5223. {
  5224. //*************startPeriod****************/
  5225. c = 0;
  5226. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5227. memset(sstr ,0, sizeof(sstr) );
  5228. while (loc[strlen("startPeriod")+2+c] != ',')
  5229. {
  5230. sstr[c] = loc[strlen("startPeriod")+2+c];
  5231. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5232. c++;
  5233. }
  5234. sstr[c] = '\0';
  5235. tempStartPeriodInt = atoi(sstr);
  5236. //*************limit****************/
  5237. c = 0;
  5238. loc = strstr(SchedulePeriodList[i], "limit");
  5239. memset(sstr ,0, sizeof(sstr) );
  5240. while (loc[strlen("limit")+2+c] != ',')
  5241. {
  5242. sstr[c] = loc[strlen("limit")+2+c];
  5243. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5244. c++;
  5245. }
  5246. sstr[c] = '\0';
  5247. tempLimitInt = atof(sstr);
  5248. //*************numberPhases****************/
  5249. c = 0;
  5250. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5251. memset(sstr ,0, sizeof(sstr) );
  5252. while (loc[strlen("numberPhases")+2+c] != '}')
  5253. {
  5254. sstr[c] = loc[strlen("numberPhases")+2+c];
  5255. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5256. c++;
  5257. }
  5258. sstr[c] = '\0';
  5259. tempNumberPhasesInt = atoi(sstr);
  5260. TxProfile.Duration = durationInt;
  5261. TxProfile.TotalPeriod = n_SchedulePeriods;
  5262. TxProfile.Period[i].Limit = tempLimitInt;
  5263. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5264. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5265. }
  5266. if(MinChargingRate < tempminChargingRateFloat)
  5267. MinChargingRate = tempminChargingRateFloat;
  5268. if(confirmPeriods < n_SchedulePeriods)
  5269. confirmPeriods = n_SchedulePeriods;
  5270. }
  5271. fclose(fptr1);
  5272. }
  5273. }// the end of ACCESS TxProfile
  5274. //CompositeSchedule
  5275. int period=0;
  5276. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5277. {
  5278. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5279. {
  5280. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5281. {
  5282. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5283. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5284. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5285. period = period + 1;
  5286. }
  5287. else
  5288. {
  5289. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5290. {
  5291. }
  5292. else
  5293. {
  5294. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5295. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5296. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5297. period = period + 1;
  5298. }
  5299. }
  5300. }
  5301. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5302. {
  5303. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5304. {
  5305. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5306. {
  5307. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5308. }
  5309. else
  5310. {
  5311. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5312. }
  5313. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5314. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5315. period = period + 1;
  5316. }
  5317. }
  5318. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5319. {
  5320. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5321. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5322. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5323. period = period + 1;
  5324. }
  5325. }
  5326. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5327. {
  5328. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5329. {
  5330. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5331. {
  5332. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5333. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5334. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5335. period = period + 1;
  5336. }
  5337. else
  5338. {
  5339. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5340. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5341. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5342. period = period + 1;
  5343. }
  5344. }
  5345. }
  5346. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5347. {
  5348. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5349. {
  5350. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].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. confirmPeriods = period;
  5357. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5358. //* Define temporary variables */
  5359. struct tm *gtime;
  5360. time_t now;
  5361. char buf[28];
  5362. //* Read the current system time */
  5363. time(&now);
  5364. //* Convert the system time to GMT (now UTC) */
  5365. gtime = gmtime(&now);
  5366. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5367. // make .conf
  5368. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  5369. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = durationInt;
  5370. //DEBUG_INFO(" debug 11\n");
  5371. // if(chargingRateUnitStr[0] != 0)
  5372. // {
  5373. // strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  5374. // }
  5375. // else
  5376. {
  5377. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5378. }
  5379. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5380. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5381. }
  5382. else
  5383. {
  5384. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5385. }
  5386. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5387. return result;
  5388. }
  5389. int handleGetConfigurationRequest(char *uuid, char *payload)
  5390. {
  5391. mtrace();
  5392. int result = FAIL;
  5393. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5394. //struct json_object *jsonitem;
  5395. int MaxKeySupported = 0;
  5396. int n_keys = 0;
  5397. char requestKey[43][50]={0};
  5398. char search[]="[";
  5399. char sstr[500]={ 0 };
  5400. //int pos;
  5401. int l, c = 0;
  5402. int i = 0;
  5403. char *delim = "\",\"";
  5404. char * pch;
  5405. char *loc = strstr(payload, search);
  5406. //********************* Parsing String ***********************************/
  5407. if(loc == NULL) {
  5408. DEBUG_INFO("no key match in Configuration \n");
  5409. }
  5410. else {
  5411. //pos = loc - payload;
  5412. l = strlen(loc)-4;
  5413. while (c < l)
  5414. {
  5415. sstr[c] = loc[c+2];
  5416. c++;
  5417. }
  5418. sstr[c] = '\0';
  5419. //parsing strings to words
  5420. pch = strtok(sstr,delim);
  5421. if(pch == NULL)
  5422. {
  5423. strcpy(requestKey[0], sstr);
  5424. }
  5425. else
  5426. {
  5427. while (pch != NULL)
  5428. {
  5429. strcpy(requestKey[i], pch);
  5430. pch = strtok (NULL, delim);
  5431. i = i + 1;
  5432. }
  5433. n_keys = i;
  5434. }
  5435. }
  5436. UnknownKeynum = 0;
  5437. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5438. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5439. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5440. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5441. if(n_keys != 0)
  5442. {
  5443. for(int i=0;i<n_keys;i++)
  5444. {
  5445. getKeyValue(requestKey[i]);
  5446. //json_object_put(jsonitem);
  5447. }
  5448. }
  5449. else
  5450. {
  5451. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5452. getKeyValue("");
  5453. }
  5454. processUnkownKey();
  5455. sendGetConfigurationConfirmation(uuid);
  5456. return result;
  5457. }
  5458. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5459. {
  5460. mtrace();
  5461. int result = FAIL;
  5462. //void *ret; //
  5463. char fnamePlusPath[50]="";
  5464. char fname[16]="";
  5465. pthread_t t; // pthread 變數
  5466. time_t rawtime;
  5467. struct tm * timeinfo;
  5468. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5469. system("exec /root/logPackTools 'log' 6");
  5470. //char buffer [128];
  5471. time (&rawtime);
  5472. //printf("%ld\n", rawtime);
  5473. timeinfo = localtime (&rawtime);
  5474. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5475. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5476. if((access(fnamePlusPath,F_OK))!=-1)
  5477. {
  5478. DEBUG_INFO("fnamePlusPath exist.\n");
  5479. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5480. }
  5481. else
  5482. {
  5483. DEBUG_INFO("fnamePlusPath not exist!\n");
  5484. }
  5485. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5486. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5487. pthread_join(t, NULL/*&ret*/);
  5488. return result;
  5489. }
  5490. void* GetDiagnosticsProcess(void* data)
  5491. {
  5492. mtrace();
  5493. int retriesInt=0, retryIntervalInt=0;
  5494. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5495. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5496. char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
  5497. int port=0;
  5498. char fnamePlusPath[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  5499. char fname[16]="";
  5500. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5501. int c = 0;
  5502. char *loc;
  5503. int isSuccess = FALSE;
  5504. char ftpbuf[200]={0};
  5505. //char temp[100]={0};
  5506. char * pch;
  5507. // [2,"137d88c7-a403-4ead-bb2d-fc6ec90531c1","GetDiagnostics",{"location":"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/","retries":0,"retryInterval":0,"startTime":"0001-01-01T00:00:00.000Z","stopTime":"0001-01-01T00:00:00.000Z"}]
  5508. char *str = (char*) data; // ?��?輸入資�?
  5509. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5510. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest 1\n");
  5511. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5512. //****************location*******************/
  5513. c = 0;
  5514. memset(sstr ,0, sizeof(sstr) );
  5515. loc = strstr(str, "location");
  5516. while (loc[3+strlen("location")+c] != '\"')
  5517. {
  5518. sstr[c] = loc[3+strlen("location")+c];
  5519. c++;
  5520. }
  5521. sstr[c] = '\0';
  5522. strcpy(locationstr,sstr);
  5523. if(strcmp(locationstr,"")==0)
  5524. {
  5525. DEBUG_INFO("location is <Empty>!\n");
  5526. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5527. goto end;
  5528. }
  5529. //****************retries*******************/
  5530. c = 0;
  5531. loc = strstr(str, "retries");
  5532. if(loc == NULL)
  5533. {
  5534. retriesIsNULL = TRUE;
  5535. }
  5536. else
  5537. {
  5538. while (loc[strlen("retries")+2+c] != ',')
  5539. {
  5540. sstr[c] = loc[strlen("retries")+2+c];
  5541. c++;
  5542. }
  5543. sstr[c] = '\0';
  5544. retriesInt = atoi(sstr);
  5545. }
  5546. if(retriesIsNULL == TRUE)
  5547. {
  5548. retriesInt = 0;
  5549. }
  5550. //****************retryInterval*******************/
  5551. c = 0;
  5552. loc = strstr(str, "retryInterval");
  5553. if(loc == NULL)
  5554. {
  5555. retryIntervalIsNULL = TRUE;
  5556. }
  5557. else
  5558. {
  5559. while (loc[strlen("retryInterval")+2+c] != ',')
  5560. {
  5561. sstr[c] = loc[strlen("retryInterval")+2+c];
  5562. c++;
  5563. }
  5564. sstr[c] = '\0';
  5565. retryIntervalInt = atoi(sstr);
  5566. }
  5567. //****************startTime*******************/
  5568. c = 0;
  5569. memset(sstr ,0, sizeof(sstr) );
  5570. loc = strstr(str, "startTime");
  5571. if(loc == NULL)
  5572. {
  5573. startTimeIsNULL = TRUE;
  5574. }
  5575. else
  5576. {
  5577. while (loc[3+strlen("startTime")+c] != '\"')
  5578. {
  5579. sstr[c] = loc[3+strlen("startTime")+c];
  5580. c++;
  5581. }
  5582. sstr[c] = '\0';
  5583. strcpy(startTimestr,sstr);
  5584. }
  5585. //****************stopTime*******************/
  5586. c = 0;
  5587. memset(sstr ,0, sizeof(sstr) );
  5588. loc = strstr(str, "stopTime");
  5589. if(loc == NULL)
  5590. {
  5591. stopTimeIsNULL = TRUE;
  5592. }
  5593. else
  5594. {
  5595. while (loc[3+strlen("stopTime")+c] != '\"')
  5596. {
  5597. sstr[c] = loc[3+strlen("stopTime")+c];
  5598. c++;
  5599. }
  5600. sstr[c] = '\0';
  5601. strcpy(stopTimestr,sstr);
  5602. }
  5603. memset(protocol, 0, sizeof(protocol));
  5604. memset(user, 0, sizeof(user) );
  5605. memset(password, 0, sizeof(password));
  5606. memset(host, 0, sizeof(host));
  5607. memset(path, 0, sizeof(path));
  5608. memset(ftppath, 0, sizeof(ftppath));
  5609. memset(host1, 0, sizeof(host1));
  5610. memset(path1, 0, sizeof(path1));
  5611. /*location: ftp://user:password@host:port/path*/
  5612. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  5613. // protocol, user, password, host, &port, path);
  5614. #if 0 // remove for temporally
  5615. //zip files in /Storage
  5616. system("exec /root/logPackTools 'log' 6");
  5617. #endif
  5618. // system("exec /root/Module_WebService 'log' 6");
  5619. time_t rawtime;
  5620. struct tm * timeinfo;
  5621. //char buffer [128];
  5622. time (&rawtime);
  5623. //printf("%ld\n", rawtime);
  5624. timeinfo = localtime (&rawtime);
  5625. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5626. strftime (fname,sizeof(fname),"%4Y-%2m.zip",timeinfo);
  5627. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5628. if((access(fnamePlusPath,F_OK))!=-1)
  5629. {
  5630. DEBUG_INFO("fnamePlusPath exist.\n");
  5631. }
  5632. else
  5633. {
  5634. DEBUG_INFO("fnamePlusPath not exist!\n");
  5635. goto end;
  5636. }
  5637. pch=strchr(locationstr,'@');
  5638. if(pch==NULL)
  5639. {
  5640. sscanf(locationstr,
  5641. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5642. protocol, host, &port, path);
  5643. strcpy(user,"anonymous");
  5644. strcpy(password,"");
  5645. }
  5646. else
  5647. {
  5648. DEBUG_INFO("pch=%s\n", pch);
  5649. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5650. protocol, user, password, host, &port, path);
  5651. }
  5652. if(strcmp(protocol,"ftp")!=0)
  5653. {
  5654. DEBUG_INFO("protocol is not ftp!\n");
  5655. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5656. goto end;
  5657. }
  5658. sscanf(host,"%[^/]%s",host1, path1);
  5659. sprintf(ftppath,"%s", path1);
  5660. DEBUG_INFO("protocol =%s\n",protocol);
  5661. DEBUG_INFO("user =%s\n",user);
  5662. DEBUG_INFO("password =%s\n",password);
  5663. DEBUG_INFO("host1 =%s\n",host1);
  5664. DEBUG_INFO("port =%d\n",port);
  5665. DEBUG_INFO("path1 =%s\n",path1);
  5666. DEBUG_INFO("ftppath=%s\n",ftppath);
  5667. int ftppathlen=strlen(ftppath);
  5668. int i=1;
  5669. char filenametemp[50];
  5670. while(i < ftppathlen)
  5671. {
  5672. int len=ftppathlen-i;
  5673. if(ftppath[len]== 47) // '/' ascll code: 47
  5674. {
  5675. DEBUG_INFO("find '/' all right\n");
  5676. break;
  5677. }
  5678. i=i+1;
  5679. }
  5680. memset(filenametemp, 0, sizeof(filenametemp));
  5681. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5682. filenametemp[i+1] = 0;
  5683. //httpDownLoadFile(host, ftppath, fname);
  5684. memset(ftpbuf, 0, sizeof(ftpbuf));
  5685. if(port == 0)
  5686. port = 21;
  5687. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  5688. do{
  5689. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5690. sleep(retryIntervalInt);
  5691. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5692. if(!isSuccess)
  5693. {
  5694. //BulldogUtil.sleepMs(interval*1000);
  5695. DEBUG_INFO("Diagnostics fail.\n");
  5696. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5697. }
  5698. else
  5699. {
  5700. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5701. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5702. //isUpdateRequest = TRUE;
  5703. }
  5704. end:
  5705. // json_object_put(obj);
  5706. DiagnosticsStatusNotificationStatus = 0; //Idle
  5707. pthread_exit(NULL/*(void *) fname*/); // ?��?子執行�?
  5708. }
  5709. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5710. {
  5711. mtrace();
  5712. int result = FAIL;
  5713. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5714. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5715. {
  5716. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5717. localversion = -1;
  5718. }
  5719. else
  5720. {
  5721. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5722. OCPP_getListVerion();
  5723. }
  5724. //from db.OCPP_getListVerion
  5725. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5726. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5727. sendGetLocalListVersionConfirmation(uuid,"");
  5728. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5729. return result;
  5730. }
  5731. int handleRemoteStartRequest(char *uuid, char *payload)
  5732. {
  5733. mtrace();
  5734. int result = FAIL;
  5735. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5736. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5737. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5738. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5739. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5740. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5741. int chargingSchedulePeriodCount = 0;
  5742. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5743. int c = 0;
  5744. char *loc;
  5745. char comfirmstr[20]={0};
  5746. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5747. if(server_pending == TRUE)
  5748. {
  5749. return 0;
  5750. }
  5751. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5752. //**********connectorId****************/
  5753. c = 0;
  5754. memset(sstr ,0, sizeof(sstr) );
  5755. loc = strstr(payload, "connectorId");
  5756. if(loc == NULL)
  5757. {
  5758. connectorIdIsNULL = TRUE;
  5759. }
  5760. else
  5761. {
  5762. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5763. {
  5764. sstr[c] = loc[strlen("connectorId")+2+c];
  5765. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5766. c++;
  5767. }
  5768. sstr[c] = '\0';
  5769. connectorIdInt = atoi(sstr);
  5770. }
  5771. if(connectorIdIsNULL == TRUE) // need to discussion
  5772. {
  5773. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5774. goto end;
  5775. }
  5776. //****************idTag*******************/
  5777. c = 0;
  5778. memset(sstr ,0, sizeof(sstr) );
  5779. loc = strstr(payload, "idTag");
  5780. while (loc[3+strlen("idTag")+c] != '\"')
  5781. {
  5782. sstr[c] = loc[3+strlen("idTag")+c];
  5783. c++;
  5784. }
  5785. sstr[c] = '\0';
  5786. strcpy(idTagstr,sstr);
  5787. //****************chargingProfile*******************/
  5788. c = 0;
  5789. memset(sstr ,0, sizeof(sstr) );
  5790. loc = strstr(payload, "chargingProfile");
  5791. if(loc == NULL)
  5792. {
  5793. chargingProfileIsNULL = TRUE;
  5794. }
  5795. else
  5796. {
  5797. //****************chargingProfileId*******************/
  5798. c=0;
  5799. loc = strstr(payload, "chargingProfileId");
  5800. memset(sstr ,0, sizeof(sstr) );
  5801. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5802. {
  5803. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5804. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5805. c++;
  5806. }
  5807. sstr[c] = '\0';
  5808. chargingProfileIdInt = atoi(sstr);
  5809. //****************transactionId*******************/
  5810. loc = strstr(payload, "transactionId");
  5811. if(loc == NULL)
  5812. {
  5813. transactionIdIsNULL = TRUE;
  5814. }
  5815. else
  5816. {
  5817. c=0;
  5818. memset(sstr ,0, sizeof(sstr) );
  5819. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5820. {
  5821. sstr[c] = loc[strlen("transactionId")+2+c];
  5822. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5823. c++;
  5824. }
  5825. sstr[c] = '\0';
  5826. transactionIdInt = atoi(sstr);
  5827. }
  5828. //****************stackLevel*******************/
  5829. c=0;
  5830. loc = strstr(payload, "stackLevel");
  5831. memset(sstr ,0, sizeof(sstr) );
  5832. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5833. {
  5834. sstr[c] = loc[strlen("stackLevel")+2+c];
  5835. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5836. c++;
  5837. }
  5838. sstr[c] = '\0';
  5839. stackLevelInt = atoi(sstr);
  5840. //****************chargingProfilePurpose*******************/
  5841. c = 0;
  5842. memset(sstr ,0, sizeof(sstr) );
  5843. loc = strstr(payload, "chargingProfilePurpose");
  5844. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5845. {
  5846. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5847. c++;
  5848. }
  5849. sstr[c] = '\0';
  5850. strcpy(chargingProfilePurposestr,sstr);
  5851. //****************chargingProfileKind*******************/
  5852. c = 0;
  5853. memset(sstr ,0, sizeof(sstr) );
  5854. loc = strstr(payload, "chargingProfileKind");
  5855. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5856. {
  5857. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5858. c++;
  5859. }
  5860. sstr[c] = '\0';
  5861. strcpy(chargingProfileKindstr,sstr);
  5862. //****************recurrencyKind*******************/
  5863. loc = strstr(payload, "recurrencyKind");
  5864. if(loc == NULL)
  5865. {
  5866. recurrencyKindIsNULL = TRUE;
  5867. }
  5868. else
  5869. {
  5870. c = 0;
  5871. memset(sstr ,0, sizeof(sstr) );
  5872. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5873. {
  5874. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5875. c++;
  5876. }
  5877. sstr[c] = '\0';
  5878. strcpy(recurrencyKindstr,sstr);
  5879. }
  5880. //****************validFrom*******************/
  5881. loc = strstr(payload, "validFrom");
  5882. if(loc == NULL)
  5883. {
  5884. validFromIsNULL = TRUE;
  5885. }
  5886. else
  5887. {
  5888. c = 0;
  5889. memset(sstr ,0, sizeof(sstr) );
  5890. while (loc[3+strlen("validFrom")+c] != '\"')
  5891. {
  5892. sstr[c] = loc[3+strlen("validFrom")+c];
  5893. c++;
  5894. }
  5895. sstr[c] = '\0';
  5896. strcpy(validFromstr,sstr);
  5897. }
  5898. //****************validTo*******************/
  5899. loc = strstr(payload, "validTo");
  5900. if(loc == NULL)
  5901. {
  5902. validToIsNULL = TRUE;
  5903. }
  5904. else
  5905. {
  5906. c = 0;
  5907. memset(sstr ,0, sizeof(sstr) );
  5908. while (loc[3+strlen("validTo")+c] != '\"')
  5909. {
  5910. sstr[c] = loc[3+strlen("validTo")+c];
  5911. c++;
  5912. }
  5913. sstr[c] = '\0';
  5914. strcpy(validTostr,sstr);
  5915. }
  5916. //****************chargingSchedule*******************/
  5917. loc = strstr(payload, "chargingSchedule");
  5918. if(loc != NULL)
  5919. {
  5920. //****************duration*******************/
  5921. loc = strstr(payload, "duration");
  5922. if(loc == NULL)
  5923. {
  5924. durationIsNULL = TRUE;
  5925. }
  5926. else
  5927. {
  5928. c=0;
  5929. memset(sstr ,0, sizeof(sstr) );
  5930. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5931. {
  5932. sstr[c] = loc[strlen("duration")+2+c];
  5933. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5934. c++;
  5935. }
  5936. sstr[c] = '\0';
  5937. durationInt = atoi(sstr);
  5938. }
  5939. //****************startSchedule******************/
  5940. loc = strstr(payload, "startSchedule");
  5941. if(loc == NULL)
  5942. {
  5943. startScheduleIsNULL = TRUE;
  5944. }
  5945. else
  5946. {
  5947. c = 0;
  5948. memset(sstr ,0, sizeof(sstr) );
  5949. while (loc[3+strlen("startSchedule")+c] != '\"')
  5950. {
  5951. sstr[c] = loc[3+strlen("startSchedule")+c];
  5952. c++;
  5953. }
  5954. sstr[c] = '\0';
  5955. strcpy(startSchedulestr,sstr);
  5956. }
  5957. //****************chargingRateUnit*******************/
  5958. c = 0;
  5959. memset(sstr ,0, sizeof(sstr) );
  5960. loc = strstr(payload, "chargingRateUnit");
  5961. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5962. {
  5963. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5964. c++;
  5965. }
  5966. sstr[c] = '\0';
  5967. strcpy(chargingRateUnitstr,sstr);
  5968. //****************minChargingRate*******************/
  5969. loc = strstr(payload, "minChargingRate");
  5970. if(loc == NULL)
  5971. {
  5972. minChargingRateIsNULL = TRUE;
  5973. }
  5974. else
  5975. {
  5976. c=0;
  5977. memset(sstr ,0, sizeof(sstr) );
  5978. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5979. {
  5980. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5981. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5982. c++;
  5983. }
  5984. sstr[c] = '\0';
  5985. minChargingRateflaot = atof(sstr);
  5986. }
  5987. //****************chargingSchedulePeriod count*******************/
  5988. int what_len = strlen("startPeriod");
  5989. char *where = payload;
  5990. while ((where = strstr(where, "startPeriod"))) {
  5991. where += what_len;
  5992. chargingSchedulePeriodCount++;
  5993. }
  5994. where = payload;
  5995. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5996. {
  5997. //****************startPeriod*******************/
  5998. c=0;
  5999. loc = strstr(where, "startPeriod");
  6000. memset(sstr ,0, sizeof(sstr) );
  6001. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6002. {
  6003. sstr[c] = loc[strlen("startPeriod")+2+c];
  6004. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6005. c++;
  6006. }
  6007. sstr[c] = '\0';
  6008. startPeriodInt[periodNums] = atoi(sstr);
  6009. //****************limit*******************/
  6010. c=0;
  6011. loc = strstr(where, "limit");
  6012. memset(sstr ,0, sizeof(sstr) );
  6013. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6014. {
  6015. sstr[c] = loc[strlen("limit")+2+c];
  6016. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6017. c++;
  6018. }
  6019. sstr[c] = '\0';
  6020. limitflaot[periodNums] = atof(sstr);
  6021. //****************numberPhases*******************/
  6022. loc = strstr(where, "numberPhases");
  6023. if(loc == NULL)
  6024. {
  6025. numberPhasesIsNULL = TRUE;
  6026. }
  6027. else
  6028. {
  6029. c=0;
  6030. memset(sstr ,0, sizeof(sstr) );
  6031. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6032. {
  6033. sstr[c] = loc[strlen("numberPhases")+2+c];
  6034. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6035. c++;
  6036. }
  6037. sstr[c] = '\0';
  6038. numberPhasesInt[periodNums] = atoi(sstr);
  6039. }
  6040. where = loc;
  6041. }
  6042. }
  6043. }
  6044. /*
  6045. enum _SYSTEM_STATUS
  6046. {
  6047. S_BOOTING = 0,
  6048. S_IDLE, = 1
  6049. S_AUTHORIZING, =2
  6050. S_REASSIGN_CHECK, =3
  6051. S_REASSIGN, =4
  6052. S_PRECHARGE, =5
  6053. S_PREPARING_FOR_EV, =6
  6054. S_PREPARING_FOR_EVSE, =7
  6055. S_CHARGING, =8
  6056. S_TERMINATING, =9
  6057. S_COMPLETE, =10
  6058. S_ALARM, =11
  6059. S_FAULT =12
  6060. }
  6061. */
  6062. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6063. {
  6064. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6065. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6066. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6067. //check Transaction active
  6068. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6069. {
  6070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6071. {
  6072. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6073. {
  6074. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6075. {
  6076. //Reserved
  6077. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6078. }
  6079. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6080. {
  6081. //Reserved
  6082. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6083. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6084. goto end;
  6085. }
  6086. else
  6087. {
  6088. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6089. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6090. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6091. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6092. {
  6093. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6094. goto end;
  6095. }
  6096. }//END FOR ELSE
  6097. }
  6098. }// END FOR CHAdeMO_QUANTITY
  6099. for (int index = 0; index < CCS_QUANTITY; index++)
  6100. {
  6101. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6102. {
  6103. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6104. {
  6105. //Reserved
  6106. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6107. }
  6108. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6109. {
  6110. //Reserved
  6111. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6112. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6113. goto end;
  6114. }
  6115. else
  6116. {
  6117. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6118. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6119. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6120. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6121. {
  6122. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6123. goto end;
  6124. }
  6125. }// END FOR ELSE
  6126. }
  6127. }// END FOR CCS_QUANTITY
  6128. for (int index = 0; index < GB_QUANTITY; index++)
  6129. {
  6130. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6131. {
  6132. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6133. {
  6134. //Reserved
  6135. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6136. }
  6137. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6138. {
  6139. //Reserved
  6140. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6141. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6142. goto end;
  6143. }
  6144. else
  6145. {
  6146. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6147. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6148. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6149. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6150. {
  6151. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6152. goto end;
  6153. }
  6154. }// END FOR ELSE
  6155. }
  6156. } // END FOR GB_QUANTITY
  6157. }
  6158. else
  6159. {
  6160. for (int index = 0; index < AC_QUANTITY; index++)
  6161. {
  6162. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6163. {
  6164. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6165. {
  6166. //Reserved
  6167. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6168. }
  6169. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6170. {
  6171. //Reserved
  6172. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6173. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6174. goto end;
  6175. }
  6176. else
  6177. {
  6178. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6179. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6180. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6181. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6182. {
  6183. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6184. goto end;
  6185. }
  6186. }//END FOR ELSE
  6187. }
  6188. }// END FOR AC_QUANTITY
  6189. }
  6190. if(chargingProfileIsNULL == FALSE)
  6191. {
  6192. //ChargingProfile
  6193. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6194. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6195. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6196. if(recurrencyKindIsNULL == FALSE) //OPTION
  6197. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6198. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6199. if(transactionIdIsNULL == FALSE) // OPTION
  6200. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6201. if(validFromIsNULL == FALSE) // OPTION
  6202. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6203. if(validToIsNULL == FALSE) //OPTION
  6204. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6205. //ChargingSchedule
  6206. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6207. if(durationIsNULL == FALSE) //OPTION
  6208. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6209. if(minChargingRateIsNULL == FALSE) //OPTION
  6210. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6211. if(startScheduleIsNULL == FALSE) //OPTION
  6212. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6213. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6214. {
  6215. //ChargingSchedulePeriod
  6216. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6217. if(numberPhasesIsNULL == FALSE)
  6218. {
  6219. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6220. }
  6221. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6222. }
  6223. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6224. {
  6225. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6226. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6227. }
  6228. else
  6229. {
  6230. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6231. }
  6232. }
  6233. else
  6234. {
  6235. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6236. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6237. }
  6238. }
  6239. else
  6240. {
  6241. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6242. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6243. }
  6244. end:
  6245. if(connectorIdIsNULL == FALSE)
  6246. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6247. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6248. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6249. //OCPP send RemoteStartConfirmation by first.
  6250. sendRemoteStartConfirmation(uuid, comfirmstr);
  6251. return result;
  6252. }
  6253. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6254. {
  6255. mtrace();
  6256. int result = FAIL;
  6257. int match = FALSE;
  6258. int GunNO = 0;
  6259. int transactionIdInt=0;
  6260. int transactionIdIsNULL= FALSE;
  6261. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6262. int c = 0;
  6263. char *loc;
  6264. char comfirmstr[20];
  6265. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6266. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6267. if(server_pending == TRUE)
  6268. {
  6269. return 0;
  6270. }
  6271. c=0;
  6272. loc = strstr(payload, "transactionId");
  6273. if(loc == NULL)
  6274. {
  6275. transactionIdIsNULL= TRUE;
  6276. }
  6277. else
  6278. {
  6279. memset(sstr ,0, sizeof(sstr) );
  6280. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6281. {
  6282. sstr[c] = loc[strlen("transactionId")+2+c];
  6283. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6284. c++;
  6285. }
  6286. sstr[c] = '\0';
  6287. transactionIdInt = atoi(sstr);
  6288. }
  6289. if(transactionIdIsNULL == FALSE)
  6290. {
  6291. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6292. {
  6293. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6294. {
  6295. //check Transaction active
  6296. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6297. {
  6298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6299. {
  6300. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6301. {
  6302. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6303. {
  6304. match = TRUE;
  6305. GunNO = gun_index;
  6306. }
  6307. }
  6308. }// END FOR CHAdeMO_QUANTITY
  6309. for (int index = 0; index < CCS_QUANTITY; index++)
  6310. {
  6311. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6312. {
  6313. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6314. {
  6315. match = TRUE;
  6316. GunNO = gun_index;
  6317. }
  6318. }
  6319. }// END FOR CCS_QUANTITY
  6320. for (int index = 0; index < GB_QUANTITY; index++)
  6321. {
  6322. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6323. {
  6324. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6325. {
  6326. match = TRUE;
  6327. GunNO = gun_index;
  6328. }
  6329. }
  6330. }// END FOR GB_QUANTITY
  6331. }
  6332. else
  6333. {
  6334. for (int index = 0; index < AC_QUANTITY; index++)
  6335. {
  6336. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6337. {
  6338. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6339. {
  6340. match = TRUE;
  6341. GunNO = gun_index;
  6342. }
  6343. }
  6344. }// END FOR CHAdeMO_QUANTITY
  6345. }// END FOR AC ELSE
  6346. }// CHECK IF ResponseTransactionId == transactionIdInt
  6347. }//END FOR
  6348. if( match == TRUE)
  6349. {
  6350. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6351. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6352. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6353. }
  6354. else
  6355. {
  6356. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6357. }
  6358. }
  6359. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6360. return result;
  6361. }
  6362. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6363. {
  6364. mtrace();
  6365. int result = FAIL;
  6366. int connectorIdInt=0, reservationIdInt=0;
  6367. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6368. char comfirmstr[20]={0};
  6369. char sstr[180]={ 0 };
  6370. int c = 0;
  6371. char *loc;
  6372. //char *ptr;
  6373. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6374. //***(1)connectorId ****/
  6375. c=0;
  6376. loc = strstr(payload, "connectorId");
  6377. memset(sstr ,0, sizeof(sstr) );
  6378. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6379. {
  6380. sstr[c] = loc[strlen("connectorId")+2+c];
  6381. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6382. c++;
  6383. }
  6384. sstr[c] = '\0';
  6385. connectorIdInt = atoi(sstr);
  6386. //***(2)expiryDate ****/
  6387. loc = strstr(payload, "expiryDate");
  6388. memset(sstr ,0, sizeof(sstr) );
  6389. c = 0;
  6390. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6391. {
  6392. sstr[c] = loc[3+strlen("expiryDate")+c];
  6393. c++;
  6394. }
  6395. sstr[c] = '\0';
  6396. strcpy(expiryDatestr, sstr);
  6397. //***(3)idTag ****/
  6398. loc = strstr(payload, "idTag");
  6399. memset(sstr ,0, sizeof(sstr) );
  6400. c = 0;
  6401. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6402. {
  6403. sstr[c] = loc[3+strlen("idTag")+c];
  6404. c++;
  6405. }
  6406. sstr[c] = '\0';
  6407. strcpy(idTagstr, sstr);
  6408. //***(4)parentIdTag ****/
  6409. loc = strstr(payload, "parentIdTag");
  6410. memset(sstr ,0, sizeof(sstr) );
  6411. c = 0;
  6412. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6413. {
  6414. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6415. c++;
  6416. }
  6417. sstr[c] = '\0';
  6418. strcpy(parentIdTagstr, sstr);
  6419. //***(5)reservationId ****/
  6420. c=0;
  6421. loc = strstr(payload, "reservationId");
  6422. memset(sstr ,0, sizeof(sstr) );
  6423. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6424. {
  6425. sstr[c] = loc[strlen("reservationId")+2+c];
  6426. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6427. c++;
  6428. }
  6429. sstr[c] = '\0';
  6430. reservationIdInt = atoi(sstr);
  6431. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6432. /*
  6433. enum _SYSTEM_STATUS
  6434. {
  6435. S_BOOTING = 0,
  6436. S_IDLE, = 1
  6437. S_AUTHORIZING, =2
  6438. S_REASSIGN_CHECK, =3
  6439. S_REASSIGN, =4
  6440. S_PRECHARGE, =5
  6441. S_PREPARING_FOR_EV, =6
  6442. S_PREPARING_FOR_EVSE, =7
  6443. S_CHARGING, =8
  6444. S_TERMINATING, =9
  6445. S_COMPLETE, =10
  6446. S_ALARM, =11
  6447. S_FAULT =12
  6448. }
  6449. */
  6450. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6451. {
  6452. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6453. goto end;
  6454. }
  6455. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6456. {
  6457. //check Transaction active
  6458. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6459. {
  6460. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6461. {
  6462. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6463. {
  6464. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6465. {
  6466. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6467. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6468. {
  6469. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6470. {
  6471. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6472. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6473. }
  6474. 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'))
  6475. {
  6476. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6477. }
  6478. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6479. {
  6480. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6481. }
  6482. else
  6483. {
  6484. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6485. }
  6486. }
  6487. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6488. {
  6489. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6490. }
  6491. }
  6492. else
  6493. {
  6494. //replace reservation
  6495. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6496. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6497. }
  6498. }
  6499. } // END FOR CHAdeMO_QUANTITY
  6500. for (int index = 0; index < CCS_QUANTITY; index++)
  6501. {
  6502. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6503. {
  6504. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6505. {
  6506. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6507. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6508. {
  6509. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6510. {
  6511. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6512. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6513. }
  6514. 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'))
  6515. {
  6516. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6517. }
  6518. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6519. {
  6520. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6521. }
  6522. else
  6523. {
  6524. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6525. }
  6526. }
  6527. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6528. {
  6529. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6530. }
  6531. }
  6532. else
  6533. {
  6534. //replace reservation
  6535. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6536. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6537. }
  6538. }
  6539. } // END FOR CCS_QUANTITY
  6540. for (int index = 0; index < GB_QUANTITY; index++)
  6541. {
  6542. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6543. {
  6544. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6545. {
  6546. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6547. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6548. {
  6549. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6550. {
  6551. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6552. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6553. }
  6554. 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'))
  6555. {
  6556. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6557. }
  6558. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6559. {
  6560. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6561. }
  6562. else
  6563. {
  6564. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6565. }
  6566. }
  6567. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6568. {
  6569. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6570. }
  6571. }
  6572. else
  6573. {
  6574. //replace reservation
  6575. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6577. }
  6578. }
  6579. }// END FOR GB_QUANTITY
  6580. }
  6581. else
  6582. {
  6583. for (int index = 0; index < AC_QUANTITY; index++)
  6584. {
  6585. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6586. {
  6587. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6588. {
  6589. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6590. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6591. {
  6592. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6593. {
  6594. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6596. }
  6597. 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'))
  6598. {
  6599. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6600. }
  6601. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6602. {
  6603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6604. }
  6605. else
  6606. {
  6607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6608. }
  6609. }
  6610. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6611. {
  6612. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6613. }
  6614. }
  6615. else
  6616. {
  6617. //replace reservation
  6618. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6619. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6620. }
  6621. }
  6622. } // END FOR AC_QUANTITY
  6623. }//END FOR AC ELSE
  6624. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6625. }
  6626. else if(connectorIdInt == 0)
  6627. {
  6628. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6629. {
  6630. //check Transaction active
  6631. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6632. {
  6633. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6634. {
  6635. 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'))
  6636. {
  6637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6638. goto end;
  6639. }
  6640. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6641. {
  6642. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6643. goto end;
  6644. }
  6645. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6646. {
  6647. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6648. goto end;
  6649. }
  6650. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6651. {
  6652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6653. goto end;
  6654. }
  6655. }
  6656. }// END FOR CHAdeMO_QUANTITY
  6657. for (int index = 0; index < CCS_QUANTITY; index++)
  6658. {
  6659. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6660. {
  6661. 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'))
  6662. {
  6663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6664. }
  6665. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6666. {
  6667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6668. }
  6669. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6670. {
  6671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6672. }
  6673. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6674. {
  6675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6676. }
  6677. }
  6678. } // END FOR CCS_QUANTITY
  6679. for (int index = 0; index < GB_QUANTITY; index++)
  6680. {
  6681. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6682. {
  6683. 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'))
  6684. {
  6685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6686. }
  6687. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6688. {
  6689. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6690. }
  6691. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6692. {
  6693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6694. }
  6695. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6696. {
  6697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6698. }
  6699. }
  6700. } // END FOR GB_QUANTITY
  6701. }
  6702. else
  6703. {
  6704. for (int index = 0; index < AC_QUANTITY; index++)
  6705. {
  6706. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6707. {
  6708. 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'))
  6709. {
  6710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6711. goto end;
  6712. }
  6713. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6714. {
  6715. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6716. goto end;
  6717. }
  6718. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6719. {
  6720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6721. goto end;
  6722. }
  6723. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6724. {
  6725. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6726. goto end;
  6727. }
  6728. }
  6729. }// END FOR AC_QUANTITY
  6730. }
  6731. //The connectorId is 0
  6732. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6733. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6734. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6735. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6736. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6737. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6738. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6739. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6740. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6741. result = TRUE;
  6742. return result;
  6743. }
  6744. else
  6745. {
  6746. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6747. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6748. }
  6749. if(strcmp(comfirmstr,"Accepted") == 0)
  6750. {
  6751. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6752. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6753. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6754. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6755. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6756. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6757. result = TRUE;
  6758. return result;
  6759. }
  6760. end:
  6761. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6762. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6763. return result;
  6764. }
  6765. int handleResetRequest(char *uuid, char *payload)
  6766. {
  6767. mtrace();
  6768. int result = FAIL;
  6769. char sstr[10]={0};
  6770. char typestr[10]={0};
  6771. char comfirmstr[20]={0};
  6772. int c = 0;
  6773. char *loc;
  6774. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6775. DEBUG_INFO("handleResetRequest ...\n");
  6776. loc = strstr(payload, "type");
  6777. memset(sstr ,0, sizeof(sstr) );
  6778. c = 0;
  6779. while (loc[3+strlen("type")+c] != '\"')
  6780. {
  6781. sstr[c] = loc[3+strlen("type")+c];
  6782. c++;
  6783. }
  6784. sstr[c] = '\0';
  6785. strcpy(typestr,sstr);
  6786. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6787. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6788. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6789. {
  6790. //check Transaction active
  6791. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6792. {
  6793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6794. {
  6795. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6796. {
  6797. //0: unplug, 1: Plug-in
  6798. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6799. }
  6800. }
  6801. for (int index = 0; index < CCS_QUANTITY; index++)
  6802. {
  6803. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6804. {
  6805. //0: unplug, 1: Plug-in
  6806. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6807. }
  6808. }
  6809. for (int index = 0; index < GB_QUANTITY; index++)
  6810. {
  6811. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6812. {
  6813. //0: unplug, 1: Plug-in
  6814. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6815. }
  6816. }
  6817. }
  6818. else
  6819. {
  6820. for (int index = 0; index < AC_QUANTITY; index++)
  6821. {
  6822. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6823. {
  6824. //0: unplug, 1: Plug-in
  6825. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6826. }
  6827. }
  6828. }// END FOR AC ELSE
  6829. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6830. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6831. result = TRUE;
  6832. return result;
  6833. }
  6834. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6835. {
  6836. //check Transaction active
  6837. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6838. {
  6839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6840. {
  6841. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6842. {
  6843. //0: unplug, 1: Plug-in
  6844. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6845. }
  6846. }
  6847. for (int index = 0; index < CCS_QUANTITY; index++)
  6848. {
  6849. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6850. {
  6851. //0: unplug, 1: Plug-in
  6852. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6853. }
  6854. }
  6855. for (int index = 0; index < GB_QUANTITY; index++)
  6856. {
  6857. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6858. {
  6859. //0: unplug, 1: Plug-in
  6860. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6861. }
  6862. }
  6863. }
  6864. else
  6865. {
  6866. for (int index = 0; index < AC_QUANTITY; index++)
  6867. {
  6868. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6869. {
  6870. //0: unplug, 1: Plug-in
  6871. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6872. }
  6873. }
  6874. }// END FOR AC ELSE
  6875. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6876. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6877. result = TRUE;
  6878. return result;
  6879. }
  6880. else
  6881. {
  6882. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6883. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6884. goto errorend;
  6885. }
  6886. errorend:
  6887. sendResetConfirmation(uuid, comfirmstr);
  6888. return result;
  6889. }
  6890. int handleSendLocalListRequest(char *uuid, char *payload)
  6891. {
  6892. mtrace();
  6893. int result = FAIL;
  6894. int listVersionInt;
  6895. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6896. char listsearch[]="listVersion";
  6897. char updateTypesearch[]="updateType";
  6898. char localAuthorizationListsearch[]="localAuthorizationList";
  6899. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6900. char CardList[500][160]={0};
  6901. char updateTypestr[15]={0};
  6902. char idTagstr[20]={0};
  6903. char parentIdTag[20]={0};
  6904. char expiryDate[30]={0};
  6905. char idTagstatus[16]={0};
  6906. int c = 0;
  6907. int i = 0;
  6908. char *delim1 = "}";
  6909. char * pch;
  6910. char *loc;
  6911. //char *ptr;
  6912. char comfirmstr[20];
  6913. //int n_localAuthorizations = 0;
  6914. int checkState_Faulted = FALSE;
  6915. DEBUG_INFO("handleSendLocalListRequest\n");
  6916. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6917. {
  6918. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6919. goto end;
  6920. }
  6921. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  6922. {
  6923. //check Charge Point state
  6924. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6925. {
  6926. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6927. {
  6928. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6929. }
  6930. }
  6931. for (int index = 0; index < CCS_QUANTITY; index++)
  6932. {
  6933. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6934. {
  6935. checkState_Faulted = TRUE; //OCPP Status
  6936. }
  6937. }
  6938. for (int index = 0; index < GB_QUANTITY; index++)
  6939. {
  6940. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6941. {
  6942. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6943. }
  6944. }
  6945. }
  6946. else
  6947. {
  6948. //check Charge Point state
  6949. for (int index = 0; index < AC_QUANTITY; index++)
  6950. {
  6951. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6952. {
  6953. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6954. }
  6955. }
  6956. }// END FOR AC ELSE
  6957. if(checkState_Faulted == TRUE)
  6958. {
  6959. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6960. goto end;
  6961. }
  6962. //listVersion
  6963. c = 0;
  6964. loc = strstr(payload, listsearch);
  6965. while (loc[strlen("listVersion")+2+c] != ',')
  6966. {
  6967. sstr[c] = loc[strlen("listVersion")+2+c];
  6968. c++;
  6969. }
  6970. sstr[c] = '\0';
  6971. listVersionInt = atoi(sstr);
  6972. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6973. //updateType
  6974. loc = strstr(payload, updateTypesearch);
  6975. c = 0;
  6976. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6977. {
  6978. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6979. c++;
  6980. }
  6981. sstr[c] = '\0';
  6982. strcpy(updateTypestr, sstr);
  6983. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6984. //localAuthorizationList
  6985. memset(sstr ,0, sizeof(sstr) );
  6986. loc = strstr(payload, localAuthorizationListsearch);
  6987. if(loc != NULL) // localAuthorizationList is not NULL
  6988. {
  6989. //Check UpdateType
  6990. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6991. {
  6992. //Local list full update
  6993. printf("Local list full update.\n");
  6994. OCPP_cleanLocalList();
  6995. }
  6996. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6997. {
  6998. //Local list different update
  6999. printf("Local list different update.\n");
  7000. OCPP_getListVerion();
  7001. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7002. {
  7003. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7004. goto end;
  7005. }
  7006. }
  7007. else
  7008. {
  7009. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7010. goto end;
  7011. }
  7012. c = 0;
  7013. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7014. {
  7015. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7016. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7017. c++;
  7018. }
  7019. sstr[c] = '\0';
  7020. //parsing strings to words
  7021. i = 0;
  7022. pch = strtok(sstr,delim1);
  7023. while (pch != NULL)
  7024. {
  7025. strcpy(CardList[i], pch);
  7026. pch = strtok (NULL, delim1);
  7027. i = i + 1;
  7028. }
  7029. //local Authorizations List Numbers
  7030. //n_localAuthorizations = i;
  7031. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7032. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7033. c= 0;
  7034. while(c < i)
  7035. {
  7036. //Search "IdToken"
  7037. memset(sstr ,0, sizeof(sstr) );
  7038. loc = strstr(CardList[c], "idTag");
  7039. int j = 0;
  7040. while (loc[3+strlen("idTag")+j] != '\"')
  7041. {
  7042. sstr[j] = loc[3+strlen("idTag")+j];
  7043. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7044. j++;
  7045. }
  7046. sstr[j] = '\0';
  7047. strcpy(idTagstr, sstr);
  7048. //Search "expiryDate"
  7049. memset(sstr ,0, sizeof(sstr) );
  7050. loc = strstr(CardList[c], "expiryDate");
  7051. j = 0;
  7052. while (loc[3+strlen("expiryDate")+j] != '\"')
  7053. {
  7054. sstr[j] = loc[3+strlen("expiryDate")+j];
  7055. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7056. j++;
  7057. }
  7058. sstr[j] = '\0';
  7059. strcpy(expiryDate, sstr);
  7060. //Search "parentIdTag"
  7061. memset(sstr ,0, sizeof(sstr) );
  7062. loc = strstr(CardList[c], "parentIdTag");
  7063. j = 0;
  7064. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7065. {
  7066. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7067. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7068. j++;
  7069. }
  7070. sstr[j] = '\0';
  7071. strcpy(parentIdTag, sstr);
  7072. //Search "status"
  7073. memset(sstr ,0, sizeof(sstr) );
  7074. loc = strstr(CardList[c], "status");
  7075. j = 0;
  7076. while (loc[3+strlen("status")+j] != '\"')
  7077. {
  7078. sstr[j] = loc[3+strlen("status")+j];
  7079. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7080. j++;
  7081. }
  7082. sstr[j] = '\0';
  7083. strcpy(idTagstatus, sstr);
  7084. OCPP_getIdTag(idTagstr);
  7085. //OCPP_getIdTag("test"); For Test
  7086. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7087. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7088. {
  7089. //Local list full update
  7090. DEBUG_INFO("Local list full update.\n");
  7091. // update list
  7092. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7093. OCPP_get_TableAuthlocalAllData();
  7094. }
  7095. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7096. {
  7097. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7098. {
  7099. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7100. }
  7101. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7102. {
  7103. OCPP_deleteIdTag(idTagstr);
  7104. }
  7105. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7106. {
  7107. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7108. }
  7109. }
  7110. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7111. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7112. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7113. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7114. c++;
  7115. }
  7116. }
  7117. else
  7118. {
  7119. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7120. {
  7121. //Local list different update
  7122. DEBUG_INFO("Local list different update.\n");
  7123. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7124. goto end;
  7125. }
  7126. }
  7127. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7128. end:
  7129. sendSendLocalListConfirmation(uuid, comfirmstr);
  7130. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7131. #if 0
  7132. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7133. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7134. #endif
  7135. return result;
  7136. }
  7137. /*
  7138. enum _SYSTEM_STATUS
  7139. {
  7140. S_BOOTING = 0,
  7141. S_IDLE, =1
  7142. S_AUTHORIZING, =2
  7143. S_REASSIGN_CHECK, =3
  7144. S_REASSIGN, =4
  7145. S_PRECHARGE, =5
  7146. S_PREPARING_FOR_EV, =6
  7147. S_PREPARING_FOR_EVSE, =7
  7148. S_CHARGING, =8
  7149. S_TERMINATING, =9
  7150. S_COMPLETE, =10
  7151. S_ALARM, =11
  7152. S_FAULT =12
  7153. };
  7154. */
  7155. #define MAX 200
  7156. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7157. {
  7158. mtrace();
  7159. int result = FAIL;
  7160. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7161. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7162. char chargingProfilePurposeStr[30]={0};
  7163. char chargingProfileKindStr[16]={0};
  7164. char recurrencyKindStr[10]={0};
  7165. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7166. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7167. int chargingSchedulePeriodCount = 0;
  7168. //int updateflag = FALSE;
  7169. char comfirmstr[20]={0};
  7170. int meet= FALSE;
  7171. char sstr[10]={0};
  7172. int c = 0;
  7173. char *loc;
  7174. FILE *fptr1;//, *fptr2;
  7175. //int lno=0;//, linectr = 0;
  7176. //int modifyflag = FALSE;
  7177. char filename[MAX]={0};
  7178. char tempfile[] = "../Storage/OCPP/temp.json";
  7179. int resultRename=0;
  7180. char rmFileCmd[50]={0};
  7181. char tempchargingProfilePurposeStr[30]={0};
  7182. //[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}}}]
  7183. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7184. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7185. //*********************connectorId***************************/
  7186. loc = strstr(payload, "connectorId");
  7187. c = 0;
  7188. memset(sstr ,0, sizeof(sstr) );
  7189. while (loc[strlen("connectorId")+2+c] != ',')
  7190. {
  7191. sstr[c] = loc[strlen("connectorId")+2+c];
  7192. c++;
  7193. }
  7194. sstr[c] = '\0';
  7195. connectorIdInt = atoi(sstr);
  7196. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7197. {
  7198. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7199. }
  7200. else
  7201. {
  7202. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7203. }
  7204. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7205. //*********************chargingProfileId***************************/
  7206. loc = strstr(payload, "chargingProfileId");
  7207. c = 0;
  7208. memset(sstr ,0, sizeof(sstr) );
  7209. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7210. {
  7211. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7212. c++;
  7213. }
  7214. sstr[c] = '\0';
  7215. chargingProfileIdInt = atoi(sstr);
  7216. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7217. {
  7218. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7219. }
  7220. else
  7221. {
  7222. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7223. }
  7224. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7225. //*********************transactionId***************************/
  7226. loc = strstr(payload, "transactionId");
  7227. if(loc != NULL)
  7228. {
  7229. c = 0;
  7230. memset(sstr ,0, sizeof(sstr) );
  7231. while (loc[strlen("transactionId")+2+c] != ',')
  7232. {
  7233. sstr[c] = loc[strlen("transactionId")+2+c];
  7234. c++;
  7235. }
  7236. sstr[c] = '\0';
  7237. transactionIdInt = atoi(sstr);
  7238. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7239. {
  7240. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7241. }
  7242. else
  7243. {
  7244. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7245. }
  7246. }
  7247. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7248. //*********************stackLevel***************************/
  7249. loc = strstr(payload, "stackLevel");
  7250. c = 0;
  7251. memset(sstr ,0, sizeof(sstr) );
  7252. while (loc[strlen("stackLevel")+2+c] != ',')
  7253. {
  7254. sstr[c] = loc[strlen("stackLevel")+2+c];
  7255. c++;
  7256. }
  7257. sstr[c] = '\0';
  7258. stackLevelInt = atoi(sstr);
  7259. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7260. {
  7261. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7262. }
  7263. else
  7264. {
  7265. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7266. }
  7267. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7268. //*********************chargingProfilePurpose***************************/
  7269. loc = strstr(payload, "chargingProfilePurpose");
  7270. c = 0;
  7271. memset(sstr ,0, sizeof(sstr) );
  7272. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7273. {
  7274. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7276. c++;
  7277. }
  7278. sstr[c] = '\0';
  7279. strcpy(chargingProfilePurposeStr,sstr);
  7280. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7281. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7282. {
  7283. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7284. }
  7285. else
  7286. {
  7287. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7288. }
  7289. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7290. //*********************chargingProfileKind***************************/
  7291. loc = strstr(payload, "chargingProfileKind");
  7292. c = 0;
  7293. memset(sstr ,0, sizeof(sstr) );
  7294. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7295. {
  7296. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7297. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7298. c++;
  7299. }
  7300. sstr[c] = '\0';
  7301. strcpy(chargingProfileKindStr,sstr);
  7302. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7303. {
  7304. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7305. }
  7306. else
  7307. {
  7308. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7309. }
  7310. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7311. //*********************recurrencyKind***************************/
  7312. loc = strstr(payload, "recurrencyKind");
  7313. if(loc != NULL)
  7314. {
  7315. c = 0;
  7316. memset(sstr ,0, sizeof(sstr) );
  7317. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7318. {
  7319. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7320. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7321. c++;
  7322. }
  7323. sstr[c] = '\0';
  7324. strcpy(recurrencyKindStr,sstr);
  7325. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7326. {
  7327. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7328. }
  7329. else
  7330. {
  7331. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7332. }
  7333. }
  7334. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7335. //*********************validFrom***************************/
  7336. loc = strstr(payload, "validFrom");
  7337. if(loc != NULL)
  7338. {
  7339. c = 0;
  7340. memset(sstr ,0, sizeof(sstr) );
  7341. while (loc[3+strlen("validFrom")+c] != '\"')
  7342. {
  7343. sstr[c] = loc[3+strlen("validFrom")+c];
  7344. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7345. c++;
  7346. }
  7347. sstr[c] = '\0';
  7348. strcpy(validFromStr,sstr);
  7349. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7350. {
  7351. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7352. }
  7353. else
  7354. {
  7355. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7356. }
  7357. }
  7358. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7359. //*********************validTo***************************/
  7360. loc = strstr(payload, "validTo");
  7361. if(loc != NULL)
  7362. {
  7363. c = 0;
  7364. memset(sstr ,0, sizeof(sstr) );
  7365. while (loc[3+strlen("validTo")+c] != '\"')
  7366. {
  7367. sstr[c] = loc[3+strlen("validTo")+c];
  7368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7369. c++;
  7370. }
  7371. sstr[c] = '\0';
  7372. strcpy(validToStr,sstr);
  7373. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7374. {
  7375. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7376. }
  7377. else
  7378. {
  7379. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7380. }
  7381. }
  7382. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7383. //*********************duration***************************/
  7384. loc = strstr(payload, "duration");
  7385. if(loc != NULL)
  7386. {
  7387. c = 0;
  7388. memset(sstr ,0, sizeof(sstr) );
  7389. while (loc[strlen("duration")+2+c] != ',')
  7390. {
  7391. sstr[c] = loc[strlen("duration")+2+c];
  7392. c++;
  7393. }
  7394. sstr[c] = '\0';
  7395. durationInt = atoi(sstr);
  7396. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7397. {
  7398. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7399. }
  7400. else
  7401. {
  7402. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7403. }
  7404. }
  7405. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7406. //*********************startSchedule***************************/
  7407. loc = strstr(payload, "startSchedule");
  7408. if(loc != NULL)
  7409. {
  7410. c = 0;
  7411. memset(sstr ,0, sizeof(sstr) );
  7412. while (loc[3+strlen("startSchedule")+c] != '\"')
  7413. {
  7414. sstr[c] = loc[3+strlen("startSchedule")+c];
  7415. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7416. c++;
  7417. }
  7418. sstr[c] = '\0';
  7419. strcpy(startScheduleStr,sstr);
  7420. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7421. {
  7422. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7423. }
  7424. else
  7425. {
  7426. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7427. }
  7428. }
  7429. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7430. //*********************chargingRateUnit***************************/
  7431. loc = strstr(payload, "chargingRateUnit");
  7432. if(loc != NULL)
  7433. {
  7434. c = 0;
  7435. memset(sstr ,0, sizeof(sstr) );
  7436. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7437. {
  7438. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7439. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7440. c++;
  7441. }
  7442. sstr[c] = '\0';
  7443. strcpy(chargingRateUnitStr,sstr);
  7444. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7445. {
  7446. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7447. }
  7448. else
  7449. {
  7450. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7451. }
  7452. }
  7453. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7454. //****************chargingSchedulePeriod count start*******************/
  7455. int what_len = strlen("startPeriod");
  7456. char *where = payload;
  7457. if (what_len)
  7458. while ((where = strstr(where, "startPeriod"))) {
  7459. where += what_len;
  7460. chargingSchedulePeriodCount++;
  7461. }
  7462. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7463. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7464. where = payload;
  7465. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7466. {
  7467. //****************startPeriod*******************/
  7468. c=0;
  7469. loc = strstr(where, "startPeriod");
  7470. memset(sstr ,0, sizeof(sstr) );
  7471. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7472. {
  7473. sstr[c] = loc[strlen("startPeriod")+2+c];
  7474. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7475. c++;
  7476. }
  7477. sstr[c] = '\0';
  7478. startPeriodInt[periodNums] = atoi(sstr);
  7479. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7480. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7481. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7482. {
  7483. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7484. }
  7485. else
  7486. {
  7487. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7488. }
  7489. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7490. //****************limit*******************/
  7491. c=0;
  7492. loc = strstr(where, "limit");
  7493. memset(sstr ,0, sizeof(sstr) );
  7494. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7495. {
  7496. sstr[c] = loc[strlen("limit")+2+c];
  7497. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7498. c++;
  7499. }
  7500. sstr[c] = '\0';
  7501. limitflaot[periodNums] = atof(sstr);
  7502. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7503. {
  7504. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7505. }
  7506. else
  7507. {
  7508. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7509. }
  7510. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7511. //****************numberPhases*******************/
  7512. loc = strstr(where, "numberPhases");
  7513. if(loc != NULL)
  7514. {
  7515. c=0;
  7516. memset(sstr ,0, sizeof(sstr) );
  7517. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7518. {
  7519. sstr[c] = loc[strlen("numberPhases")+2+c];
  7520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7521. c++;
  7522. }
  7523. sstr[c] = '\0';
  7524. numberPhasesInt[periodNums] = atoi(sstr);
  7525. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7526. {
  7527. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7528. }
  7529. else
  7530. {
  7531. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7532. }
  7533. }
  7534. where = loc;
  7535. }
  7536. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7537. //****************chargingSchedulePeriod count end*******************/
  7538. //*********************minChargingRate***************************/
  7539. loc = strstr(payload, "minChargingRate");
  7540. if(loc != NULL)
  7541. {
  7542. c = 0;
  7543. memset(sstr ,0, sizeof(sstr) );
  7544. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7545. {
  7546. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7547. c++;
  7548. }
  7549. sstr[c] = '\0';
  7550. minChargingRateFloat = atof(sstr);
  7551. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7552. {
  7553. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7554. }
  7555. else
  7556. {
  7557. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7558. }
  7559. }
  7560. DEBUG_INFO("\n\n Replace a specific line in a text file with a new text :\n");
  7561. DEBUG_INFO("-------------------------------------------------------------\n");
  7562. DEBUG_INFO(" Input the file name to be opened : ");
  7563. //fgets(fname, MAX, stdin);
  7564. //fname[strlen(fname) - 1] = '\0';
  7565. #if 0
  7566. switch(connectorIdInt)
  7567. {
  7568. case 0:
  7569. strcpy(filename, ChargingProfile_0_JSON );
  7570. break;
  7571. case 1:
  7572. strcpy(filename, ChargingProfile_1_JSON );
  7573. break;
  7574. case 2:
  7575. strcpy(filename, ChargingProfile_2_JSON );
  7576. break;
  7577. default:
  7578. strcpy(filename, ChargingProfile_0_JSON );
  7579. break;
  7580. }
  7581. fptr1 = fopen(filename, "r");
  7582. if (!fptr1)
  7583. {
  7584. //file not exist
  7585. DEBUG_INFO("Unable to open the input file!!\n");
  7586. fptr1 = fopen(filename, "w+");
  7587. }
  7588. fclose(fptr1);
  7589. #endif
  7590. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7591. //DEBUG_INFO(" ChargingProfilePurposeTypeStr[TxProfile]=%s\n", ChargingProfilePurposeTypeStr[TxProfile]);
  7592. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7593. {
  7594. //printf("set chargingProfile 1-2\n");
  7595. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7596. if(connectorIdInt != 0)
  7597. {
  7598. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7599. goto end;
  7600. }
  7601. strcpy(filename, ChargePointMaxProfile_JSON );
  7602. fptr1 = fopen(filename, "r");
  7603. if (!fptr1)
  7604. {
  7605. //file not exist
  7606. DEBUG_INFO("Unable to open the input file!!\n");
  7607. fptr1 = fopen(filename, "w+");
  7608. }
  7609. fclose(fptr1);
  7610. }
  7611. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7612. {
  7613. //printf("set chargingProfile 1-3\n");
  7614. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7615. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7616. {
  7617. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7618. goto end;
  7619. }
  7620. switch(connectorIdInt)
  7621. {
  7622. case 0:
  7623. strcpy(filename, TxDefaultProfile_0_JSON );
  7624. break;
  7625. case 1:
  7626. strcpy(filename, TxDefaultProfile_1_JSON );
  7627. break;
  7628. case 2:
  7629. strcpy(filename, TxDefaultProfile_2_JSON );
  7630. break;
  7631. default:
  7632. strcpy(filename, TxDefaultProfile_0_JSON );
  7633. break;
  7634. }
  7635. fptr1 = fopen(filename, "r");
  7636. if (!fptr1)
  7637. {
  7638. //file not exist
  7639. DEBUG_INFO("Unable to open the input file!!\n");
  7640. fptr1 = fopen(filename, "w+");
  7641. }
  7642. fclose(fptr1);
  7643. }
  7644. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7645. {
  7646. //printf("set chargingProfile 1-4\n");
  7647. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7648. //check Transaction active
  7649. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7650. {
  7651. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7652. {
  7653. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7654. {
  7655. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7656. {
  7657. meet = TRUE;
  7658. break;
  7659. }
  7660. }
  7661. }
  7662. }
  7663. for (int index = 0; index < CCS_QUANTITY; index++)
  7664. {
  7665. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7666. {
  7667. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7668. {
  7669. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7670. {
  7671. meet = TRUE;
  7672. break;
  7673. }
  7674. }
  7675. }
  7676. }
  7677. for (int index = 0; index < GB_QUANTITY; index++)
  7678. {
  7679. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7680. {
  7681. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7682. {
  7683. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7684. {
  7685. meet = TRUE;
  7686. break;
  7687. }
  7688. }
  7689. }
  7690. }
  7691. if(meet == FALSE)
  7692. {
  7693. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7694. goto end;
  7695. }
  7696. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7697. {
  7698. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7699. goto end;
  7700. }
  7701. switch(connectorIdInt)
  7702. {
  7703. case 0:
  7704. break;
  7705. case 1:
  7706. strcpy(filename, TxProfile_1_JSON);
  7707. break;
  7708. case 2:
  7709. strcpy(filename, TxProfile_2_JSON);
  7710. break;
  7711. default:
  7712. strcpy(filename, TxProfile_1_JSON);
  7713. break;
  7714. }
  7715. fptr1 = fopen(filename, "r");
  7716. if (!fptr1)
  7717. {
  7718. //file not exist
  7719. DEBUG_INFO("Unable to open the input file!!\n");
  7720. fptr1 = fopen(filename, "w+");
  7721. }
  7722. fclose(fptr1);
  7723. }
  7724. //**********************************Write to File********************************************************/
  7725. FILE *infile;
  7726. FILE *outfile;
  7727. // open file for writing
  7728. infile = fopen (filename, "r");
  7729. outfile = fopen (tempfile, "w");
  7730. int d =0;
  7731. d = fgetc(infile);
  7732. DEBUG_INFO("d:%d\n",d);
  7733. rewind(infile);
  7734. //*检测到文件结束标识返回1,否则返回0。*/
  7735. if(d == EOF)
  7736. {
  7737. DEBUG_INFO("ChargingProfile content is NULL\n");
  7738. fprintf(outfile,"[%s]\n",payload);
  7739. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7740. fclose(infile);
  7741. fclose(outfile);
  7742. sprintf(rmFileCmd,"rm -f %s",filename);
  7743. system(rmFileCmd);
  7744. resultRename = rename(tempfile, filename);
  7745. if(resultRename == 0)
  7746. {
  7747. DEBUG_INFO("File chargingProfile renamed successfully");
  7748. }
  7749. else
  7750. {
  7751. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7752. }
  7753. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7754. //system(rmFileCmd);
  7755. }
  7756. else
  7757. {
  7758. char buf[1000]={0};
  7759. while (fgets(buf, sizeof(buf), infile) != NULL)
  7760. {
  7761. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7762. //*************************tempconnectorIdInt*********************************/
  7763. loc = strstr(buf, "connectorId");
  7764. c = 0;
  7765. memset(sstr ,0, sizeof(sstr) );
  7766. while (loc[strlen("connectorId")+2+c] != ',')
  7767. {
  7768. sstr[c] = loc[strlen("connectorId")+2+c];
  7769. c++;
  7770. }
  7771. sstr[c] = '\0';
  7772. tempconnectorIdInt = atoi(sstr);
  7773. //*************************tempchargingProfileIdInt*********************************/
  7774. loc = strstr(buf, "chargingProfileId");
  7775. c = 0;
  7776. memset(sstr ,0, sizeof(sstr) );
  7777. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7778. {
  7779. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7780. c++;
  7781. }
  7782. sstr[c] = '\0';
  7783. tempchargingProfileIdInt = atoi(sstr);
  7784. //*************************tempstackLevelInt*********************************/
  7785. loc = strstr(buf, "stackLevel");
  7786. c = 0;
  7787. memset(sstr ,0, sizeof(sstr) );
  7788. while (loc[strlen("stackLevel")+2+c] != ',')
  7789. {
  7790. sstr[c] = loc[strlen("stackLevel")+2+c];
  7791. c++;
  7792. }
  7793. sstr[c] = '\0';
  7794. tempstackLevelInt = atoi(sstr);
  7795. //*************************tempchargingProfilePurposeStr*********************************/
  7796. loc = strstr(payload, "chargingProfilePurpose");
  7797. c = 0;
  7798. memset(sstr ,0, sizeof(sstr) );
  7799. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7800. {
  7801. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7802. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7803. c++;
  7804. }
  7805. sstr[c] = '\0';
  7806. strcpy(tempchargingProfilePurposeStr,sstr);
  7807. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7808. {
  7809. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7810. {
  7811. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7812. fprintf(outfile,"[%s]\n",payload);
  7813. }
  7814. else
  7815. {
  7816. //DEBUG_INFO("update set chargingProfile to file -1\n");
  7817. if(tempstackLevelInt < stackLevelInt)
  7818. {
  7819. //DEBUG_INFO("update set chargingProfile to file -2\n");
  7820. fprintf(outfile,"[%s]\n",payload);
  7821. fprintf(outfile,"[%s]\n",buf);
  7822. }
  7823. else
  7824. {
  7825. fprintf(outfile,"[%s]\n",buf);
  7826. fprintf(outfile,"[%s]\n",payload);
  7827. }
  7828. }
  7829. DEBUG_INFO("update set chargingProfile to file\n");
  7830. }
  7831. else
  7832. {
  7833. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7834. {
  7835. fprintf(outfile,"[%s]\n",payload);
  7836. fprintf(outfile,"[%s]\n",buf);
  7837. }
  7838. else if(tempstackLevelInt < stackLevelInt)
  7839. {
  7840. fprintf(outfile,"[%s]\n",payload);
  7841. fprintf(outfile,"[%s]\n",buf);
  7842. }
  7843. else
  7844. {
  7845. fprintf(outfile,"[%s]\n",buf);
  7846. fprintf(outfile,"[%s]\n",payload);
  7847. }
  7848. fprintf(outfile,"[%s]\n",buf);
  7849. DEBUG_INFO("add set chargingProfile to file\n");
  7850. }
  7851. } // end of while loop
  7852. fclose(infile);
  7853. fclose(outfile);
  7854. sprintf(rmFileCmd,"rm -f %s",filename);
  7855. system(rmFileCmd);
  7856. resultRename = rename(tempfile, filename);
  7857. if(resultRename == 0)
  7858. {
  7859. DEBUG_INFO("File chargingProfile renamed successfully");
  7860. }
  7861. else
  7862. {
  7863. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7864. }
  7865. result = TRUE;
  7866. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7867. }
  7868. end:
  7869. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7870. return result;
  7871. return result;
  7872. }
  7873. int handleTriggerMessageRequest(char *uuid, char *payload)
  7874. {
  7875. mtrace();
  7876. int result = FAIL;
  7877. int connectorIdIsNULL = FALSE;
  7878. int connectorIdInt =0;
  7879. char sstr[40]={0};
  7880. char requestedMessagestr[40]={0};
  7881. char comfirmstr[20]={0};
  7882. int c = 0;
  7883. char *loc;
  7884. DEBUG_INFO("handleTriggerMessageRequest\n");
  7885. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7886. c = 0;
  7887. loc = strstr(payload, "requestedMessage");
  7888. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7889. {
  7890. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7891. c++;
  7892. }
  7893. sstr[c] = '\0';
  7894. strcpy(requestedMessagestr, sstr);
  7895. c = 0;
  7896. loc = strstr(payload, "connectorId");
  7897. if(loc == NULL)
  7898. {
  7899. connectorIdIsNULL = TRUE;
  7900. }
  7901. else
  7902. {
  7903. memset(sstr ,0, sizeof(sstr) );
  7904. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7905. {
  7906. sstr[c] = loc[strlen("connectorId")+2+c];
  7907. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7908. c++;
  7909. }
  7910. sstr[c] = '\0';
  7911. connectorIdInt = atoi(sstr);
  7912. }
  7913. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7914. {
  7915. //connectorIdInt = json_object_get_int(connectorId);
  7916. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7917. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7918. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7919. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7920. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7921. }
  7922. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7923. {
  7924. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7925. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7926. return TRUE;
  7927. }
  7928. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7929. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7930. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7931. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7932. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7933. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7934. {
  7935. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7936. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7937. return TRUE;
  7938. }
  7939. else
  7940. {
  7941. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7942. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7943. }
  7944. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7945. {
  7946. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7947. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7948. }
  7949. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7950. {
  7951. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7952. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7953. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7954. }
  7955. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7956. {
  7957. sendBootNotificationRequest();
  7958. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7959. }
  7960. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7961. {
  7962. sendHeartbeatRequest(connectorIdInt);
  7963. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7964. }
  7965. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7966. {
  7967. if(connectorIdIsNULL == FALSE)
  7968. {
  7969. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7970. {
  7971. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7972. sendMeterValuesRequest(connectorIdInt -1);
  7973. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7974. }
  7975. }
  7976. else
  7977. {
  7978. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7979. {
  7980. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  7981. sendMeterValuesRequest(idx);
  7982. }
  7983. }
  7984. }
  7985. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  7986. {
  7987. if(connectorIdIsNULL == FALSE)
  7988. {
  7989. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7990. {
  7991. sendStatusNotificationRequest(connectorIdInt -1);
  7992. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7993. }
  7994. }
  7995. else
  7996. {
  7997. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7998. sendStatusNotificationRequest(idx);
  7999. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8000. }
  8001. }
  8002. return result;
  8003. }
  8004. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8005. {
  8006. mtrace();
  8007. int result = FAIL;
  8008. char sstr[6]={0};
  8009. int connectorIdInt =0;
  8010. char comfirmstr[20]={0};
  8011. int c = 0;
  8012. char *loc;
  8013. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8014. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8015. c = 0;
  8016. loc = strstr(payload, "connectorId");
  8017. memset(sstr ,0, sizeof(sstr) );
  8018. while (loc[strlen("connectorId")+2+c] != '}')
  8019. {
  8020. sstr[c] = loc[strlen("connectorId")+2+c];
  8021. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8022. c++;
  8023. }
  8024. sstr[c] = '\0';
  8025. connectorIdInt = atoi(sstr);
  8026. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8027. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8028. {
  8029. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8030. goto end;
  8031. }
  8032. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8033. {
  8034. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8035. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8036. goto end;
  8037. }
  8038. else
  8039. {
  8040. //check Transaction active
  8041. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  8042. {
  8043. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8044. {
  8045. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8046. {
  8047. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8048. }
  8049. }
  8050. for (int index = 0; index < CCS_QUANTITY; index++)
  8051. {
  8052. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8053. {
  8054. //stop Transaction
  8055. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8056. }
  8057. }
  8058. for (int index = 0; index < GB_QUANTITY; index++)
  8059. {
  8060. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8061. {
  8062. //stop Transaction
  8063. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8064. }
  8065. }
  8066. }
  8067. else
  8068. {
  8069. for (int index = 0; index < AC_QUANTITY; index++)
  8070. {
  8071. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8072. {
  8073. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8074. }
  8075. }
  8076. }// END FOR AC ELSE
  8077. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8078. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8079. result = TRUE;
  8080. return result;
  8081. }
  8082. end:
  8083. //json_object_put(obj); --- remove temporally
  8084. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8085. return result;
  8086. }
  8087. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8088. {
  8089. mtrace();
  8090. int result = FAIL;
  8091. pthread_t t;
  8092. sendUpdateFirmwareConfirmation(uuid);
  8093. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8094. pthread_join(t, NULL); // 等�?子執行�??��?完�?
  8095. //sendUpdateFirmwareConfirmation(uuid);
  8096. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8097. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8098. return result;
  8099. }
  8100. void *UpdateFirmwareProcess(void *data)
  8101. {
  8102. mtrace();
  8103. int retriesInt =0, retryIntervalInt=0;
  8104. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8105. int port=0;
  8106. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8107. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8108. //char comfirmstr[20];
  8109. int isSuccess = 0;
  8110. char ftpbuf[200];
  8111. char temp[100];
  8112. char * pch;
  8113. int retriesISNULL=FALSE;
  8114. int retryInterval=FALSE;
  8115. int c = 0;
  8116. //int i = 0;
  8117. char *loc;
  8118. char sstr[300]={ 0 };
  8119. char *str = (char*) data; // ?��?輸入資�?
  8120. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8121. //***************location **************/
  8122. loc = strstr(str, "location");
  8123. memset(sstr ,0, sizeof(sstr) );
  8124. c = 0;
  8125. while (loc[3+strlen("location")+c] != '\"')
  8126. {
  8127. sstr[c] = loc[3+strlen("location")+c];
  8128. c++;
  8129. }
  8130. sstr[c] = '\0';
  8131. strcpy(locationstr, sstr);
  8132. //***************retries**************/
  8133. c = 0;
  8134. loc = strstr(str, "retries");
  8135. if(loc == NULL)
  8136. {
  8137. retriesISNULL=TRUE;
  8138. }
  8139. else
  8140. {
  8141. memset(sstr ,0, sizeof(sstr) );
  8142. while (loc[strlen("retries")+2+c] != ',')
  8143. {
  8144. sstr[c] = loc[strlen("retries")+2+c];
  8145. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8146. c++;
  8147. }
  8148. sstr[c] = '\0';
  8149. }
  8150. if(retriesISNULL == FALSE)
  8151. {
  8152. retriesInt = atoi(sstr);
  8153. }
  8154. //***************retrieveDate **************/
  8155. loc = strstr(str, "retrieveDate");
  8156. memset(sstr ,0, sizeof(sstr) );
  8157. c = 0;
  8158. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8159. {
  8160. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8161. c++;
  8162. }
  8163. sstr[c] = '\0';
  8164. strcpy(retrieveDatestr, sstr);
  8165. //***************retryInterval **************/
  8166. c = 0;
  8167. loc = strstr(str, "retryInterval");
  8168. memset(sstr ,0, sizeof(sstr) );
  8169. if(loc == NULL)
  8170. {
  8171. retryInterval=TRUE;
  8172. }
  8173. else
  8174. {
  8175. while (loc[strlen("retryInterval")+2+c] != ',')
  8176. {
  8177. sstr[c] = loc[strlen("retryInterval")+2+c];
  8178. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8179. c++;
  8180. }
  8181. sstr[c] = '\0';
  8182. }
  8183. if(retryInterval==FALSE)
  8184. {
  8185. retryIntervalInt = atoi(sstr);
  8186. }
  8187. memset(ftppath, 0, sizeof(ftppath));
  8188. memset(path, 0, sizeof(path));
  8189. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8190. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8191. if(strncmp(locationstr,"http", 4) == 0)
  8192. {
  8193. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8194. protocol, host, path);
  8195. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8196. // protocol, user, password, host, path);
  8197. sprintf(ftppath,"/%s", path);
  8198. DEBUG_INFO("protocol =%s\n",protocol);
  8199. DEBUG_INFO("host =%s\n",host);
  8200. DEBUG_INFO("path =%s\n",path);
  8201. DEBUG_INFO("ftppath=%s\n",ftppath);
  8202. int ftppathlen=strlen(ftppath);
  8203. int i=1;
  8204. char filenametemp[50];
  8205. while(i < ftppathlen)
  8206. {
  8207. int len=ftppathlen-i;
  8208. if(ftppath[len]== 47) // '/' ascll code: 47
  8209. {
  8210. DEBUG_INFO("compare '/' all right\n");
  8211. break;
  8212. }
  8213. i=i+1;
  8214. }
  8215. memset(filenametemp, 0, sizeof(filenametemp));
  8216. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8217. filenametemp[i+1] = 0;
  8218. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8219. do{
  8220. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8221. sleep(retryIntervalInt);
  8222. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8223. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8224. if(!isSuccess)
  8225. {
  8226. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8227. }
  8228. else
  8229. {
  8230. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8231. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8232. isUpdateRequest = TRUE;
  8233. }
  8234. }
  8235. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8236. {
  8237. memset(ftpbuf, 0, sizeof(ftpbuf));
  8238. memset(temp, 0, sizeof(temp));
  8239. DEBUG_INFO("locationstr=%s\n",locationstr);
  8240. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8241. int ftppathlen=strlen(ftpbuf);
  8242. int i=1;
  8243. char filenametemp[50];
  8244. while(i < ftppathlen)
  8245. {
  8246. int len=ftppathlen-i;
  8247. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8248. {
  8249. DEBUG_INFO(" compare '/' all right\n");
  8250. break;
  8251. }
  8252. i=i+1;
  8253. }
  8254. memset(filenametemp, 0, sizeof(filenametemp));
  8255. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8256. filenametemp[i+1] = 0;
  8257. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8258. pch=strchr(temp,'@');
  8259. if(pch==NULL)
  8260. {
  8261. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8262. protocol, host, &port, path);
  8263. strcpy(user,"anonymous");
  8264. strcpy(password,"");
  8265. }
  8266. else
  8267. {
  8268. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8269. protocol, user, password, host, &port, path);
  8270. }
  8271. sscanf(host,"%[^/]%s",host1, path1);
  8272. sprintf(ftppath,"%s", path1);
  8273. DEBUG_INFO("protocol =%s\n",protocol);
  8274. DEBUG_INFO("user =%s\n",user);
  8275. DEBUG_INFO("password =%s\n",password);
  8276. DEBUG_INFO("host1 =%s\n",host1);
  8277. DEBUG_INFO("port =%d\n",port);
  8278. DEBUG_INFO("path1 =%s\n",path1);
  8279. DEBUG_INFO("ftppath=%s\n",ftppath);
  8280. //ftpFile(host, user, password, port, ftppath, fname);
  8281. //download firmware pthred
  8282. if(port == 0)
  8283. {
  8284. port = 21;
  8285. }
  8286. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8287. do{
  8288. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8289. sleep(retryIntervalInt);
  8290. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8291. if(!isSuccess)
  8292. {
  8293. //BulldogUtil.sleepMs(interval*1000);
  8294. DEBUG_INFO("Update firmware request and download file fail.\n");
  8295. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8296. }
  8297. else
  8298. {
  8299. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8300. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8301. isUpdateRequest = TRUE;
  8302. }
  8303. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8304. }
  8305. else
  8306. {
  8307. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8308. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8309. }
  8310. pthread_exit(NULL);
  8311. }
  8312. //==========================================
  8313. // Handle server response routine
  8314. //==========================================
  8315. void handleAuthorizeResponse(char *payload, int gun_index)
  8316. {
  8317. mtrace();
  8318. char expiryDatestr[30]={0};
  8319. char parentIdTagstr[20]={0};
  8320. char statusstr[20]={0};
  8321. char expiryDatestrtemp[30]={0};
  8322. char parentIdTagstrtemp[20]={0};
  8323. char IdTagstrtemp[20]={0};
  8324. char statusstrtemp[20]={0};
  8325. int expiryDateISNULL=FALSE;
  8326. int parentIdTagISNULL=FALSE;
  8327. char sstr[160]={ 0 };
  8328. char* filename = AuthorizationCache_JSON;
  8329. char tempfile[] = "../Storage/OCPP/temp.json";
  8330. int c = 0;
  8331. char *loc;
  8332. int resultRename=0;
  8333. int responseIdTagInfoAsZero= 0;
  8334. char rmFileCmd[50]={0};
  8335. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8336. //***********expiryDate*************/
  8337. loc = strstr(payload, "expiryDate");
  8338. memset(sstr ,0, sizeof(sstr) );
  8339. c = 0;
  8340. if(loc == NULL)
  8341. {
  8342. expiryDateISNULL = TRUE;
  8343. }
  8344. else
  8345. {
  8346. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8347. {
  8348. sstr[c] = loc[3+strlen("expiryDate")+c];
  8349. c++;
  8350. }
  8351. sstr[c] = '\0';
  8352. strcpy(expiryDatestr, sstr);
  8353. }
  8354. //***********parentIdTag*************/
  8355. loc = strstr(payload, "parentIdTag");
  8356. memset(sstr ,0, sizeof(sstr) );
  8357. c = 0;
  8358. if(loc == NULL)
  8359. {
  8360. parentIdTagISNULL = TRUE;
  8361. }
  8362. else
  8363. {
  8364. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8365. {
  8366. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8367. c++;
  8368. }
  8369. sstr[c] = '\0';
  8370. strcpy(parentIdTagstr, sstr);
  8371. }
  8372. //***********status*************/
  8373. loc = strstr(payload, "status");
  8374. memset(sstr ,0, sizeof(sstr) );
  8375. c = 0;
  8376. while (loc[3+strlen("status")+c] != '\"')
  8377. {
  8378. sstr[c] = loc[3+strlen("status")+c];
  8379. c++;
  8380. }
  8381. sstr[c] = '\0';
  8382. strcpy(statusstr, sstr);
  8383. //#ifdef SystemLogMessage
  8384. // if(expiryDateISNULL == FALSE)
  8385. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8386. // if(parentIdTagISNULL == FALSE)
  8387. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8388. // DEBUG_INFO("status: %s\n", statusstr);
  8389. //#endif
  8390. if(expiryDateISNULL == FALSE)
  8391. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8392. if(parentIdTagISNULL == FALSE)
  8393. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8394. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8395. //Update idTag information to authorization cache if supproted
  8396. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8397. {
  8398. if((access(filename,F_OK))!=-1)
  8399. {
  8400. DEBUG_INFO("AuthorizationCache exist.\n");
  8401. }
  8402. else
  8403. {
  8404. DEBUG_INFO("AuthorizationCache not exist\n");
  8405. FILE *log = fopen(filename, "w+");
  8406. if(log == NULL)
  8407. {
  8408. DEBUG_INFO("log is NULL\n");
  8409. goto out;
  8410. }
  8411. else
  8412. {
  8413. fclose(log);
  8414. }
  8415. }
  8416. FILE *infile;
  8417. FILE *outfile;
  8418. // open file for writing
  8419. infile = fopen (filename, "r");
  8420. outfile = fopen (tempfile, "w");
  8421. //*检测到文件结束标识返回1,否则返回0。*/
  8422. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8423. int c;
  8424. c = fgetc(infile);
  8425. //DEBUG_INFO("c:%d\n",c);
  8426. rewind(infile);
  8427. if(c == EOF)
  8428. {
  8429. DEBUG_INFO("Orignal File is NULL\n");
  8430. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8431. {
  8432. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8433. }
  8434. else
  8435. {
  8436. strcpy(expiryDatestrtemp, "");
  8437. }
  8438. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8439. {
  8440. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8441. }
  8442. else
  8443. {
  8444. //write Authorize IdTag
  8445. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8446. }
  8447. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8448. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8449. fclose(infile);
  8450. fclose(outfile);
  8451. sprintf(rmFileCmd,"rm -f %s",filename);
  8452. system(rmFileCmd);
  8453. resultRename = rename(tempfile, filename);
  8454. if(resultRename == 0)
  8455. {
  8456. DEBUG_INFO("File renamed successfully");
  8457. }
  8458. else
  8459. {
  8460. DEBUG_INFO("Error: unable to rename the file");
  8461. }
  8462. }
  8463. else
  8464. {
  8465. char buf[160]={0};
  8466. //DEBUG_INFO("Orignal File is not NULL\n");
  8467. while (fgets(buf, sizeof(buf), infile) != NULL)
  8468. {
  8469. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8470. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8471. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8472. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8473. memset(statusstr, 0, sizeof(statusstrtemp));
  8474. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8475. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8476. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8477. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8478. //------------------IdTag-----------------------
  8479. loc = strstr(buf, "idTag");
  8480. memset(sstr ,0, sizeof(sstr) );
  8481. c = 0;
  8482. while (loc[3+strlen("idTag")+c] != '\"')
  8483. {
  8484. sstr[c] = loc[3+strlen("idTag")+c];
  8485. c++;
  8486. }
  8487. sstr[c] = '\0';
  8488. strcpy(IdTagstrtemp,sstr);
  8489. //*********************expiryDate***************/
  8490. loc = strstr(buf, "expiryDate");
  8491. memset(sstr ,0, sizeof(sstr) );
  8492. c = 0;
  8493. while (loc[3+strlen("expiryDate")+c] != '\"')
  8494. {
  8495. sstr[c] = loc[3+strlen("expiryDate")+c];
  8496. c++;
  8497. }
  8498. sstr[c] = '\0';
  8499. strcpy(expiryDatestr,sstr);
  8500. //*********************parentIdTag***************/
  8501. loc = strstr(buf, "parentIdTag");
  8502. memset(sstr ,0, sizeof(sstr) );
  8503. c = 0;
  8504. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8505. {
  8506. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8507. c++;
  8508. }
  8509. sstr[c] = '\0';
  8510. strcpy(parentIdTagstr,sstr);
  8511. //*********************status***************/
  8512. loc = strstr(buf, "status");
  8513. memset(sstr ,0, sizeof(sstr) );
  8514. c = 0;
  8515. while (loc[3+strlen("status")+c] != '\"')
  8516. {
  8517. sstr[c] = loc[3+strlen("status")+c];
  8518. c++;
  8519. }
  8520. sstr[c] = '\0';
  8521. strcpy(statusstr,sstr);
  8522. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8523. {
  8524. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8525. responseIdTagInfoAsZero = 1;
  8526. }
  8527. else
  8528. {
  8529. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8530. }
  8531. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8532. {
  8533. //modify item
  8534. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8535. {
  8536. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8537. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8538. }
  8539. else
  8540. {
  8541. strcpy(expiryDatestrtemp, "");
  8542. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8543. }
  8544. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8545. {
  8546. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8547. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8548. }
  8549. else
  8550. {
  8551. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8552. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8553. }
  8554. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8555. }
  8556. else
  8557. {
  8558. //wrie original item
  8559. strcpy(expiryDatestrtemp, expiryDatestr);
  8560. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8561. strcpy(statusstrtemp, statusstr);
  8562. }
  8563. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8564. }
  8565. fclose(infile);
  8566. fclose(outfile);
  8567. sprintf(rmFileCmd,"rm -f %s",filename);
  8568. system(rmFileCmd);
  8569. resultRename = rename(tempfile, filename);
  8570. if(resultRename == 0)
  8571. {
  8572. DEBUG_INFO("File renamed successfully");
  8573. }
  8574. else
  8575. {
  8576. DEBUG_INFO("Error: unable to rename the file");
  8577. }
  8578. }
  8579. }
  8580. out:
  8581. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8582. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8583. authorizeRetryTimes = 0;
  8584. }
  8585. void handleBootNotificationResponse(char *payload, int gun_index)
  8586. {
  8587. mtrace();
  8588. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8589. char statusStr[12]={0};
  8590. char currentTimeStr[30]={0};
  8591. char *loc;
  8592. int intervalInt = 0;
  8593. int c = 0;
  8594. //double diff_t;
  8595. struct tm tp;
  8596. char buf[28]={0};
  8597. char timebuf[50]={0};
  8598. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8599. //*** interval ****/
  8600. c = 0;
  8601. loc = strstr(payload, "interval");
  8602. printf("loc=%s\n",loc);
  8603. memset(sstr ,0, sizeof(sstr) );
  8604. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8605. {
  8606. sstr[c] = loc[strlen("interval")+2+c];
  8607. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8608. c++;
  8609. }
  8610. sstr[c] = '\0';
  8611. DEBUG_INFO("id=%d\n",atoi(sstr));
  8612. intervalInt = atoi(sstr);
  8613. //***status ****/
  8614. loc = strstr(payload, "status");
  8615. memset(sstr ,0, sizeof(sstr) );
  8616. c = 0;
  8617. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8618. {
  8619. sstr[c] = loc[3+strlen("status")+c];
  8620. c++;
  8621. }
  8622. sstr[c] = '\0';
  8623. strcpy(statusStr, sstr);
  8624. //***currentTime ****/
  8625. loc = strstr(payload, "currentTime");
  8626. //printf("loc=%s\n",loc);
  8627. memset(sstr ,0, sizeof(sstr) );
  8628. c = 0;
  8629. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8630. {
  8631. sstr[c] = loc[3+strlen("currentTime")+c];
  8632. c++;
  8633. }
  8634. sstr[c] = '\0';
  8635. strcpy(currentTimeStr, sstr);
  8636. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8637. HeartBeatWaitTime = BootNotificationInterval;
  8638. //#ifdef SystemLogMessage
  8639. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8640. // DEBUG_INFO("interval: %d\n", intervalInt);
  8641. // DEBUG_INFO("status: %s\n", statusStr);
  8642. //#endif
  8643. //write back to ShmOCPP16Data->BootNotification
  8644. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8645. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8646. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8647. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8648. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8649. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8650. {
  8651. server_sign = TRUE;
  8652. server_pending =FALSE;
  8653. }
  8654. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8655. {
  8656. server_pending = TRUE;
  8657. }
  8658. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8659. tp.tm_isdst = -1;
  8660. //time_t utc = mktime(&tp);
  8661. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8662. memset(timebuf, 0, sizeof timebuf);
  8663. sprintf(timebuf,"date -s '%s'",buf);
  8664. DEBUG_INFO("timebuf=%s\n",timebuf);
  8665. system(timebuf);
  8666. //==============================================
  8667. // RTC sync
  8668. //==============================================
  8669. system("/sbin/hwclock -w --systohc");
  8670. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8671. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8672. }
  8673. void handleDataTransferResponse(char *payload, int gun_index)
  8674. {
  8675. char sstr[160]={0};//sstr[200]={ 0 };
  8676. int c = 0;
  8677. char *loc;
  8678. DEBUG_INFO("handleDataTransferResponse ...\n");
  8679. loc = strstr(payload, "status");
  8680. printf("loc=%s\n",loc);
  8681. c = 0;
  8682. while (loc[3+strlen("status")+c] != '\"')
  8683. {
  8684. sstr[c] = loc[3+strlen("status")+c];
  8685. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8686. c++;
  8687. }
  8688. sstr[c] = '\0';
  8689. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8690. //#ifdef SystemLogMessage
  8691. //DEBUG_INFO("data: %s\n", payload);
  8692. //#endif
  8693. }
  8694. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8695. {
  8696. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8697. //struct json_object *obj;
  8698. // obj = json_tokener_parse(payload);
  8699. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8700. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8701. //No fields are defined.
  8702. }
  8703. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8704. {
  8705. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8706. //struct json_object *obj;
  8707. // obj = json_tokener_parse(payload);
  8708. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8709. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8710. //No fields are defined.
  8711. }
  8712. void handleHeartbeatResponse(char *payload, int gun_index)
  8713. {
  8714. mtrace();
  8715. //double diff_t;
  8716. struct tm tp;
  8717. char buf[28]={0};
  8718. char timebuf[50]={0};
  8719. char sstr[30]={ 0 };
  8720. int c = 0;
  8721. char *loc;
  8722. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8723. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8724. c = 0;
  8725. loc = strstr(payload, "currentTime");
  8726. memset(sstr ,0, sizeof(sstr) );
  8727. while (loc[3+strlen("currentTime")+c] != '\"')
  8728. {
  8729. sstr[c] = loc[3+strlen("currentTime")+c];
  8730. c++;
  8731. }
  8732. sstr[c] = '\0';
  8733. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8734. #ifdef SystemLogMessage
  8735. DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8736. #endif
  8737. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8738. tp.tm_isdst = -1;
  8739. //time_t utc = mktime(&tp);
  8740. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8741. memset(timebuf, 0, sizeof timebuf);
  8742. sprintf(timebuf,"date -s '%s'",buf);
  8743. system(timebuf);
  8744. //==============================================
  8745. // RTC sync
  8746. //==============================================
  8747. system("/sbin/hwclock -w --systohc");
  8748. if(FirstHeartBeat == 0)
  8749. {
  8750. FirstHeartBeat = 1;
  8751. }
  8752. }
  8753. void handleMeterValuesResponse(char *payload, int gun_index)
  8754. {
  8755. mtrace();
  8756. //struct json_object *obj;
  8757. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8758. //No fields are defined.
  8759. }
  8760. void handleStartTransactionResponse(char *payload, int gun_index)
  8761. {
  8762. mtrace();
  8763. char sstr[30]={ 0 };
  8764. int c = 0;
  8765. char *loc;
  8766. int transactionIdInt = 0;
  8767. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8768. DEBUG_INFO("handleStartTransactionResponse\n");
  8769. //****************expiryDate********************/
  8770. loc = strstr(payload, "expiryDate");
  8771. if(loc == NULL)
  8772. {
  8773. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8774. }
  8775. else
  8776. {
  8777. c = 0;
  8778. memset(sstr ,0, sizeof(sstr) );
  8779. while (loc[3+strlen("expiryDate")+c] != '\"')
  8780. {
  8781. sstr[c] = loc[3+strlen("expiryDate")+c];
  8782. c++;
  8783. }
  8784. sstr[c] = '\0';
  8785. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8786. }
  8787. //****************parentIdTag********************/
  8788. loc = strstr(payload, "parentIdTag");
  8789. if(loc == NULL)
  8790. {
  8791. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8792. }
  8793. else
  8794. {
  8795. c = 0;
  8796. memset(sstr ,0, sizeof(sstr) );
  8797. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8798. {
  8799. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8800. c++;
  8801. }
  8802. sstr[c] = '\0';
  8803. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8804. }
  8805. //****************status********************/
  8806. loc = strstr(payload, "status");
  8807. if(loc == NULL)
  8808. {
  8809. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8810. }
  8811. else
  8812. {
  8813. c = 0;
  8814. memset(sstr ,0, sizeof(sstr) );
  8815. while (loc[3+strlen("status")+c] != '\"')
  8816. {
  8817. sstr[c] = loc[3+strlen("status")+c];
  8818. c++;
  8819. }
  8820. sstr[c] = '\0';
  8821. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8822. }
  8823. //****************transactionId********************/
  8824. c=0;
  8825. loc = strstr(payload, "transactionId");
  8826. memset(sstr ,0, sizeof(sstr) );
  8827. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8828. {
  8829. sstr[c] = loc[strlen("transactionId")+2+c];
  8830. c++;
  8831. }
  8832. sstr[c] = '\0';
  8833. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8834. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8835. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8836. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8837. #ifdef SystemLogMessage
  8838. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8839. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8840. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8841. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8842. #endif
  8843. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8844. {
  8845. //add Charging Record
  8846. SettingChargingRecord(gun_index, transactionIdInt);
  8847. }
  8848. }
  8849. void handleStatusNotificationResponse(char *payload, int gun_index)
  8850. {
  8851. mtrace();
  8852. printf("handleStatusNotificationResponse\n");
  8853. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8854. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8855. }
  8856. void handleStopTransactionnResponse(char *payload, int gun_index)
  8857. {
  8858. mtrace();
  8859. char sstr[30]={ 0 };
  8860. int c = 0;
  8861. char *loc;
  8862. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8863. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8864. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8865. loc = strstr(payload, "idTagInfo");
  8866. //***********************idTagInfo************************/
  8867. if(loc != NULL)
  8868. {
  8869. //***********************expiryDate************************/
  8870. loc = strstr(payload, "expiryDate");
  8871. if(loc != NULL)
  8872. {
  8873. memset(sstr ,0, sizeof(sstr) );
  8874. c = 0;
  8875. while (loc[3+strlen("expiryDate")+c] != '\"')
  8876. {
  8877. sstr[c] = loc[3+strlen("expiryDate")+c];
  8878. c++;
  8879. }
  8880. sstr[c] = '\0';
  8881. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8882. }
  8883. //***********************parentIdTag************************/
  8884. loc = strstr(payload, "parentIdTag");
  8885. if(loc != NULL)
  8886. {
  8887. memset(sstr ,0, sizeof(sstr) );
  8888. c = 0;
  8889. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8890. {
  8891. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8892. c++;
  8893. }
  8894. sstr[c] = '\0';
  8895. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8896. }
  8897. //***********************status************************/
  8898. loc = strstr(payload, "status");
  8899. memset(sstr ,0, sizeof(sstr) );
  8900. c = 0;
  8901. while (loc[3+strlen("status")+c] != '\"')
  8902. {
  8903. sstr[c] = loc[3+strlen("status")+c];
  8904. c++;
  8905. }
  8906. sstr[c] = '\0';
  8907. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8908. }
  8909. #ifdef SystemLogMessage
  8910. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8911. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8912. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8913. #endif
  8914. }
  8915. //==========================================
  8916. // Handle Error routine
  8917. //==========================================
  8918. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8919. {
  8920. mtrace();
  8921. #ifdef SystemLogMessage
  8922. DEBUG_INFO("errorCode: %s\n", errorCode);
  8923. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8924. DEBUG_INFO("errorDetails: %s\n", payload);
  8925. #endif
  8926. }
  8927. //===============================================
  8928. // Common routine
  8929. //===============================================
  8930. int initialConfigurationTable(void)
  8931. {
  8932. printf("initialConfigurationTable \n");
  8933. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8934. /*Core Profile*/
  8935. //AllowOfflineTxForUnknownId
  8936. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8937. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8940. //AuthorizationCacheEnabled
  8941. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8943. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8944. //AuthorizeRemoteTxRequests
  8945. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8948. //BlinkRepeat
  8949. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8952. //ClockAlignedDataInterval
  8953. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8956. //ConnectionTimeOut
  8957. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  8960. //GetConfigurationMaxKeys
  8961. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  8962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  8963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  8964. // HeartbeatInterval
  8965. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  8966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  8967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  8968. // LightIntensity
  8969. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  8970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  8971. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  8972. // LocalAuthorizeOffline
  8973. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  8974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  8975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  8976. // LocalPreAuthorize
  8977. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  8978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  8979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  8980. // MaxEnergyOnInvalidId
  8981. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  8982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  8983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  8984. // MeterValuesAlignedData
  8985. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  8986. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  8987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export(A),Energy.Active.Export.Interval(KWh),Power.Active.Export(KW),Voltage(V),SOC(Percent)" );
  8988. // MeterValuesAlignedDataMaxLength
  8989. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  8990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  8991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  8992. // MeterValuesSampledData
  8993. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  8994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  8995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export(A),Energy.Active.Export.Interval(KWh),Power.Active.Export(KW),Voltage(V),SOC(Percent)" );
  8996. // MeterValuesSampledDataMaxLength
  8997. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  8998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  8999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9000. // MeterValueSampleInterval
  9001. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9004. // MinimumStatusDuration
  9005. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9008. // NumberOfConnectors
  9009. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  9012. // ResetRetries
  9013. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9016. // ConnectorPhaseRotation
  9017. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  9020. // ConnectorPhaseRotationMaxLength
  9021. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9024. // StopTransactionOnEVSideDisconnect
  9025. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9028. // StopTransactionOnInvalidId
  9029. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9032. // StopTxnAlignedData
  9033. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9036. // StopTxnAlignedDataMaxLength
  9037. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9040. // StopTxnSampledData
  9041. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9044. // StopTxnSampledDataMaxLength
  9045. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9048. // SupportedFeatureProfiles
  9049. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9052. // SupportedFeatureProfilesMaxLength
  9053. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9056. // TransactionMessageAttempts
  9057. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9060. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9061. // TransactionMessageRetryInterval
  9062. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9065. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9066. // UnlockConnectorOnEVSideDisconnect
  9067. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9070. // WebSocketPingInterval
  9071. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9072. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9074. //* Local Auth List Management Profile*/
  9075. #if 0
  9076. //For OCTT Test Case
  9077. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9080. #endif
  9081. #if 1
  9082. //LocalAuthListEnabled
  9083. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9086. #endif
  9087. //LocalAuthListMaxLength
  9088. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9091. //SendLocalListMaxLength
  9092. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9093. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9095. //ReserveConnectorZeroSupported
  9096. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9099. //* Smart Charging Profile */
  9100. //ChargeProfileMaxStackLevel
  9101. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9104. // ChargingScheduleAllowedChargingRateUnit
  9105. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9108. // ChargingScheduleMaxPeriods
  9109. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9112. // ConnectorSwitch3to1PhaseSupported
  9113. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9116. // MaxChargingProfilesInstalled
  9117. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9120. return 0;
  9121. }
  9122. void getKeyValue(char *keyReq)
  9123. {
  9124. int isEmpty = FALSE;
  9125. int isKnowKey = FALSE;
  9126. //int unKnowIndex = 0;
  9127. DEBUG_INFO("getKeyValue \n");
  9128. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9129. isEmpty = TRUE;
  9130. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9131. {
  9132. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9134. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9135. {
  9136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9137. }
  9138. else
  9139. {
  9140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9141. }
  9142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9143. isKnowKey = TRUE;
  9144. }
  9145. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9146. {
  9147. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9150. {
  9151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9152. }
  9153. else
  9154. {
  9155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9156. }
  9157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9158. isKnowKey = TRUE;
  9159. }
  9160. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9161. {
  9162. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9165. {
  9166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9167. }
  9168. else
  9169. {
  9170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9171. }
  9172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9173. isKnowKey = TRUE;
  9174. }
  9175. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9176. {
  9177. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9180. {
  9181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9182. }
  9183. else
  9184. {
  9185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9186. }
  9187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9188. isKnowKey = TRUE;
  9189. }
  9190. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9191. {
  9192. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9194. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9195. {
  9196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9197. }
  9198. else
  9199. {
  9200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9201. }
  9202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9203. isKnowKey = TRUE;
  9204. }
  9205. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9206. {
  9207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9210. {
  9211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9212. }
  9213. else
  9214. {
  9215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9216. }
  9217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9218. isKnowKey = TRUE;
  9219. }
  9220. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9221. {
  9222. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9225. {
  9226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9227. }
  9228. else
  9229. {
  9230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9231. }
  9232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9233. isKnowKey = TRUE;
  9234. }
  9235. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9236. {
  9237. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9240. {
  9241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9242. }
  9243. else
  9244. {
  9245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9246. }
  9247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9248. isKnowKey = TRUE;
  9249. }
  9250. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9251. {
  9252. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9255. {
  9256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9257. }
  9258. else
  9259. {
  9260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9261. }
  9262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9263. isKnowKey = TRUE;
  9264. }
  9265. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9266. {
  9267. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9270. {
  9271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9272. }
  9273. else
  9274. {
  9275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9276. }
  9277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9278. isKnowKey = TRUE;
  9279. }
  9280. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9281. {
  9282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9285. {
  9286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9287. }
  9288. else
  9289. {
  9290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9291. }
  9292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9293. isKnowKey = TRUE;
  9294. }
  9295. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9296. {
  9297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9300. {
  9301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9302. }
  9303. else
  9304. {
  9305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9306. }
  9307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  9308. isKnowKey = TRUE;
  9309. }
  9310. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  9311. {
  9312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  9313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  9314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  9315. {
  9316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9317. }
  9318. else
  9319. {
  9320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9321. }
  9322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  9323. isKnowKey = TRUE;
  9324. }
  9325. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  9326. {
  9327. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  9328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  9329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  9330. {
  9331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9332. }
  9333. else
  9334. {
  9335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9336. }
  9337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  9338. isKnowKey = TRUE;
  9339. }
  9340. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  9341. {
  9342. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  9343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  9344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  9345. {
  9346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  9347. }
  9348. else
  9349. {
  9350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  9351. }
  9352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  9353. isKnowKey = TRUE;
  9354. }
  9355. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  9356. {
  9357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  9358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  9359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  9360. {
  9361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9362. }
  9363. else
  9364. {
  9365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9366. }
  9367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  9368. isKnowKey = TRUE;
  9369. }
  9370. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  9371. {
  9372. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  9373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  9374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  9375. {
  9376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  9377. }
  9378. else
  9379. {
  9380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  9381. }
  9382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  9383. isKnowKey = TRUE;
  9384. }
  9385. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  9386. {
  9387. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  9388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  9389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  9390. {
  9391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  9392. }
  9393. else
  9394. {
  9395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  9396. }
  9397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  9398. isKnowKey = TRUE;
  9399. }
  9400. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  9401. {
  9402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  9403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  9404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  9405. {
  9406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  9407. }
  9408. else
  9409. {
  9410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  9411. }
  9412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  9413. isKnowKey = TRUE;
  9414. }
  9415. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  9416. {
  9417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  9418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  9419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  9420. {
  9421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  9422. }
  9423. else
  9424. {
  9425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  9426. }
  9427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  9428. isKnowKey = TRUE;
  9429. }
  9430. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  9431. {
  9432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  9433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  9434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  9435. {
  9436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  9437. }
  9438. else
  9439. {
  9440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  9441. }
  9442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  9443. isKnowKey = TRUE;
  9444. }
  9445. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  9446. {
  9447. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  9448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  9449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  9450. {
  9451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9452. }
  9453. else
  9454. {
  9455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9456. }
  9457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  9458. isKnowKey = TRUE;
  9459. }
  9460. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  9461. {
  9462. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  9463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  9464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  9465. {
  9466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9467. }
  9468. else
  9469. {
  9470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9471. }
  9472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  9473. isKnowKey = TRUE;
  9474. }
  9475. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  9476. {
  9477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  9478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  9479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  9480. {
  9481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9482. }
  9483. else
  9484. {
  9485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9486. }
  9487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  9488. isKnowKey = TRUE;
  9489. }
  9490. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  9491. {
  9492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  9493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  9494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  9495. {
  9496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  9497. }
  9498. else
  9499. {
  9500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  9501. }
  9502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  9503. isKnowKey = TRUE;
  9504. }
  9505. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  9506. {
  9507. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  9508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  9509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  9510. {
  9511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9512. }
  9513. else
  9514. {
  9515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9516. }
  9517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  9518. isKnowKey = TRUE;
  9519. }
  9520. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  9521. {
  9522. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  9523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  9524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  9525. {
  9526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  9527. }
  9528. else
  9529. {
  9530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  9531. }
  9532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  9533. isKnowKey = TRUE;
  9534. }
  9535. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  9536. {
  9537. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  9538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  9539. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  9540. {
  9541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9542. }
  9543. else
  9544. {
  9545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9546. }
  9547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  9548. isKnowKey = TRUE;
  9549. }
  9550. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  9551. {
  9552. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  9553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  9554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  9555. {
  9556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  9557. }
  9558. else
  9559. {
  9560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  9561. }
  9562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  9563. isKnowKey = TRUE;
  9564. }
  9565. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  9566. {
  9567. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  9568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  9569. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  9570. {
  9571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9572. }
  9573. else
  9574. {
  9575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9576. }
  9577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  9578. isKnowKey = TRUE;
  9579. }
  9580. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  9581. {
  9582. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  9583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  9584. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  9585. {
  9586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  9587. }
  9588. else
  9589. {
  9590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  9591. }
  9592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  9593. isKnowKey = TRUE;
  9594. }
  9595. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  9596. {
  9597. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  9598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  9599. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  9600. {
  9601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  9602. }
  9603. else
  9604. {
  9605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  9606. }
  9607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  9608. isKnowKey = TRUE;
  9609. }
  9610. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  9611. {
  9612. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  9613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  9614. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  9615. {
  9616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  9617. }
  9618. else
  9619. {
  9620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  9621. }
  9622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  9623. isKnowKey = TRUE;
  9624. }
  9625. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  9626. {
  9627. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  9628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  9629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  9630. {
  9631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  9632. }
  9633. else
  9634. {
  9635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  9636. }
  9637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  9638. isKnowKey = TRUE;
  9639. }
  9640. #if 0
  9641. //For OCTT Test Case
  9642. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  9643. {
  9644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  9645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  9646. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9647. {
  9648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9649. }
  9650. else
  9651. {
  9652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9653. }
  9654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9655. isKnowKey = TRUE;
  9656. }
  9657. #endif
  9658. #if 1
  9659. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  9660. {
  9661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  9662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  9663. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  9664. {
  9665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  9666. }
  9667. else
  9668. {
  9669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  9670. }
  9671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  9672. isKnowKey = TRUE;
  9673. }
  9674. #endif
  9675. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  9676. {
  9677. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  9678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  9679. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  9680. {
  9681. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9682. }
  9683. else
  9684. {
  9685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9686. }
  9687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  9688. isKnowKey = TRUE;
  9689. }
  9690. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  9691. {
  9692. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  9693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  9694. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  9695. {
  9696. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  9697. }
  9698. else
  9699. {
  9700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  9701. }
  9702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  9703. isKnowKey = TRUE;
  9704. }
  9705. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  9706. {
  9707. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  9708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  9709. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  9710. {
  9711. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  9712. }
  9713. else
  9714. {
  9715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  9716. }
  9717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9718. isKnowKey = TRUE;
  9719. }
  9720. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  9721. {
  9722. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  9723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  9724. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  9725. {
  9726. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  9727. }
  9728. else
  9729. {
  9730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  9731. }
  9732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9733. isKnowKey = TRUE;
  9734. }
  9735. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  9736. {
  9737. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  9738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  9739. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  9740. {
  9741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  9742. }
  9743. else
  9744. {
  9745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  9746. }
  9747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9748. isKnowKey = TRUE;
  9749. }
  9750. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  9751. {
  9752. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  9753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  9754. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  9755. {
  9756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  9757. }
  9758. else
  9759. {
  9760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  9761. }
  9762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9763. isKnowKey = TRUE;
  9764. }
  9765. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  9766. {
  9767. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  9768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  9769. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  9770. {
  9771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  9772. }
  9773. else
  9774. {
  9775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  9776. }
  9777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9778. isKnowKey = TRUE;
  9779. }
  9780. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  9781. {
  9782. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  9783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  9784. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  9785. {
  9786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  9787. }
  9788. else
  9789. {
  9790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  9791. }
  9792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9793. isKnowKey = TRUE;
  9794. }
  9795. //=========================================================
  9796. if(!isEmpty && !isKnowKey)
  9797. {
  9798. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  9799. strcpy(unknownkey[UnknownKeynum], keyReq);
  9800. UnknownKeynum = UnknownKeynum + 1;
  9801. }
  9802. }
  9803. void processUnkownKey(void)
  9804. {
  9805. DEBUG_INFO("processUnkownKey\n");
  9806. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  9807. for(int index=0; index < UnknownKeynum; index++)
  9808. {
  9809. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  9810. {
  9811. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  9812. }
  9813. }
  9814. }
  9815. int setKeyValue(char *key, char *value)
  9816. {
  9817. int isSuccess = NotSupported;
  9818. int check_ascii=0;
  9819. #ifdef Debug
  9820. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  9821. #endif
  9822. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  9823. {
  9824. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9825. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9826. {
  9827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9828. isSuccess = ConfigurationStatus_Accepted;
  9829. }
  9830. else
  9831. {
  9832. isSuccess = ConfigurationStatus_Rejected;
  9833. }
  9834. }
  9835. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  9836. {
  9837. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9839. {
  9840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  9841. isSuccess = ConfigurationStatus_Accepted;
  9842. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  9843. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  9844. }
  9845. else
  9846. {
  9847. isSuccess = ConfigurationStatus_Rejected;
  9848. }
  9849. }
  9850. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  9851. {
  9852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9853. {
  9854. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  9855. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9856. isSuccess = ConfigurationStatus_Accepted;
  9857. }
  9858. else
  9859. {
  9860. isSuccess = ConfigurationStatus_Rejected;
  9861. }
  9862. }
  9863. if(strcmp(key, "BlinkRepeat") == 0)
  9864. {
  9865. //Charger.BlinkRepeat = Integer.parseInt(value);
  9866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9867. {
  9868. check_ascii = value[0];
  9869. if( (check_ascii < 48) || (check_ascii > 57) )
  9870. {
  9871. isSuccess = ConfigurationStatus_Rejected;
  9872. }
  9873. else
  9874. {
  9875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  9876. isSuccess = ConfigurationStatus_Accepted;
  9877. }
  9878. }
  9879. else
  9880. {
  9881. isSuccess = ConfigurationStatus_Rejected;
  9882. }
  9883. }
  9884. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  9885. {
  9886. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9887. {
  9888. check_ascii = value[0];
  9889. if( (check_ascii < 48) || (check_ascii > 57) )
  9890. {
  9891. isSuccess = ConfigurationStatus_Rejected;
  9892. }
  9893. else
  9894. {
  9895. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  9896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  9897. isSuccess = ConfigurationStatus_Accepted;
  9898. }
  9899. }
  9900. else
  9901. {
  9902. isSuccess = ConfigurationStatus_Rejected;
  9903. }
  9904. }
  9905. if(strcmp(key, "ConnectionTimeOut") == 0 )
  9906. {
  9907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9908. {
  9909. check_ascii = value[0];
  9910. if( (check_ascii < 48) || (check_ascii > 57) )
  9911. {
  9912. isSuccess = ConfigurationStatus_Rejected;
  9913. }
  9914. else
  9915. {
  9916. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  9917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  9918. isSuccess = ConfigurationStatus_Accepted;
  9919. }
  9920. }
  9921. else
  9922. {
  9923. isSuccess = ConfigurationStatus_Rejected;
  9924. }
  9925. }
  9926. if(strcmp(key, "HeartbeatInterval") == 0)
  9927. {
  9928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9929. {
  9930. check_ascii = value[0];
  9931. if( (check_ascii < 48) || (check_ascii > 57) )
  9932. {
  9933. isSuccess = ConfigurationStatus_Rejected;
  9934. }
  9935. else
  9936. {
  9937. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  9938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  9939. HeartBeatWaitTime = atoi(value);
  9940. isSuccess = ConfigurationStatus_Accepted;
  9941. }
  9942. }
  9943. else
  9944. {
  9945. isSuccess = ConfigurationStatus_Rejected;
  9946. }
  9947. }
  9948. if(strcmp(key, "LightIntensity") == 0)
  9949. {
  9950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9951. {
  9952. check_ascii = value[0];
  9953. if( (check_ascii < 48) || (check_ascii > 57) )
  9954. {
  9955. isSuccess = ConfigurationStatus_Rejected;
  9956. }
  9957. else
  9958. {
  9959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  9960. isSuccess = ConfigurationStatus_Accepted;
  9961. }
  9962. }
  9963. else
  9964. {
  9965. isSuccess = ConfigurationStatus_Rejected;
  9966. }
  9967. }
  9968. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  9969. {
  9970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9971. {
  9972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9973. isSuccess = ConfigurationStatus_Accepted;
  9974. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9975. }
  9976. else
  9977. {
  9978. isSuccess = ConfigurationStatus_Rejected;
  9979. }
  9980. }
  9981. if(strcmp(key, "LocalPreAuthorize") == 0)
  9982. {
  9983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9984. {
  9985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  9986. isSuccess = ConfigurationStatus_Accepted;
  9987. }
  9988. else
  9989. {
  9990. isSuccess = ConfigurationStatus_Rejected;
  9991. }
  9992. }
  9993. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  9994. {
  9995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9996. {
  9997. check_ascii = value[0];
  9998. if( (check_ascii < 48) || (check_ascii > 57) )
  9999. {
  10000. isSuccess = ConfigurationStatus_Rejected;
  10001. }
  10002. else
  10003. {
  10004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10005. isSuccess = ConfigurationStatus_Accepted;
  10006. }
  10007. }
  10008. else
  10009. {
  10010. isSuccess = ConfigurationStatus_Rejected;
  10011. }
  10012. }
  10013. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10014. {
  10015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10016. {
  10017. //int valueLength = strlen(value);
  10018. for(int i = 0; value[i]; i++){
  10019. value[i] = tolower(value[i]);
  10020. }
  10021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10022. isSuccess = ConfigurationStatus_Accepted;
  10023. }
  10024. else
  10025. {
  10026. isSuccess = ConfigurationStatus_Rejected;
  10027. }
  10028. }
  10029. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10030. {
  10031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10032. {
  10033. //int valueLength = strlen(value);
  10034. for(int i = 0; value[i]; i++){
  10035. value[i] = tolower(value[i]);
  10036. }
  10037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10038. isSuccess = ConfigurationStatus_Accepted;
  10039. }
  10040. else
  10041. {
  10042. isSuccess = ConfigurationStatus_Rejected;
  10043. }
  10044. }
  10045. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10046. {
  10047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10048. {
  10049. check_ascii = value[0];
  10050. if( (check_ascii < 48) || (check_ascii > 57) )
  10051. {
  10052. isSuccess = ConfigurationStatus_Rejected;
  10053. }
  10054. else
  10055. {
  10056. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10058. isSuccess = ConfigurationStatus_Accepted;
  10059. }
  10060. #ifdef Debug
  10061. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Accepted \n");
  10062. #endif
  10063. }
  10064. else
  10065. {
  10066. isSuccess = ConfigurationStatus_Rejected;
  10067. #ifdef Debug
  10068. DEBUG_INFO(" MeterValueSampleInterval is ConfigurationStatus_Rejected \n");
  10069. #endif
  10070. }
  10071. }
  10072. if(strcmp(key, "MinimumStatusDuration") == 0)
  10073. {
  10074. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10075. {
  10076. check_ascii = value[0];
  10077. if( (check_ascii < 48) || (check_ascii > 57) )
  10078. {
  10079. isSuccess = ConfigurationStatus_Rejected;
  10080. }
  10081. else
  10082. {
  10083. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10084. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10085. isSuccess = ConfigurationStatus_Accepted;
  10086. }
  10087. }
  10088. else
  10089. {
  10090. isSuccess = ConfigurationStatus_Rejected;
  10091. }
  10092. }
  10093. if(strcmp(key, "ResetRetries") == 0)
  10094. {
  10095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10096. {
  10097. check_ascii = value[0];
  10098. if( (check_ascii < 48) || (check_ascii > 57) )
  10099. {
  10100. isSuccess = ConfigurationStatus_Rejected;
  10101. }
  10102. else
  10103. {
  10104. //Charger.ResetRetries = Integer.parseInt(value);
  10105. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10106. isSuccess = ConfigurationStatus_Accepted;
  10107. }
  10108. }
  10109. else
  10110. {
  10111. isSuccess = ConfigurationStatus_Rejected;
  10112. }
  10113. }
  10114. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10115. {
  10116. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10117. {
  10118. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  10119. //int valueLength = strlen(value);
  10120. for(int i = 0; value[i]; i++){
  10121. value[i] = tolower(value[i]);
  10122. }
  10123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10124. isSuccess = ConfigurationStatus_Accepted;
  10125. }
  10126. else
  10127. {
  10128. isSuccess = ConfigurationStatus_Rejected;
  10129. }
  10130. }
  10131. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10132. {
  10133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10134. {
  10135. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10137. isSuccess = ConfigurationStatus_Accepted;
  10138. }
  10139. else
  10140. {
  10141. isSuccess = ConfigurationStatus_Rejected;
  10142. }
  10143. }
  10144. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10145. {
  10146. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10147. {
  10148. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10149. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10150. isSuccess = ConfigurationStatus_Accepted;
  10151. }
  10152. else
  10153. {
  10154. isSuccess = ConfigurationStatus_Rejected;
  10155. }
  10156. }
  10157. if(strcmp(key, "StopTxnAlignedData") == 0)
  10158. {
  10159. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10160. {
  10161. //Charger.StopTxnAlignedData = value.toLowerCase();
  10162. //int valueLength = strlen(value);
  10163. for(int i = 0; value[i]; i++){
  10164. value[i] = tolower(value[i]);
  10165. }
  10166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10167. isSuccess = ConfigurationStatus_Accepted;
  10168. }
  10169. else
  10170. {
  10171. isSuccess = ConfigurationStatus_Rejected;
  10172. }
  10173. }
  10174. if(strcmp(key, "StopTxnSampledData") == 0)
  10175. {
  10176. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10177. {
  10178. //Charger.StopTxnSampledData = value.toLowerCase();
  10179. //int valueLength = strlen(value);
  10180. for(int i = 0; value[i]; i++){
  10181. value[i] = tolower(value[i]);
  10182. }
  10183. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  10184. isSuccess = ConfigurationStatus_Accepted;
  10185. }
  10186. else
  10187. {
  10188. isSuccess = ConfigurationStatus_Rejected;
  10189. }
  10190. }
  10191. if(strcmp(key, "TransactionMessageAttempts") == 0)
  10192. {
  10193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10194. {
  10195. check_ascii = value[0];
  10196. if( (check_ascii < 48) || (check_ascii > 57) )
  10197. {
  10198. isSuccess = ConfigurationStatus_Rejected;
  10199. }
  10200. else
  10201. {
  10202. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  10203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  10204. TransactionMessageAttemptsValue = atoi(value);
  10205. isSuccess = ConfigurationStatus_Accepted;
  10206. }
  10207. }
  10208. else
  10209. {
  10210. isSuccess = ConfigurationStatus_Rejected;
  10211. }
  10212. }
  10213. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  10214. {
  10215. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10216. {
  10217. check_ascii = value[0];
  10218. if( (check_ascii < 48) || (check_ascii > 57) )
  10219. {
  10220. isSuccess = ConfigurationStatus_Rejected;
  10221. }
  10222. else
  10223. {
  10224. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  10225. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  10226. TransactionMessageRetryIntervalValue = atoi(value);
  10227. isSuccess = ConfigurationStatus_Accepted;
  10228. }
  10229. }
  10230. else
  10231. {
  10232. isSuccess = ConfigurationStatus_Rejected;
  10233. }
  10234. }
  10235. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  10236. {
  10237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10238. {
  10239. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10241. isSuccess = ConfigurationStatus_Accepted;
  10242. }
  10243. else
  10244. {
  10245. isSuccess = ConfigurationStatus_Rejected;
  10246. }
  10247. }
  10248. if(strcmp(key, "WebSocketPingInterval") == 0)
  10249. {
  10250. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10251. {
  10252. check_ascii = value[0];
  10253. if( (check_ascii < 48) || (check_ascii > 57) )
  10254. {
  10255. isSuccess = ConfigurationStatus_Rejected;
  10256. }
  10257. else
  10258. {
  10259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  10260. isSuccess = ConfigurationStatus_Accepted;
  10261. }
  10262. }
  10263. else
  10264. {
  10265. isSuccess = ConfigurationStatus_Rejected;
  10266. }
  10267. }
  10268. #if 0
  10269. //For OCPP Test Case
  10270. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  10271. {
  10272. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10273. {
  10274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10275. isSuccess = ConfigurationStatus_Accepted;
  10276. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10277. }
  10278. else
  10279. {
  10280. isSuccess = ConfigurationStatus_Rejected;
  10281. }
  10282. }
  10283. #endif
  10284. #if 1
  10285. if(strcmp(key, "LocalAuthListEnabled") == 0)
  10286. {
  10287. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10288. {
  10289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  10290. isSuccess = ConfigurationStatus_Accepted;
  10291. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10292. }
  10293. else
  10294. {
  10295. isSuccess = ConfigurationStatus_Rejected;
  10296. }
  10297. }
  10298. #endif
  10299. return isSuccess;
  10300. }
  10301. int updateSetting(char *key, char *value)
  10302. {
  10303. mtrace();
  10304. int isSuccess = FALSE;
  10305. char string[1000]={0}, buffer[1000]={0};
  10306. char strtemp[50]={0};
  10307. char sstr[50]={ 0 };//sstr[200]={ 0 };
  10308. int pos, c = 0;
  10309. char *loc;
  10310. int pos1=0;
  10311. FILE *f = fopen("/var/www/settings1", "r");
  10312. if(f == NULL)
  10313. {
  10314. #ifdef Debug
  10315. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  10316. #endif
  10317. return isSuccess;
  10318. }
  10319. fseek(f, 0, SEEK_END);
  10320. long fsize = ftell(f);
  10321. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  10322. fread(string, 1, fsize, f);
  10323. fclose(f);
  10324. string[fsize] = 0;
  10325. loc = strstr(string, key);
  10326. if(loc != NULL)
  10327. {
  10328. DEBUG_INFO("key exist!\n");
  10329. pos = loc - string-1;
  10330. f = fopen("/var/www/settings1", "w");
  10331. strncpy(buffer, string, pos);
  10332. fprintf(f, "%s", buffer);
  10333. memset(sstr ,0, sizeof(sstr) );
  10334. c = 0;
  10335. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  10336. {
  10337. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  10338. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10339. c++;
  10340. }
  10341. sstr[c] = '\0';
  10342. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  10343. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  10344. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  10345. memset(buffer ,0, sizeof(buffer) );
  10346. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  10347. //printf("buffer=%s",buffer);
  10348. fprintf(f, "%s", buffer);
  10349. fclose(f);
  10350. }
  10351. else
  10352. {
  10353. printf("key not exist!\n");
  10354. f = fopen("/var/www/settings1", "w+");
  10355. fputs(string, f);
  10356. fseek(f, -1, SEEK_CUR);
  10357. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  10358. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  10359. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  10360. fclose(f);
  10361. }
  10362. isSuccess = TRUE;
  10363. return isSuccess;
  10364. }
  10365. int TransactionMessageAttemptsGet(void)
  10366. {
  10367. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10368. }
  10369. int FirstHeartBeatResponse(void)
  10370. {
  10371. return FirstHeartBeat;
  10372. }
  10373. int TransactionMessageRetryIntervalGet(void)
  10374. {
  10375. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10376. }
  10377. #define SA struct sockaddr
  10378. #define MAXBUF 1024
  10379. //static int m_socket_data;
  10380. //static int sockfd;
  10381. int ReadHttpStatus(int sock){
  10382. //char c;
  10383. char buff[1024]="",*ptr=buff+1;
  10384. int bytes_received, status;
  10385. DEBUG_INFO("Begin Response ..\n");
  10386. while((bytes_received = recv(sock, ptr, 1, 0))){
  10387. if(bytes_received==-1){
  10388. perror("ReadHttpStatus");
  10389. exit(1);
  10390. }
  10391. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  10392. ptr++;
  10393. }
  10394. *ptr=0;
  10395. ptr=buff+1;
  10396. sscanf(ptr,"%*s %d ", &status);
  10397. DEBUG_INFO("%s\n",ptr);
  10398. DEBUG_INFO("status=%d\n",status);
  10399. DEBUG_INFO("End Response ..\n");
  10400. return (bytes_received>0)?status:0;
  10401. }
  10402. //the only filed that it parsed is 'Content-Length'
  10403. int ParseHeader(int sock){
  10404. //char c;
  10405. char buff[1024]="",*ptr=buff+4;
  10406. int bytes_received;
  10407. DEBUG_INFO("Begin HEADER ..\n");
  10408. while((bytes_received = recv(sock, ptr, 1, 0))){
  10409. if(bytes_received==-1){
  10410. perror("Parse Header");
  10411. exit(1);
  10412. }
  10413. if(
  10414. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  10415. (ptr[-1]=='\r') && (*ptr=='\n' )
  10416. ) break;
  10417. ptr++;
  10418. }
  10419. *ptr=0;
  10420. ptr=buff+4;
  10421. //printf("%s",ptr);
  10422. if(bytes_received){
  10423. ptr=strstr(ptr,"Content-Length:");
  10424. if(ptr){
  10425. sscanf(ptr,"%*s %d",&bytes_received);
  10426. }else
  10427. bytes_received=-1; //unknown size
  10428. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  10429. }
  10430. DEBUG_INFO("End HEADER ..\n");
  10431. return bytes_received ;
  10432. }
  10433. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  10434. {
  10435. char ftpbuf[200];
  10436. int systemresult;
  10437. DEBUG_INFO("filename=%s\n",filename);
  10438. DEBUG_INFO("url=%s\n",url);
  10439. memset(ftpbuf, 0, sizeof(ftpbuf));
  10440. sprintf(ftpbuf, "wget --tries=3 -O %s -c %s",filename, url);
  10441. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10442. systemresult = system(ftpbuf);
  10443. DEBUG_INFO("systemresult=%d\n",systemresult);
  10444. if(systemresult != 0)
  10445. {
  10446. DEBUG_INFO("http DownLoad error!\n");
  10447. return FALSE;
  10448. }
  10449. return TRUE;
  10450. }
  10451. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  10452. {
  10453. char ftpbuf[200];
  10454. int systemresult;
  10455. //char temp[100];
  10456. #if 0
  10457. struct hostent* server;
  10458. char *IPbuffer;
  10459. server = gethostbyname(location);
  10460. // To convert an Internet network
  10461. // address into ASCII string
  10462. IPbuffer = inet_ntoa(*((struct in_addr*)
  10463. server->h_addr_list[0]));
  10464. #endif
  10465. memset(ftpbuf, 0, sizeof(ftpbuf));
  10466. sprintf(ftpbuf, "wget --tries=3 -O %s -c %s",filename, url);
  10467. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  10468. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10469. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10470. systemresult = system(ftpbuf);
  10471. DEBUG_INFO("systemresult=%d\n",systemresult);
  10472. if(systemresult != 0)
  10473. {
  10474. printf("ftpget error!\n");
  10475. return FALSE;
  10476. }
  10477. return TRUE;
  10478. }
  10479. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  10480. {
  10481. struct hostent* server;
  10482. char *IPbuffer;
  10483. char ftpbuf[200];
  10484. int systemresult;
  10485. // To retrieve host information
  10486. server = gethostbyname(location);
  10487. // To convert an Internet network
  10488. // address into ASCII string
  10489. IPbuffer = inet_ntoa(*((struct in_addr*)
  10490. server->h_addr_list[0]));
  10491. memset(ftpbuf, 0, sizeof(ftpbuf));
  10492. /* format : ftpput -u username -p passwd IP target source*/
  10493. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  10494. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  10495. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  10496. systemresult = system(ftpbuf);
  10497. DEBUG_INFO("systemresult=%d\n",systemresult);
  10498. if(systemresult != 0)
  10499. {
  10500. DEBUG_INFO("ftpput error!\n");
  10501. return FALSE;
  10502. }
  10503. return TRUE;
  10504. }
  10505. int SettingChargingRecord(int target, int transactionId)
  10506. {
  10507. if(strstr((const char *)ShmSysConfigAndInfo->SysConfig.ModelName ,"DC") != NULL)
  10508. {
  10509. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10510. {
  10511. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10512. {
  10513. addBuff(target, transactionId, 0);
  10514. return TRUE;
  10515. }
  10516. }
  10517. for (int index = 0; index < CCS_QUANTITY; index++)
  10518. {
  10519. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10520. {
  10521. addBuff(target, transactionId, 0);
  10522. return TRUE;
  10523. }
  10524. }
  10525. for (int index = 0; index < GB_QUANTITY; index++)
  10526. {
  10527. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10528. {
  10529. addBuff(target, transactionId, 0);
  10530. return TRUE;
  10531. }
  10532. }
  10533. }
  10534. else
  10535. {
  10536. for (int index = 0; index < AC_QUANTITY; index++)
  10537. {
  10538. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  10539. {
  10540. addBuff(target, transactionId, 0);
  10541. return TRUE;
  10542. }
  10543. }
  10544. }
  10545. return FALSE;
  10546. }
  10547. int addBuff(int gun_idx, int user_id, int cmd_sn)
  10548. {
  10549. int isSuccess = FALSE;
  10550. //char *query = NULL;
  10551. sqlite3_stmt *stmt;
  10552. int rc; // return code
  10553. char str[20];
  10554. sprintf(str,"%d",user_id);
  10555. 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 */
  10556. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  10557. rc = sqlite3_step(stmt); /* 3 */
  10558. if (rc != SQLITE_DONE) {
  10559. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  10560. goto out;
  10561. }
  10562. sqlite3_finalize(stmt);
  10563. // free(query);
  10564. out:
  10565. //----------------------
  10566. // close SQLite database
  10567. //----------------------
  10568. sqlite3_close(db);
  10569. printf("database closed.\n");
  10570. return isSuccess;
  10571. }
  10572. /**
  10573. * Place the contents of the specified file into a memory buffer
  10574. *
  10575. * @param[in] filename The path and name of the file to read
  10576. * @param[out] filebuffer A pointer to the contents in memory
  10577. * @return status 0 success, 1 on failure
  10578. */
  10579. int get_file_contents(const char* filename, char** outbuffer) {
  10580. FILE* file = NULL;
  10581. long filesize;
  10582. const int blocksize = 1;
  10583. size_t readsize;
  10584. char* filebuffer;
  10585. // Open the file
  10586. file = fopen(filename, "r");
  10587. if (NULL == file)
  10588. {
  10589. printf("'%s' not opened\n", filename);
  10590. exit(EXIT_FAILURE);
  10591. }
  10592. // Determine the file size
  10593. fseek(file, 0, SEEK_END);
  10594. filesize = ftell(file);
  10595. rewind (file);
  10596. // Allocate memory for the file contents
  10597. filebuffer = (char*) malloc(sizeof(char) * filesize);
  10598. *outbuffer = filebuffer;
  10599. if (filebuffer == NULL)
  10600. {
  10601. fputs ("malloc out-of-memory", stderr);
  10602. exit(EXIT_FAILURE);
  10603. }
  10604. // Read in the file
  10605. readsize = fread(filebuffer, blocksize, filesize, file);
  10606. if (readsize != filesize)
  10607. {
  10608. fputs ("didn't read file completely",stderr);
  10609. exit(EXIT_FAILURE);
  10610. }
  10611. // Clean exit
  10612. fclose(file);
  10613. return EXIT_SUCCESS;
  10614. }
  10615. static int selectSqlCount = 0;
  10616. static int callback(void *data, int argc, char **argv, char **azColName){
  10617. int i;
  10618. printf("%s: ", (const char*)data);
  10619. selectSqlCount = argc;
  10620. for(i = 0; i<argc; i++){
  10621. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  10622. }
  10623. printf("\n");
  10624. return 0;
  10625. }
  10626. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  10627. //int i;
  10628. //printf("%s:\n", (const char*)data);
  10629. localversion = argv[5] ? atoi(argv[5]) : 0;
  10630. printf("localversion=%d\n", localversion);
  10631. return 0;
  10632. }
  10633. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  10634. //int i;
  10635. //printf("%s:\n", (const char*)data);
  10636. //idTag
  10637. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  10638. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  10639. //parentIdTag
  10640. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  10641. //expir_date
  10642. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  10643. //status
  10644. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  10645. //version
  10646. idTagQuery.listVersionInt = atoi(argv[5]);
  10647. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  10648. return 0;
  10649. }
  10650. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  10651. int i;
  10652. //printf("%s:\n", (const char*)data);
  10653. #if 1
  10654. for(i=0; i<argc; i++){
  10655. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  10656. }
  10657. //printf("");
  10658. #endif
  10659. // localversion = argv[5] ? atoi(argv[5]) : 0;
  10660. // printf("localversion=%d\n", localversion);
  10661. return 0;
  10662. }
  10663. /** sqlite3_exec的回调。
  10664. *
  10665. * 向控制台打印查询的结果。
  10666. *
  10667. * @param in data 传递给回调函数的数据。
  10668. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  10669. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  10670. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  10671. * @return 状态码。
  10672. */
  10673. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  10674. {
  10675. for (int i = 0; i < n_columns; i++)
  10676. {
  10677. DEBUG_INFO("%s/t", col_values[i]);
  10678. }
  10679. DEBUG_INFO("/n");
  10680. return 0;
  10681. }
  10682. void OCPP_getListVerion()
  10683. {
  10684. int rc = 0;
  10685. // const char* data = "Callback function called";
  10686. char sql[100];
  10687. char zErrMsg[100];
  10688. memset(sql, 0, 100);
  10689. memset(zErrMsg, 0, 100);
  10690. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  10691. /* Execute SQL statement */
  10692. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  10693. DEBUG_INFO("rc=%d\n",rc);
  10694. if( rc != SQLITE_OK ){
  10695. DEBUG_INFO("SQL error: %s", zErrMsg);
  10696. //sqlite3_free(zErrMsg);
  10697. }else{
  10698. DEBUG_INFO("Operation done successfully");
  10699. }
  10700. }
  10701. void OCPP_getIdTag(char *idTag)
  10702. {
  10703. int rc = 0;
  10704. // const char* data = "Callback function called";
  10705. char sql[100];
  10706. char zErrMsg[100];
  10707. memset(sql, 0, 100);
  10708. memset(zErrMsg, 0, 100);
  10709. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  10710. memset(&idTagQuery, 0, sizeof(idTagQuery));
  10711. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10712. /* Execute SQL statement */
  10713. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  10714. if( rc != SQLITE_OK ){
  10715. DEBUG_INFO("SQL error: %s", zErrMsg);
  10716. //sqlite3_free(zErrMsg);
  10717. }else{
  10718. printf("Operation done successfully");
  10719. }
  10720. //return ver;
  10721. }
  10722. void OCPP_get_TableAuthlocalAllData(void)
  10723. {
  10724. int rc = 0;
  10725. // const char* data = "Callback function called";
  10726. char sql[100];
  10727. char zErrMsg[100];
  10728. memset(sql, 0, 100);
  10729. memset(zErrMsg, 0, 100);
  10730. sprintf(sql,"select * from ocpp_auth_local ");
  10731. /* Execute SQL statement */
  10732. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  10733. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  10734. if( rc != SQLITE_OK ){
  10735. DEBUG_INFO("SQL error: %s", zErrMsg);
  10736. //sqlite3_free(zErrMsg);
  10737. }else{
  10738. DEBUG_INFO("Operation done successfully");
  10739. }
  10740. //return ver;
  10741. }
  10742. int OCPP_cleanLocalList()
  10743. {
  10744. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  10745. char *errMsg = 0;
  10746. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  10747. if (SQLITE_OK != rc)
  10748. {
  10749. DEBUG_INFO("%s\n",errMsg);
  10750. return FALSE;
  10751. }
  10752. else
  10753. {
  10754. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  10755. }
  10756. return TRUE;
  10757. }
  10758. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10759. {
  10760. int isSuccess = FALSE;
  10761. int ret = 0;
  10762. //const char* data = "Callback function called";
  10763. char sql[200];
  10764. char zErrMsg[100];
  10765. memset(sql, 0, 200);
  10766. memset(zErrMsg, 0, 100);
  10767. 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);
  10768. //* Execute SQL statement */
  10769. //zErrMsg = 0;
  10770. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  10771. if( ret != SQLITE_OK ){
  10772. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  10773. // free(zErrMsg);
  10774. // free(sql);
  10775. return isSuccess;
  10776. }
  10777. DEBUG_INFO("successfully Insert records created\n");
  10778. isSuccess = TRUE;
  10779. return isSuccess;
  10780. }
  10781. void OCPP_deleteIdTag(char *idTag)
  10782. {
  10783. //int ver = 0;
  10784. //int isSuccess = FALSE;
  10785. int rc = 0;
  10786. char sql[100];
  10787. char zErrMsg[100];
  10788. memset(sql, 0, 100);
  10789. memset(zErrMsg, 0, 100);
  10790. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  10791. //* Execute SQL statement */
  10792. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  10793. if( rc != SQLITE_OK ){
  10794. DEBUG_INFO("SQL error: %s", zErrMsg);
  10795. //sqlite3_free(zErrMsg);
  10796. }else{
  10797. DEBUG_INFO("Operation done successfully");
  10798. }
  10799. }
  10800. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  10801. {
  10802. int isSuccess = FALSE;
  10803. int ret = 0;
  10804. const char* data = "Callback function called";
  10805. char sql[200];
  10806. char zErrMsg[100];
  10807. memset(sql, 0, 200);
  10808. memset(zErrMsg, 0, 100);
  10809. //* selectFromTable */
  10810. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  10811. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  10812. //* Execute SQL statement */
  10813. selectSqlCount = 0;
  10814. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10815. if( ret != SQLITE_OK ){
  10816. printf("Error SQL: %s\n", zErrMsg);
  10817. }
  10818. printf("successfully select operation done\n");
  10819. memset(sql, 0, 200);
  10820. memset(zErrMsg, 0, 100);
  10821. if(selectSqlCount == 0)
  10822. {
  10823. //Insert
  10824. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
  10825. 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);
  10826. DEBUG_INFO("sql:%s\n", sql);
  10827. //* Execute SQL statement */
  10828. //zErrMsg = 0;
  10829. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  10830. if( ret != SQLITE_OK ){
  10831. printf("SQL error: %s\n", zErrMsg);
  10832. return isSuccess;
  10833. }
  10834. DEBUG_INFO("successfully Insert records created\n");
  10835. isSuccess = TRUE;
  10836. }
  10837. else
  10838. {
  10839. //Update
  10840. //* Create merged SQL statement */
  10841. 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);
  10842. /* Execute SQL statement */
  10843. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  10844. if( ret != SQLITE_OK ){
  10845. printf("SQL error: %s\n", zErrMsg);
  10846. //sqlite3_free(zErrMsg);
  10847. //sqlite3_free(sql);
  10848. return isSuccess;
  10849. }
  10850. DEBUG_INFO("Successfully operation done \n");
  10851. isSuccess = TRUE;
  10852. }
  10853. return isSuccess;
  10854. }
  10855. char *GetOcppServerURL()
  10856. {
  10857. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  10858. memset(OcppHost, 0, sizeof(OcppHost));
  10859. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  10860. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  10861. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10862. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  10863. DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  10864. DEBUG_INFO("OcppHost =%s\n",OcppHost);
  10865. DEBUG_INFO("OcppPort =%d\n",OcppPort);
  10866. DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  10867. return OcppHost;
  10868. }
  10869. char *GetOcppPath()
  10870. {
  10871. if(OcppTempPath == NULL)
  10872. {
  10873. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  10874. }
  10875. else
  10876. {
  10877. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  10878. }
  10879. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  10880. return OcppPath;
  10881. }
  10882. int GetOcppPort()
  10883. {
  10884. return OcppPort;
  10885. }
  10886. int GetOcppConnStatus(void)
  10887. {
  10888. return ShmOCPP16Data->OcppConnStatus;
  10889. }
  10890. void SetOcppConnStatus(uint8_t status)
  10891. {
  10892. ShmOCPP16Data->OcppConnStatus = status;
  10893. }
  10894. #if 0
  10895. void Send(struct json_object *message)
  10896. {
  10897. printf("Send -1 \n");
  10898. printf("message=%s\n",json_object_to_json_string(message));
  10899. LWS_Send(json_object_to_json_string(message));
  10900. }
  10901. #endif
  10902. void LWS_Send(char * str)
  10903. {
  10904. #if 1
  10905. //=====================================================
  10906. // Check InternetConn 0: disconnected, 1: connected
  10907. //====================================================
  10908. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  10909. {
  10910. DEBUG_INFO("\n offline now !!!\n");
  10911. return;
  10912. }
  10913. #endif
  10914. pthread_mutex_lock(&lock);
  10915. memset(SendBuffer,0,SendBufLen);
  10916. sprintf((char *)SendBuffer, "%s", str);
  10917. pthread_mutex_unlock(&lock);
  10918. lws_callback_on_writable(wsi_client);
  10919. lws_service(context, 10000);//timeout_ms
  10920. //usleep(10000); // 等�??��?微�?
  10921. //DEBUG_INFO("Send message end\n");
  10922. }