MessageHandler.c 327 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031
  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 <json.h>
  19. #include <json_config.h>
  20. #include <json_object.h>
  21. #include <json_tokener.h>
  22. //#include <json-c/json.h> remove temporally
  23. //#include <json-c/json_config.h> remove temporally
  24. //#include <json-c/json_object.h> remove temporally
  25. //#include <json-c/json_tokener.h> remove temporally
  26. #include <libwebsockets.h>
  27. #include <lws_config.h>
  28. //#include "./json-c/JsonParser.h" remove temporally
  29. #include "JsonParser.h"
  30. #include "hashmap.h"
  31. #include "ShareMemory.h"
  32. #include "TransactionQueue.h"
  33. #include "SystemLogMessage.h"
  34. #include "../../Projects/define.h"
  35. #include "ShareMemory.h"
  36. #include "SystemLogMessage.h"
  37. //#include "config.h"
  38. #include <sys/socket.h>
  39. #include <netinet/in.h>
  40. #include <stdlib.h>
  41. /*for sendfile()*/
  42. #include <sys/sendfile.h>
  43. /*for O_RDONLY*/
  44. #include <fcntl.h>
  45. #include "sqlite3.h"
  46. #include <arpa/inet.h>
  47. #define _GNU_SOURCE
  48. #include <time.h>
  49. #include "MessageHandler.h"
  50. #include <assert.h>
  51. #include <pthread.h>
  52. #define PASS 1
  53. #define FAIL -1
  54. #define FALSE 0
  55. #define TRUE 1 // Option 1
  56. #define ChargingProfile_0_JSON "chargingprofile_0.json"
  57. #define ChargingProfile_1_JSON "chargingprofile_1.json"
  58. #define ChargingProfile_2_JSON "chargingprofile_2.json"
  59. #define AuthorizationCache_JSON "AuthorizationCache.json"
  60. #define LocalAuthorizationList_JSON "LocalAuthorizationList.json"
  61. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  62. struct StatusCodeData *ShmStatusCodeData;
  63. struct PsuData *ShmPsuData ;
  64. struct OCPP16Data *ShmOCPP16Data;
  65. /* define Macro */
  66. #define SystemLogMessage
  67. /* OCPP Message Type */
  68. #define MESSAGE_TYPE_CALL 2
  69. #define MESSAGE_TYPE_CALLRESULT 3
  70. #define MESSAGE_TYPE_CALLERROR 4
  71. /* */
  72. #define server_cycle_Status 120
  73. #define MACROSTR(k) #k
  74. extern struct lws *wsi_client;
  75. extern struct lws_context *context;
  76. extern unsigned char *SendBuffer;
  77. extern int SendBufLen;
  78. //char guid[37];
  79. char queuedata[2000];
  80. static char unknownkey[10][20];
  81. static int UnknownKeynum = 0;
  82. static int localversion=0;
  83. static char idTagAuthorization[32]={};
  84. char OcppPath[100]={};
  85. char OcppProtocol[10],OcppHost[50], OcppTempPath[50];
  86. int OcppPort=0;
  87. extern map_t hashMap;
  88. extern data_struct_t* mapItem;
  89. extern char *random_uuid( char buf[37] );
  90. extern void split(char **arr, char *str, const char *del);
  91. extern pthread_mutex_t mutex1;
  92. int updateSetting(char *key, char *value);
  93. int setKeyValue(char *key, char *value);
  94. int server_sign = FALSE;
  95. int server_pending = FALSE;
  96. int authenrequest = FALSE;
  97. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  98. int BootNotificationInterval = 0;
  99. //number of Retry times
  100. int authorizeRetryTimes = 0;
  101. int isUpdateRequest = FALSE;
  102. int statusModeChage = FALSE;
  103. int HeartBeatWaitTime = 10;
  104. //Test Variables
  105. int teststatus =100; //0: enter test ; 100: test
  106. int testCount= 5;
  107. int testCountInc = 0;
  108. int UserPlugGun = 0; // user plug gun or not
  109. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  110. extern struct Charger_Info Charger;
  111. extern sqlite3 *db;
  112. struct ClientTime
  113. {
  114. unsigned int Heartbeat;
  115. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  116. unsigned int StartTransaction;
  117. unsigned int StopTransaction;
  118. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY];
  119. }clientTime;
  120. typedef union
  121. {
  122. //Operations Initiated by Central System
  123. unsigned char CsMsgValue[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  124. struct
  125. {
  126. //CsMsgValue[0]
  127. unsigned char StatusNotificationReq :1; //bit 0,
  128. unsigned char StatusNotificationConf :1; //bit 0,
  129. unsigned char :6; //bit 2~7
  130. }bits[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  131. }CpinitiateMsg;
  132. CpinitiateMsg cpinitateMsg;
  133. //==========================================
  134. // Init all Enumeration & Mapping String
  135. //==========================================
  136. /*ChargePointErrorCode*/
  137. typedef enum {
  138. ConnectorLockFailure,
  139. EVCommunicationError,
  140. GroundFailure,
  141. HighTemperature,
  142. InternalError,
  143. LocalListConflict,
  144. NoError,
  145. OtherError,
  146. OverCurrentFailure,
  147. OverVoltage,
  148. PowerMeterFailure,
  149. PowerSwitchFailure,
  150. ReaderFailure,
  151. ResetFailure,
  152. UnderVoltage,
  153. WeakSignal
  154. } ChargePointErrorCode;
  155. static char *ChargePointErrorCodeStr[] = {
  156. MACROSTR(ConnectorLockFailure),
  157. MACROSTR(EVCommunicationError),
  158. MACROSTR(GroundFailure),
  159. MACROSTR(HighTemperature),
  160. MACROSTR(InternalError),
  161. MACROSTR(LocalListConflict),
  162. MACROSTR(NoError),
  163. MACROSTR(OtherError),
  164. MACROSTR(OverCurrentFailure),
  165. MACROSTR(OverVoltage),
  166. MACROSTR(PowerMeterFailure),
  167. MACROSTR(PowerSwitchFailure),
  168. MACROSTR(ReaderFailure),
  169. MACROSTR(ResetFailure),
  170. MACROSTR(UnderVoltage),
  171. MACROSTR(WeakSignal)
  172. };
  173. /*ChargePointStatus*/
  174. typedef enum {
  175. Available,
  176. Preparing,
  177. Charging,
  178. SuspendedEVSE,
  179. SuspendedEV,
  180. Finishing,
  181. Reserved,
  182. Unavailable,
  183. Faulted
  184. } ChargePointStatus;
  185. static char * ChargePointStatusStr[] = {
  186. MACROSTR(Available),
  187. MACROSTR(Preparing),
  188. MACROSTR(Charging),
  189. MACROSTR(SuspendedEVSE),
  190. MACROSTR(SuspendedEV),
  191. MACROSTR(Finishing),
  192. MACROSTR(Reserved),
  193. MACROSTR(Unavailable),
  194. MACROSTR(Faulted)
  195. };
  196. /*AvailabilityType*/
  197. typedef enum {
  198. RegistrationStatus_Accepted,
  199. RegistrationStatus_Pending,
  200. RegistrationStatus_Rejected
  201. } RegistrationStatus;
  202. static char *RegistrationStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Pending),
  205. MACROSTR(Rejected)
  206. };
  207. /*AvailabilityType*/
  208. typedef enum {
  209. Inoperative,
  210. Operative
  211. } AvailabilityType;
  212. static char *AvailabilityTypeStr[] = {
  213. MACROSTR(Inoperative),
  214. MACROSTR(Operative)
  215. };
  216. /*AvailabilityStatus*/
  217. typedef enum {
  218. Accepted,
  219. Rejected,
  220. Scheduled
  221. } AvailabilityStatus;
  222. static char *AvailabilityStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected),
  225. MACROSTR(Scheduled)
  226. };
  227. /*ConfigurationStatus*/
  228. typedef enum {
  229. ConfigurationStatus_Accepted,
  230. ConfigurationStatus_Rejected,
  231. RebootRequired,
  232. NotSupported
  233. } ConfigurationStatus;
  234. static char *ConfigurationStatusStr[] = {
  235. MACROSTR(Accepted),
  236. MACROSTR(Rejected),
  237. MACROSTR(RebootRequired),
  238. MACROSTR(NotSupported)
  239. };
  240. /*ClearCacheStatus*/
  241. typedef enum {
  242. ClearCacheStatus_Accepted,
  243. ClearCacheStatus_Rejected
  244. } ClearCacheStatus;
  245. static char *ClearCacheStatusStr[] = {
  246. MACROSTR(Accepted),
  247. MACROSTR(Rejected)
  248. };
  249. /*ChargingProfilePurposeType*/
  250. typedef enum {
  251. ChargePointMaxProfile,
  252. TxDefaultProfile,
  253. TxProfile
  254. } ChargingProfilePurposeType;
  255. static char *ChargingProfilePurposeTypeStr[] = {
  256. MACROSTR(ChargePointMaxProfile),
  257. MACROSTR(TxDefaultProfile),
  258. MACROSTR(TxProfile)
  259. };
  260. /*ChargingProfileStatus*/
  261. typedef enum {
  262. ChargingProfileStatus_Accepted,
  263. ChargingProfileStatus_Rejected,
  264. ChargingProfileStatus_NotSupported
  265. } ChargingProfileStatus;
  266. static char *ChargingProfileStatusStr[] = {
  267. MACROSTR(Accepted),
  268. MACROSTR(Rejected),
  269. MACROSTR(NotSupported)
  270. };
  271. /*ClearChargingProfileStatus*/
  272. typedef enum {
  273. ClearChargingProfileStatus_Accepted,
  274. ClearChargingProfileStatus_Unknown
  275. } ClearChargingProfileStatus;
  276. static char *ClearChargingProfileStatusStr[] = {
  277. MACROSTR(Accepted),
  278. MACROSTR(Unknown)
  279. };
  280. /*GetCompositeScheduleStatus*/
  281. typedef enum {
  282. GetCompositeScheduleStatus_Accepted,
  283. GetCompositeScheduleStatus_Rejected
  284. } GetCompositeScheduleStatus;
  285. static char *GetCompositeScheduleStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected)
  288. };
  289. /*ChargingRateUnitType*/
  290. typedef enum {
  291. ChargingRateUnitType_W,
  292. ChargingRateUnitType_A
  293. } ChargingRateUnitType;
  294. static char *ChargingRateUnitTypeStr[] = {
  295. MACROSTR(W),
  296. MACROSTR(A)
  297. };
  298. /*AuthorizationStatus*/
  299. typedef enum {
  300. AuthorizationStatus_Accepted ,
  301. AuthorizationStatus_Blocked ,
  302. AuthorizationStatus_Expired ,
  303. AuthorizationStatus_Invalid ,
  304. AuthorizationStatus_ConcurrentTx
  305. } AuthorizationStatus;
  306. static char *AuthorizationStatusStr[] = {
  307. MACROSTR(Accepted),
  308. MACROSTR(Blocked),
  309. MACROSTR(Expired),
  310. MACROSTR(Invalid),
  311. MACROSTR(ConcurrentTx)
  312. };
  313. /*UpdateType*/
  314. typedef enum {
  315. Differential ,
  316. Full
  317. } UpdateType;
  318. static char *UpdateTypeStr[] = {
  319. MACROSTR(Differential),
  320. MACROSTR(Full)
  321. };
  322. /*UpdateStatus*/
  323. typedef enum {
  324. UpdateStatus_Accepted ,
  325. UpdateStatus_Failed ,
  326. UpdateStatus_NotSupported ,
  327. UpdateStatus_VersionMismatch
  328. } UpdateStatus;
  329. static char *UpdateStatusStr[] = {
  330. MACROSTR(Accepted),
  331. MACROSTR(Failed),
  332. MACROSTR(NotSupported),
  333. MACROSTR(VersionMismatch)
  334. };
  335. /*RemoteStartStopStatus*/
  336. typedef enum {
  337. RemoteStartStopStatus_Accepted,
  338. RemoteStartStopStatus_Rejected
  339. } RemoteStartStopStatus;
  340. static char *RemoteStartStopStatusStr[] = {
  341. MACROSTR(Accepted),
  342. MACROSTR(Rejected)
  343. };
  344. /*ReservationStatus*/
  345. typedef enum {
  346. ReservationStatus_Accepted,
  347. ReservationStatus_Faulted,
  348. ReservationStatus_Occupied,
  349. ReservationStatus_Rejected,
  350. ReservationStatus_Unavailable
  351. } ReservationStatus;
  352. static char *ReservationStatusStr[] = {
  353. MACROSTR(Accepted),
  354. MACROSTR(Faulted),
  355. MACROSTR(Occupied),
  356. MACROSTR(Rejected),
  357. MACROSTR(Unavailable)
  358. };
  359. /*ResetType*/
  360. typedef enum {
  361. Hard,
  362. Soft
  363. } ResetType;
  364. static char *ResetTypeStr[] = {
  365. MACROSTR(Hard),
  366. MACROSTR(Soft)
  367. };
  368. /*ResetStatus*/
  369. typedef enum {
  370. ResetStatus_Accepted,
  371. ResetStatus_Rejected
  372. } ResetStatus;
  373. static char *ResetStatusStr[] = {
  374. MACROSTR(Accepted),
  375. MACROSTR(Rejected)
  376. };
  377. /*DiagnosticsStatus*/
  378. typedef enum {
  379. DiagnosticsStatus_Idle,
  380. DiagnosticsStatus_Uploaded,
  381. DiagnosticsStatus_UploadFailed,
  382. DiagnosticsStatus_Uploading
  383. } DiagnosticsStatus;
  384. static char * DiagnosticsStatusStr[] = {
  385. MACROSTR(Idle),
  386. MACROSTR(Uploaded),
  387. MACROSTR(UploadFailed),
  388. MACROSTR(Uploading)
  389. };
  390. /*FirmwareStatus*/
  391. typedef enum {
  392. FirmwareStatus_Downloaded,
  393. FirmwareStatus_DownloadFailed,
  394. FirmwareStatus_Downloading,
  395. FirmwareStatus_Idle,
  396. FirmwareStatus_InstallationFailed,
  397. FirmwareStatus_Installing,
  398. FirmwareStatus_Installed
  399. } FirmwareStatus;
  400. static char * FirmwareStatusStr[] = {
  401. MACROSTR(Downloaded),
  402. MACROSTR(DownloadFailed),
  403. MACROSTR(Downloading),
  404. MACROSTR(Idle),
  405. MACROSTR(InstallationFailed),
  406. MACROSTR(Installing),
  407. MACROSTR(Installed)
  408. };
  409. /*MessageTrigger*/
  410. typedef enum {
  411. BootNotification,
  412. DiagnosticsStatusNotification,
  413. FirmwareStatusNotification,
  414. Heartbeat,
  415. MeterValues,
  416. StatusNotification
  417. } MessageTrigger;
  418. static char * MessageTriggerStr[] = {
  419. MACROSTR(BootNotification),
  420. MACROSTR(DiagnosticsStatusNotification),
  421. MACROSTR(FirmwareStatusNotification),
  422. MACROSTR(Heartbeat),
  423. MACROSTR(MeterValues),
  424. MACROSTR(StatusNotification)
  425. };
  426. /*TriggerMessageStatus*/
  427. typedef enum {
  428. TriggerMessageStatus_Accepted ,
  429. TriggerMessageStatus_Rejected ,
  430. TriggerMessageStatus_NotImplemented
  431. } TriggerMessageStatus;
  432. static char * TriggerMessageStatusStr[] = {
  433. MACROSTR(Accepted),
  434. MACROSTR(Rejected),
  435. MACROSTR(NotImplemented)
  436. };
  437. /*UnlockStatus*/
  438. typedef enum {
  439. Unlocked,
  440. UnlockFailed,
  441. UnlockStatus_NotSupported
  442. } UnlockStatus;
  443. static char * UnlockStatusStr[] = {
  444. MACROSTR(Unlocked),
  445. MACROSTR(UnlockFailed),
  446. MACROSTR(NotSupported)
  447. };
  448. /*StopTransactionReason*/
  449. typedef enum {
  450. EmergencyStop,
  451. EVDisconnected,
  452. HardReset,
  453. Local,
  454. Other,
  455. PowerLoss,
  456. Reboot,
  457. Remote,
  458. SoftReset,
  459. UnlockCommand,
  460. DeAuthorized
  461. } StopTransactionReason;
  462. static char * StopTransactionReasonStr[] = {
  463. MACROSTR(EmergencyStop),
  464. MACROSTR(EVDisconnected),
  465. MACROSTR(HardReset),
  466. MACROSTR(Local),
  467. MACROSTR(Other),
  468. MACROSTR(PowerLoss),
  469. MACROSTR(Reboot),
  470. MACROSTR(Remote),
  471. MACROSTR(SoftReset),
  472. MACROSTR(UnlockCommand),
  473. MACROSTR(DeAuthorized)
  474. };
  475. /*CancelReservationStatus*/
  476. typedef enum {
  477. CancelReservationStatus_Accepted,
  478. CancelReservationStatus_Rejected
  479. } CancelReservationStatus;
  480. static char * CancelReservationStatusStr[] = {
  481. MACROSTR(Accepted),
  482. MACROSTR(Rejected)
  483. };
  484. /*ReadingContext*/
  485. typedef enum {
  486. ReadingContext_Interruption_Begin,
  487. ReadingContext_Interruption_End,
  488. ReadingContext_Other,
  489. ReadingContext_Sample_Clock,
  490. ReadingContext_Sample_Periodic ,
  491. ReadingContext_Transaction_Begin ,
  492. ReadingContext_Transaction_End,
  493. ReadingContext_Trigger
  494. } ReadingContext;
  495. static char * ReadingContextStr[] = {
  496. MACROSTR(Interruption.Begin),
  497. MACROSTR(Interruption.End),
  498. MACROSTR(Other),
  499. MACROSTR(Sample.Clock),
  500. MACROSTR(Sample.Periodic),
  501. MACROSTR(Transaction.Begin),
  502. MACROSTR(Transaction.End),
  503. MACROSTR(Trigger)
  504. };
  505. /*ValueFormat*/
  506. typedef enum {
  507. Raw,
  508. SignedData
  509. } ValueFormat;
  510. static char * ValueFormatStr[] = {
  511. MACROSTR(Raw),
  512. MACROSTR(SignedData)
  513. };
  514. /*Measurand*/
  515. typedef enum {
  516. Current_Export ,
  517. Current_Import,
  518. Current_Offered,
  519. Energy_Active_Export_Register,
  520. Energy_Active_Import_Register,
  521. Energy_Reactive_Export_Register,
  522. Energy_Reactive_Import_Register,
  523. Energy_Active_Export_Interval,
  524. Energy_Active_Import_Interval,
  525. Energy_Reactive_Export_Interval,
  526. Energy_Reactive_Import_Interval,
  527. Frequency,
  528. Power_Active_Export ,
  529. Power_Active_Import,
  530. Power_Factor,
  531. Power_Offered,
  532. Power_Reactive_Export,
  533. Power_Reactive_Import,
  534. RPM,
  535. SoC,
  536. Temperature ,
  537. Voltage
  538. } Measurand;
  539. static char * MeasurandStr[] = {
  540. MACROSTR(Current.Export),
  541. MACROSTR(Current.Import),
  542. MACROSTR(Current.Offered),
  543. MACROSTR(Energy.Active.Export.Register),
  544. MACROSTR(Energy.Active.Import.Register),
  545. MACROSTR(Energy_Reactive_Export_Register),
  546. MACROSTR(Energy_Reactive_Import_Register),
  547. MACROSTR(Energy_Active_Export_Interval),
  548. MACROSTR(Energy_Active_Import_Interval),
  549. MACROSTR(Energy_Reactive_Export_Interval),
  550. MACROSTR(Energy_Reactive_Import_Interval),
  551. MACROSTR(Frequency),
  552. MACROSTR(Power_Active_Export),
  553. MACROSTR(Power_Active_Import),
  554. MACROSTR(Power_Factor),
  555. MACROSTR(Power_Offered),
  556. MACROSTR(Power_Reactive_ExportMACROSTR),
  557. MACROSTR(Power_Reactive_Import),
  558. MACROSTR(RPM),
  559. MACROSTR(SoC),
  560. MACROSTR(Temperature),
  561. MACROSTR(Voltage)
  562. };
  563. /*Location*/
  564. typedef enum {
  565. Location_Body,
  566. Location_Cable,
  567. Location_EV,
  568. Location_Inlet ,
  569. Location_Outlet
  570. } Location;
  571. static char * LocationStr[] = {
  572. MACROSTR(Body),
  573. MACROSTR(Cable),
  574. MACROSTR(EV),
  575. MACROSTR(Inlet),
  576. MACROSTR(Outlet)
  577. };
  578. /*Phase*/
  579. typedef enum {
  580. L1,
  581. L2,
  582. L3,
  583. N,
  584. L1_N,
  585. L2_N,
  586. L3_N,
  587. L1_L2,
  588. L2_L3,
  589. L3_L1
  590. } Phase;
  591. static char * PhaseStr[] = {
  592. MACROSTR(L1),
  593. MACROSTR(L2),
  594. MACROSTR(L3),
  595. MACROSTR(N),
  596. MACROSTR(L1-N),
  597. MACROSTR(L2-N),
  598. MACROSTR(L3-N),
  599. MACROSTR(L1-L2),
  600. MACROSTR(L2-L3),
  601. MACROSTR(L3-L1)
  602. };
  603. /*UnitOfMeasure*/
  604. typedef enum {
  605. UnitOfMeasure_Wh,
  606. UnitOfMeasure_kWh ,
  607. UnitOfMeasure_varh ,
  608. UnitOfMeasure_kvarh ,
  609. UnitOfMeasure_W ,
  610. UnitOfMeasure_kW ,
  611. UnitOfMeasure_VA ,
  612. UnitOfMeasure_kVA ,
  613. UnitOfMeasure_var ,
  614. UnitOfMeasure_kvar ,
  615. UnitOfMeasure_A ,
  616. UnitOfMeasure_V ,
  617. UnitOfMeasure_Celsius ,
  618. UnitOfMeasure_Fahrenheit ,
  619. UnitOfMeasure_K ,
  620. UnitOfMeasure_Percent
  621. } UnitOfMeasure;
  622. static char * UnitOfMeasureStr[] = {
  623. MACROSTR(Wh),
  624. MACROSTR(kWh),
  625. MACROSTR(varh),
  626. MACROSTR(kvarh),
  627. MACROSTR(W),
  628. MACROSTR(kW),
  629. MACROSTR(VA),
  630. MACROSTR(kVA),
  631. MACROSTR(var),
  632. MACROSTR(kvar),
  633. MACROSTR(A),
  634. MACROSTR(V),
  635. MACROSTR(Celsius),
  636. MACROSTR(Fahrenheit),
  637. MACROSTR(K),
  638. MACROSTR(Percent)
  639. };
  640. /*Configuration enum*/
  641. enum CoreProfile {
  642. AllowOfflineTxForUnknownId=0,
  643. AuthorizationCacheEnabled,
  644. AuthorizeRemoteTxRequests,
  645. BlinkRepeat,
  646. ClockAlignedDataInterval,
  647. ConnectionTimeOut,
  648. GetConfigurationMaxKeys,
  649. HeartbeatInterval,
  650. LightIntensity,
  651. LocalAuthorizeOffline,
  652. LocalPreAuthorize,
  653. MaxEnergyOnInvalidId,
  654. MeterValuesAlignedData,
  655. MeterValuesAlignedDataMaxLength,
  656. MeterValuesSampledData,
  657. MeterValuesSampledDataMaxLength,
  658. MeterValueSampleInterval,
  659. MinimumStatusDuration,
  660. NumberOfConnectors,
  661. ResetRetries,
  662. ConnectorPhaseRotation,
  663. ConnectorPhaseRotationMaxLength,
  664. StopTransactionOnEVSideDisconnect,
  665. StopTransactionOnInvalidId,
  666. StopTxnAlignedData,
  667. StopTxnAlignedDataMaxLength,
  668. StopTxnSampledData,
  669. StopTxnSampledDataMaxLength,
  670. SupportedFeatureProfiles,
  671. SupportedFeatureProfilesMaxLength,
  672. TransactionMessageAttempts,
  673. TransactionMessageRetryInterval,
  674. UnlockConnectorOnEVSideDisconnect,
  675. WebSocketPingInterval,
  676. _CoreProfile_CNT
  677. };
  678. enum LocalAuthListManagementProfile{
  679. LocalAuthListEnabled=0,
  680. LocalAuthListMaxLength,
  681. SendLocalListMaxLength,
  682. _LocalAuthListManagementProfile_CNT
  683. };
  684. enum ReservationProfile{
  685. ReserveConnectorZeroSupported
  686. };
  687. enum SmartChargingProfile{
  688. ChargeProfileMaxStackLevel,
  689. ChargingScheduleAllowedChargingRateUnit,
  690. ChargingScheduleMaxPeriods,
  691. ConnectorSwitch3to1PhaseSupported,
  692. MaxChargingProfilesInstalled
  693. };
  694. enum ChargerSystemStatus{
  695. ChargerSystemStatus_Booting,
  696. ChargerSystemStatus_Idle,
  697. ChargerSystemStatus_Authorizing,
  698. ChargerSystemStatus_Preparing,
  699. ChargerSystemStatus_Charging,
  700. ChargerSystemStatus_Terminating,
  701. ChargerSystemStatus_Alarm,
  702. ChargerSystemStatus_Fault
  703. };
  704. enum GetConfigurationKey {
  705. GetConfiguration_AllowOfflineTxForUnknownId=0,
  706. GetConfiguration_AuthorizationCacheEnabled,
  707. GetConfiguration_AuthorizeRemoteTxRequests,
  708. GetConfiguration_BlinkRepeat,
  709. GetConfiguration_ClockAlignedDataInterval,
  710. GetConfiguration_ConnectionTimeOut,
  711. GetConfiguration_GetConfigurationMaxKeys,
  712. GetConfiguration_HeartbeatInterval,
  713. GetConfiguration_LightIntensity,
  714. GetConfiguration_LocalAuthorizeOffline,
  715. GetConfiguration_LocalPreAuthorize,
  716. GetConfiguration_MaxEnergyOnInvalidId,
  717. GetConfiguration_MeterValuesAlignedData,
  718. GetConfiguration_MeterValuesAlignedDataMaxLength,
  719. GetConfiguration_MeterValuesSampledData,
  720. GetConfiguration_MeterValuesSampledDataMaxLength,
  721. GetConfiguration_MeterValueSampleInterval,
  722. GetConfiguration_MinimumStatusDuration,
  723. GetConfiguration_NumberOfConnectors,
  724. GetConfiguration_ResetRetries,
  725. GetConfiguration_ConnectorPhaseRotation,
  726. GetConfiguration_ConnectorPhaseRotationMaxLength,
  727. GetConfiguration_StopTransactionOnEVSideDisconnect,
  728. GetConfiguration_StopTransactionOnInvalidId,
  729. GetConfiguration_StopTxnAlignedData,
  730. GetConfiguration_StopTxnAlignedDataMaxLength,
  731. GetConfiguration_StopTxnSampledData,
  732. GetConfiguration_StopTxnSampledDataMaxLength,
  733. GetConfiguration_SupportedFeatureProfiles,
  734. GetConfiguration_SupportedFeatureProfilesMaxLength,
  735. GetConfiguration_TransactionMessageAttempts,
  736. GetConfiguration_TransactionMessageRetryInterval,
  737. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  738. GetConfiguration_WebSocketPingInterval,
  739. GetConfiguration_LocalAuthListEnabled,
  740. GetConfiguration_LocalAuthListMaxLength,
  741. GetConfiguration_SendLocalListMaxLength,
  742. GetConfiguration_ReserveConnectorZeroSupported,
  743. GetConfiguration_ChargeProfileMaxStackLevel,
  744. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  745. GetConfiguration_ChargingScheduleMaxPeriods,
  746. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  747. GetConfiguration_MaxChargingProfilesInstalled,
  748. };
  749. //==========================================
  750. // Init all share memory
  751. //==========================================
  752. int InitShareMemory()
  753. {
  754. int result = PASS;
  755. int MeterSMId;
  756. printf("1\n");
  757. //creat ShmSysConfigAndInfo
  758. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  759. {
  760. #ifdef SystemLogMessage
  761. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  762. #endif
  763. result = FAIL;
  764. }
  765. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  766. {
  767. #ifdef SystemLogMessage
  768. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  769. #endif
  770. result = FAIL;
  771. }
  772. else
  773. {}
  774. printf("2\n");
  775. //creat ShmStatusCodeData
  776. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  777. {
  778. #ifdef SystemLogMessage
  779. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  780. #endif
  781. result = FAIL;
  782. }
  783. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  784. {
  785. #ifdef SystemLogMessage
  786. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  787. #endif
  788. result = FAIL;
  789. }
  790. else
  791. {}
  792. printf("3\n");
  793. //creat ShmPsuData
  794. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  795. {
  796. #ifdef SystemLogMessage
  797. DEBUG_ERROR("shmget ShmPsuData NG\n");
  798. #endif
  799. result = FAIL;
  800. }
  801. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  802. {
  803. #ifdef SystemLogMessage
  804. DEBUG_ERROR("shmat ShmPsuData NG\n");
  805. #endif
  806. result = FAIL;
  807. }
  808. else
  809. {}
  810. printf("4\n");
  811. //creat ShmOCPP16Data
  812. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  813. {
  814. #ifdef SystemLogMessage
  815. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  816. #endif
  817. result = FAIL;
  818. }
  819. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  820. {
  821. #ifdef SystemLogMessage
  822. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  823. #endif
  824. result = FAIL;
  825. }
  826. else
  827. {}
  828. printf("5\n");
  829. //memset(ShmOCPP16Data,0,sizeof(struct OCPP16Data));
  830. /****************************** For TEST ************************************************/
  831. //strcpy(ShmOCPP16Data->OcppServerURL,"172.17.40.13");
  832. //strcpy(ShmOCPP16Data->ChargeBoxId,"RDTEST103");
  833. //inital settings
  834. #if 0 // For Test
  835. sprintf(ShmOCPP16Data->BootNotification.CbSN, "");
  836. sprintf(ShmOCPP16Data->BootNotification.CpModel, "EA873E3EF8P1");
  837. sprintf(ShmOCPP16Data->BootNotification.CpSN, "RDTEST103");
  838. sprintf(ShmOCPP16Data->BootNotification.CpVendor, "Phihong Technology");
  839. sprintf(ShmOCPP16Data->BootNotification.CpFwVersion, "D0.13.50.0087.PH");
  840. sprintf(ShmOCPP16Data->BootNotification.CpIccid, "");
  841. sprintf(ShmOCPP16Data->BootNotification.CpImsi,"");
  842. sprintf(ShmOCPP16Data->BootNotification.CpMeterSerialNumber,"N/A");
  843. sprintf(ShmOCPP16Data->BootNotification.CpMeterType,"AC");
  844. memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  845. for(int gun_index=0; gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY); gun_index++ )
  846. {
  847. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  848. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  849. //allocate memory
  850. if(ShmOCPP16Data->StopTransaction[gun_index].TransactionData == NULL)
  851. {
  852. ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  853. }
  854. if(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue == NULL)
  855. {
  856. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*5);
  857. }
  858. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  859. strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  860. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Info, "N/A");
  861. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  862. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Timestamp, "2019-05-04T18:15:33Z");
  863. strcpy(ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  864. strcpy(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  865. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  866. }
  867. printf("6\n");
  868. strcpy(ShmOCPP16Data->Authorize.IdTag,"PaHdImHiOnNG");
  869. // ShmOCPP16Data->CpMsg.bits[0].StartTransactionReq = 1;
  870. //Authorize
  871. //memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
  872. //strcpy(ShmSysConfigAndInfo->SysConfig.UserId, "B014EA9C");
  873. //gun index
  874. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].Index = 0;
  875. ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].Index = 1;
  876. ShmSysConfigAndInfo->SysInfo.GbChargingData[0].Index = 2;
  877. //Chademo
  878. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus ='1'; //idle
  879. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].PreviousSystemStatus = '1';
  880. cpinitateMsg.bits[0].StatusNotificationReq = 1;
  881. #endif
  882. printf("7\n");
  883. // Charger PRE_SYS_MODE
  884. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  885. memset( (void *)unknownkey, 0, sizeof(char)*10*20 );
  886. clientTime.Heartbeat=time((time_t*)NULL);
  887. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY/*+ CCS_QUANTITY + GB_QUANTITY*/) ;gun_index++)
  888. {
  889. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  890. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  891. }
  892. printf("8\n");
  893. HeartBeatWaitTime = 10;
  894. //memset(unknownkey, 0, 10);
  895. return result;
  896. }
  897. int ProcessShareMemory()
  898. {
  899. if(InitShareMemory() == FAIL)
  900. {
  901. #ifdef SystemLogMessage
  902. DEBUG_ERROR("InitShareMemory NG\n");
  903. #endif
  904. if(ShmStatusCodeData!=NULL)
  905. {
  906. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  907. }
  908. sleep(5);
  909. return FAIL;
  910. }
  911. return PASS;
  912. }
  913. void CheckSystemValue(void)
  914. {
  915. printf("CheckSystemValue \n");
  916. int meterValueSend=0;
  917. int IdleModeCnt = 0;
  918. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  919. {
  920. //parameter for test
  921. sendHeartbeatRequest(0);
  922. //==============================================
  923. // Reset Waiting Time
  924. //==============================================
  925. clientTime.Heartbeat=time((time_t*)NULL);
  926. }
  927. //==============================================
  928. // Update request
  929. //==============================================
  930. if(isUpdateRequest == TRUE )
  931. {
  932. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  933. {
  934. //check SystemStatus // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  936. {
  937. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 1)) //S_IDLE
  938. {
  939. IdleModeCnt = IdleModeCnt + 1;
  940. }
  941. }
  942. for (int index = 0; index < CCS_QUANTITY; index++)
  943. {
  944. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 1)) //S_IDLE
  945. {
  946. IdleModeCnt = IdleModeCnt + 1;
  947. }
  948. }
  949. for (int index = 0; index < GB_QUANTITY; index++)
  950. {
  951. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  952. {
  953. IdleModeCnt = IdleModeCnt + 1;
  954. }
  955. }
  956. }
  957. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  958. {
  959. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installed]);
  960. isUpdateRequest = FALSE;
  961. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  962. }
  963. }
  964. printf("gun no %d\n",(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY));
  965. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ) ;gun_index++)
  966. {
  967. //==============================================
  968. // Charger status report
  969. //==============================================
  970. /* Check Mode Change */
  971. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  972. {
  973. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  974. {
  975. printf("Chademo Mode status:\n");
  976. printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus: %c\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  977. printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus: %c\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus);
  978. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus/*PRE_SYS_MODE[gun_index]*/ )
  979. {
  980. printf("Chademo Mode Change\n");
  981. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  982. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  983. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  984. statusModeChage = TRUE;
  985. }
  986. }
  987. }
  988. for (int index = 0; index < CCS_QUANTITY; index++)
  989. {
  990. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  991. {
  992. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus/*PRE_SYS_MODE[gun_index]*/ )
  993. {
  994. printf("Ccs Mode Change\n");
  995. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  996. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  997. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  998. statusModeChage = TRUE;
  999. }
  1000. }
  1001. }
  1002. for (int index = 0; index < GB_QUANTITY; index++)
  1003. {
  1004. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1005. {
  1006. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus/*PRE_SYS_MODE[gun_index]*/ )
  1007. {
  1008. printf("Gb Mode Change\n");
  1009. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1010. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1011. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1012. statusModeChage = TRUE;
  1013. }
  1014. }
  1015. }
  1016. if((server_sign == TRUE) && ((statusModeChage == TRUE)||((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > server_cycle_Status)|| ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30))))
  1017. {
  1018. sendStatusNotificationRequest(gun_index);
  1019. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1020. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1021. statusModeChage = FALSE;
  1022. }
  1023. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1024. {
  1025. sendAuthorizeRequest(0);
  1026. authorizeRetryTimes = authorizeRetryTimes + 1;
  1027. /* authenrequest = TRUE; */
  1028. if(authorizeRetryTimes < 3)
  1029. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1030. //Test Variables
  1031. UserPlugGun = 1;
  1032. teststatus = 0;
  1033. }
  1034. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1035. {
  1036. authorizeRetryTimes = 0;
  1037. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1038. }
  1039. #if 1
  1040. //==============================================
  1041. // Charger start transaction
  1042. //==============================================
  1043. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1044. {
  1045. #if 0 // for test
  1046. if(teststatus == 0)
  1047. {
  1048. #endif
  1049. sendStartTransactionRequest(gun_index);
  1050. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1051. clientTime.StartTransaction = time((time_t*)NULL);
  1052. #if 0// for test
  1053. teststatus = 1; // finish startTransaction
  1054. }
  1055. #endif
  1056. }
  1057. //==============================================
  1058. // Charger stop transaction
  1059. //==============================================
  1060. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1061. {
  1062. #if 0 // for test
  1063. if(teststatus == 2)
  1064. {
  1065. #endif
  1066. sendStopTransactionRequest(gun_index);
  1067. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1068. clientTime.StopTransaction = time((time_t*)NULL);
  1069. #if 0// for test
  1070. teststatus = 100;
  1071. }
  1072. #endif
  1073. }
  1074. //==============================================
  1075. // Meter report
  1076. //==============================================
  1077. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)) )
  1078. {
  1079. //check Transaction active
  1080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1081. {
  1082. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1083. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8))
  1084. {
  1085. meterValueSend =1;
  1086. }
  1087. }
  1088. for (int index = 0; index < CCS_QUANTITY; index++)
  1089. {
  1090. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1091. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8))
  1092. {
  1093. meterValueSend =1;
  1094. }
  1095. }
  1096. for (int index = 0; index < GB_QUANTITY; index++)
  1097. {
  1098. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1099. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8))
  1100. {
  1101. meterValueSend =1;
  1102. }
  1103. }
  1104. printf("sendMeterValuesRequest \n");
  1105. // if(meterValueSend == 1)
  1106. #if 0 // for test
  1107. if((teststatus == 1) && (testCountInc <= testCount))
  1108. {
  1109. #endif
  1110. sleep(1); //?��?1�?
  1111. if(meterValueSend == 1)
  1112. sendMeterValuesRequest(gun_index);
  1113. #if 0 //for test
  1114. testCountInc = testCountInc + 1;
  1115. printf("testCountInc=%d\n",testCountInc);
  1116. }
  1117. else if((meterValueSend == 1) && (testCountInc > testCount))
  1118. {
  1119. teststatus = 2;
  1120. meterValueSend = 0;
  1121. testCountInc = 0;
  1122. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 1;
  1123. }
  1124. #endif
  1125. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1126. }
  1127. #endif
  1128. //==============================================
  1129. // Check Connector reserved
  1130. //==============================================
  1131. printf("ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate=%s\n",ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate);
  1132. if((server_sign == TRUE) && (strcmp(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "") != 0) )
  1133. {
  1134. double diff_t;
  1135. struct tm tp;
  1136. // current time
  1137. time_t t = time(NULL);
  1138. sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1139. printf("ExpiryDate : %s\n", (char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate);
  1140. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1141. printf("handle check value 1\n");
  1142. tp.tm_isdst = -1;
  1143. printf("handle check value 2\n");
  1144. time_t utc = mktime(&tp);
  1145. printf("handle check value 3\n");
  1146. struct tm e0 = { .tm_year = tp.tm_year, .tm_mday = tp.tm_mday, .tm_mon = tp.tm_mon, .tm_hour = tp.tm_hour, .tm_isdst = -1 };
  1147. time_t pseudo = mktime(&e0);
  1148. struct tm e1 = *gmtime(&pseudo);
  1149. e0.tm_sec += utc - diff_tm(&e1, &e0);
  1150. time_t local = e0.tm_sec;
  1151. // ?�到封�??�起始�???- chargingScedule起�??��?
  1152. diff_t = difftime(t, local);
  1153. if(diff_t < 0)
  1154. {
  1155. printf("reserve expired !!! \n");
  1156. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1157. }
  1158. else if((ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf == 1) &&
  1159. (ShmOCPP16Data->StartTransaction[gun_index].ReservationId == ShmOCPP16Data->ReserveNow[gun_index].ReservationId)&&
  1160. (strcmp(ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->ReserveNow[gun_index].IdTag) ==0))
  1161. {
  1162. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1163. }
  1164. else
  1165. {
  1166. //check Transaction active
  1167. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1168. {
  1169. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1170. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) &&(1/*預約旗標*//*ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != '8'*/))
  1171. {
  1172. //if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9') )
  1173. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 12) ) // S_ALARM, S_FAULT
  1174. {
  1175. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1176. }
  1177. }
  1178. }
  1179. for (int index = 0; index < CCS_QUANTITY; index++)
  1180. {
  1181. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1182. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(1/*預約旗標*//*ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != '8'*/))
  1183. {
  1184. //if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9') )
  1185. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 12) ) // S_ALARM, S_FAULT
  1186. {
  1187. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1188. }
  1189. }
  1190. }
  1191. for (int index = 0; index < GB_QUANTITY; index++)
  1192. {
  1193. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  1194. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(1/*預約旗標*//*ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != '8'*/) )
  1195. {
  1196. //if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '7') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9') )
  1197. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 12) ) // S_ALARM, S_FAULT
  1198. {
  1199. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1200. }
  1201. }
  1202. }
  1203. }
  1204. }
  1205. // csu trigger FirmwareStatusNotificationReq
  1206. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1207. {
  1208. sendFirmwareStatusNotificationRequest(ShmOCPP16Data->FirmwareStatusNotification.Status);
  1209. }
  1210. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1211. {
  1212. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1213. sendCancelReservationConfirmation(ShmOCPP16Data->CancelReservation[gun_index].guid, ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1214. }
  1215. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1216. {
  1217. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1218. }
  1219. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1220. {
  1221. sendUnlockConnectorConfirmation(ShmOCPP16Data->UnlockConnector[gun_index].guid, ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1222. }
  1223. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1224. {
  1225. sendReserveNowTransactionConfirmation(ShmOCPP16Data->ReserveNow[gun_index].guid, ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1226. }
  1227. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1228. {
  1229. sendResetConfirmation(ShmOCPP16Data->Reset.guid, ShmOCPP16Data->Reset.ResponseStatus);
  1230. }
  1231. }
  1232. }
  1233. //==========================================
  1234. // send request routine
  1235. //==========================================
  1236. int sendAuthorizeRequest(int gun_index)
  1237. {
  1238. printf("sendAuthorizeRequest \n");
  1239. int result = FAIL;
  1240. int i = 0;
  1241. char *str = NULL;
  1242. char *arr[1];
  1243. const char *del = ",";
  1244. char *senstr = NULL;
  1245. char *temp = NULL;
  1246. struct json_object *message, *payload;
  1247. char guid[37];
  1248. message = json_object_new_array();
  1249. payload = json_object_new_object();
  1250. //initailize struct Authorize
  1251. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1252. //get data from shared memory
  1253. strcpy(ShmOCPP16Data->Authorize.IdTag, ShmSysConfigAndInfo->SysConfig.UserId);
  1254. //json_object_object_add(payload, "idTag", json_object_new_string((const char *)request.IdTag));
  1255. json_object_object_add(payload, "idTag", json_object_new_string((const char *)ShmOCPP16Data->Authorize.IdTag));
  1256. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1257. random_uuid(guid);
  1258. json_object_array_add(message, json_object_new_string(guid));
  1259. json_object_array_add(message, json_object_new_string("Authorize"));
  1260. json_object_array_add(message, payload);
  1261. Send(message);
  1262. // Put request guid to hash map
  1263. if(mapItem == NULL)
  1264. {
  1265. mapItem = malloc(sizeof(data_struct_t));
  1266. printf("mapItem is null\n");
  1267. }
  1268. sprintf(mapItem->key_string, "%s", guid);
  1269. sprintf(mapItem->key_value, "Authorize,%d", gun_index);//sprintf(mapItem->key_value, senstr);//sprintf(mapItem->key_value, "Authorize");
  1270. printf("Authorize mapItem->key_string=%s\n",mapItem->key_string);
  1271. printf("Authorize mapItem->key_value=%s\n",mapItem->key_value);
  1272. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1273. {
  1274. result = PASS;
  1275. printf("Authorize mapItem pass\n");
  1276. }
  1277. #ifdef SystemLogMessage
  1278. DEBUG_INFO(">>>>>Authorize request\n");
  1279. DEBUG_INFO("Message: %s\n", SendBuffer);
  1280. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1281. #endif
  1282. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1283. json_object_put(message); // Delete the json object
  1284. //for test
  1285. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus ='3'; //preparing
  1286. //ShmOCPP16Data->CpMsg.bits[0].StartTransactionReq = 1;
  1287. return result;
  1288. }
  1289. int sendBootNotificationRequest(void)
  1290. {
  1291. int result = FAIL;
  1292. int i = 0;
  1293. struct json_object *message, *payload;
  1294. int count = 0;
  1295. int gun_index = 0;
  1296. char guid[37];
  1297. message = json_object_new_array();
  1298. payload = json_object_new_object();
  1299. // Fill BootNotification fields
  1300. strcpy(ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1301. strcpy(ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1302. strcpy(ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1303. strcpy(ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1304. json_object_object_add(payload, "chargeBoxSerialNumber", json_object_new_string((const char *)ShmOCPP16Data->ChargeBoxId));
  1305. json_object_object_add(payload, "chargePointModel", json_object_new_string((const char *)ShmSysConfigAndInfo->SysConfig.ModelName));
  1306. json_object_object_add(payload, "chargePointSerialNumber", json_object_new_string((const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber));
  1307. json_object_object_add(payload, "chargePointVendor", json_object_new_string((const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor));
  1308. json_object_object_add(payload, "firmwareVersion", json_object_new_string((const char *)ShmOCPP16Data->BootNotification.CpFwVersion));
  1309. json_object_object_add(payload, "iccid", json_object_new_string((const char *)ShmOCPP16Data->BootNotification.CpIccid));
  1310. json_object_object_add(payload, "imsi", json_object_new_string((const char *)ShmOCPP16Data->BootNotification.CpImsi));
  1311. json_object_object_add(payload, "meterSerialNumber", json_object_new_string((const char *)ShmOCPP16Data->BootNotification.CpMeterSerialNumber));
  1312. json_object_object_add(payload, "meterType", json_object_new_string((const char *)ShmOCPP16Data->BootNotification.CpMeterType));
  1313. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1314. random_uuid(guid);
  1315. json_object_array_add(message, json_object_new_string(guid));
  1316. json_object_array_add(message, json_object_new_string("BootNotification"));
  1317. json_object_array_add(message, payload);
  1318. Send(message);
  1319. // Put request guid to hash map
  1320. sprintf(mapItem->key_string, "%s", guid);
  1321. sprintf(mapItem->key_value, "BootNotification,0");
  1322. printf("BootNotification mapItem->key_string=%s\n",mapItem->key_string);
  1323. printf("BootNotification mapItem->key_value=%s\n",mapItem->key_value);
  1324. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1325. {
  1326. result = PASS;
  1327. }
  1328. printf("8-2\n");
  1329. memset(queuedata, 0, strlen(queuedata));
  1330. strcpy(queuedata,(char*)json_object_to_json_string(message));
  1331. //addq(guid, queuedata);
  1332. #ifdef SystemLogMessage
  1333. DEBUG_INFO(">>>>>BootNotification request\n");
  1334. DEBUG_INFO("Message: %s\n", SendBuffer);
  1335. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1336. #endif
  1337. json_object_put(message); // Delete the json object
  1338. //ShmOCPP16Data->SpMsg.bits.BootNotificationReq = 1;
  1339. return result;
  1340. }
  1341. int sendDataTransferRequest(int gun_index)
  1342. {
  1343. int result = FAIL;
  1344. struct json_object *message, *payload, *data;
  1345. char *senstr = NULL;
  1346. char *temp = NULL;
  1347. const char *del = ",";
  1348. char guid[37];
  1349. message = json_object_new_array();
  1350. payload = json_object_new_object();
  1351. data = json_object_new_object();
  1352. json_object_object_add(payload, "vendorId", json_object_new_string("PhihongTechnology"));
  1353. json_object_object_add(payload, "messageId", json_object_new_string("TestingMessage"));
  1354. json_object_object_add(data, "data-1", json_object_new_string("data1 content"));
  1355. json_object_object_add(data, "data-2", json_object_new_string("data2 content"));
  1356. json_object_object_add(payload, "data", json_object_new_string(json_object_get_string(data)));
  1357. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1358. random_uuid(guid);
  1359. json_object_array_add(message, json_object_new_string(guid));
  1360. json_object_array_add(message, json_object_new_string("DataTransfer"));
  1361. json_object_array_add(message, payload);
  1362. Send(message);
  1363. // Put request guid to hash map
  1364. if(mapItem == NULL)
  1365. {
  1366. mapItem = malloc(sizeof(data_struct_t));
  1367. printf("mapItem is null\n");
  1368. }
  1369. if(guid == NULL || mapItem->key_string == NULL)
  1370. {
  1371. printf("guid is NULL \n");
  1372. }
  1373. if(mapItem->key_string == NULL)
  1374. {
  1375. printf("mapItem->key_string is NULL\n");
  1376. }
  1377. sprintf(mapItem->key_string, "%s", guid);
  1378. sprintf(mapItem->key_value, "DataTransfer,%d", (gun_index + 1));
  1379. printf("DataTransfer mapItem->key_string=%s\n", mapItem->key_string);
  1380. printf("DataTransfer mapItem->key_value=%s\n", mapItem->key_value);
  1381. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1382. {
  1383. result = PASS;
  1384. printf("DataTransfer mapItem pass\n");
  1385. }
  1386. #ifdef SystemLogMessage
  1387. DEBUG_INFO(">>>>>DataTransfer request\n");
  1388. DEBUG_INFO("Message: %s\n", SendBuffer);
  1389. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1390. #endif
  1391. json_object_put(message); // Delete the json object
  1392. return result;
  1393. }
  1394. int sendDiagnosticsStatusNotificationRequest(char *status)
  1395. {
  1396. int result = FAIL;
  1397. char *str = NULL;
  1398. struct json_object *message, *payload;
  1399. char guid[37];
  1400. message = json_object_new_array();
  1401. payload = json_object_new_object();
  1402. printf("sendDiagnosticsStatusNotificationRequest \n");
  1403. printf("DiagnosticsStatusNotification-1\n");
  1404. printf("DiagnosticsStatusNotification.Status=%s\n", status);
  1405. sprintf(ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1406. printf("DiagnosticsStatusNotification.Status=%s\n", str);
  1407. json_object_object_add(payload, "status", json_object_new_string((const char *)status));
  1408. printf("DiagnosticsStatusNotification-2\n");
  1409. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1410. random_uuid(guid);
  1411. json_object_array_add(message, json_object_new_string(guid));
  1412. json_object_array_add(message, json_object_new_string("DiagnosticsStatusNotification"));
  1413. json_object_array_add(message, payload);
  1414. Send(message);
  1415. if(mapItem == NULL)
  1416. {
  1417. mapItem = malloc(sizeof(data_struct_t));
  1418. printf("mapItem is null\n");
  1419. }
  1420. if(guid == NULL || mapItem->key_string == NULL)
  1421. {
  1422. printf("guid is NULL \n");
  1423. }
  1424. if(mapItem->key_string == NULL)
  1425. {
  1426. printf("mapItem->key_string is NULL\n");
  1427. }
  1428. // Put request guid to hash map
  1429. sprintf(mapItem->key_string, "%s", guid);
  1430. sprintf(mapItem->key_value, "DiagnosticsStatusNotification,%d", 0);
  1431. printf("DiagnosticsStatusNotification mapItem->key_string=%s\n", mapItem->key_string);
  1432. printf("DiagnosticsStatusNotification mapItem->key_value=%s\n", mapItem->key_value);
  1433. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1434. {
  1435. result = PASS;
  1436. printf("DiagnosticsStatusNotification mapItem pass\n");
  1437. }
  1438. #ifdef SystemLogMessage
  1439. DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1440. DEBUG_INFO("Message: %s\n", SendBuffer);
  1441. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1442. #endif
  1443. json_object_put(message); // Delete the json object
  1444. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  1445. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1446. return result;
  1447. }
  1448. int sendFirmwareStatusNotificationRequest(char *status)
  1449. {
  1450. int result = FAIL;
  1451. char *str = NULL;
  1452. struct json_object *message, *payload;
  1453. char guid[37];
  1454. message = json_object_new_array();
  1455. payload = json_object_new_object();
  1456. sprintf(ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1457. json_object_object_add(payload, "status", json_object_new_string((const char *)status));
  1458. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1459. random_uuid(guid);
  1460. json_object_array_add(message, json_object_new_string(guid));
  1461. json_object_array_add(message, json_object_new_string("FirmwareStatusNotification"));
  1462. json_object_array_add(message, payload);
  1463. Send(message);
  1464. if(mapItem == NULL)
  1465. {
  1466. mapItem = malloc(sizeof(data_struct_t));
  1467. printf("mapItem is null\n");
  1468. }
  1469. if(guid == NULL || mapItem->key_string == NULL)
  1470. {
  1471. printf("guid is NULL \n");
  1472. }
  1473. if(mapItem->key_string == NULL)
  1474. {
  1475. printf("mapItem->key_string is NULL\n");
  1476. }
  1477. // Put request guid to hash map
  1478. sprintf(mapItem->key_string, "%s", guid);
  1479. sprintf(mapItem->key_value, "FirmwareStatusNotification,%d", 0);
  1480. printf("FirmwareStatusNotification mapItem->key_string=%s\n", mapItem->key_string);
  1481. printf("FirmwareStatusNotification mapItem->key_value=%s\n", mapItem->key_value);
  1482. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1483. {
  1484. result = PASS;
  1485. printf("FirmwareStatusNotification mapItem pass\n");
  1486. }
  1487. #ifdef SystemLogMessage
  1488. DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1489. DEBUG_INFO("Message: %s\n", SendBuffer);
  1490. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1491. #endif
  1492. json_object_put(message); // Delete the json object
  1493. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  1494. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1495. return result;
  1496. }
  1497. int sendHeartbeatRequest(int gun_index)
  1498. {
  1499. int result = FAIL;
  1500. struct json_object *message, *payload;
  1501. char *senstr = NULL;
  1502. char *temp = NULL;
  1503. const char *del = ",";
  1504. char guid[37];
  1505. message = json_object_new_array();
  1506. payload = json_object_new_object();
  1507. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1508. random_uuid(guid);
  1509. json_object_array_add(message, json_object_new_string(guid));
  1510. json_object_array_add(message, json_object_new_string("Heartbeat"));
  1511. json_object_array_add(message, payload);
  1512. Send(message);
  1513. if(mapItem == NULL)
  1514. {
  1515. mapItem = malloc(sizeof(data_struct_t));
  1516. printf("mapItem is null\n");
  1517. }
  1518. if(guid == NULL || mapItem->key_string == NULL)
  1519. {
  1520. printf("guid is NULL \n");
  1521. }
  1522. if(mapItem->key_string == NULL)
  1523. {
  1524. printf("mapItem->key_string is NULL\n");
  1525. }
  1526. sprintf(mapItem->key_string, "%s", guid);
  1527. sprintf(mapItem->key_value, "Heartbeat,%d", 0);
  1528. printf("Heartbeat mapItem->key_string=%s\n", mapItem->key_string);
  1529. printf("Heartbeat mapItem->key_value=%s\n", mapItem->key_value);
  1530. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1531. {
  1532. result = PASS;
  1533. printf("Heartbeat mapItem\n");
  1534. }
  1535. #ifdef SystemLogMessage
  1536. DEBUG_INFO(">>>>>Heartbeat request\n");
  1537. DEBUG_INFO("Message: %s\n", SendBuffer);
  1538. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1539. #endif
  1540. json_object_put(message);
  1541. return result;
  1542. }
  1543. int sendStartTransactionRequest(int gun_index)
  1544. {
  1545. int result = FAIL;
  1546. struct json_object *message, *payload;
  1547. char *senstr = NULL;
  1548. char *temp = NULL;
  1549. const char *del = ",";
  1550. char guid[37];
  1551. struct timeval tmnow;
  1552. struct tm *tm;
  1553. char buf[30], usec_buf[6];
  1554. message = json_object_new_array();
  1555. payload = json_object_new_object();
  1556. gettimeofday(&tmnow, NULL);
  1557. time_t t;
  1558. t = time(NULL);
  1559. /*UTC time and date*/
  1560. tm = gmtime(&t);
  1561. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1562. strcat(buf,".");
  1563. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1564. strcat(buf,usec_buf);
  1565. printf("%s",buf);
  1566. // set value
  1567. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1568. strcpy(ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1569. strcpy(ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmSysConfigAndInfo->SysConfig.UserId);
  1570. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1571. {
  1572. printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index );
  1573. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1574. {
  1575. printf("Chademo : 0\n");
  1576. #if 1 // for test
  1577. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy =100.0;
  1578. #endif
  1579. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1580. }
  1581. }
  1582. for (int index = 0; index < CCS_QUANTITY; index++)
  1583. {
  1584. printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  1585. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1586. {
  1587. printf("Ccs : 0\n");
  1588. #if 1 // fo test
  1589. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  1590. #endif
  1591. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1592. }
  1593. }
  1594. for (int index = 0; index < GB_QUANTITY; index++)
  1595. {
  1596. printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index );
  1597. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1598. {
  1599. printf("Gb : 0\n");
  1600. #if 1 // fo test
  1601. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  1602. #endif
  1603. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1604. }
  1605. }
  1606. //ShmOCPP16Data->StartTransaction[gun_index].MeterStart = 100;
  1607. json_object_object_add(payload, "connectorId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ConnectorId));
  1608. json_object_object_add(payload, "idTag", json_object_new_string((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag));
  1609. json_object_object_add(payload, "meterStart", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].MeterStart));
  1610. json_object_object_add(payload, "reservationId", json_object_new_int(ShmOCPP16Data->StartTransaction[gun_index].ReservationId));
  1611. json_object_object_add(payload, "timestamp", json_object_new_string((const char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp));
  1612. printf("test s 1\n");
  1613. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1614. random_uuid(guid);
  1615. json_object_array_add(message, json_object_new_string(guid));
  1616. json_object_array_add(message, json_object_new_string("StartTransaction"));
  1617. json_object_array_add(message, payload);
  1618. Send(message);
  1619. //usleep(500); // 等�??��?微�?
  1620. printf("test s 2\n");
  1621. if(mapItem == NULL)
  1622. {
  1623. mapItem = malloc(sizeof(data_struct_t));
  1624. printf("mapItem is null\n");
  1625. }
  1626. if(guid == NULL || mapItem->key_string == NULL)
  1627. {
  1628. printf("guid is NULL \n");
  1629. }
  1630. if(mapItem->key_string == NULL)
  1631. {
  1632. printf("mapItem->key_string is NULL\n");
  1633. }
  1634. // Put request guid to hash map
  1635. sprintf(mapItem->key_string, "%s", guid);
  1636. printf("test s 2-0-1\n");
  1637. sprintf(mapItem->key_value, "StartTransaction,%d", (gun_index));
  1638. printf("test s 2-0-2\n");
  1639. printf("StartTransaction mapItem->key_string=%s\n",mapItem->key_string);
  1640. printf("StartTransaction mapItem->key_value=%s\n",mapItem->key_value);
  1641. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1642. {
  1643. printf("test s 2-1\n");
  1644. result = PASS;
  1645. }
  1646. printf("test s 3\n");
  1647. strcpy(queuedata, (char*)json_object_to_json_string(message));
  1648. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1649. #ifdef SystemLogMessage
  1650. DEBUG_INFO(">>>>>StartTransaction request\n");
  1651. DEBUG_INFO("Message: %s\n", SendBuffer);
  1652. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1653. #endif
  1654. json_object_put(message);
  1655. return result;
  1656. }
  1657. int sendStatusNotificationRequest(int gun_index)
  1658. {
  1659. int result = FAIL;
  1660. struct json_object *message, *payload;
  1661. char *senstr = NULL;
  1662. char *temp = NULL;
  1663. const char *del = ",";
  1664. char guid[37];
  1665. int currentStatus = 0;
  1666. struct timeval tmnow;
  1667. struct tm *tm;
  1668. char buf[30], usec_buf[6];
  1669. message = json_object_new_array();
  1670. payload = json_object_new_object();
  1671. gettimeofday(&tmnow, NULL);
  1672. time_t t;
  1673. t = time(NULL);
  1674. /*UTC time and date*/
  1675. tm = gmtime(&t);
  1676. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1677. strcat(buf,".");
  1678. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1679. strcat(buf,usec_buf);
  1680. printf("%s",buf);
  1681. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1682. strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  1683. // it's option
  1684. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1685. /*
  1686. enum _SYSTEM_STATUS
  1687. {
  1688. S_BOOTING = 0,
  1689. S_IDLE, = 1
  1690. S_AUTHORIZING, =2
  1691. S_REASSIGN_CHECK, =3
  1692. S_REASSIGN, =4
  1693. S_PRECHARGE, =5
  1694. S_PREPARING_FOR_EV, =6
  1695. S_PREPARING_FOR_EVSE, =7
  1696. S_CHARGING, =8
  1697. S_TERMINATING, =9
  1698. S_COMPLETE, =10
  1699. S_ALARM, =11
  1700. S_FAULT =12
  1701. }
  1702. */
  1703. //check Transaction active
  1704. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1705. {
  1706. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 1)) //S_IDLE
  1707. {
  1708. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1709. currentStatus = 0;
  1710. }
  1711. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 5)) //S_PRECHARGE
  1712. {
  1713. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1714. currentStatus = 1;
  1715. }
  1716. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8)) //S_CHARGING
  1717. {
  1718. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1719. currentStatus = 2;
  1720. }
  1721. }
  1722. for (int index = 0; index < CCS_QUANTITY; index++)
  1723. {
  1724. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 1)) //S_IDLE
  1725. {
  1726. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1727. currentStatus = 0;
  1728. }
  1729. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 5)) //S_PRECHARGE
  1730. {
  1731. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1732. currentStatus = 1;
  1733. }
  1734. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8)) //S_CHARGING
  1735. {
  1736. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1737. currentStatus = 2;
  1738. }
  1739. }
  1740. for (int index = 0; index < GB_QUANTITY; index++)
  1741. {
  1742. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1743. {
  1744. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1745. currentStatus = 0;
  1746. }
  1747. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 5)) //S_PRECHARGE
  1748. {
  1749. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1750. currentStatus = 1;
  1751. }
  1752. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8)) //S_CHARGING
  1753. {
  1754. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1755. currentStatus = 2;
  1756. }
  1757. }
  1758. //it's option
  1759. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1760. strcpy(ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1761. strcpy(ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  1762. strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1763. json_object_object_add(payload, "connectorId", json_object_new_int(ShmOCPP16Data->StatusNotification[gun_index].ConnectorId));
  1764. json_object_object_add(payload, "errorCode", json_object_new_string((const char *)(&ShmOCPP16Data->StatusNotification[gun_index].ErrorCode)));
  1765. json_object_object_add(payload, "info", json_object_new_string((const char *)ShmOCPP16Data->StatusNotification[gun_index].Info));
  1766. json_object_object_add(payload, "status", json_object_new_string((const char *)ShmOCPP16Data->StatusNotification[gun_index].Status));
  1767. json_object_object_add(payload, "timestamp", json_object_new_string((const char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp));
  1768. json_object_object_add(payload, "vendorId", json_object_new_string((const char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId));
  1769. json_object_object_add(payload, "vendorErrorCode", json_object_new_string((const char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode));
  1770. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1771. random_uuid(guid);
  1772. json_object_array_add(message, json_object_new_string(guid));
  1773. json_object_array_add(message, json_object_new_string("StatusNotification"));
  1774. json_object_array_add(message, payload);
  1775. Send(message);
  1776. //usleep(500); // 等�??��?微�?
  1777. // Put request guid to hash map
  1778. if(mapItem == NULL)
  1779. {
  1780. mapItem = malloc(sizeof(data_struct_t));
  1781. printf("mapItem is null\n");
  1782. }
  1783. sprintf(mapItem->key_string, "%s", guid);
  1784. sprintf(mapItem->key_value, "StatusNotification,%d", (gun_index));
  1785. //sprintf(mapItem->key_value, "StatusNotification,%d", gun_index + 1);
  1786. printf("statusNotification mapItem->key_string=%s\n",mapItem->key_string);
  1787. printf("statusNotification mapItem->key_value=%s\n",mapItem->key_value);
  1788. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1789. {
  1790. printf("statusNotification mapitem pass");
  1791. result = PASS;
  1792. }
  1793. #ifdef SystemLogMessage
  1794. DEBUG_INFO(">>>>>StatusNotification request\n");
  1795. DEBUG_INFO("Message: %s\n", SendBuffer);
  1796. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  1797. #endif
  1798. json_object_put(message);
  1799. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1800. //for test
  1801. #if 0
  1802. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1803. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus =='1' )
  1804. {
  1805. //ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 1;
  1806. }
  1807. if(UserPlugGun == 0 && ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus == '3')
  1808. {
  1809. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus = '1';
  1810. }
  1811. #endif
  1812. return result;
  1813. }
  1814. int sendStopTransactionRequest(int gun_index)
  1815. {
  1816. int result = FAIL;
  1817. struct json_object *message, *payload, *transactionDataArray, *transactionData, *sampledArray, *sampledValue;
  1818. char *senstr = NULL;
  1819. char *temp = NULL;
  1820. const char *del = ",";
  1821. char guid[37];
  1822. int idx_sample=0;
  1823. message = json_object_new_array();
  1824. payload = json_object_new_object();
  1825. transactionDataArray = json_object_new_array();
  1826. sampledArray = json_object_new_array();
  1827. printf("sendStopTransactionRequest \n");
  1828. strcpy(ShmOCPP16Data->StopTransaction[gun_index].IdTag, ShmOCPP16Data->Authorize.IdTag);
  1829. //ENERGY_ACTIVE_IMPORT_REGISTER
  1830. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1831. {
  1832. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1833. {
  1834. //for test
  1835. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy =100.0;
  1836. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1837. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  1838. }
  1839. }
  1840. for (int index = 0; index < CCS_QUANTITY; index++)
  1841. {
  1842. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1843. {
  1844. //for test
  1845. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  1846. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1847. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  1848. }
  1849. }
  1850. for (int index = 0; index < GB_QUANTITY; index++)
  1851. {
  1852. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1853. {
  1854. // for test
  1855. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  1856. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1857. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  1858. }
  1859. }
  1860. struct timeval tmnow;
  1861. struct tm *tm;
  1862. char buf[30], usec_buf[6];
  1863. gettimeofday(&tmnow, NULL);
  1864. time_t t;
  1865. t = time(NULL);
  1866. /*UTC time and date*/
  1867. tm = gmtime(&t);
  1868. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1869. strcat(buf,".");
  1870. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1871. strcat(buf,usec_buf);
  1872. printf("%s",buf);
  1873. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  1874. strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  1875. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  1876. strcpy(ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  1877. json_object_object_add(payload, "idTag", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  1878. json_object_object_add(payload, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  1879. json_object_object_add(payload, "timestamp", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  1880. json_object_object_add(payload, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  1881. json_object_object_add(payload, "reason", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  1882. printf("sendStopTransactionRequest 1\n");
  1883. ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*3);
  1884. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  1885. {
  1886. transactionData = json_object_new_object();
  1887. //json_object_object_add(transactionData, "timestamp", json_object_new_string("2019-05-04T18:15:33Z"));
  1888. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp, buf/*"2019-05-04T18:15:33Z"*/);
  1889. json_object_object_add(transactionData, "timestamp", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].TimeStamp));
  1890. //for(int idx_sample=0;idx_sample<1;idx_sample++)
  1891. {
  1892. sampledValue = json_object_new_object();
  1893. printf("sendStopTransactionRequest -2\n");
  1894. //Transaction_Begin
  1895. idx_sample=0;
  1896. printf("ShmOCPP16Data->StartTransaction[gun_index].MeterStart=%d\n",ShmOCPP16Data->StartTransaction[gun_index].MeterStart);
  1897. printf("ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value=%s\n",ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value);
  1898. sprintf(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%d",ShmOCPP16Data->StartTransaction[gun_index].MeterStart);
  1899. printf("sendStopTransactionRequest -2-1\n");
  1900. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  1901. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  1902. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Import_Register]);
  1903. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  1904. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  1905. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  1906. printf("sendStopTransactionRequest -2-0\n");
  1907. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value));
  1908. json_object_object_add(sampledValue, "context", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context));
  1909. json_object_object_add(sampledValue, "format", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format));
  1910. json_object_object_add(sampledValue, "measurand", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand));
  1911. json_object_object_add(sampledValue, "phase", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase));
  1912. json_object_object_add(sampledValue, "location", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location));
  1913. json_object_object_add(sampledValue, "unit", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit));
  1914. json_object_array_add(sampledArray, sampledValue);
  1915. //Transaction_End
  1916. idx_sample=1;
  1917. //sampledValue = NULL;
  1918. sampledValue = json_object_new_object();
  1919. //ENERGY_ACTIVE_IMPORT_REGISTER
  1920. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1921. {
  1922. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1923. {
  1924. // for test
  1925. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower = 100.0;
  1926. sprintf(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  1927. }
  1928. }
  1929. for (int index = 0; index < CCS_QUANTITY; index++)
  1930. {
  1931. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1932. {
  1933. // for test
  1934. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower = 100.0;
  1935. sprintf(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  1936. }
  1937. }
  1938. for (int index = 0; index < GB_QUANTITY; index++)
  1939. {
  1940. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1941. {
  1942. // for test
  1943. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  1944. sprintf(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );
  1945. }
  1946. }
  1947. //sprintf(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value, "%s",ShmOCPP16Data->StartTransaction[gun_index].MeterStart);
  1948. printf("sendStopTransactionRequest -2-1\n");
  1949. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  1950. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format,ValueFormatStr[Raw]);
  1951. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand,MeasurandStr[Energy_Active_Import_Register]);
  1952. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase,PhaseStr[L1_N]);
  1953. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location,LocationStr[Location_Outlet]);
  1954. strcpy(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  1955. printf("sendStopTransactionRequest -2-0\n");
  1956. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Value));
  1957. json_object_object_add(sampledValue, "context", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Context));
  1958. json_object_object_add(sampledValue, "format", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Format));
  1959. json_object_object_add(sampledValue, "measurand", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Measurand));
  1960. json_object_object_add(sampledValue, "phase", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Phase));
  1961. json_object_object_add(sampledValue, "location", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Location));
  1962. json_object_object_add(sampledValue, "unit", json_object_new_string((const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idx_transaction].SampledValue[idx_sample].Unit));
  1963. json_object_array_add(sampledArray, sampledValue);
  1964. }
  1965. printf("sendStopTransactionRequest -2-1\n");
  1966. json_object_object_add(transactionData, "sampledValue", sampledArray);
  1967. json_object_array_add(transactionDataArray, transactionData);
  1968. }
  1969. printf("sendStopTransactionRequest -3\n");
  1970. json_object_object_add(payload, "transactionData", transactionDataArray);
  1971. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  1972. random_uuid(guid);
  1973. json_object_array_add(message, json_object_new_string(guid));
  1974. json_object_array_add(message, json_object_new_string("StopTransaction"));
  1975. json_object_array_add(message, payload);
  1976. Send(message);
  1977. if(mapItem == NULL)
  1978. {
  1979. mapItem = malloc(sizeof(data_struct_t));
  1980. printf("mapItem is null\n");
  1981. }
  1982. // Put request guid to hash map
  1983. sprintf(mapItem->key_string, "%s", guid);
  1984. sprintf(mapItem->key_value, "StopTransaction,%d", (gun_index));
  1985. printf("StopTransaction mapItem->key_string=%s\n",mapItem->key_string);
  1986. printf("StopTransaction mapItem->key_value=%s\n",mapItem->key_value);
  1987. //sprintf(mapItem->key_value, senstr);//sprintf(mapItem->key_value, "StopTransaction");
  1988. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  1989. {
  1990. result = PASS;
  1991. printf("StopTransaction mapitem pass");
  1992. }
  1993. strcpy(queuedata, (char*)json_object_to_json_string(message));
  1994. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1995. //addq(guid, (char*)json_object_to_json_string(message));
  1996. #ifdef SystemLogMessage
  1997. DEBUG_INFO(">>>>>StopTransaction request\n");
  1998. DEBUG_INFO("Message: %s\n", SendBuffer);
  1999. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  2000. #endif
  2001. json_object_put(message);
  2002. //for test
  2003. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2004. return result;
  2005. }
  2006. int sendMeterValuesRequest(int gun_index)
  2007. {
  2008. int result = FAIL;
  2009. struct json_object *message, *payload, *meterValueDataArray, *transactionData, *sampledArray, *sampledValue;
  2010. char *senstr = NULL;
  2011. char *temp = NULL;
  2012. const char *del = ",";
  2013. char guid[37];
  2014. int idx_sample=0;
  2015. message = json_object_new_array();
  2016. payload = json_object_new_object();
  2017. meterValueDataArray = json_object_new_array();
  2018. sampledArray = json_object_new_array();
  2019. //set value
  2020. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2021. //ShmOCPP16Data->MeterValues[gun_index].TransactionId = 93507754;
  2022. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2023. json_object_object_add(payload, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  2024. json_object_object_add(payload, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  2025. printf("enter sendMeterValuesRequest -2\n");
  2026. for(int idx_transaction=0;idx_transaction<1;idx_transaction++)
  2027. {
  2028. transactionData = json_object_new_object();
  2029. //allocate memory space
  2030. ShmOCPP16Data->MeterValues[gun_index].MeterValue = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2031. //UTC Date time
  2032. struct timeval tmnow;
  2033. struct tm *tm;
  2034. char buf[30], usec_buf[6];
  2035. gettimeofday(&tmnow, NULL);
  2036. time_t t;
  2037. t = time(NULL);
  2038. /*UTC time and date*/
  2039. tm = gmtime(&t);
  2040. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2041. strcat(buf,".");
  2042. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2043. strcat(buf,usec_buf);
  2044. printf("%s",buf);
  2045. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp, buf);
  2046. json_object_object_add(transactionData, "timestamp", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].TimeStamp));
  2047. //allocate memory space
  2048. ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*5);
  2049. //for(int idx_sample=0;idx_sample<1;idx_sample++)
  2050. //{
  2051. sampledValue = json_object_new_object();
  2052. #if 1 //DC
  2053. /****************************************************(1)ENERGY_ACTIVE_IMPORT_REGISTER*********************************************/
  2054. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2055. {
  2056. printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index );
  2057. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2058. {
  2059. printf("Chademo : 0\n");
  2060. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy =100.0;
  2061. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2062. }
  2063. }
  2064. for (int index = 0; index < CCS_QUANTITY; index++)
  2065. {
  2066. printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2067. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2068. {
  2069. printf("Ccs : 0\n");
  2070. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2071. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2072. }
  2073. }
  2074. for (int index = 0; index < GB_QUANTITY; index++)
  2075. {
  2076. printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index );
  2077. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2078. {
  2079. printf("Gb : 0\n");
  2080. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2081. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2082. }
  2083. }
  2084. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2085. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2086. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  2087. // strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1]);
  2088. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2089. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh]);
  2090. printf("meter error 1\n");
  2091. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value));
  2092. printf("meter error 2\n");
  2093. json_object_object_add(sampledValue, "context", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context));
  2094. printf("meter error 3\n");
  2095. json_object_object_add(sampledValue, "format", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format));
  2096. printf("meter error 4\n");
  2097. json_object_object_add(sampledValue, "measurand", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand));
  2098. // json_object_object_add(sampledValue, "phase", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase));
  2099. printf("meter error 5\n");
  2100. json_object_object_add(sampledValue, "location", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location));
  2101. printf("meter error 6\n");
  2102. json_object_object_add(sampledValue, "unit", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit));
  2103. printf("meter error 7\n");
  2104. json_object_array_add(sampledArray, sampledValue);
  2105. printf("meter error 8\n");
  2106. idx_sample=1;
  2107. //sampledValue = NULL;
  2108. sampledValue = json_object_new_object();
  2109. /***********************************************(2)VOLTAGE******************************************************/
  2110. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2111. {
  2112. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2113. {
  2114. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage = 80.0;
  2115. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2116. }
  2117. }
  2118. for (int index = 0; index < CCS_QUANTITY; index++)
  2119. {
  2120. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2121. {
  2122. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage = 80.0;
  2123. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2124. }
  2125. }
  2126. for (int index = 0; index < GB_QUANTITY; index++)
  2127. {
  2128. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2129. {
  2130. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage = 80.0;
  2131. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2132. }
  2133. }
  2134. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2135. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2136. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Voltage]);
  2137. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2138. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2139. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2140. printf("meter error 9\n");
  2141. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value));
  2142. printf("meter error 10\n");
  2143. json_object_object_add(sampledValue, "context", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context));
  2144. printf("meter error 11\n");
  2145. json_object_object_add(sampledValue, "format", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format));
  2146. printf("meter error 12\n");
  2147. json_object_object_add(sampledValue, "measurand", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand));
  2148. printf("meter error 13\n");
  2149. json_object_object_add(sampledValue, "phase", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase));
  2150. printf("meter error 14\n");
  2151. json_object_object_add(sampledValue, "location", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location));
  2152. printf("meter error 15\n");
  2153. json_object_object_add(sampledValue, "unit", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit));
  2154. printf("meter error 16\n");
  2155. json_object_array_add(sampledArray, sampledValue);
  2156. idx_sample=2;
  2157. //sampledValue = NULL;
  2158. sampledValue = json_object_new_object();
  2159. /********************************(3)Current************************************************/
  2160. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2161. {
  2162. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2163. {
  2164. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent = 60.0;
  2165. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2166. }
  2167. }
  2168. for (int index = 0; index < CCS_QUANTITY; index++)
  2169. {
  2170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2171. {
  2172. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent = 60.0;
  2173. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2174. }
  2175. }
  2176. for (int index = 0; index < GB_QUANTITY; index++)
  2177. {
  2178. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2179. {
  2180. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent = 60.0;
  2181. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2182. }
  2183. }
  2184. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2185. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2186. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Current_Import]);
  2187. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2188. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2189. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2190. printf("meter error 17\n");
  2191. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value));
  2192. printf("meter error 18\n");
  2193. json_object_object_add(sampledValue, "context", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context));
  2194. printf("meter error 19\n");
  2195. json_object_object_add(sampledValue, "format", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format));
  2196. printf("meter error 20\n");
  2197. json_object_object_add(sampledValue, "measurand", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand));
  2198. printf("meter error 21\n");
  2199. json_object_object_add(sampledValue, "phase", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase));
  2200. printf("meter error 22\n");
  2201. json_object_object_add(sampledValue, "location", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location));
  2202. printf("meter error 23\n");
  2203. json_object_object_add(sampledValue, "unit", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit));
  2204. printf("meter error 24\n");
  2205. json_object_array_add(sampledArray, sampledValue);
  2206. printf("meter error 25\n");
  2207. idx_sample=3;
  2208. //sampledValue = NULL;
  2209. sampledValue = json_object_new_object();
  2210. /********************************(4)Power.Active.Import************************************************/
  2211. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2212. {
  2213. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2214. {
  2215. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower = 100.0;
  2216. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2217. }
  2218. }
  2219. for (int index = 0; index < CCS_QUANTITY; index++)
  2220. {
  2221. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2222. {
  2223. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower = 100.0;
  2224. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2225. }
  2226. }
  2227. for (int index = 0; index < GB_QUANTITY; index++)
  2228. {
  2229. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2230. {
  2231. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2232. sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2233. }
  2234. }
  2235. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2236. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format, ValueFormatStr[Raw]);
  2237. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand, MeasurandStr[Power_Active_Import]);
  2238. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase, PhaseStr[L1_N]);
  2239. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location, LocationStr[Location_Outlet]);
  2240. strcpy(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2241. printf("meter error 35\n");
  2242. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value));
  2243. printf("meter error 36\n");
  2244. json_object_object_add(sampledValue, "context", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Context));
  2245. printf("meter error 37\n");
  2246. json_object_object_add(sampledValue, "format", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Format));
  2247. printf("meter error 38\n");
  2248. json_object_object_add(sampledValue, "measurand", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Measurand));
  2249. printf("meter error 39\n");
  2250. json_object_object_add(sampledValue, "phase", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Phase));
  2251. printf("meter error 40\n");
  2252. json_object_object_add(sampledValue, "location", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Location));
  2253. printf("meter error 41\n");
  2254. json_object_object_add(sampledValue, "unit", json_object_new_string((const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Unit));
  2255. printf("meter error 42\n");
  2256. json_object_array_add(sampledArray, sampledValue);
  2257. printf("meter error 43\n");
  2258. #endif
  2259. //}
  2260. json_object_object_add(transactionData, "sampledValue", sampledArray);
  2261. json_object_array_add(meterValueDataArray, transactionData);
  2262. }
  2263. json_object_object_add(payload, "meterValue", meterValueDataArray);
  2264. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALL));
  2265. random_uuid(guid);
  2266. json_object_array_add(message, json_object_new_string(guid));
  2267. json_object_array_add(message, json_object_new_string("MeterValues"));
  2268. json_object_array_add(message, payload);
  2269. printf("enter sendMeterValuesRequest -3\n");
  2270. printf("before send message=%s\n",json_object_to_json_string(message));
  2271. Send(message);
  2272. if(mapItem == NULL)
  2273. {
  2274. mapItem = malloc(sizeof(data_struct_t));
  2275. printf("mapItem is null\n");
  2276. }
  2277. if(guid == NULL || mapItem->key_string == NULL)
  2278. {
  2279. printf("guid is NULL \n");
  2280. }
  2281. if(mapItem->key_string == NULL)
  2282. {
  2283. printf("mapItem->key_string is NULL\n");
  2284. }
  2285. printf("enter sendMeterValuesRequest -4\n");
  2286. // Put request guid to hash map
  2287. sprintf(mapItem->key_string, "%s", guid);
  2288. sprintf(mapItem->key_value, "MeterValues,%d", (gun_index));
  2289. //sprintf(mapItem->key_value, senstr);//sprintf(mapItem->key_value, "StopTransaction");
  2290. if(hashmap_operation(0,hashMap, mapItem->key_string, mapItem->key_value/*mapItem*/, (void**)(&mapItem)) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2291. {
  2292. result = PASS;
  2293. printf("MeterValues mapitem pass");
  2294. }
  2295. strcpy(queuedata, (char*)json_object_to_json_string(message));
  2296. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2297. printf("enter sendMeterValuesRequest -5\n");
  2298. //addq(guid, (char*)json_object_to_json_string(message));
  2299. #ifdef SystemLogMessage
  2300. DEBUG_INFO(">>>>>MeerValues request\n");
  2301. DEBUG_INFO("Message: %s\n", SendBuffer);
  2302. DEBUG_INFO("After push hash length: %d\n", hashmap_length(hashMap));
  2303. #endif
  2304. json_object_put(message);
  2305. return result;
  2306. }
  2307. //==========================================
  2308. // send confirm routine
  2309. //==========================================
  2310. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2311. {
  2312. int result = FAIL;
  2313. struct json_object *message, *comfirmpayload;
  2314. char guid[37];
  2315. printf("handle CancelReservationRequest\n");
  2316. message = json_object_new_array();
  2317. comfirmpayload = json_object_new_object();
  2318. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2319. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2320. json_object_array_add(message, json_object_new_string(uuid));
  2321. json_object_array_add(message, comfirmpayload);
  2322. Send(message);
  2323. json_object_put(message);
  2324. return result;
  2325. }
  2326. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2327. {
  2328. int result = FAIL;
  2329. struct json_object *message, *comfirmpayload;
  2330. char guid[37];
  2331. printf("handle sendChangeAvailabilityConfirmation\n");
  2332. message = json_object_new_array();
  2333. comfirmpayload = json_object_new_object();
  2334. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2335. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2336. json_object_array_add(message, json_object_new_string(uuid));
  2337. json_object_array_add(message, comfirmpayload);
  2338. Send(message);
  2339. json_object_put(message);
  2340. return result;
  2341. }
  2342. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2343. {
  2344. int result = FAIL;
  2345. struct json_object *message, *comfirmpayload;
  2346. char guid[37];
  2347. printf("handle sendChangeConfigurationConfirmation\n");
  2348. message = json_object_new_array();
  2349. comfirmpayload = json_object_new_object();
  2350. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2351. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2352. json_object_array_add(message, json_object_new_string(uuid));
  2353. json_object_array_add(message, comfirmpayload);
  2354. printf("handle sendChangeConfigurationConfirmation -1\n");
  2355. Send(message);
  2356. printf("handle sendChangeConfigurationConfirmation- 2\n");
  2357. json_object_put(message);
  2358. return result;
  2359. }
  2360. int sendClearCacheConfirmation(char *uuid,char *payload)
  2361. {
  2362. int result = FAIL;
  2363. struct json_object *message, *comfirmpayload;
  2364. char guid[37];
  2365. printf("sendClearCacheConfirmation\n");
  2366. message = json_object_new_array();
  2367. comfirmpayload = json_object_new_object();
  2368. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2369. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2370. json_object_array_add(message, json_object_new_string(uuid));
  2371. json_object_array_add(message, comfirmpayload);
  2372. Send(message);
  2373. json_object_put(message);
  2374. return result;
  2375. }
  2376. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2377. {
  2378. int result = FAIL;
  2379. struct json_object *message, *comfirmpayload;
  2380. char guid[37];
  2381. printf("sendClearChargingProfileConfirmation\n");
  2382. message = json_object_new_array();
  2383. comfirmpayload = json_object_new_object();
  2384. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2385. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2386. json_object_array_add(message, json_object_new_string(uuid));
  2387. json_object_array_add(message, comfirmpayload);
  2388. Send(message);
  2389. json_object_put(message);
  2390. return result;
  2391. }
  2392. int sendDataTransferConfirmation(char *uuid,char *payload)
  2393. {
  2394. int result = FAIL;
  2395. struct json_object *obj;
  2396. char guid[37];
  2397. obj = json_tokener_parse(payload);
  2398. printf("handle DataTransferRequest\n");
  2399. return result;
  2400. }
  2401. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2402. {
  2403. int result = FAIL;
  2404. struct json_object *message, *comfirmpayload, *chargingSchedule, *sampledArray, *sampledValue;
  2405. printf("handle sendGetCompositeScheduleConfirmation\n");
  2406. message = json_object_new_array();
  2407. comfirmpayload = json_object_new_object();
  2408. chargingSchedule = json_object_new_object();
  2409. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2410. json_object_object_add(comfirmpayload, "connectorId ", json_object_new_int(connectorIdInt));
  2411. json_object_object_add(comfirmpayload, "scheduleStart", json_object_new_string((const char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule));
  2412. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration) );
  2413. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((const char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule) );
  2414. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((const char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit) );
  2415. sampledArray = json_object_new_array();
  2416. int len = nPeriod;//sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod)/sizeof(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0]);
  2417. printf("sendGetCompositeScheduleConfirmation nPeriod =%d\n", len);
  2418. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2419. {
  2420. sampledValue = json_object_new_object();
  2421. json_object_object_add(sampledValue, "startPeriod", json_object_new_int(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].StartPeriod));
  2422. json_object_object_add(sampledValue, "limit", json_object_new_double((double)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].Limit));
  2423. json_object_object_add(sampledValue, "numberPhases", json_object_new_int(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].NumberPhases));
  2424. json_object_array_add(sampledArray, sampledValue);
  2425. }
  2426. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", sampledArray);
  2427. json_object_object_add(chargingSchedule, "minChargingRate ", json_object_new_double((double)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate) );
  2428. json_object_object_add(comfirmpayload, "chargingSchedule", chargingSchedule );
  2429. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2430. json_object_array_add(message, json_object_new_string(uuid));
  2431. json_object_array_add(message, comfirmpayload);
  2432. Send(message);
  2433. json_object_put(message);
  2434. return result;
  2435. }
  2436. int sendGetConfigurationConfirmation(char *uuid)
  2437. {
  2438. int result = FAIL;
  2439. int MaxKeySupported = 0;
  2440. struct json_object *message, *comfirmpayload, *configurationKeyArray, *unknownKeyArray, *sampledValue;
  2441. printf("handle sendGetConfigurationConfirmation\n");
  2442. message = json_object_new_array();
  2443. comfirmpayload = json_object_new_object();
  2444. configurationKeyArray = json_object_new_array();
  2445. MaxKeySupported = atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  2446. printf("MaxKeySupported=%d\n",MaxKeySupported);
  2447. // int configurationKeyArraylen = sizeof(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey)/sizeof(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[0]);
  2448. // printf("configurationKeyArraylen =%d\n", configurationKeyArraylen);
  2449. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  2450. {
  2451. if(strcmp(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  2452. {
  2453. printf("test test enter add configurationKey\n");
  2454. sampledValue = json_object_new_object();
  2455. json_object_object_add(sampledValue, "key", json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey+idx_sample)->Key)));
  2456. json_object_object_add(sampledValue, "readonly", json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey+idx_sample)->ReadOnly)));
  2457. json_object_object_add(sampledValue, "value", json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey+idx_sample)->Value)));
  2458. json_object_array_add(configurationKeyArray, sampledValue);
  2459. }
  2460. }
  2461. json_object_object_add(comfirmpayload, "configurationKey", configurationKeyArray );
  2462. unknownKeyArray = json_object_new_array();
  2463. sampledValue = NULL;
  2464. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  2465. {
  2466. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  2467. printf("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  2468. json_object *jstring1 = json_object_new_string((const char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item));
  2469. json_object_array_add(unknownKeyArray, jstring1);
  2470. }
  2471. json_object_object_add(comfirmpayload, "unknownKey ", unknownKeyArray );
  2472. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2473. json_object_array_add(message, json_object_new_string(uuid));
  2474. json_object_array_add(message, comfirmpayload);
  2475. Send(message);
  2476. json_object_put(message);
  2477. return result;
  2478. }
  2479. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  2480. {
  2481. int result = FAIL;
  2482. printf("handle GetDiagnosticsRequest\n");
  2483. struct json_object *message, *comfirmpayload;
  2484. printf("handle sendChangeConfigurationConfirmation\n");
  2485. message = json_object_new_array();
  2486. comfirmpayload = json_object_new_object();
  2487. json_object_object_add(comfirmpayload, "fileName", json_object_new_string((const char *)payload));
  2488. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2489. json_object_array_add(message, json_object_new_string(uuid));
  2490. json_object_array_add(message, comfirmpayload);
  2491. Send(message);
  2492. json_object_put(message);
  2493. return result;
  2494. }
  2495. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  2496. {
  2497. int result = FAIL;
  2498. printf("handle GetLocalListVersionRequest\n");
  2499. struct json_object *message, *comfirmpayload;
  2500. message = json_object_new_array();
  2501. comfirmpayload = json_object_new_object();
  2502. json_object_object_add(comfirmpayload, "listVersion", json_object_new_int(ShmOCPP16Data->GetLocalListVersion.ResponseListVersion));
  2503. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2504. json_object_array_add(message, json_object_new_string(uuid));
  2505. json_object_array_add(message, comfirmpayload);
  2506. Send(message);
  2507. json_object_put(message);
  2508. return result;
  2509. }
  2510. int sendRemoteStartConfirmation(char *uuid,char *payload)
  2511. {
  2512. int result = FAIL;
  2513. printf("handleRemoteStartRequest\n");
  2514. struct json_object *message, *comfirmpayload;
  2515. message = json_object_new_array();
  2516. comfirmpayload = json_object_new_object();
  2517. json_object_object_add(comfirmpayload, "status", json_object_new_string(payload));
  2518. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2519. json_object_array_add(message, json_object_new_string(uuid));
  2520. json_object_array_add(message, comfirmpayload);
  2521. Send(message);
  2522. json_object_put(message);
  2523. return result;
  2524. }
  2525. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  2526. {
  2527. int result = FAIL;
  2528. struct json_object *message, *comfirmpayload;
  2529. printf("handleRemoteStopTransactionRequest\n");
  2530. message = json_object_new_array();
  2531. comfirmpayload = json_object_new_object();
  2532. json_object_object_add(comfirmpayload, "status", json_object_new_string(payload));
  2533. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2534. json_object_array_add(message, json_object_new_string(uuid));
  2535. json_object_array_add(message, comfirmpayload);
  2536. Send(message);
  2537. json_object_put(message);
  2538. return result;
  2539. }
  2540. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  2541. {
  2542. int result = FAIL;
  2543. struct json_object *message, *comfirmpayload;
  2544. printf("sendReserveNowTransactionConfirmation\n");
  2545. message = json_object_new_array();
  2546. comfirmpayload = json_object_new_object();
  2547. json_object_object_add(comfirmpayload, "status", json_object_new_string(payload));
  2548. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2549. json_object_array_add(message, json_object_new_string(uuid));
  2550. json_object_array_add(message, comfirmpayload);
  2551. Send(message);
  2552. json_object_put(message);
  2553. return result;
  2554. }
  2555. int sendResetConfirmation(char *uuid,char *payload)
  2556. {
  2557. int result = FAIL;
  2558. struct json_object *message, *comfirmpayload;
  2559. printf("sendResetConfirmation\n");
  2560. message = json_object_new_array();
  2561. comfirmpayload = json_object_new_object();
  2562. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2563. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2564. json_object_array_add(message, json_object_new_string(uuid));
  2565. json_object_array_add(message, comfirmpayload);
  2566. Send(message);
  2567. json_object_put(message);
  2568. return result;
  2569. }
  2570. int sendSendLocalListConfirmation(char *uuid,char *payload)
  2571. {
  2572. int result = FAIL;
  2573. struct json_object *message, *comfirmpayload;
  2574. printf("handle sendSendLocalListConfirmation\n");
  2575. message = json_object_new_array();
  2576. comfirmpayload = json_object_new_object();
  2577. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2578. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2579. json_object_array_add(message, json_object_new_string(uuid));
  2580. json_object_array_add(message, comfirmpayload);
  2581. Send(message);
  2582. json_object_put(message);
  2583. return result;
  2584. }
  2585. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  2586. {
  2587. int result = FAIL;
  2588. printf("handleSetChargingProfileRequest\n");
  2589. struct json_object *message, *comfirmpayload;
  2590. message = json_object_new_array();
  2591. comfirmpayload = json_object_new_object();
  2592. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2593. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2594. json_object_array_add(message, json_object_new_string(uuid));
  2595. json_object_array_add(message, comfirmpayload);
  2596. Send(message);
  2597. json_object_put(message);
  2598. return result;
  2599. }
  2600. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  2601. {
  2602. int result = FAIL;
  2603. printf("sendTriggerMessageConfirmation\n");
  2604. struct json_object *message, *comfirmpayload;
  2605. message = json_object_new_array();
  2606. comfirmpayload = json_object_new_object();
  2607. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2608. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2609. json_object_array_add(message, json_object_new_string(uuid));
  2610. json_object_array_add(message, comfirmpayload);
  2611. Send(message);
  2612. json_object_put(message);
  2613. return result;
  2614. }
  2615. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  2616. {
  2617. int result = FAIL;
  2618. printf("sendUnlockConnectorConfirmation\n");
  2619. struct json_object *message, *comfirmpayload;
  2620. message = json_object_new_array();
  2621. comfirmpayload = json_object_new_object();
  2622. json_object_object_add(comfirmpayload, "status", json_object_new_string((const char *)payload));
  2623. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2624. json_object_array_add(message, json_object_new_string(uuid));
  2625. json_object_array_add(message, comfirmpayload);
  2626. Send(message);
  2627. json_object_put(message);
  2628. return result;
  2629. }
  2630. int sendUpdateFirmwareConfirmation(char *uuid)
  2631. {
  2632. int result = FAIL;
  2633. printf("sendUpdateFirmwareConfirmation\n");
  2634. struct json_object *message, *comfirmpayload;
  2635. message = json_object_new_array();
  2636. comfirmpayload = json_object_new_object();
  2637. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLRESULT));
  2638. json_object_array_add(message, json_object_new_string(uuid));
  2639. json_object_array_add(message, comfirmpayload);
  2640. Send(message);
  2641. json_object_put(message);
  2642. return result;
  2643. }
  2644. //==========================================
  2645. // send CallError routine
  2646. //==========================================
  2647. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  2648. {
  2649. #ifdef SystemLogMessage
  2650. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  2651. uniqueId, action, errorCode, errorDescription);
  2652. #endif
  2653. printf("SendCallError\n");
  2654. struct json_object *message/*, *comfirmpayload*/;
  2655. message = json_object_new_array();
  2656. //comfirmpayload = json_object_new_object();
  2657. json_object_array_add(message, json_object_new_int(MESSAGE_TYPE_CALLERROR));
  2658. json_object_array_add(message, json_object_new_string(uniqueId));
  2659. json_object_array_add(message, json_object_new_string(errorCode));
  2660. json_object_array_add(message, json_object_new_string(errorDescription));
  2661. json_object_array_add(message, json_object_new_string("{}"));
  2662. Send(message);
  2663. json_object_put(message);
  2664. }
  2665. //==========================================
  2666. // Handle server request routine Start
  2667. //==========================================
  2668. #define GUN_NUM 1
  2669. int handleCancelReservationRequest(char *uuid, char *payload)
  2670. {
  2671. int result = FAIL;
  2672. int gunNO = 0;
  2673. struct json_object *obj, *reservationId;
  2674. int reservationIdInt =0;
  2675. char comfirmstr[20];
  2676. obj = json_tokener_parse(payload);
  2677. printf("handle CancelReservationRequest\n");
  2678. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  2679. reservationId = json_object_object_get(obj, "reservationId");
  2680. reservationIdInt = json_object_get_int(reservationId);
  2681. memset(comfirmstr, 0, sizeof comfirmstr);
  2682. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  2683. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  2684. //check Transaction active
  2685. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2686. {
  2687. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  2688. {
  2689. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  2690. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  2691. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  2692. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  2693. }
  2694. }
  2695. for (int index = 0; index < CCS_QUANTITY; index++)
  2696. {
  2697. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  2698. {
  2699. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  2700. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  2701. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  2702. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  2703. }
  2704. }
  2705. for (int index = 0; index < GB_QUANTITY; index++)
  2706. {
  2707. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  2708. {
  2709. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  2710. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  2711. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  2712. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  2713. }
  2714. }
  2715. // Fill in ocpp packet uuid
  2716. strcpy(ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  2717. json_object_put(obj);
  2718. #if 0 // CSU Will do it.
  2719. sendCancelReservationConfirmation(uuid, comfirmstr);
  2720. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationConf = 1;
  2721. #endif
  2722. return result;
  2723. }
  2724. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  2725. {
  2726. int result = FAIL;
  2727. int gunIndex = 0;
  2728. struct json_object *obj, *connectorId, *type;
  2729. char comfirmstr[20];
  2730. int specificId = FALSE;
  2731. obj = json_tokener_parse(payload);
  2732. printf("handle ChangeAvailabilityRequest\n");
  2733. connectorId = json_object_object_get(obj, "connectorId");
  2734. type = json_object_object_get(obj, "type");
  2735. gunIndex = json_object_get_int(connectorId);
  2736. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  2737. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", json_object_get_string(type) );
  2738. memset(comfirmstr, 0, sizeof comfirmstr);
  2739. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  2740. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  2741. if((gunIndex == 0) || ((gunIndex - 1) < (CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)))
  2742. {
  2743. specificId = TRUE;
  2744. }
  2745. if(specificId == FALSE)
  2746. goto end;
  2747. /*
  2748. enum _SYSTEM_STATUS
  2749. {
  2750. S_BOOTING = 0,
  2751. S_IDLE, = 1
  2752. S_AUTHORIZING, =2
  2753. S_REASSIGN_CHECK, =3
  2754. S_REASSIGN, =4
  2755. S_PRECHARGE, =5
  2756. S_PREPARING_FOR_EV, =6
  2757. S_PREPARING_FOR_EVSE, =7
  2758. S_CHARGING, =8
  2759. S_TERMINATING, =9
  2760. S_COMPLETE, =10
  2761. S_ALARM, =11
  2762. S_FAULT =12
  2763. }
  2764. */
  2765. if(strcmp((const char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, AvailabilityTypeStr[Inoperative]) == 0)
  2766. {
  2767. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  2768. //check Transaction active
  2769. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2770. {
  2771. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  2772. {
  2773. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 5) // S_PRECHARGE
  2774. {
  2775. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  2776. }
  2777. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8) // S_CHARGING
  2778. {
  2779. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  2780. }
  2781. else
  2782. {
  2783. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  2784. }
  2785. goto end;
  2786. }
  2787. }
  2788. for (int index = 0; index < CCS_QUANTITY; index++)
  2789. {
  2790. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  2791. {
  2792. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 5)// S_PRECHARGE
  2793. {
  2794. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  2795. }
  2796. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8) // S_CHARGING
  2797. {
  2798. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  2799. }
  2800. else
  2801. {
  2802. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  2803. }
  2804. goto end;
  2805. }
  2806. }
  2807. for (int index = 0; index < GB_QUANTITY; index++)
  2808. {
  2809. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  2810. {
  2811. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 5) // S_PRECHARGE
  2812. {
  2813. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  2814. }
  2815. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8) // S_CHARGING
  2816. {
  2817. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  2818. }
  2819. else
  2820. {
  2821. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  2822. }
  2823. goto end;
  2824. }
  2825. }
  2826. }
  2827. if(strcmp((const char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, AvailabilityTypeStr[Operative]) == 0)
  2828. {
  2829. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  2830. //check Transaction active
  2831. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2832. {
  2833. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 12)) //S_FAULT
  2834. {
  2835. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  2836. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  2837. goto end;
  2838. }
  2839. }
  2840. for (int index = 0; index < CCS_QUANTITY; index++)
  2841. {
  2842. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 12)) //S_FAULT
  2843. {
  2844. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  2845. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  2846. goto end;
  2847. }
  2848. }
  2849. for (int index = 0; index < GB_QUANTITY; index++)
  2850. {
  2851. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 12)) //S_FAULT
  2852. {
  2853. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  2854. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  2855. goto end;
  2856. }
  2857. }
  2858. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  2859. }
  2860. end:
  2861. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  2862. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  2863. json_object_put(obj);
  2864. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  2865. return result;
  2866. }
  2867. int handleChangeConfigurationRequest(char *uuid, char *payload)
  2868. {
  2869. int result = FAIL;
  2870. char comfirmstr[20];
  2871. printf("handle ChangeConfigurationRequest\n");
  2872. struct json_object *obj, *key, *value;
  2873. char *keystr, *valuestr;
  2874. obj = json_tokener_parse(payload);
  2875. key = json_object_object_get(obj, "key");
  2876. value = json_object_object_get(obj, "value");
  2877. keystr= json_object_get_string(key);
  2878. valuestr = json_object_get_string(value);
  2879. if((uuid==NULL) || (payload ==NULL) )
  2880. {
  2881. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  2882. }
  2883. else
  2884. {
  2885. int status = setKeyValue(keystr, valuestr);
  2886. switch(status)
  2887. {
  2888. case ConfigurationStatus_Accepted:
  2889. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  2890. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  2891. break;
  2892. case ConfigurationStatus_Rejected:
  2893. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  2894. break;
  2895. case RebootRequired:
  2896. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  2897. break;
  2898. case NotSupported:
  2899. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  2900. break;
  2901. default:
  2902. break;
  2903. }
  2904. }
  2905. if(errno >=1)
  2906. {
  2907. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  2908. fprintf(stderr,"%d %s\\n",errno,strerror(errno));
  2909. }
  2910. //confirmation.setStatus(ConfigurationStatus.Rejected);
  2911. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  2912. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  2913. json_object_put(obj);
  2914. return result;
  2915. }
  2916. int handleClearCacheRequest(char *uuid, char *payload)
  2917. {
  2918. int result = FAIL;
  2919. char comfirmstr[20];
  2920. int fd;
  2921. printf("handle ClearCacheRequest\n");
  2922. /* ?��?一个�?�?*/
  2923. fd = open(AuthorizationCache_JSON,O_RDWR);
  2924. if(fd < 0)
  2925. {
  2926. printf("open AuthorizationCache file failed\n");
  2927. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  2928. }
  2929. else
  2930. {
  2931. printf("open AuthorizationCache file successful\n");
  2932. /* 清空?�件 */
  2933. ftruncate(fd,0);
  2934. /* ?�新设置?�件?�移??*/
  2935. lseek(fd,0,SEEK_SET);
  2936. close(fd);
  2937. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  2938. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  2939. }
  2940. sendClearCacheConfirmation(uuid, comfirmstr);
  2941. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  2942. return result;
  2943. }
  2944. int handleClearChargingProfileRequest(char *uuid, char *payload)
  2945. {
  2946. int result = FAIL;
  2947. struct json_object *obj, *connectorId, *csChargingProfiles, *chargingProfileId, *stackLevel, *chargingProfilePurpose;
  2948. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  2949. const char*chargingProfilePurposeStr;
  2950. struct json_object *tempobj, *tempconnectorId, *tempcsChargingProfiles, *tempchargingProfileId, *tempstackLevel, *tempchargingProfilePurpose;
  2951. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  2952. char *tempchargingProfilePurposeStr;
  2953. char fname[200];
  2954. json_object *test_obj = NULL;
  2955. json_object *tmp_obj = NULL;
  2956. struct array_list *json_list;
  2957. struct json_object *jsonitem;
  2958. char comfirmstr[20];
  2959. size_t n_friends;
  2960. int clearflag = FALSE;
  2961. FILE *fptr1, *fptr2;
  2962. char temp[] = "./mnt/temp.json";
  2963. struct json_object *newHeatMap = json_object_new_array();
  2964. obj = json_tokener_parse(payload);
  2965. printf("handle ClearChargingProfileRequest\n");
  2966. connectorId = json_object_object_get(obj, "connectorId");
  2967. chargingProfileId = json_object_object_get(obj, "id");
  2968. stackLevel = json_object_object_get(obj, "stackLevel");
  2969. chargingProfilePurpose = json_object_object_get(obj, "chargingProfilePurpose");
  2970. if(connectorId != NULL)
  2971. connectorIdInt = json_object_get_int(connectorId);
  2972. if(chargingProfileId != NULL)
  2973. chargingProfileIdInt = json_object_get_int(chargingProfileId);
  2974. if(stackLevel != NULL)
  2975. stackLevelInt = json_object_get_int(stackLevel);
  2976. if(chargingProfilePurpose != NULL)
  2977. chargingProfilePurposeStr = json_object_get_string(chargingProfilePurpose);
  2978. if(connectorId != NULL)
  2979. {
  2980. switch(connectorIdInt)
  2981. {
  2982. case 0:
  2983. strcpy(fname, ChargingProfile_0_JSON );
  2984. break;
  2985. case 1:
  2986. strcpy(fname, ChargingProfile_1_JSON );
  2987. break;
  2988. case 2:
  2989. strcpy(fname, ChargingProfile_2_JSON );
  2990. break;
  2991. default:
  2992. strcpy(fname, ChargingProfile_0_JSON );
  2993. break;
  2994. }
  2995. }
  2996. else
  2997. {
  2998. strcpy(fname, ChargingProfile_0_JSON );
  2999. }
  3000. fptr1 = fopen(fname, "r");
  3001. if (!fptr1)
  3002. {
  3003. //file not exist
  3004. printf("Unable to open the input file!!\n");
  3005. fptr1 = fopen(fname, "w+");
  3006. }
  3007. fclose(fptr1);
  3008. if(connectorId != NULL && (connectorIdInt != 0) && ( (connectorIdInt-1) > (CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY) ) )
  3009. {
  3010. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3011. goto end;
  3012. }
  3013. //get json object from file
  3014. test_obj = json_object_from_file(fname);
  3015. if(json_object_get_type(test_obj) == json_type_array)
  3016. {
  3017. //
  3018. if(connectorId == NULL || connectorIdInt == 0 )
  3019. {
  3020. //clear the whole contents of a file in C
  3021. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3022. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3023. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3024. }
  3025. else
  3026. {
  3027. n_friends = json_object_array_length(test_obj);
  3028. printf("Found %lu friends\n",n_friends);
  3029. for(int i=0;i<n_friends;i++)
  3030. {
  3031. jsonitem = json_object_array_get_idx(test_obj, i);
  3032. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  3033. tempconnectorId = json_object_object_get(jsonitem, "connectorId");
  3034. tempcsChargingProfiles = json_object_object_get(jsonitem, "csChargingProfiles");
  3035. tempchargingProfileId = json_object_object_get(tempcsChargingProfiles, "chargingProfileId");
  3036. tempstackLevel = json_object_object_get(tempcsChargingProfiles, "stackLevel");
  3037. tempchargingProfilePurpose = json_object_object_get(tempcsChargingProfiles, "chargingProfilePurpose");
  3038. tempconnectorIdInt = json_object_get_int(tempconnectorId);
  3039. tempchargingProfileIdInt = json_object_get_int(tempchargingProfileId);
  3040. tempstackLevelInt = json_object_get_int(tempstackLevel);
  3041. tempchargingProfilePurposeStr = (char *)json_object_get_string(tempchargingProfilePurpose);
  3042. if(chargingProfileId != NULL)
  3043. {
  3044. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3045. {
  3046. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3047. clearflag = TRUE;
  3048. continue;
  3049. }
  3050. else
  3051. {
  3052. json_object_array_add(newHeatMap, jsonitem);
  3053. }
  3054. }
  3055. else
  3056. {
  3057. if((tempconnectorIdInt == connectorIdInt) && ((tempchargingProfileIdInt == chargingProfileIdInt) || (tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3058. {
  3059. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3060. clearflag = TRUE;
  3061. continue;
  3062. }
  3063. else
  3064. {
  3065. json_object_array_add(newHeatMap, jsonitem);
  3066. }
  3067. }
  3068. }
  3069. if(clearflag == FALSE)
  3070. {
  3071. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3072. goto end;
  3073. }
  3074. }
  3075. FILE *fp;
  3076. fp=fopen(temp,"w");
  3077. fclose(fp);
  3078. remove(fname);
  3079. rename(temp, fname);
  3080. json_object_to_file(fname, newHeatMap);
  3081. }
  3082. else
  3083. {
  3084. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3085. }
  3086. end:
  3087. json_object_put(obj);
  3088. json_object_put(test_obj);
  3089. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3090. return result;
  3091. }
  3092. int handleDataTransferRequest(char *uuid, char *payload)
  3093. {
  3094. int result = FAIL;
  3095. struct json_object *obj;
  3096. obj = json_tokener_parse(payload);
  3097. printf("handle DataTransferRequest\n");
  3098. return result;
  3099. }
  3100. long long diff_tm(struct tm *a, struct tm *b) {
  3101. return a->tm_sec - b->tm_sec
  3102. + 60LL * (a->tm_min - b->tm_min)
  3103. + 3600LL * (a->tm_hour - b->tm_hour)
  3104. + 86400LL * (a->tm_yday - b->tm_yday)
  3105. + (a->tm_year - 70) * 31536000LL
  3106. - (a->tm_year - 69) / 4 * 86400LL
  3107. + (a->tm_year - 1) / 100 * 86400LL
  3108. - (a->tm_year + 299) / 400 * 86400LL
  3109. - (b->tm_year - 70) * 31536000LL
  3110. + (b->tm_year - 69) / 4 * 86400LL
  3111. - (b->tm_year - 1) / 100 * 86400LL
  3112. + (b->tm_year + 299) /400 * 86400LL;
  3113. }
  3114. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  3115. {
  3116. int result = FAIL;
  3117. struct json_object *obj, *connectorId, *duration, *chargingRateUnit;
  3118. int connectorIdInt, durationInt;
  3119. const char*chargingRateUnitStr;
  3120. struct json_object *tempobj, *tempconnectorId, *tempcsChargingProfiles, *tempvalidFrom,*tempChargingSchedule, *tempstartSchedule, *tempchargingSchedulePeriod, *tempminChargingRate;
  3121. int tempconnectorIdInt, tempdurationInt;
  3122. float tempminChargingRateFloat = 0.0;
  3123. char *tempvalidFromStr,*tempchargingRateUnitStr, *tempstartScheduleStr;
  3124. char fname[200];
  3125. json_object *test_obj = NULL;
  3126. json_object *tmp_obj = NULL;
  3127. struct array_list *json_list;
  3128. struct json_object *jsonitem;
  3129. char comfirmstr[20];
  3130. size_t n_friends;
  3131. float totallimit =0.0;
  3132. float MinChargingRate =0.0;
  3133. int clearflag = FALSE;
  3134. int n_periods = 0;
  3135. int nPeriod = 0;
  3136. FILE *fptr1, *fptr2;
  3137. char temp[] = "temp.json";
  3138. struct json_object *newHeatMap = json_object_new_array();
  3139. printf("handle GetCompositeScheduleRequest\n");
  3140. obj = json_tokener_parse(payload);
  3141. connectorId = json_object_object_get(obj, "connectorId");
  3142. duration = json_object_object_get(obj, "duration");
  3143. chargingRateUnit = json_object_object_get(obj, "chargingRateUnit");
  3144. connectorIdInt = json_object_get_int(connectorId);
  3145. durationInt = json_object_get_int(duration);
  3146. if(chargingRateUnit != NULL)
  3147. chargingRateUnitStr = json_object_get_string(chargingRateUnit);
  3148. // current time
  3149. time_t t = time(NULL);
  3150. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)* (CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY) );
  3151. if(connectorIdInt==0) // connectorId is 0
  3152. {
  3153. strcpy(fname, ChargingProfile_0_JSON );
  3154. test_obj = NULL;
  3155. test_obj = json_object_from_file(fname);
  3156. n_friends = 0;
  3157. n_friends = json_object_array_length(test_obj);
  3158. printf("Found %lu friends\n",n_friends);
  3159. for(int i=0;i<n_friends;i++)
  3160. {
  3161. printf("handle GetCompositeScheduleRequest -1\n");
  3162. jsonitem = json_object_array_get_idx(test_obj, i);
  3163. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  3164. printf("handle GetCompositeScheduleRequest -2\n");
  3165. tempconnectorId = json_object_object_get(jsonitem, "connectorId");
  3166. tempcsChargingProfiles = json_object_object_get(jsonitem, "csChargingProfiles");
  3167. tempvalidFrom = json_object_object_get(tempcsChargingProfiles, "validFrom");
  3168. tempChargingSchedule = json_object_object_get(tempcsChargingProfiles, "chargingSchedule");
  3169. printf("handle GetCompositeScheduleRequest -3\n");
  3170. tempstartSchedule = json_object_object_get(tempChargingSchedule, "startSchedule");
  3171. tempminChargingRate = json_object_object_get(tempstartSchedule, "minChargingRate");
  3172. printf("handle GetCompositeScheduleRequest -4n");
  3173. tempminChargingRateFloat = (float)json_object_get_double(tempminChargingRate);
  3174. tempchargingSchedulePeriod = json_object_object_get(tempChargingSchedule, "chargingSchedulePeriod");
  3175. tempstartScheduleStr = (char *)json_object_get_string(tempstartSchedule);
  3176. printf("handle GetCompositeScheduleRequest -5\n");
  3177. tempvalidFromStr = (char *)json_object_get_string(tempvalidFrom);
  3178. double diff_t;
  3179. struct tm tp;
  3180. printf("tempstartScheduleStr 1 : %s\n", tempstartScheduleStr);
  3181. printf("handle GetCompositeScheduleRequest -6\n");
  3182. printf("tempstartScheduleStr 2 : %s\n", tempstartScheduleStr);
  3183. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3184. printf("handle GetCompositeScheduleRequest -6 -1\n");
  3185. tp.tm_isdst = -1;
  3186. printf("handle GetCompositeScheduleRequest -6 -2\n");
  3187. time_t utc = mktime(&tp);
  3188. printf("handle GetCompositeScheduleRequest -7\n");
  3189. struct tm e0 = { .tm_year = tp.tm_year, .tm_mday = tp.tm_mday, .tm_mon = tp.tm_mon, .tm_hour = tp.tm_hour, .tm_isdst = -1 };
  3190. time_t pseudo = mktime(&e0);
  3191. struct tm e1 = *gmtime(&pseudo);
  3192. e0.tm_sec += utc - diff_tm(&e1, &e0);
  3193. time_t local = e0.tm_sec;
  3194. printf("handle GetCompositeScheduleRequest -8\n");
  3195. // ?�到封�??�起始�???- chargingScedule起�??��?
  3196. diff_t = difftime(t, local);
  3197. n_periods = json_object_array_length(tempchargingSchedulePeriod);
  3198. printf("handle GetCompositeScheduleRequest -9\n");
  3199. for(int i=0;i<n_periods;i++)
  3200. {
  3201. struct json_object *tempstartPeriod, *templimit, *tempnumberPhases;
  3202. jsonitem = json_object_array_get_idx(tempchargingSchedulePeriod, i);
  3203. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  3204. tempstartPeriod = json_object_object_get(jsonitem, "startPeriod");
  3205. templimit = json_object_object_get(jsonitem, "limit");
  3206. tempnumberPhases = json_object_object_get(jsonitem, "numberPhases");
  3207. int tempstartPeriodInt = json_object_get_int(tempstartPeriod);
  3208. if(diff_t >= 0)
  3209. {
  3210. diff_t = ((diff_t - tempstartPeriodInt) <=0) ? 0 : (diff_t - tempstartPeriodInt);
  3211. printf("diff_t=%d\n",diff_t);
  3212. }
  3213. float temp = (float)json_object_get_double(templimit);
  3214. if(diff_t == 0)
  3215. {
  3216. //loat temp = (float)json_object_get_double(templimit);
  3217. if(totallimit < temp)
  3218. {
  3219. totallimit = temp;
  3220. printf("totallimit=%d\n",totallimit);
  3221. }
  3222. }
  3223. }
  3224. if(MinChargingRate < tempminChargingRateFloat)
  3225. MinChargingRate = tempminChargingRateFloat;
  3226. }
  3227. printf("handle GetCompositeScheduleRequest -10\n");
  3228. /* Define temporary variables */
  3229. struct tm *gtime;
  3230. time_t now;
  3231. char buf[28];
  3232. /* Read the current system time */
  3233. printf("handle GetCompositeScheduleRequest -11\n");
  3234. time(&now);
  3235. printf("handle GetCompositeScheduleRequest -12\n");
  3236. /* Convert the system time to GMT (now UTC) */
  3237. gtime = gmtime(&now);
  3238. printf("handle GetCompositeScheduleRequest -13\n");
  3239. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  3240. printf("handle GetCompositeScheduleRequest -14\n");
  3241. // make .conf
  3242. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  3243. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* n_periods);
  3244. memset(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* n_periods);
  3245. nPeriod = 1;
  3246. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].Limit = 100.0;//totallimit;
  3247. printf("(1)ChargingSchedulePeriod[0].Limit =%d\n",ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].Limit);
  3248. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].NumberPhases = 3.0;
  3249. printf("(2)NumberPhases =%f\n",ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].NumberPhases);
  3250. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].StartPeriod = 0;
  3251. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = durationInt;
  3252. sleep(10);
  3253. printf("1.totallimit =%d\n",totallimit);
  3254. printf("2. totallimit =%d\n",ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].Limit);
  3255. printf("NumberPhases =%f\n",ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].NumberPhases);
  3256. printf("StartPeriod = %d\n",ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[0].StartPeriod);
  3257. printf("durationInt = %d\n",ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration);
  3258. printf("handle GetCompositeScheduleRequest -14 -1\n");
  3259. if(chargingRateUnitStr != NULL)
  3260. {
  3261. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  3262. }
  3263. else
  3264. {
  3265. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, "" );
  3266. }
  3267. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  3268. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  3269. printf("handle GetCompositeScheduleRequest -15\n");
  3270. }
  3271. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < (CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)) )
  3272. {
  3273. //connectorId is specific Id
  3274. switch(connectorIdInt)
  3275. {
  3276. case 0:
  3277. strcpy(fname, ChargingProfile_0_JSON );
  3278. break;
  3279. case 1:
  3280. strcpy(fname, ChargingProfile_1_JSON );
  3281. break;
  3282. case 2:
  3283. strcpy(fname, ChargingProfile_2_JSON );
  3284. break;
  3285. default:
  3286. strcpy(fname, ChargingProfile_0_JSON );
  3287. break;
  3288. }
  3289. //get json object from file
  3290. test_obj = json_object_from_file(fname);
  3291. n_friends = 0;
  3292. n_friends = json_object_array_length(test_obj);
  3293. printf("Found %lu friends\n",n_friends);
  3294. for(int i=0;i<n_friends;i++)
  3295. {
  3296. printf("GetCompositeScheduleRequest -1\n");
  3297. jsonitem = json_object_array_get_idx(test_obj, i);
  3298. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  3299. tempconnectorId = json_object_object_get(jsonitem, "connectorId");
  3300. tempcsChargingProfiles = json_object_object_get(jsonitem, "csChargingProfiles");
  3301. tempvalidFrom = json_object_object_get(tempcsChargingProfiles, "validFrom");
  3302. tempChargingSchedule = json_object_object_get(tempcsChargingProfiles, "ChargingSchedule");
  3303. tempstartSchedule = json_object_object_get(tempChargingSchedule, "startSchedule");
  3304. tempminChargingRate = json_object_object_get(tempChargingSchedule, "minChargingRate");
  3305. tempminChargingRateFloat = (float)json_object_get_double(tempminChargingRate);
  3306. tempchargingSchedulePeriod = json_object_object_get(tempChargingSchedule, "chargingSchedulePeriod");
  3307. tempstartScheduleStr =(char *) json_object_get_string(tempstartSchedule);
  3308. printf("GetCompositeScheduleRequest -2\n");
  3309. tempvalidFromStr = (char *)json_object_get_string(tempvalidFrom);
  3310. double diff_t;
  3311. struct tm tp;
  3312. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3313. tp.tm_isdst = -1;
  3314. time_t utc = mktime(&tp);
  3315. struct tm e0 = { .tm_year = tp.tm_year, .tm_mday = tp.tm_mday, .tm_mon = tp.tm_mon, .tm_hour = tp.tm_hour, .tm_isdst = -1 };
  3316. time_t pseudo = mktime(&e0);
  3317. struct tm e1 = *gmtime(&pseudo);
  3318. e0.tm_sec += utc - diff_tm(&e1, &e0);
  3319. time_t local = e0.tm_sec;
  3320. // ?�到封�??�起始�???- chargingScedule起�??��?
  3321. diff_t = difftime(t, local);
  3322. n_periods = json_object_array_length(tempchargingSchedulePeriod);
  3323. nPeriod = n_periods;
  3324. printf("GetCompositeScheduleRequest -3\n");
  3325. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* nPeriod);
  3326. for(int i=0;i<n_periods;i++)
  3327. {
  3328. struct json_object *tempstartPeriod, *templimit, *tempnumberPhases;
  3329. printf("GetCompositeScheduleRequest -4\n");
  3330. jsonitem = json_object_array_get_idx(tempchargingSchedulePeriod, i);
  3331. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  3332. tempstartPeriod = json_object_object_get(jsonitem, "startPeriod");
  3333. templimit = json_object_object_get(jsonitem, "limit");
  3334. tempnumberPhases = json_object_object_get(jsonitem, "numberPhases");
  3335. int tempstartPeriodInt = json_object_get_int(tempstartPeriod);
  3336. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[i].Limit = json_object_get_int(templimit);
  3337. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[i].NumberPhases = (float)json_object_get_double(templimit);
  3338. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[i].StartPeriod = json_object_get_int(tempstartPeriod);
  3339. if(diff_t >= 0)
  3340. diff_t = ((diff_t - tempstartPeriodInt) <=0) ? 0 : (diff_t - tempstartPeriodInt);
  3341. if(diff_t < 0)
  3342. {
  3343. float temp = (float)json_object_get_double(templimit);
  3344. if(totallimit < temp)
  3345. {
  3346. totallimit = temp;
  3347. }
  3348. }
  3349. }
  3350. if(MinChargingRate < tempminChargingRateFloat)
  3351. MinChargingRate = tempminChargingRateFloat;
  3352. }
  3353. /* Define temporary variables */
  3354. struct tm *gtime;
  3355. time_t now;
  3356. char buf[28];
  3357. /* Read the current system time */
  3358. time(&now);
  3359. /* Convert the system time to GMT (now UTC) */
  3360. gtime = gmtime(&now);
  3361. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  3362. // make .conf
  3363. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule,buf);
  3364. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration = durationInt;
  3365. if(chargingRateUnitStr != NULL)
  3366. {
  3367. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  3368. }
  3369. else
  3370. {
  3371. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit, "" );
  3372. }
  3373. ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  3374. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  3375. }
  3376. else
  3377. {
  3378. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  3379. }
  3380. json_object_put(obj);
  3381. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, nPeriod);
  3382. return result;
  3383. }
  3384. int handleGetConfigurationRequest(char *uuid, char *payload)
  3385. {
  3386. int result = FAIL;
  3387. struct json_object *obj, *key, *test_obj, *jsonitem;
  3388. int MaxKeySupported = 0;
  3389. obj = json_tokener_parse(payload);
  3390. printf("handle GetConfigurationRequest\n");
  3391. key = json_object_object_get(obj, "key");
  3392. int n_keys = json_object_array_length(key);
  3393. UnknownKeynum = 0;
  3394. memset( (void *)unknownkey, 0, sizeof(int)*10*20 );
  3395. MaxKeySupported = atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3396. if(ShmOCPP16Data->GetConfiguration.Key == NULL)
  3397. {
  3398. ShmOCPP16Data->GetConfiguration.Key = (struct StructConfigurationKeyItems *)malloc(sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  3399. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  3400. printf("memset 0 for GetConfiguration table \n");
  3401. }
  3402. else
  3403. {
  3404. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  3405. }
  3406. if(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey == NULL)
  3407. {
  3408. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = (struct StructConfigurationKey *)malloc(sizeof(struct StructConfigurationKey)*MaxKeySupported);
  3409. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  3410. }
  3411. else
  3412. {
  3413. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  3414. }
  3415. if(n_keys != 0)
  3416. {
  3417. printf("key sent num=%d\n",n_keys);
  3418. for(int i=0;i<n_keys;i++)
  3419. {
  3420. jsonitem = json_object_array_get_idx(key, i);
  3421. getKeyValue((char *)json_object_get_string(jsonitem));
  3422. }
  3423. }
  3424. else
  3425. {
  3426. printf("no key sent, get all configuration\n");
  3427. getKeyValue("");
  3428. }
  3429. processUnkownKey();
  3430. ShmOCPP16Data->MsMsg.bits.GetConfigurationReq = 1;
  3431. sendGetConfigurationConfirmation(uuid);
  3432. ShmOCPP16Data->MsMsg.bits.GetConfigurationConf = 1;
  3433. json_object_put(obj);
  3434. return result;
  3435. }
  3436. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  3437. {
  3438. int result = FAIL;
  3439. void *ret; // 子執行�??��???
  3440. pthread_t t; // �?? pthread 變數
  3441. pthread_create(&t, NULL, GetDiagnosticsProcess, payload); // 建�?子執行�?
  3442. pthread_join(t, &ret);
  3443. // ShmOCPP16Data->MsMsg.bits.GetDiagnosticsReq = 1;
  3444. //sendGetDiagnosticsConfirmation(uuid,fname);
  3445. sendGetDiagnosticsConfirmation(uuid,(char*) ret);
  3446. // ShmOCPP16Data->MsMsg.bits.GetDiagnosticsConf = 1;
  3447. return result;
  3448. }
  3449. void* GetDiagnosticsProcess(void* data)
  3450. {
  3451. struct json_object *obj, *location , *retries, *retryInterval , *startTime , *stopTime;
  3452. int retriesInt=0, retryIntervalInt=0;
  3453. const char *locationstr, *startTimestr, *stopTimestr ;
  3454. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[50];
  3455. int port=0;
  3456. char fname[50]="";//="00000_2019-06-09_160902_CSULog.zip";
  3457. char *str = (char*) data; // ?��?輸入資�?
  3458. int isSuccess = FALSE;
  3459. char ftpbuf[200];
  3460. char temp[100];
  3461. char * pch;
  3462. obj = json_tokener_parse(str);
  3463. printf("handle GetDiagnosticsRequest\n");
  3464. location = json_object_object_get(obj, "location");
  3465. retries = json_object_object_get(obj, "retries");
  3466. retryInterval = json_object_object_get(obj, "retryInterval");
  3467. startTime = json_object_object_get(obj, "startTime");
  3468. stopTime = json_object_object_get(obj, "stopTime");
  3469. locationstr = json_object_get_string(location);
  3470. if(retries != NULL)
  3471. retriesInt = json_object_get_int(retries);
  3472. if(retryInterval != NULL)
  3473. retryIntervalInt = json_object_get_int(retryInterval);
  3474. if(startTime != NULL)
  3475. startTimestr = json_object_get_string(startTime);
  3476. if(stopTime != NULL)
  3477. stopTimestr = json_object_get_string(stopTime);
  3478. printf("handle GetDiagnosticsRequest -1\n");
  3479. memset(protocol, 0, sizeof(protocol));
  3480. memset(user, 0, sizeof(user) );
  3481. memset(password, 0, sizeof(password));
  3482. memset(host, 0, sizeof(host));
  3483. memset(path, 0, sizeof(path));
  3484. memset(ftppath, 0, sizeof(ftppath));
  3485. memset(host1, 0, sizeof(host1));
  3486. memset(path1, 0, sizeof(path1));
  3487. /*location: ftp://user:password@host:port/path*/
  3488. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]%d[^/]/%[a-zA-Z0-9._/-]",
  3489. // protocol, user, password, host, &port, path);
  3490. //zip files in /Storage
  3491. system("exec /root/logPackTools 'log' 6");
  3492. time_t rawtime;
  3493. struct tm * timeinfo;
  3494. //char buffer [128];
  3495. time (&rawtime);
  3496. //printf("%ld\n", rawtime);
  3497. timeinfo = localtime (&rawtime);
  3498. strftime (fname,sizeof(fname),"/mnt/%4Y_%2m.zip",timeinfo);
  3499. if((access(fname,F_OK))!=-1)
  3500. {
  3501. printf("文件 test.c exist.\n");
  3502. }
  3503. else
  3504. {
  3505. printf("test.c not exist!\n");
  3506. goto end;
  3507. }
  3508. pch=strchr(locationstr,'@');
  3509. if(pch==NULL)
  3510. {
  3511. sscanf(locationstr,
  3512. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  3513. protocol, host, &port, path);
  3514. strcpy(user,"anonymous");
  3515. strcpy(password,"");
  3516. }
  3517. else
  3518. {
  3519. printf("pch=%s\n", pch);
  3520. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  3521. protocol, user, password, host, &port, path);
  3522. }
  3523. sscanf(host,"%[^/]%s",host1, path1);
  3524. sprintf(ftppath,"%s", path1);
  3525. printf("protocol =%s\n",protocol);
  3526. printf("user =%s\n",user);
  3527. printf("password =%s\n",password);
  3528. printf("host1 =%s\n",host1);
  3529. printf("port =%d\n",port);
  3530. printf("path1 =%s\n",path1);
  3531. printf("ftppath=%s\n",ftppath);
  3532. int ftppathlen=strlen(ftppath);
  3533. int i=1;
  3534. char filenametemp[50];
  3535. while(i < ftppathlen)
  3536. {
  3537. printf("ftppath[ftppathlen-i]:%c\n",ftppath[ftppathlen-i]);
  3538. int len=ftppathlen-i;
  3539. if(ftppath[len]== 47) // '/' ascll code: 47
  3540. {
  3541. printf("all right\n");
  3542. break;
  3543. }
  3544. printf("test substr\n");
  3545. i=i+1;
  3546. }
  3547. memset(filenametemp, 0, sizeof(filenametemp));
  3548. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  3549. filenametemp[i+1] = 0;
  3550. printf("filenametemp:%s\n", filenametemp);
  3551. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  3552. //httpDownLoadFile(host, ftppath, fname);
  3553. memset(ftpbuf, 0, sizeof(ftpbuf));
  3554. if(port == 0)
  3555. port = 21;
  3556. //isSuccess = httpDownLoadFile(host1, ftppath, filenametemp, "http://evsocket.phihong.com.tw/UploadFiles/SW/C81FBD4A740F69286B276C68B5074373.jar");
  3557. do{
  3558. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fname);
  3559. sleep(retryIntervalInt);
  3560. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  3561. if(!isSuccess)
  3562. {
  3563. //BulldogUtil.sleepMs(interval*1000);
  3564. printf("Update firmware request and download file fail.\n");
  3565. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  3566. }
  3567. else
  3568. {
  3569. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  3570. isUpdateRequest = TRUE;
  3571. }
  3572. end:
  3573. json_object_put(obj);
  3574. pthread_exit((void *) fname); // ?��?子執行�?
  3575. }
  3576. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  3577. {
  3578. int result = FAIL;
  3579. printf("handle GetLocalListVersionRequest\n");
  3580. if(strcmp(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  3581. {
  3582. localversion = -1;
  3583. }
  3584. else
  3585. {
  3586. OCPP_getListVerion();
  3587. }
  3588. //from db.OCPP_getListVerion
  3589. printf("handle GetLocalListVersionRequest -1\n");
  3590. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  3591. printf("handle GetLocalListVersionRequest -2\n");
  3592. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  3593. sendGetLocalListVersionConfirmation(uuid,"");
  3594. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  3595. return result;
  3596. }
  3597. int handleRemoteStartRequest(char *uuid, char *payload)
  3598. {
  3599. int result = FAIL;
  3600. struct json_object *obj, *connectorId, *idTag, *chargingProfile,
  3601. *chargingProfileId, *transactionId, *stackLevel,
  3602. *chargingProfilePurpose, *chargingProfileKind,
  3603. *recurrencyKind, *validFrom, *validTo, *chargingSchedule,
  3604. *duration, *startSchedule, *chargingRateUnit, *chargingSchedulePeriod,
  3605. *minChargingRate,*limit, *startPeriod, *numberPhases;
  3606. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  3607. durationInt=0, startPeriodInt =0, numberPhasesInt=0;
  3608. char *idTagstr, *chargingProfilePurposestr, *chargingProfileKindstr, *recurrencyKindstr,
  3609. *validFromstr, *validTostr, *startSchedulestr, *chargingRateUnitstr, *chargingSchedulePeriodstr;
  3610. float minChargingRateflaot=0.0, limitflaot=0.0;
  3611. char comfirmstr[20];
  3612. if(server_pending == TRUE)
  3613. {
  3614. return 0;
  3615. }
  3616. obj = json_tokener_parse(payload);
  3617. printf("handleRemoteStartRequest\n");
  3618. connectorId = json_object_object_get(obj, "connectorId");
  3619. idTag = json_object_object_get(obj, "idTag");
  3620. chargingProfile = json_object_object_get(obj, "chargingProfile");
  3621. if(connectorId != NULL)
  3622. {
  3623. connectorIdInt = json_object_get_int(connectorId);
  3624. }
  3625. else
  3626. {
  3627. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3628. goto end;
  3629. }
  3630. idTagstr = (char *)json_object_get_string(idTag);
  3631. if(chargingProfile != NULL)
  3632. {
  3633. chargingProfileId = json_object_object_get(chargingProfile, "chargingProfileId");
  3634. transactionId = json_object_object_get(chargingProfile, "transactionId");
  3635. stackLevel = json_object_object_get(chargingProfile, "stackLevel");
  3636. chargingProfilePurpose = json_object_object_get(chargingProfile, "chargingProfilePurpose");
  3637. chargingProfileKind = json_object_object_get(chargingProfile, "chargingProfileKind");
  3638. recurrencyKind = json_object_object_get(chargingProfile, "recurrencyKind");
  3639. validFrom = json_object_object_get(chargingProfile, "validFrom");
  3640. validTo = json_object_object_get(chargingProfile, "validTo");
  3641. chargingSchedule = json_object_object_get(chargingProfile, "chargingSchedule");
  3642. chargingProfileIdInt = json_object_get_int(chargingProfileId);
  3643. if(transactionId != NULL) // OPTION
  3644. transactionIdInt = json_object_get_int(transactionId);
  3645. stackLevelInt = json_object_get_int(stackLevel);
  3646. chargingProfilePurposestr =(char *)json_object_get_string(chargingProfilePurpose);
  3647. chargingProfileKindstr = (char *)json_object_get_string(chargingProfileKind);
  3648. if(recurrencyKind != NULL) //OPTION
  3649. recurrencyKindstr = (char *)json_object_get_string(recurrencyKind);
  3650. if(validFrom != NULL) // OPTION
  3651. validFromstr = (char *)json_object_get_string(validFrom);
  3652. if(validTo != NULL) //OPTION
  3653. validTostr = (char *)json_object_get_string(validTo);
  3654. duration = json_object_object_get(chargingSchedule, "duration");
  3655. startSchedule = json_object_object_get(chargingSchedule, "startSchedule");
  3656. chargingRateUnit = json_object_object_get(chargingSchedule, "chargingRateUnit");
  3657. chargingSchedulePeriod = json_object_object_get(chargingSchedule, "chargingSchedulePeriod");
  3658. minChargingRate = json_object_object_get(chargingSchedule, "minChargingRate");
  3659. if(duration != NULL) //OPTION
  3660. durationInt = json_object_get_int(duration);
  3661. if(startSchedule != NULL) //OPTION
  3662. startSchedulestr = (char *)json_object_get_string(startSchedule);
  3663. chargingRateUnitstr = (char *)json_object_get_string(chargingRateUnit);
  3664. chargingSchedulePeriodstr = (char *)json_object_get_string(chargingSchedulePeriod);
  3665. if(minChargingRate != NULL) //OPTION
  3666. minChargingRateflaot = (float)json_object_get_double(minChargingRate);
  3667. limit = json_object_object_get(chargingSchedulePeriod, "limit");
  3668. startPeriod = json_object_object_get(chargingSchedulePeriod, "startPeriod");
  3669. numberPhases = json_object_object_get(chargingSchedulePeriod, "numberPhases");
  3670. startPeriodInt = json_object_get_int(startPeriod);
  3671. limitflaot = (float)json_object_get_double(limit);
  3672. if(numberPhases != NULL)
  3673. numberPhasesInt = json_object_get_int(numberPhases);
  3674. }
  3675. /*
  3676. enum _SYSTEM_STATUS
  3677. {
  3678. S_BOOTING = 0,
  3679. S_IDLE, = 1
  3680. S_AUTHORIZING, =2
  3681. S_REASSIGN_CHECK, =3
  3682. S_REASSIGN, =4
  3683. S_PRECHARGE, =5
  3684. S_PREPARING_FOR_EV, =6
  3685. S_PREPARING_FOR_EVSE, =7
  3686. S_CHARGING, =8
  3687. S_TERMINATING, =9
  3688. S_COMPLETE, =10
  3689. S_ALARM, =11
  3690. S_FAULT =12
  3691. }
  3692. */
  3693. if((connectorId != NULL)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)))
  3694. {
  3695. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  3696. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  3697. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  3698. //check Transaction active
  3699. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3700. {
  3701. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  3702. {
  3703. if((1/*預約旗標*//*ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '8'*/)&&(strcmp(ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  3704. {
  3705. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[connectorIdInt-1].SystemStatus = 8; //S_CHARGING
  3706. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3707. }
  3708. else
  3709. {
  3710. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 1) //S_IDLE
  3711. {
  3712. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3713. goto end;
  3714. }
  3715. }
  3716. }
  3717. }
  3718. for (int index = 0; index < CCS_QUANTITY; index++)
  3719. {
  3720. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  3721. {
  3722. if((1/*預約旗標*//*ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '8'*/)&&(strcmp(ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  3723. {
  3724. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[connectorIdInt-1].SystemStatus = 8; //S_CHARGING
  3725. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3726. }
  3727. else
  3728. {
  3729. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 1) //S_IDLE
  3730. {
  3731. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3732. goto end;
  3733. }
  3734. }
  3735. }
  3736. }
  3737. for (int index = 0; index < GB_QUANTITY; index++)
  3738. {
  3739. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  3740. {
  3741. if((1/*預約旗標*//*ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '8'*/)&&(strcmp(ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  3742. {
  3743. //ShmSysConfigAndInfo->SysInfo.GbChargingData[connectorIdInt-1].SystemStatus = 8; //S_CHARGING
  3744. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3745. }
  3746. else
  3747. {
  3748. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 1) //S_IDLE
  3749. {
  3750. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3751. goto end;
  3752. }
  3753. }
  3754. }
  3755. }
  3756. if(chargingProfile != NULL)
  3757. {
  3758. //ChargingProfile
  3759. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  3760. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  3761. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  3762. if(recurrencyKind != NULL) //OPTION
  3763. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  3764. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  3765. if(transactionId != NULL) // OPTION
  3766. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  3767. if(validFrom != NULL) // OPTION
  3768. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  3769. if(validTo != NULL) //OPTION
  3770. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  3771. //ChargingSchedule
  3772. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  3773. if(duration != NULL) //OPTION
  3774. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  3775. if(minChargingRate != NULL) //OPTION
  3776. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  3777. if(startSchedule != NULL) //OPTION
  3778. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  3779. //ChargingSchedulePeriod
  3780. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod->Limit = limitflaot ;
  3781. if(numberPhases != NULL)
  3782. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod->NumberPhases = numberPhasesInt;
  3783. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod->StartPeriod = startPeriodInt;
  3784. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3785. {
  3786. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3787. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  3788. }
  3789. else
  3790. {
  3791. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3792. }
  3793. }
  3794. else
  3795. {
  3796. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3797. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  3798. }
  3799. }
  3800. else
  3801. {
  3802. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3803. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  3804. }
  3805. end:
  3806. if(connectorId != NULL)
  3807. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  3808. strcpy(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  3809. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  3810. json_object_put(obj);
  3811. //OCPP send RemoteStartConfirmation by first.
  3812. sendRemoteStartConfirmation(uuid, comfirmstr);
  3813. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionConf = 1;
  3814. return result;
  3815. }
  3816. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  3817. {
  3818. int result = FAIL;
  3819. int match = FALSE;
  3820. int GunNO = 0;
  3821. struct json_object *obj, *transactionId;
  3822. int transactionIdInt=0;
  3823. char comfirmstr[20];
  3824. printf("handleRemoteStopTransactionRequest\n");
  3825. if(server_pending == TRUE)
  3826. {
  3827. return 0;
  3828. }
  3829. obj = json_tokener_parse(payload);
  3830. transactionId = json_object_object_get(obj, "transactionId");
  3831. transactionIdInt = json_object_get_int(transactionId);
  3832. if(transactionId != NULL)
  3833. {
  3834. for(int gun_index=0;gun_index< (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY);gun_index++)
  3835. {
  3836. if(ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId == transactionIdInt)
  3837. {
  3838. //check Transaction active
  3839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3840. {
  3841. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  3842. {
  3843. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8) // S_CHARGING
  3844. {
  3845. match = TRUE;
  3846. GunNO = gun_index;
  3847. }
  3848. }
  3849. }
  3850. for (int index = 0; index < CCS_QUANTITY; index++)
  3851. {
  3852. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  3853. {
  3854. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8) // S_CHARGING
  3855. {
  3856. match = TRUE;
  3857. GunNO = gun_index;
  3858. }
  3859. }
  3860. }
  3861. for (int index = 0; index < GB_QUANTITY; index++)
  3862. {
  3863. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  3864. {
  3865. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8) // S_CHARGING
  3866. {
  3867. match = TRUE;
  3868. GunNO = gun_index;
  3869. }
  3870. }
  3871. }
  3872. }
  3873. }
  3874. if( match == TRUE)
  3875. {
  3876. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  3877. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  3878. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  3879. }
  3880. else
  3881. {
  3882. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  3883. }
  3884. }
  3885. json_object_put(obj);
  3886. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  3887. //ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionConf = 1;
  3888. return result;
  3889. }
  3890. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  3891. {
  3892. int result = FAIL;
  3893. struct json_object *obj, *connectorId, *expiryDate, *idTag, *parentIdTag, *reservationId;
  3894. int connectorIdInt=0, reservationIdInt=0;
  3895. char *expiryDatestr, *idTagstr, *parentIdTagstr;
  3896. char comfirmstr[20];
  3897. obj = json_tokener_parse(payload);
  3898. printf("handleReserveNowRequest\n");
  3899. connectorId = json_object_object_get(obj, "connectorId");
  3900. expiryDate = json_object_object_get(obj, "expiryDate");
  3901. idTag = json_object_object_get(obj, "idTag");
  3902. parentIdTag = json_object_object_get(obj, "parentIdTag");
  3903. reservationId = json_object_object_get(obj, "reservationId");
  3904. connectorIdInt = json_object_get_int(connectorId);
  3905. expiryDatestr = (char *)json_object_get_string(expiryDate);
  3906. idTagstr = (char *)json_object_get_string(idTag);
  3907. if(parentIdTag != NULL) // option flag
  3908. parentIdTagstr = (char *)json_object_get_string(parentIdTag);
  3909. reservationIdInt = json_object_get_int(reservationId);
  3910. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  3911. /*
  3912. enum _SYSTEM_STATUS
  3913. {
  3914. S_BOOTING = 0,
  3915. S_IDLE, = 1
  3916. S_AUTHORIZING, =2
  3917. S_REASSIGN_CHECK, =3
  3918. S_REASSIGN, =4
  3919. S_PRECHARGE, =5
  3920. S_PREPARING_FOR_EV, =6
  3921. S_PREPARING_FOR_EVSE, =7
  3922. S_CHARGING, =8
  3923. S_TERMINATING, =9
  3924. S_COMPLETE, =10
  3925. S_ALARM, =11
  3926. S_FAULT =12
  3927. }
  3928. */
  3929. if((connectorIdInt > 0) && ((connectorIdInt -1) <= (CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)))
  3930. {
  3931. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3932. //check Transaction active
  3933. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3934. {
  3935. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  3936. {
  3937. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  3938. {
  3939. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3940. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != 12) //S_FAULT
  3941. {
  3942. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 1) //S_IDLE
  3943. {
  3944. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  3945. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  3946. }
  3947. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) //S_ALARM //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  3948. {
  3949. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  3950. }
  3951. else
  3952. {
  3953. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  3954. }
  3955. }
  3956. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 12) //S_FAULT
  3957. {
  3958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  3959. }
  3960. }
  3961. else
  3962. {
  3963. //replace reservation
  3964. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  3965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  3966. }
  3967. }
  3968. }
  3969. for (int index = 0; index < CCS_QUANTITY; index++)
  3970. {
  3971. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  3972. {
  3973. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  3974. {
  3975. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3976. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != 12) //S_FAULT
  3977. {
  3978. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 1) //S_IDLE
  3979. {
  3980. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  3981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  3982. }
  3983. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 11) //S_ALARM //else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '9'))
  3984. {
  3985. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  3986. }
  3987. else
  3988. {
  3989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  3990. }
  3991. }
  3992. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==12) //S_FAULT
  3993. {
  3994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  3995. }
  3996. }
  3997. else
  3998. {
  3999. //replace reservation
  4000. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  4001. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  4002. }
  4003. }
  4004. }
  4005. for (int index = 0; index < GB_QUANTITY; index++)
  4006. {
  4007. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  4008. {
  4009. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  4010. {
  4011. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  4012. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != 12) //S_FAULT
  4013. {
  4014. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1) //S_IDLE
  4015. {
  4016. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  4017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  4018. }
  4019. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 11) //S_ALARM //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  4020. {
  4021. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  4022. }
  4023. else
  4024. {
  4025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  4026. }
  4027. }
  4028. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==12) //S_FAULT
  4029. {
  4030. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  4031. }
  4032. }
  4033. else
  4034. {
  4035. //replace reservation
  4036. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  4037. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  4038. }
  4039. }
  4040. }
  4041. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  4042. }
  4043. else
  4044. {
  4045. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  4046. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  4047. }
  4048. if(strcmp(comfirmstr,"Accepted") == 0)
  4049. {
  4050. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  4051. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  4052. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  4053. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  4054. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  4055. strcpy(ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  4056. json_object_put(obj);
  4057. result = TRUE;
  4058. return result;
  4059. }
  4060. json_object_put(obj);
  4061. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  4062. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  4063. return result;
  4064. }
  4065. int handleResetRequest(char *uuid, char *payload)
  4066. {
  4067. int result = FAIL;
  4068. struct json_object *obj, *type;
  4069. char *typestr;
  4070. char comfirmstr[20];
  4071. obj = json_tokener_parse(payload);
  4072. printf("handleResetRequest\n");
  4073. type = json_object_object_get(obj, "type");
  4074. typestr = (char *)json_object_get_string(type);
  4075. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  4076. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  4077. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  4078. {
  4079. //check Transaction active
  4080. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4081. {
  4082. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8)
  4083. {
  4084. //0: unplug, 1: Plug-in
  4085. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  4086. }
  4087. }
  4088. for (int index = 0; index < CCS_QUANTITY; index++)
  4089. {
  4090. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8)
  4091. {
  4092. //0: unplug, 1: Plug-in
  4093. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  4094. }
  4095. }
  4096. for (int index = 0; index < GB_QUANTITY; index++)
  4097. {
  4098. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8)
  4099. {
  4100. //0: unplug, 1: Plug-in
  4101. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  4102. }
  4103. }
  4104. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  4105. strcpy(ShmOCPP16Data->Reset.guid, uuid);
  4106. json_object_put(obj);
  4107. result = TRUE;
  4108. return result;
  4109. // strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  4110. // sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  4111. }
  4112. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  4113. {
  4114. //check Transaction active
  4115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4116. {
  4117. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 8)
  4118. {
  4119. //0: unplug, 1: Plug-in
  4120. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  4121. }
  4122. }
  4123. for (int index = 0; index < CCS_QUANTITY; index++)
  4124. {
  4125. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == 8)
  4126. {
  4127. //0: unplug, 1: Plug-in
  4128. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  4129. }
  4130. }
  4131. for (int index = 0; index < GB_QUANTITY; index++)
  4132. {
  4133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 8)
  4134. {
  4135. //0: unplug, 1: Plug-in
  4136. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  4137. }
  4138. }
  4139. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  4140. strcpy(ShmOCPP16Data->Reset.guid, uuid);
  4141. json_object_put(obj);
  4142. result = TRUE;
  4143. return result;
  4144. // strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  4145. // sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  4146. }
  4147. else
  4148. {
  4149. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  4150. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  4151. goto errorend;
  4152. }
  4153. errorend:
  4154. json_object_put(obj);
  4155. sendResetConfirmation(uuid, comfirmstr);
  4156. //ShmOCPP16Data->MsMsg.bits.ResetConf = 1;
  4157. return result;
  4158. }
  4159. int handleSendLocalListRequest(char *uuid, char *payload)
  4160. {
  4161. int result = FAIL;
  4162. struct json_object *obj, *listVersion , *localAuthorizationList, *updateType, *jsonitem, *idTag, *idTagInfo ,
  4163. *expiryDate, *parentIdTag, *status;
  4164. int listVersionInt;
  4165. char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  4166. char comfirmstr[20];
  4167. int n_localAuthorizations = 0;
  4168. obj = json_tokener_parse(payload);
  4169. printf("handleSendLocalListRequest\n");
  4170. listVersion = json_object_object_get(obj, "listVersion");
  4171. localAuthorizationList = json_object_object_get(obj, "localAuthorizationList");
  4172. updateType = json_object_object_get(obj, "updateType");
  4173. listVersionInt = json_object_get_int(listVersion);
  4174. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  4175. updateTypestr = (char *)json_object_get_string(updateType);
  4176. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  4177. printf("handleSendLocalListRequest -1\n");
  4178. if(localAuthorizationList != NULL)
  4179. n_localAuthorizations = json_object_array_length(localAuthorizationList);
  4180. printf("n_localAuthorizations=%d\n",n_localAuthorizations);
  4181. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  4182. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  4183. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = (struct StructLocalAuthorizationList *)malloc(sizeof(struct StructLocalAuthorizationList)*n_localAuthorizations);
  4184. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 ,sizeof(ShmOCPP16Data->SendLocalList.LocalAuthorizationList));
  4185. //ShmOCPP16Data->MsMsg.bits.SendLocalListReq = 1;
  4186. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  4187. {
  4188. //Local list full update
  4189. printf("Local list full update.\n");
  4190. OCPP_cleanLocalList();
  4191. }
  4192. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  4193. {
  4194. //Local list different update
  4195. printf("Local list different update.\n");
  4196. if(localAuthorizationList == NULL)
  4197. {
  4198. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  4199. goto end;
  4200. }
  4201. OCPP_getListVerion();
  4202. if(listVersionInt <= localversion )
  4203. {
  4204. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  4205. goto end;
  4206. }
  4207. }
  4208. else
  4209. {
  4210. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  4211. goto end;
  4212. }
  4213. for(int i=0;i<n_localAuthorizations;i++)
  4214. {
  4215. printf("handleSendLocalListRequest -2\n");
  4216. jsonitem = json_object_array_get_idx(localAuthorizationList, i);
  4217. printf("handleSendLocalListRequest -2 -0\n");
  4218. idTag = json_object_object_get(jsonitem, "IdToken"/*"idTag"*/);
  4219. printf("handleSendLocalListRequest -2 -0 -0\n");
  4220. idTagInfo = json_object_object_get(jsonitem, "idTagInfo");
  4221. printf("handleSendLocalListRequest -2 -0 -0 -0\n");
  4222. if(idTagInfo != NULL)
  4223. {
  4224. expiryDate = json_object_object_get(idTagInfo, "expiryDate");
  4225. printf("handleSendLocalListRequest -2 -0 -0 -0 -0\n");
  4226. parentIdTag = json_object_object_get(idTagInfo, "parentIdTag");
  4227. printf("handleSendLocalListRequest -2 -0 -0 -0 -0 -0\n");
  4228. status = json_object_object_get(idTagInfo, "status");
  4229. }
  4230. if(idTag != NULL)
  4231. idTagstr = (char *)json_object_get_string(idTag);
  4232. printf("idTagstr=%s\n",idTagstr);
  4233. if(expiryDate != NULL)
  4234. expiryDatestr = (char *)json_object_get_string(expiryDate);
  4235. printf("expiryDatestr=%s\n",expiryDatestr);
  4236. if(parentIdTag != NULL)
  4237. parentIdTagstr = (char *)json_object_get_string(parentIdTag);
  4238. printf("parentIdTagstr=%s\n",parentIdTagstr);
  4239. statusstr = (char *)json_object_get_string(status);
  4240. printf("statusstr=%s\n",statusstr);
  4241. printf("handleSendLocalListRequest -2 -1\n");
  4242. OCPP_getIdTag(idTagstr);
  4243. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  4244. {
  4245. //Local list full update
  4246. printf("Local list full update.\n");
  4247. // update list
  4248. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTagstr, expiryDatestr, statusstr);
  4249. }
  4250. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  4251. {
  4252. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag != NULL))
  4253. {
  4254. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTagstr, expiryDatestr, statusstr);
  4255. }
  4256. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag == NULL))
  4257. {
  4258. OCPP_deleteIdTag(idTagstr);
  4259. }
  4260. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag != NULL))
  4261. {
  4262. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTagstr, expiryDatestr, statusstr);
  4263. }
  4264. }
  4265. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[i].IdTag, idTagstr);
  4266. printf("handleSendLocalListRequest -2 -1 -1\n");
  4267. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[i].IdTagInfo.ExpiryDate, expiryDatestr);
  4268. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[i].IdTagInfo.ParentIdTag, parentIdTagstr);
  4269. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[i].IdTagInfo.Status, statusstr);
  4270. printf("handleSendLocalListRequest -3\n");
  4271. }
  4272. printf("handleSendLocalListRequest -4\n");
  4273. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  4274. end:
  4275. json_object_put(obj);
  4276. sendSendLocalListConfirmation(uuid, comfirmstr);
  4277. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  4278. printf("handleSendLocalListRequest -5\n");
  4279. return result;
  4280. }
  4281. #define MAX 2000
  4282. int handleSetChargingProfileRequest(char *uuid, char *payload)
  4283. {
  4284. int result = FAIL;
  4285. struct json_object *obj, *connectorId, *csChargingProfiles, *chargingProfileId, *stackLevel, *chargingProfilePurpose;
  4286. struct json_object *tempobj, *tempconnectorId, *tempcsChargingProfiles, *tempchargingProfileId, *tempstackLevel, *tempchargingProfilePurpose;
  4287. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  4288. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  4289. const char*chargingProfilePurposeStr;
  4290. char *tempchargingProfilePurposeStr;
  4291. int updateflag = FALSE;
  4292. char comfirmstr[20];
  4293. int meet= FALSE;
  4294. printf("handleSetChargingProfileRequest\n");
  4295. obj = json_tokener_parse(payload);
  4296. connectorId = json_object_object_get(obj, "connectorId");
  4297. csChargingProfiles = json_object_object_get(obj, "csChargingProfiles");
  4298. chargingProfileId = json_object_object_get(csChargingProfiles, "chargingProfileId");
  4299. stackLevel = json_object_object_get(csChargingProfiles, "stackLevel");
  4300. chargingProfilePurpose = json_object_object_get(csChargingProfiles, "chargingProfilePurpose");
  4301. connectorIdInt = json_object_get_int(connectorId);
  4302. chargingProfileIdInt = json_object_get_int(chargingProfileId);
  4303. stackLevelInt = json_object_get_int(stackLevel);
  4304. chargingProfilePurposeStr = json_object_get_string(chargingProfilePurpose);
  4305. #if 1 // get json object from file
  4306. FILE *fptr1, *fptr2;
  4307. int lno, linectr = 0;
  4308. int modifyflag = FALSE;
  4309. char str[MAX],fname[MAX];
  4310. char newln[MAX], temp[] = "temp.json";
  4311. struct json_object *newHeatMap = json_object_new_array();
  4312. printf("\n\n Replace a specific line in a text file with a new text :\n");
  4313. printf("-------------------------------------------------------------\n");
  4314. printf(" Input the file name to be opened : ");
  4315. //fgets(fname, MAX, stdin);
  4316. //fname[strlen(fname) - 1] = '\0';
  4317. switch(connectorIdInt)
  4318. {
  4319. case 0:
  4320. strcpy(fname, ChargingProfile_0_JSON );
  4321. break;
  4322. case 1:
  4323. strcpy(fname, ChargingProfile_1_JSON );
  4324. break;
  4325. case 2:
  4326. strcpy(fname, ChargingProfile_2_JSON );
  4327. break;
  4328. default:
  4329. strcpy(fname, ChargingProfile_0_JSON );
  4330. break;
  4331. }
  4332. fptr1 = fopen(fname, "r");
  4333. if (!fptr1)
  4334. {
  4335. //file not exist
  4336. printf("Unable to open the input file!!\n");
  4337. fptr1 = fopen(fname, "w+");
  4338. }
  4339. fclose(fptr1);
  4340. json_object *test_obj = NULL;
  4341. json_object *tmp_obj = NULL;
  4342. struct array_list *json_list;
  4343. struct json_object *jsonitem;
  4344. size_t n_friends;
  4345. printf("set chargingProfile 1\n");
  4346. //get json object from file
  4347. test_obj = json_object_from_file(fname);
  4348. if(test_obj ==NULL)
  4349. {
  4350. printf("set chargingProfile: test_obj is Null!!!\n");
  4351. //assert(test_obj != NULL);
  4352. }
  4353. tempchargingProfilePurposeStr = NULL;
  4354. printf("set chargingProfile 1-1\n");
  4355. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  4356. {
  4357. printf("set chargingProfile 1-2\n");
  4358. if(connectorIdInt != 0)
  4359. {
  4360. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  4361. goto end;
  4362. }
  4363. }
  4364. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  4365. {
  4366. printf("set chargingProfile 1-3\n");
  4367. if((connectorIdInt != 0) && (connectorIdInt > (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)))
  4368. {
  4369. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  4370. goto end;
  4371. }
  4372. }
  4373. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  4374. {
  4375. printf("set chargingProfile 1-4\n");
  4376. //check Transaction active
  4377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4378. {
  4379. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == connectorIdInt)
  4380. {
  4381. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '4')
  4382. {
  4383. meet = TRUE;
  4384. }
  4385. }
  4386. }
  4387. for (int index = 0; index < CCS_QUANTITY; index++)
  4388. {
  4389. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == connectorIdInt)
  4390. {
  4391. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '4')
  4392. {
  4393. meet = TRUE;
  4394. }
  4395. }
  4396. }
  4397. for (int index = 0; index < GB_QUANTITY; index++)
  4398. {
  4399. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == connectorIdInt)
  4400. {
  4401. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')
  4402. {
  4403. meet = TRUE;
  4404. }
  4405. }
  4406. }
  4407. if(meet == FALSE)
  4408. {
  4409. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  4410. goto end;
  4411. }
  4412. if((connectorIdInt != 0) && (connectorIdInt > (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)))
  4413. {
  4414. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  4415. goto end;
  4416. }
  4417. }
  4418. printf("set chargingProfile 2\n");
  4419. if((test_obj != NULL) &&(json_object_get_type(test_obj) == json_type_array))
  4420. {
  4421. /* Get array of tests */
  4422. json_list = json_object_get_array(test_obj);
  4423. n_friends = json_object_array_length(test_obj);
  4424. printf("Found %lu friends\n",n_friends);
  4425. for(int i=0;i<n_friends;i++)
  4426. {
  4427. jsonitem = json_object_array_get_idx(test_obj, i);
  4428. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  4429. tempconnectorId = json_object_object_get(jsonitem, "connectorId");
  4430. tempcsChargingProfiles = json_object_object_get(jsonitem, "csChargingProfiles");
  4431. tempchargingProfileId = json_object_object_get(tempcsChargingProfiles, "chargingProfileId");
  4432. tempstackLevel = json_object_object_get(tempcsChargingProfiles, "stackLevel");
  4433. tempchargingProfilePurpose = json_object_object_get(tempcsChargingProfiles, "chargingProfilePurpose");
  4434. tempconnectorIdInt = json_object_get_int(tempconnectorId);
  4435. tempchargingProfileIdInt = json_object_get_int(tempchargingProfileId);
  4436. tempstackLevelInt = json_object_get_int(tempstackLevel);
  4437. tempchargingProfilePurposeStr =(char *)json_object_get_string(tempchargingProfilePurpose);
  4438. printf("s t 1\n");
  4439. if((tempconnectorIdInt == connectorIdInt) && ((tempchargingProfileIdInt == chargingProfileIdInt) || (tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4440. {
  4441. //fprintf(fptr2, "%s", str);
  4442. //fprintf(fptr2, "%s", newln);
  4443. //modifyflag = TRUE;
  4444. //tmp_obj = json_object_new_string(payload);
  4445. //json_object_array_add(newHeatMap, tmp_obj);
  4446. printf("s t 2\n");
  4447. json_object_array_add(newHeatMap, obj);
  4448. printf("s t 3\n");
  4449. //updateflag = TRUE;
  4450. printf("update set chargingProfile to file\n");
  4451. }
  4452. else
  4453. {
  4454. // fprintf(fptr2, "%s", newln);
  4455. //fprintf(fptr2, "%s", str);
  4456. json_object_array_add(newHeatMap, jsonitem);
  4457. printf("add set chargingProfile to file\n");
  4458. }
  4459. }
  4460. #if 0
  4461. if(updateflag == FALSE)
  4462. {
  4463. tmp_obj = json_object_new_string(payload);
  4464. json_object_array_add(newHeatMap, tmp_obj);
  4465. updateflag = TRUE;
  4466. }
  4467. #endif
  4468. remove(fname);
  4469. rename(temp, fname);
  4470. json_object_to_file(fname, newHeatMap);
  4471. json_object_put ( newHeatMap );
  4472. result = TRUE;
  4473. #if 0
  4474. if(errno >=1)
  4475. {
  4476. printf("has errno \n");
  4477. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  4478. }
  4479. else
  4480. #endif
  4481. {
  4482. printf("has no error \n");
  4483. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  4484. }
  4485. }
  4486. else
  4487. {
  4488. printf("set chargingProfile 3\n");
  4489. //write the base object to write.json
  4490. json_object_array_add(newHeatMap, obj);
  4491. json_object_to_file(fname, newHeatMap);
  4492. //sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  4493. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  4494. json_object_put ( newHeatMap );
  4495. printf("set chargingProfile 4\n");
  4496. }
  4497. end:
  4498. printf("set chargingProfile 1-5\n");
  4499. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  4500. return result;
  4501. #endif
  4502. #if 0 // file style handleing
  4503. FILE *fptr1, *fptr2;
  4504. int lno, linectr = 0;
  4505. int modifyflag = FALSE;
  4506. char str[MAX],fname[MAX];
  4507. char newln[MAX], temp[] = "./mnt/temp.json";
  4508. printf("\n\n Replace a specific line in a text file with a new text :\n");
  4509. printf("-------------------------------------------------------------\n");
  4510. printf(" Input the file name to be opened : ");
  4511. //fgets(fname, MAX, stdin);
  4512. //fname[strlen(fname) - 1] = '\0';
  4513. switch(connectorIdInt)
  4514. {
  4515. case 0:
  4516. strcpy(fname, ChargingProfile_0_JSON );
  4517. break;
  4518. case 1:
  4519. strcpy(fname, ChargingProfile_1_JSON );
  4520. break;
  4521. case 2:
  4522. strcpy(fname, ChargingProfile_2_JSON );
  4523. break;
  4524. default:
  4525. strcpy(fname, ChargingProfile_0_JSON );
  4526. break;
  4527. }
  4528. fptr1 = fopen(fname, "r");
  4529. if (!fptr1)
  4530. {
  4531. //file not exist
  4532. printf("Unable to open the input file!!\n");
  4533. fptr1 = fopen(fname, "wb");
  4534. fwrite(newln , 1 , sizeof(newln) , fptr1 );
  4535. fclose(fptr1);
  4536. json_object_put(obj);
  4537. json_object_put(tempobj);
  4538. return result;
  4539. }
  4540. fptr2 = fopen(temp, "w");
  4541. if (!fptr2)
  4542. {
  4543. printf("Unable to open a temporary file to write!!\n");
  4544. fclose(fptr1);
  4545. return 0;
  4546. }
  4547. /* get the new line from the user */
  4548. printf(" Input the content of the new line : ");
  4549. //fgets(newln, MAX, stdin);
  4550. memcpy(newln,payload,strlen(payload));
  4551. /* get the line number to delete the specific line */
  4552. printf(" Input the line no you want to replace : ");
  4553. //scanf("%d", &lno);
  4554. //lno++;
  4555. // copy all contents to the temporary file other except specific line
  4556. while (!feof(fptr1))
  4557. {
  4558. strcpy(str, "\0");
  4559. fgets(str, MAX, fptr1);
  4560. if (!feof(fptr1))
  4561. {
  4562. // linectr++;
  4563. // if (linectr != lno)
  4564. tempobj = json_tokener_parse(str);
  4565. tempconnectorId = json_object_object_get(tempobj, "connectorId");
  4566. tempcsChargingProfiles = json_object_object_get(tempobj, "csChargingProfiles");
  4567. tempchargingProfileId = json_object_object_get(tempcsChargingProfiles, "chargingProfileId");
  4568. tempstackLevel = json_object_object_get(tempcsChargingProfiles, "stackLevel");
  4569. tempchargingProfilePurpose = json_object_object_get(tempcsChargingProfiles, "chargingProfilePurpose");
  4570. tempconnectorIdInt = json_object_get_int(connectorId);
  4571. tempchargingProfileIdInt = json_object_get_int(chargingProfileIdInt);
  4572. tempstackLevelInt = json_object_get_int(stackLevel);
  4573. tempchargingProfilePurposeStr = json_object_get_string(chargingProfilePurpose);
  4574. if((tempconnectorId == connectorId) && ((tempchargingProfileIdInt == chargingProfileIdInt) || (tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  4575. {
  4576. //fprintf(fptr2, "%s", str);
  4577. fprintf(fptr2, "%s", newln);
  4578. modifyflag = TRUE;
  4579. }
  4580. else
  4581. {
  4582. // fprintf(fptr2, "%s", newln);
  4583. fprintf(fptr2, "%s", str);
  4584. }
  4585. }
  4586. }
  4587. if(modifyflag == FALSE)
  4588. {
  4589. fwrite(newln , 1 , sizeof(newln) , fptr2 );
  4590. }
  4591. result = TRUE;
  4592. fclose(fptr1);
  4593. fclose(fptr2);
  4594. remove(fname);
  4595. rename(temp, fname);
  4596. printf(" Replacement did successfully..!! \n");
  4597. #endif
  4598. json_object_put(obj);
  4599. json_object_put(tempobj);
  4600. return result;
  4601. }
  4602. int handleTriggerMessageRequest(char *uuid, char *payload)
  4603. {
  4604. int result = FAIL;
  4605. struct json_object *obj, *requestedMessage, *connectorId;
  4606. int connectorIdInt =0;
  4607. char *requestedMessagestr;
  4608. char comfirmstr[20];
  4609. obj = json_tokener_parse(payload);
  4610. printf("handleTriggerMessageRequest\n");
  4611. requestedMessage = json_object_object_get(obj, "requestedMessage");
  4612. connectorId = json_object_object_get(obj, "connectorId");
  4613. requestedMessagestr = (char *)json_object_get_string(requestedMessage);
  4614. if(connectorId != NULL && connectorId > 0)
  4615. {
  4616. connectorIdInt = json_object_get_int(connectorId);
  4617. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  4618. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  4619. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  4620. }
  4621. else if(connectorId != NULL && connectorId <= 0)
  4622. {
  4623. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  4624. goto end;
  4625. }
  4626. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  4627. {
  4628. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  4629. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4630. }
  4631. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  4632. {
  4633. printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  4634. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  4635. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4636. }
  4637. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  4638. {
  4639. sendBootNotificationRequest();
  4640. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4641. }
  4642. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  4643. {
  4644. sendHeartbeatRequest(connectorIdInt);
  4645. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4646. }
  4647. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  4648. {
  4649. if(connectorId != NULL)
  4650. {
  4651. if((connectorIdInt > 0) && ((connectorIdInt -1) < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)))
  4652. {
  4653. sendMeterValuesRequest(connectorIdInt -1);
  4654. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4655. }
  4656. else
  4657. {
  4658. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  4659. }
  4660. }
  4661. else
  4662. {
  4663. for(int idx=0;idx<(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY);idx++)
  4664. sendMeterValuesRequest(idx);
  4665. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4666. }
  4667. }
  4668. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  4669. {
  4670. if(connectorId != NULL)
  4671. {
  4672. if((connectorIdInt > 0) && ((connectorIdInt -1) < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)))
  4673. {
  4674. sendStatusNotificationRequest(connectorIdInt -1);
  4675. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4676. }
  4677. else
  4678. {
  4679. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  4680. }
  4681. }
  4682. else
  4683. {
  4684. for(int idx=0;idx<(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY);idx++)
  4685. sendStatusNotificationRequest(idx);
  4686. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  4687. }
  4688. }
  4689. else
  4690. {
  4691. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  4692. }
  4693. end:
  4694. json_object_put(obj);
  4695. sendTriggerMessageConfirmation(uuid,comfirmstr);
  4696. //if(connectorId != NULL)
  4697. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageConf = 1;
  4698. return result;
  4699. }
  4700. int handleUnlockConnectorRequest(char *uuid, char *payload)
  4701. {
  4702. int result = FAIL;
  4703. struct json_object *obj, *connectorId;
  4704. int connectorIdInt =0;
  4705. char comfirmstr[20];
  4706. obj = json_tokener_parse(payload);
  4707. printf("handleUnlockConnectorRequest\n");
  4708. connectorId = json_object_object_get(obj, "connectorId");
  4709. connectorIdInt = json_object_get_int(connectorId);
  4710. if(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY == 0)
  4711. {
  4712. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  4713. goto end;
  4714. }
  4715. else if((connectorIdInt > CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY) || (connectorIdInt <= 0))
  4716. {
  4717. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  4718. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockFailed] );
  4719. goto end;
  4720. }
  4721. else
  4722. {
  4723. //check Transaction active
  4724. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4725. {
  4726. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == connectorIdInt ) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '4') )
  4727. {
  4728. //stop Transaction
  4729. //ShmOCPP16Data->CpMsg.bits[connectorIdInt-1].StopTransactionReq = 1;
  4730. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  4731. }
  4732. }
  4733. for (int index = 0; index < CCS_QUANTITY; index++)
  4734. {
  4735. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == connectorIdInt ) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '4'))
  4736. {
  4737. //stop Transaction
  4738. //ShmOCPP16Data->CpMsg.bits[connectorIdInt-1].StopTransactionReq = 1;
  4739. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  4740. }
  4741. }
  4742. for (int index = 0; index < GB_QUANTITY; index++)
  4743. {
  4744. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == connectorIdInt ) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4'))
  4745. {
  4746. //stop Transaction
  4747. //ShmOCPP16Data->CpMsg.bits[connectorIdInt-1].StopTransactionReq = 1;
  4748. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  4749. }
  4750. }
  4751. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  4752. strcpy(ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  4753. // sprintf(comfirmstr, "%s", UnlockStatusStr[Unlocked] );
  4754. json_object_put(obj);
  4755. result = TRUE;
  4756. return result;
  4757. }
  4758. end:
  4759. json_object_put(obj);
  4760. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  4761. return result;
  4762. }
  4763. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  4764. {
  4765. int result = FAIL;
  4766. pthread_t t;
  4767. pthread_create(&t, NULL, UpdateFirmwareProcess, payload); // 建�?子執行�?
  4768. pthread_join(t, NULL); // 等�?子執行�??��?完�?
  4769. sendUpdateFirmwareConfirmation(uuid);
  4770. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  4771. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  4772. return result;
  4773. }
  4774. void UpdateFirmwareProcess(void* data)
  4775. {
  4776. struct json_object *obj, *location, *retries, *retrieveDate, *retryInterval;
  4777. int retriesInt =0, retryIntervalInt=0;
  4778. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  4779. int port=0;
  4780. char *locationstr, *retrieveDatestr;
  4781. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  4782. char comfirmstr[20];
  4783. int isSuccess = 0;
  4784. char ftpbuf[200];
  4785. char temp[100];
  4786. char * pch;
  4787. char *str = (char*) data; // ?��?輸入資�?
  4788. obj = json_tokener_parse(str);
  4789. printf("handleUpdateFirmwareRequest\n");
  4790. location = json_object_object_get(obj, "location");
  4791. retries = json_object_object_get(obj, "retries");
  4792. retrieveDate = json_object_object_get(obj, "retrieveDate");
  4793. retryInterval = json_object_object_get(obj, "retrieveDate");
  4794. locationstr = (char *)json_object_get_string(location);
  4795. if(retries != NULL)
  4796. retriesInt = json_object_get_int(retries);
  4797. retrieveDatestr = (char *)json_object_get_string(retrieveDate);
  4798. if(retryInterval != NULL)
  4799. retryIntervalInt = json_object_get_int(retryInterval);
  4800. memset(ftppath, 0, sizeof(ftppath));
  4801. memset(path, 0, sizeof(path));
  4802. if(strncmp(locationstr,"http", 4) == 0)
  4803. {
  4804. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  4805. protocol, host, path);
  4806. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  4807. // protocol, user, password, host, path);
  4808. sprintf(ftppath,"/%s", path);
  4809. printf("protocol =%s\n",protocol);
  4810. printf("host =%s\n",host);
  4811. printf("path =%s\n",path);
  4812. printf("ftppath=%s\n",ftppath);
  4813. int ftppathlen=strlen(ftppath);
  4814. int i=1;
  4815. char filenametemp[50];
  4816. while(i < ftppathlen)
  4817. {
  4818. printf("ftppath[ftppathlen-i]:%c\n",ftppath[ftppathlen-i]);
  4819. int len=ftppathlen-i;
  4820. if(ftppath[len]== 47) // '/' ascll code: 47
  4821. {
  4822. printf("compare all right\n");
  4823. break;
  4824. }
  4825. printf("test substr\n");
  4826. i=i+1;
  4827. }
  4828. memset(filenametemp, 0, sizeof(filenametemp));
  4829. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  4830. filenametemp[i+1] = 0;
  4831. printf("filenametemp:%s\n", filenametemp);
  4832. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  4833. do{
  4834. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  4835. sleep(retryIntervalInt);
  4836. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  4837. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  4838. if(!isSuccess)
  4839. {
  4840. //BulldogUtil.sleepMs(interval*1000);
  4841. printf("Update firmware request and download file fail.\n");
  4842. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  4843. }
  4844. else
  4845. {
  4846. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  4847. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  4848. isUpdateRequest = TRUE;
  4849. }
  4850. }
  4851. else // ftp
  4852. {
  4853. memset(ftpbuf, 0, sizeof(ftpbuf));
  4854. memset(temp, 0, sizeof(temp));
  4855. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  4856. int ftppathlen=strlen(ftpbuf);
  4857. int i=1;
  4858. char filenametemp[50];
  4859. while(i < ftppathlen)
  4860. {
  4861. printf("ftppath[ftppathlen-i]:%c\n",ftpbuf[ftppathlen-i]);
  4862. int len=ftppathlen-i;
  4863. if(ftpbuf[len]== 47) // '/' ascll code: 47
  4864. {
  4865. printf("all right\n");
  4866. break;
  4867. }
  4868. printf("test substr\n");
  4869. i=i+1;
  4870. }
  4871. memset(filenametemp, 0, sizeof(filenametemp));
  4872. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  4873. filenametemp[i+1] = 0;
  4874. printf("filenametemp:%s\n", filenametemp);
  4875. strncpy(temp, ftpbuf, ftppathlen-i+1);
  4876. pch=strchr(temp,'@');
  4877. if(pch==NULL)
  4878. {
  4879. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  4880. protocol, host, &port, path);
  4881. strcpy(user,"anonymous");
  4882. strcpy(password,"");
  4883. }
  4884. else
  4885. {
  4886. printf("pch=%s\n", pch);
  4887. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  4888. protocol, user, password, host, &port, path);
  4889. }
  4890. sscanf(host,"%[^/]%s",host1, path1);
  4891. sprintf(ftppath,"%s", path1);
  4892. printf("protocol =%s\n",protocol);
  4893. printf("user =%s\n",user);
  4894. printf("password =%s\n",password);
  4895. printf("host1 =%s\n",host1);
  4896. printf("port =%d\n",port);
  4897. printf("path1 =%s\n",path1);
  4898. printf("ftppath=%s\n",ftppath);
  4899. //ftpFile(host, user, password, port, ftppath, fname);
  4900. //download firmware pthred
  4901. if(port == 0)
  4902. port = 21;
  4903. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  4904. do{
  4905. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp);
  4906. sleep(retryIntervalInt);
  4907. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  4908. if(!isSuccess)
  4909. {
  4910. //BulldogUtil.sleepMs(interval*1000);
  4911. printf("Update firmware request and download file fail.\n");
  4912. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  4913. }
  4914. else
  4915. {
  4916. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  4917. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  4918. isUpdateRequest = TRUE;
  4919. }
  4920. }
  4921. json_object_put(obj);
  4922. pthread_exit(NULL); // ?��?子執行�?
  4923. }
  4924. //==========================================
  4925. // Handle server response routine
  4926. //==========================================
  4927. void handleAuthorizeResponse(char *payload, int gun_index)
  4928. {
  4929. struct json_object *obj, *message, *context;
  4930. struct json_object *root_obj, *temp_obj, *jsonitem, *expiryDateitem, *parentIdTagitem, *statusitem;
  4931. char* filename = AuthorizationCache_JSON;
  4932. char* buffer = NULL;
  4933. FILE *pFile;
  4934. char temp[400];
  4935. obj = json_tokener_parse(payload);
  4936. printf("handleAuthorizeResponse\n");
  4937. #ifdef SystemLogMessage
  4938. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate") != NULL)
  4939. DEBUG_INFO("expiryDate: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate")));
  4940. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag") != NULL)
  4941. DEBUG_INFO("parentIdTag: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag")));
  4942. DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "status")));
  4943. #endif
  4944. printf("handleAuthorizeResponse -1\n");
  4945. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate") != NULL)
  4946. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, (char *)json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate")));
  4947. printf("handleAuthorizeResponse -1-0\n");
  4948. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag") != NULL)
  4949. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (char *)json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag")));
  4950. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, (char *)json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "status")));
  4951. printf("handleAuthorizeResponse -2\n");
  4952. printf("authen reponce 1\n");
  4953. //Update idTag information to authorization cache if supproted
  4954. if((strcmp(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  4955. {
  4956. printf("authen reponce 2\n");
  4957. if((access(filename,F_OK))!=-1)
  4958. {
  4959. printf("authen reponce 3\n");
  4960. printf("AuthorizationCache exist.\n");
  4961. }
  4962. else
  4963. {
  4964. printf("authen reponce 4\n");
  4965. printf("AuthorizationCache not exist\n");
  4966. FILE *log = fopen(filename, "w+");
  4967. printf("authen reponce 4 -1\n");
  4968. //fprintf( log , "" ); --- remove temporally
  4969. printf("authen reponce 4 -2\n");
  4970. if(log == NULL)
  4971. {
  4972. printf("log is NULL\n");
  4973. goto out;
  4974. }
  4975. else
  4976. {
  4977. fclose(log);
  4978. }
  4979. }
  4980. printf("authen reponce 5\n");
  4981. get_file_contents(filename, &buffer);
  4982. printf("%s",buffer);
  4983. root_obj = json_tokener_parse(buffer);
  4984. if(root_obj == NULL)
  4985. {
  4986. message = json_object_new_array();
  4987. context = json_object_new_object();
  4988. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  4989. {
  4990. json_object_object_add(context, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  4991. }
  4992. else
  4993. {
  4994. json_object_object_add(context, "expiryDate", json_object_new_string(""));
  4995. }
  4996. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  4997. {
  4998. json_object_object_add(context, "parentIdTag",json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  4999. }
  5000. else
  5001. {
  5002. //write Authorize IdTag
  5003. json_object_object_add(context, "parentIdTag",json_object_new_string(ShmOCPP16Data->Authorize.IdTag));
  5004. }
  5005. json_object_object_add(context, "status", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
  5006. json_object_array_add(message, context);
  5007. memset(temp,0,sizeof temp);
  5008. sprintf(temp, "%s", json_object_to_json_string(message));
  5009. pFile = fopen( filename,"w" );
  5010. if( NULL == pFile ){
  5011. printf( "open failure" );
  5012. }else{
  5013. fwrite(temp,1,sizeof(temp),pFile);
  5014. fclose(pFile);
  5015. }
  5016. json_object_put(message); // Delete the json object
  5017. }
  5018. else
  5019. {
  5020. struct json_object *newHeatMap = json_object_new_array();
  5021. int n_items = json_object_array_length(root_obj);
  5022. for(int i=0;i<n_items;i++)
  5023. {
  5024. int responseIdTagInfoAsZero= 0;
  5025. jsonitem = json_object_array_get_idx(root_obj, i);
  5026. printf("%lu. %s\n",i+1,json_object_get_string(jsonitem));
  5027. expiryDateitem = json_object_object_get(jsonitem, "expiryDate");
  5028. parentIdTagitem = json_object_object_get(jsonitem, "parentIdTag");
  5029. statusitem = json_object_object_get(jsonitem, "status");
  5030. printf("parentIdTagitem=%s\n",json_object_get_string(parentIdTagitem));
  5031. //printf message
  5032. if((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0)
  5033. {
  5034. printf("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  5035. responseIdTagInfoAsZero = 1;
  5036. }
  5037. else
  5038. {
  5039. printf("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  5040. }
  5041. if((responseIdTagInfoAsZero == 0)&&(strcmp(json_object_get_string(parentIdTagitem), ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0))
  5042. {
  5043. //modify item
  5044. temp_obj = json_object_new_object();
  5045. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  5046. {
  5047. json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  5048. }
  5049. else
  5050. {
  5051. json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  5052. }
  5053. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  5054. {
  5055. json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  5056. }
  5057. else
  5058. {
  5059. json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  5060. }
  5061. json_object_object_add(temp_obj, "status", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status));
  5062. json_object_array_add(newHeatMap, temp_obj);
  5063. }
  5064. else
  5065. {
  5066. //wrie original item
  5067. json_object_array_add(newHeatMap, jsonitem);
  5068. printf("authen reponce 5-1\n");
  5069. }
  5070. }
  5071. //(1)write to temp file (2)remove original file (3) rename filename of temp file
  5072. char temp[] = "temp.json";
  5073. FILE *fp;
  5074. fp=fopen(temp,"w");
  5075. fclose(fp);
  5076. remove(filename);
  5077. rename(temp, filename);
  5078. json_object_to_file(filename, newHeatMap);
  5079. printf("authen reponce 5-2\n");
  5080. json_object_put(newHeatMap); // Delete the json object
  5081. printf("authen reponce 5-3\n");
  5082. }
  5083. printf("authen reponce 5-4\n");
  5084. free(buffer);
  5085. printf("authen reponce 5-5\n");
  5086. // json_object_put(root_obj); // Delete the json object
  5087. printf("authen reponce 5-6\n");
  5088. }
  5089. out:
  5090. json_object_put(obj);
  5091. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5092. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  5093. authorizeRetryTimes = 0;
  5094. //for test
  5095. #if 0
  5096. ShmOCPP16Data->CpMsg.bits[0].StartTransactionReq = 1;
  5097. ShmOCPP16Data->CpMsg.bits[0].StartTransactionConf = 1;
  5098. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus ='3'; //preparing
  5099. teststatus = 0; //for startTransaction
  5100. #endif
  5101. }
  5102. void handleBootNotificationResponse(char *payload, int gun_index)
  5103. {
  5104. struct json_object *obj;
  5105. char *status;
  5106. obj = json_tokener_parse(payload);
  5107. printf("handleBootNotificationResponse\n");
  5108. #ifdef SystemLogMessage
  5109. DEBUG_INFO("currentTime: %s\n", json_object_get_string(json_object_object_get(obj, "currentTime")));
  5110. DEBUG_INFO("interval: %d\n", json_object_get_int(json_object_object_get(obj, "interval")));
  5111. DEBUG_INFO("status: %s\n", json_object_get_string(json_object_object_get(obj, "status")));
  5112. #endif
  5113. //write back to ShmOCPP16Data->BootNotification
  5114. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime,(char *)json_object_get_string(json_object_object_get(obj, "currentTime")));
  5115. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = json_object_get_int(json_object_object_get(obj, "interval"));
  5116. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, (char *)json_object_get_string(json_object_object_get(obj, "status")));
  5117. status = json_object_get_string(json_object_object_get(obj, "status"));
  5118. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  5119. HeartBeatWaitTime = BootNotificationInterval;
  5120. printf("test 1\n");
  5121. if((strcmp(status, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  5122. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  5123. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  5124. {
  5125. server_sign = TRUE;
  5126. server_pending =FALSE;
  5127. }
  5128. else if(strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  5129. {
  5130. server_pending = TRUE;
  5131. }
  5132. double diff_t;
  5133. struct tm tp;
  5134. char buf[28];
  5135. char timebuf[50];
  5136. strptime(ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  5137. tp.tm_isdst = -1;
  5138. time_t utc = mktime(&tp);
  5139. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  5140. memset(timebuf, 0, sizeof timebuf);
  5141. sprintf(timebuf,"date -s '%s'",buf);
  5142. printf("timebuf=%s\n",timebuf);
  5143. system(timebuf);
  5144. //==============================================
  5145. // RTC sync
  5146. //==============================================
  5147. system("/sbin/hwclock -w --systohc");
  5148. printf("test 2\n");
  5149. json_object_put(obj); // Delete the json object
  5150. printf("test 3\n");
  5151. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  5152. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  5153. }
  5154. void handleDataTransferResponse(char *payload, int gun_index)
  5155. {
  5156. struct json_object *obj;
  5157. obj = json_tokener_parse(payload);
  5158. #ifdef SystemLogMessage
  5159. DEBUG_INFO("data: %s\n", json_object_get_string(json_object_object_get(obj, "data")));
  5160. #endif
  5161. }
  5162. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  5163. {
  5164. struct json_object *obj;
  5165. obj = json_tokener_parse(payload);
  5166. // ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  5167. // ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  5168. //No fields are defined.
  5169. }
  5170. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  5171. {
  5172. struct json_object *obj;
  5173. obj = json_tokener_parse(payload);
  5174. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  5175. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  5176. //No fields are defined.
  5177. }
  5178. void handleHeartbeatResponse(char *payload, int gun_index)
  5179. {
  5180. struct json_object *obj;
  5181. obj = json_tokener_parse(payload);
  5182. printf("handleHeartbeatResponse\n");
  5183. #ifdef SystemLogMessage
  5184. DEBUG_INFO("currentTime: %s\n", json_object_get_string(json_object_object_get(obj, "currentTime")));
  5185. #endif
  5186. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,(char *)json_object_get_string(json_object_object_get(obj, "currentTime")));
  5187. double diff_t;
  5188. struct tm tp;
  5189. char buf[28];
  5190. char timebuf[50];
  5191. strptime(ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  5192. tp.tm_isdst = -1;
  5193. time_t utc = mktime(&tp);
  5194. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  5195. memset(timebuf, 0, sizeof timebuf);
  5196. sprintf(timebuf,"date -s '%s'",buf);
  5197. printf("timebuf=%s\n",timebuf);
  5198. system(timebuf);
  5199. //==============================================
  5200. // RTC sync
  5201. //==============================================
  5202. system("/sbin/hwclock -w --systohc");
  5203. json_object_put(obj); // Delete the json object
  5204. }
  5205. void handleMeterValuesResponse(char *payload, int gun_index)
  5206. {
  5207. struct json_object *obj;
  5208. obj = json_tokener_parse(payload);
  5209. //No fields are defined.
  5210. }
  5211. void handleStartTransactionResponse(char *payload, int gun_index)
  5212. {
  5213. struct json_object *obj;
  5214. obj = json_tokener_parse(payload);
  5215. // gun_index = gun_index-1;
  5216. #ifdef SystemLogMessage
  5217. DEBUG_INFO("idTagInfo-expiryDate: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate")));
  5218. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag")));
  5219. DEBUG_INFO("idTagInfo-status: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "status")));
  5220. DEBUG_INFO("transactionId: %d\n", json_object_get_int(json_object_object_get(obj, "transactionId")));
  5221. #endif
  5222. printf("handleStartTransactionResponse\n");
  5223. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate") != NULL) // expiryDate is option
  5224. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate")));
  5225. printf("handleStartTransactionResponse 01\n");
  5226. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag") != NULL) // parentIdTag is option
  5227. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag")));
  5228. printf("handleStartTransactionResponse 02\n");
  5229. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "status")));
  5230. //ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(obj, "transactionId"));
  5231. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(obj, "transactionId"));
  5232. printf("handleStartTransactionResponse 03\n");
  5233. int transactionIdInt = json_object_get_int(json_object_object_get(obj, "transactionId"));
  5234. printf("handleStartTransactionResponse 1\n");
  5235. printf("handleStartTransactionResponse 2\n");
  5236. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  5237. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  5238. //for test
  5239. #if 0
  5240. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5241. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  5242. #endif
  5243. if(strcmp(ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  5244. {
  5245. #if 0
  5246. //check Transaction active
  5247. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5248. {
  5249. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  5250. {
  5251. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus = '4';
  5252. }
  5253. }
  5254. for (int index = 0; index < CCS_QUANTITY; index++)
  5255. {
  5256. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  5257. {
  5258. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus = '4';
  5259. }
  5260. }
  5261. for (int index = 0; index < GB_QUANTITY; index++)
  5262. {
  5263. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  5264. {
  5265. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus = '4';
  5266. }
  5267. }
  5268. #endif
  5269. //add Charging Record
  5270. SettingChargingRecord(gun_index, transactionIdInt);
  5271. }
  5272. }
  5273. void handleStatusNotificationResponse(char *payload, int gun_index)
  5274. {
  5275. struct json_object *obj;
  5276. obj = json_tokener_parse(payload);
  5277. printf("handleStatusNotificationResponse\n");
  5278. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5279. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  5280. //for test
  5281. #if 0
  5282. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[gun_index].SystemStatus =='1') // Idle
  5283. {
  5284. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[gun_index].SystemStatus ='3'; //preparing
  5285. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5286. }
  5287. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[gun_index].SystemStatus =='3')//preparing
  5288. {
  5289. printf("preparing UserPlugGun=%d\n",UserPlugGun);
  5290. if(UserPlugGun == 1)
  5291. {
  5292. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[gun_index].SystemStatus ='1';
  5293. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5294. UserPlugGun = 0;
  5295. }
  5296. else
  5297. {
  5298. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 1;
  5299. }
  5300. }
  5301. #endif
  5302. //No fields are defined.
  5303. }
  5304. void handleStopTransactionnResponse(char *payload, int gun_index)
  5305. {
  5306. struct json_object *obj;
  5307. obj = json_tokener_parse(payload);
  5308. printf("handleStopTransactionnResponse\n");
  5309. // gun_index = gun_index - 1;
  5310. if(json_object_object_get(obj, "idTagInfo") != NULL) // option
  5311. {
  5312. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate") != NULL) // option
  5313. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate")));
  5314. if(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag") != NULL) // option
  5315. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag")));
  5316. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "status")));
  5317. #ifdef SystemLogMessage
  5318. DEBUG_INFO("idTagInfo-expiryDate: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "expiryDate")));
  5319. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "parentIdTag")));
  5320. DEBUG_INFO("idTagInfo-status: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(obj, "idTagInfo"), "status")));
  5321. #endif
  5322. }
  5323. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  5324. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5325. json_object_put(obj); // Delete the json object
  5326. //for test
  5327. //UserPlugGun = 0;
  5328. #if 0
  5329. if(strcmp(ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  5330. {
  5331. //check Transaction active
  5332. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5333. {
  5334. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  5335. {
  5336. ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus = '3'; //3: preparing
  5337. }
  5338. }
  5339. for (int index = 0; index < CCS_QUANTITY; index++)
  5340. {
  5341. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  5342. {
  5343. ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus = '3'; //3: preparing
  5344. }
  5345. }
  5346. for (int index = 0; index < GB_QUANTITY; index++)
  5347. {
  5348. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  5349. {
  5350. ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus = '3'; //3: preparing
  5351. }
  5352. }
  5353. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  5354. //ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 1;
  5355. }
  5356. #endif
  5357. }
  5358. //==========================================
  5359. // Handle Error routine
  5360. //==========================================
  5361. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  5362. {
  5363. printf("handleError 1\n");
  5364. struct json_object *obj;
  5365. obj = json_tokener_parse(payload);
  5366. printf("handleError 2\n");
  5367. #ifdef SystemLogMessage
  5368. DEBUG_INFO("errorCode: %s\n", errorCode);
  5369. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  5370. if(obj != NULL)
  5371. DEBUG_INFO("errorDetails: %s\n", payload);
  5372. #endif
  5373. }
  5374. //===============================================
  5375. // Common routine
  5376. //===============================================
  5377. int initialConfigurationTable(void)
  5378. {
  5379. printf("initialConfigurationTable \n");
  5380. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  5381. /*Core Profile*/
  5382. //AllowOfflineTxForUnknownId
  5383. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  5384. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  5385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  5386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  5387. printf("initialConfigurationTable -1 \n");
  5388. //AuthorizationCacheEnabled
  5389. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  5390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  5391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  5392. //AuthorizeRemoteTxRequests
  5393. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  5394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  5395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  5396. //BlinkRepeat
  5397. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  5398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  5399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  5400. //ClockAlignedDataInterval
  5401. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  5402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  5403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  5404. //ConnectionTimeOut
  5405. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  5406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  5407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "60" );
  5408. //GetConfigurationMaxKeys
  5409. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  5410. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  5411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  5412. // HeartbeatInterval
  5413. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  5414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  5415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  5416. // LightIntensity
  5417. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  5418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  5419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  5420. // LocalAuthorizeOffline
  5421. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  5422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  5423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  5424. // LocalPreAuthorize
  5425. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  5426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  5427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  5428. // MaxEnergyOnInvalidId
  5429. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  5430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  5431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  5432. // MeterValuesAlignedData
  5433. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  5434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  5435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "V,A,KW,KWh" );
  5436. // MeterValuesAlignedDataMaxLength
  5437. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  5438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  5439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "4" );
  5440. // MeterValuesSampledData
  5441. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  5442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  5443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "V,A,KW,KWh" );
  5444. // MeterValuesSampledDataMaxLength
  5445. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  5446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  5447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "4" );
  5448. // MeterValueSampleInterval
  5449. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  5450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  5451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  5452. // MinimumStatusDuration
  5453. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  5454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  5455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  5456. // NumberOfConnectors
  5457. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  5458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  5459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "3" );
  5460. // ResetRetries
  5461. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  5462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  5463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  5464. // ConnectorPhaseRotation
  5465. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  5466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  5467. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "Unknown" );
  5468. // ConnectorPhaseRotationMaxLength
  5469. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  5470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  5471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  5472. // StopTransactionOnEVSideDisconnect
  5473. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  5474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  5475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  5476. // StopTransactionOnInvalidId
  5477. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  5478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  5479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  5480. // StopTxnAlignedData
  5481. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  5482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  5483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  5484. // StopTxnAlignedDataMaxLength
  5485. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  5486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  5487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  5488. // StopTxnSampledData
  5489. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  5490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  5491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  5492. // StopTxnSampledDataMaxLength
  5493. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  5494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  5495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  5496. // SupportedFeatureProfiles
  5497. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  5498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  5499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  5500. // SupportedFeatureProfilesMaxLength
  5501. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  5502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  5503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  5504. // TransactionMessageAttempts
  5505. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  5506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  5507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  5508. // TransactionMessageRetryInterval
  5509. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  5510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  5511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  5512. // UnlockConnectorOnEVSideDisconnect
  5513. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  5514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  5515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  5516. // WebSocketPingInterval
  5517. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  5518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  5519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  5520. /* Local Auth List Management Profile*/
  5521. //LocalAuthListEnabled
  5522. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  5523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  5524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  5525. //LocalAuthListMaxLength
  5526. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  5527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  5528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  5529. //SendLocalListMaxLength
  5530. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  5531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  5532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  5533. //ReserveConnectorZeroSupported
  5534. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  5535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  5536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  5537. /* Smart Charging Profile */
  5538. //ChargeProfileMaxStackLevel
  5539. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  5540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  5541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  5542. // ChargingScheduleAllowedChargingRateUnit
  5543. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  5544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  5545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  5546. // ChargingScheduleMaxPeriods
  5547. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  5548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  5549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  5550. // ConnectorSwitch3to1PhaseSupported
  5551. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  5552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  5553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  5554. // MaxChargingProfilesInstalled
  5555. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  5556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  5557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  5558. #if 0
  5559. //write Configuration to flash
  5560. unsigned int i,Chk;
  5561. unsigned char *ptr;
  5562. int fd,wrd;
  5563. // Save factory default setting value to flash backup setting block
  5564. fd = open("/Storage/OCPP/OCPPConfiguration.txt", O_RDWR);
  5565. if (fd < 0)
  5566. {
  5567. #ifdef SystemLogMessage
  5568. DEBUG_ERROR("open /Storage/OCPP/OCPPConfiguration.txt NG");
  5569. #endif
  5570. free(ptr);
  5571. return 0;
  5572. }
  5573. wrd=write(fd, &ShmOCPP16Data->ConfigurationTable, sizeof(struct OCPP16ConfigurationTable));
  5574. close(fd);
  5575. if(wrd!=(sizeof(struct SysConfigData)))
  5576. {
  5577. #ifdef SystemLogMessage
  5578. DEBUG_ERROR("write /Storage/OCPP/OCPPConfiguration.txt NG");
  5579. #endif
  5580. free(ptr);
  5581. return 0;
  5582. }
  5583. #endif
  5584. return 0;
  5585. }
  5586. void getKeyValue(char *keyReq)
  5587. {
  5588. int isEmpty = FALSE;
  5589. int isKnowKey = FALSE;
  5590. int unKnowIndex = 0;
  5591. printf("enter getKeyValue \n");
  5592. printf("keyReq= %s\n", keyReq);
  5593. if((keyReq == NULL) || (strlen(keyReq) == 0))
  5594. isEmpty = TRUE;
  5595. printf("getkey_1\n");
  5596. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  5597. {
  5598. printf("getkey_1_0_0\n");
  5599. //debug.logout("Request key: " + (isEmpty?"AllowOfflineTxForUnknownId":keyReq[iReq]));
  5600. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  5601. printf("getkey_1_0\n");
  5602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  5603. printf("getkey_1_1\n");
  5604. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  5605. {
  5606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "FALSE");
  5607. }
  5608. else
  5609. {
  5610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "TRUE");
  5611. }
  5612. printf("getkey_1_2\n");
  5613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  5614. isKnowKey = TRUE;
  5615. }
  5616. printf("getkey_2\n");
  5617. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  5618. {
  5619. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  5620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  5621. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  5622. {
  5623. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "FALSE");
  5624. }
  5625. else
  5626. {
  5627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "TRUE");
  5628. }
  5629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  5630. isKnowKey = TRUE;
  5631. printf("AuthorizationCacheEnabled\n");
  5632. }
  5633. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  5634. {
  5635. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  5636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  5637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  5638. {
  5639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "FALSE");
  5640. }
  5641. else
  5642. {
  5643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "TRUE"/*"False"*/);
  5644. }
  5645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  5646. isKnowKey = TRUE;
  5647. printf("AuthorizeRemoteTxRequests\n");
  5648. }
  5649. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  5650. {
  5651. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  5652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  5653. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  5654. {
  5655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "FALSE");
  5656. }
  5657. else
  5658. {
  5659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "TRUE");
  5660. }
  5661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  5662. isKnowKey = TRUE;
  5663. printf("BlinkRepeat\n");
  5664. }
  5665. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  5666. {
  5667. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  5668. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  5669. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  5670. {
  5671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "FALSE");
  5672. }
  5673. else
  5674. {
  5675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "TRUE");
  5676. }
  5677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  5678. isKnowKey = TRUE;
  5679. printf("ClockAlignedDataInterval\n");
  5680. }
  5681. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  5682. {
  5683. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  5684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  5685. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  5686. {
  5687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "FALSE");
  5688. }
  5689. else
  5690. {
  5691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "TRUE");
  5692. }
  5693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  5694. isKnowKey = TRUE;
  5695. printf("ConnectionTimeOut\n");
  5696. }
  5697. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  5698. {
  5699. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  5700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  5701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  5702. {
  5703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "FALSE");
  5704. }
  5705. else
  5706. {
  5707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "TRUE");
  5708. }
  5709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  5710. isKnowKey = TRUE;
  5711. printf("GetConfigurationMaxKeys\n");
  5712. }
  5713. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  5714. {
  5715. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  5716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  5717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  5718. {
  5719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "FALSE");
  5720. }
  5721. else
  5722. {
  5723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "TRUE");
  5724. }
  5725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  5726. isKnowKey = TRUE;
  5727. printf("HeartbeatInterval\n");
  5728. }
  5729. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  5730. {
  5731. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  5732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  5733. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  5734. {
  5735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "FALSE");
  5736. }
  5737. else
  5738. {
  5739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "TRUE");
  5740. }
  5741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  5742. isKnowKey = TRUE;
  5743. printf("LightIntensity\n");
  5744. }
  5745. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  5746. {
  5747. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  5748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  5749. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  5750. {
  5751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "FALSE");
  5752. }
  5753. else
  5754. {
  5755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "TRUE");
  5756. }
  5757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  5758. isKnowKey = TRUE;
  5759. printf("LocalAuthorizeOffline\n");
  5760. }
  5761. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  5762. {
  5763. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  5764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  5765. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  5766. {
  5767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "FALSE");
  5768. }
  5769. else
  5770. {
  5771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "TRUE");
  5772. }
  5773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  5774. isKnowKey = TRUE;
  5775. printf("LocalPreAuthorize\n");
  5776. }
  5777. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  5778. {
  5779. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  5780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  5781. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  5782. {
  5783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "FALSE");
  5784. }
  5785. else
  5786. {
  5787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "TRUE");
  5788. }
  5789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  5790. isKnowKey = TRUE;
  5791. printf("MaxEnergyOnInvalidId\n");
  5792. }
  5793. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  5794. {
  5795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  5796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  5797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  5798. {
  5799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "FALSE");
  5800. }
  5801. else
  5802. {
  5803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "TRUE");
  5804. }
  5805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  5806. isKnowKey = TRUE;
  5807. printf("MeterValuesAlignedData\n");
  5808. }
  5809. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  5810. {
  5811. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  5812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  5813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  5814. {
  5815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "FALSE");
  5816. }
  5817. else
  5818. {
  5819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "TRUE");
  5820. }
  5821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  5822. isKnowKey = TRUE;
  5823. printf("MeterValuesAlignedDataMaxLength\n");
  5824. }
  5825. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  5826. {
  5827. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  5828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  5829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  5830. {
  5831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "FALSE");
  5832. }
  5833. else
  5834. {
  5835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "TRUE");
  5836. }
  5837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  5838. isKnowKey = TRUE;
  5839. printf("MeterValuesSampledData\n");
  5840. }
  5841. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  5842. {
  5843. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  5844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  5845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  5846. {
  5847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "FALSE");
  5848. }
  5849. else
  5850. {
  5851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "TRUE");
  5852. }
  5853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  5854. isKnowKey = TRUE;
  5855. printf("MeterValuesSampledDataMaxLength\n");
  5856. }
  5857. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  5858. {
  5859. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  5860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  5861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  5862. {
  5863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "FALSE");
  5864. }
  5865. else
  5866. {
  5867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "TRUE");
  5868. }
  5869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  5870. isKnowKey = TRUE;
  5871. printf("MeterValueSampleInterval\n");
  5872. }
  5873. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  5874. {
  5875. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  5876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  5877. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  5878. {
  5879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "FALSE");
  5880. }
  5881. else
  5882. {
  5883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "TRUE");
  5884. }
  5885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  5886. isKnowKey = TRUE;
  5887. printf("MinimumStatusDuration\n");
  5888. }
  5889. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  5890. {
  5891. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  5892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  5893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  5894. {
  5895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "FALSE");
  5896. }
  5897. else
  5898. {
  5899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "TRUE");
  5900. }
  5901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  5902. isKnowKey = TRUE;
  5903. printf("NumberOfConnectors\n");
  5904. }
  5905. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  5906. {
  5907. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  5908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  5909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  5910. {
  5911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "FALSE");
  5912. }
  5913. else
  5914. {
  5915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "TRUE");
  5916. }
  5917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  5918. isKnowKey = TRUE;
  5919. printf("ResetRetries\n");
  5920. }
  5921. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  5922. {
  5923. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  5924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  5925. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  5926. {
  5927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "FALSE");
  5928. }
  5929. else
  5930. {
  5931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "TRUE");
  5932. }
  5933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  5934. isKnowKey = TRUE;
  5935. printf("ConnectorPhaseRotation\n");
  5936. }
  5937. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  5938. {
  5939. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  5940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  5941. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  5942. {
  5943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "FALSE");
  5944. }
  5945. else
  5946. {
  5947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "TRUE");
  5948. }
  5949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  5950. isKnowKey = TRUE;
  5951. printf("ConnectorPhaseRotationMaxLength\n");
  5952. }
  5953. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  5954. {
  5955. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  5956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  5957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  5958. {
  5959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "FALSE");
  5960. }
  5961. else
  5962. {
  5963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "TRUE");
  5964. }
  5965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  5966. isKnowKey = TRUE;
  5967. printf("StopTransactionOnEVSideDisconnect\n");
  5968. }
  5969. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  5970. {
  5971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  5972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  5973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  5974. {
  5975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "FALSE");
  5976. }
  5977. else
  5978. {
  5979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "TRUE");
  5980. }
  5981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  5982. isKnowKey = TRUE;
  5983. printf("StopTransactionOnInvalidId\n");
  5984. }
  5985. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  5986. {
  5987. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  5988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  5989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  5990. {
  5991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "FALSE");
  5992. }
  5993. else
  5994. {
  5995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "TRUE");
  5996. }
  5997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  5998. isKnowKey = TRUE;
  5999. printf("StopTxnAlignedData\n");
  6000. }
  6001. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  6002. {
  6003. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  6004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  6005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  6006. {
  6007. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "FALSE");
  6008. }
  6009. else
  6010. {
  6011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "TRUE");
  6012. }
  6013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  6014. isKnowKey = TRUE;
  6015. printf("StopTxnAlignedDataMaxLength\n");
  6016. }
  6017. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  6018. {
  6019. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  6020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  6021. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  6022. {
  6023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "FALSE");
  6024. }
  6025. else
  6026. {
  6027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "TRUE");
  6028. }
  6029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  6030. isKnowKey = TRUE;
  6031. printf("StopTxnSampledData\n");
  6032. }
  6033. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  6034. {
  6035. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  6036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  6037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  6038. {
  6039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "FALSE");
  6040. }
  6041. else
  6042. {
  6043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "TRUE");
  6044. }
  6045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  6046. isKnowKey = TRUE;
  6047. printf("StopTxnSampledDataMaxLength\n");
  6048. }
  6049. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  6050. {
  6051. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  6052. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  6053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  6054. {
  6055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "FALSE");
  6056. }
  6057. else
  6058. {
  6059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "TRUE");
  6060. }
  6061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  6062. isKnowKey = TRUE;
  6063. printf("SupportedFeatureProfiles\n");
  6064. }
  6065. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  6066. {
  6067. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  6068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  6069. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  6070. {
  6071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "FALSE");
  6072. }
  6073. else
  6074. {
  6075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "TRUE");
  6076. }
  6077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  6078. isKnowKey = TRUE;
  6079. printf("SupportedFeatureProfilesMaxLength\n");
  6080. }
  6081. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  6082. {
  6083. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  6084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  6085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  6086. {
  6087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "FALSE");
  6088. }
  6089. else
  6090. {
  6091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "TRUE");
  6092. }
  6093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  6094. isKnowKey = TRUE;
  6095. printf("TransactionMessageAttempts\n");
  6096. }
  6097. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  6098. {
  6099. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  6100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  6101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  6102. {
  6103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "FALSE");
  6104. }
  6105. else
  6106. {
  6107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "TRUE");
  6108. }
  6109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  6110. isKnowKey = TRUE;
  6111. printf("TransactionMessageRetryInterval\n");
  6112. }
  6113. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  6114. {
  6115. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  6116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  6117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  6118. {
  6119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "FALSE");
  6120. }
  6121. else
  6122. {
  6123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "TRUE");
  6124. }
  6125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  6126. isKnowKey = TRUE;
  6127. printf("UnlockConnectorOnEVSideDisconnect\n");
  6128. }
  6129. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  6130. {
  6131. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  6132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  6133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  6134. {
  6135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "FALSE");
  6136. }
  6137. else
  6138. {
  6139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "TRUE");
  6140. }
  6141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  6142. isKnowKey = TRUE;
  6143. printf("WebSocketPingInterval\n");
  6144. }
  6145. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  6146. {
  6147. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  6148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  6149. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  6150. {
  6151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "FALSE");
  6152. }
  6153. else
  6154. {
  6155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "TRUE");
  6156. }
  6157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  6158. isKnowKey = TRUE;
  6159. printf("LocalAuthListEnabled\n");
  6160. }
  6161. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  6162. {
  6163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  6164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  6165. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  6166. {
  6167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "FALSE");
  6168. }
  6169. else
  6170. {
  6171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "TRUE");
  6172. }
  6173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  6174. isKnowKey = TRUE;
  6175. printf("LocalAuthListMaxLength\n");
  6176. }
  6177. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  6178. {
  6179. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  6180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  6181. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  6182. {
  6183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "FALSE");
  6184. }
  6185. else
  6186. {
  6187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "TRUE");
  6188. }
  6189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  6190. isKnowKey = TRUE;
  6191. printf("SendLocalListMaxLength\n");
  6192. }
  6193. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  6194. {
  6195. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  6196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  6197. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  6198. {
  6199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "FALSE");
  6200. }
  6201. else
  6202. {
  6203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "TRUE");
  6204. }
  6205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  6206. isKnowKey = TRUE;
  6207. printf("ReserveConnectorZeroSupported\n");
  6208. }
  6209. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  6210. {
  6211. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  6212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  6213. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  6214. {
  6215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "FALSE");
  6216. }
  6217. else
  6218. {
  6219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "TRUE");
  6220. }
  6221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  6222. isKnowKey = TRUE;
  6223. printf("ChargeProfileMaxStackLevel\n");
  6224. }
  6225. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  6226. {
  6227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  6228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  6229. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  6230. {
  6231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "FALSE");
  6232. }
  6233. else
  6234. {
  6235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "TRUE");
  6236. }
  6237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  6238. isKnowKey = TRUE;
  6239. printf("ChargingScheduleAllowedChargingRateUnit\n");
  6240. }
  6241. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  6242. {
  6243. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  6244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  6245. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  6246. {
  6247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "FALSE");
  6248. }
  6249. else
  6250. {
  6251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "TRUE");
  6252. }
  6253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  6254. isKnowKey = TRUE;
  6255. printf("ChargingScheduleMaxPeriods\n");
  6256. }
  6257. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  6258. {
  6259. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  6260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  6261. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  6262. {
  6263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "FALSE");
  6264. }
  6265. else
  6266. {
  6267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "TRUE");
  6268. }
  6269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  6270. isKnowKey = TRUE;
  6271. printf("ConnectorSwitch3to1PhaseSupported\n");
  6272. }
  6273. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  6274. {
  6275. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  6276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  6277. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  6278. {
  6279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "FLASE");
  6280. }
  6281. else
  6282. {
  6283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "TRUE");
  6284. }
  6285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  6286. isKnowKey = TRUE;
  6287. printf("MaxChargingProfilesInstalled\n");
  6288. }
  6289. //=========================================================
  6290. if(!isEmpty && !isKnowKey)
  6291. {
  6292. printf("unKnowIndex =%d\n", UnknownKeynum);
  6293. strcpy(unknownkey[UnknownKeynum], keyReq);
  6294. UnknownKeynum = UnknownKeynum + 1;
  6295. }
  6296. }
  6297. void processUnkownKey(void)
  6298. {
  6299. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey != NULL)
  6300. free(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey);
  6301. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = (struct StructConfigurationKeyItems *)malloc(sizeof(struct StructConfigurationKeyItems)*UnknownKeynum);
  6302. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* UnknownKeynum);
  6303. printf("processUnkownKey UnknownKeynum =%d\n",UnknownKeynum);
  6304. for(int index=0; index < UnknownKeynum; index++)
  6305. {
  6306. printf("ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[%d].Item[0]=%c\n",index,ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0]);
  6307. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  6308. {
  6309. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  6310. printf("getkeyValue: %s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item);
  6311. }
  6312. }
  6313. }
  6314. int setKeyValue(char *key, char *value)
  6315. {
  6316. int isSuccess = NotSupported;
  6317. printf("setKeyValue : key : %s\n", key);
  6318. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  6319. {
  6320. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  6321. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  6322. {
  6323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6324. isSuccess = ConfigurationStatus_Accepted;
  6325. }
  6326. else
  6327. {
  6328. isSuccess = ConfigurationStatus_Rejected;
  6329. }
  6330. }
  6331. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  6332. {
  6333. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  6334. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  6335. {
  6336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6337. isSuccess = ConfigurationStatus_Accepted;
  6338. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  6339. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  6340. }
  6341. else
  6342. {
  6343. isSuccess = ConfigurationStatus_Rejected;
  6344. }
  6345. }
  6346. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  6347. {
  6348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  6349. {
  6350. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  6351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6352. isSuccess = ConfigurationStatus_Accepted;
  6353. }
  6354. else
  6355. {
  6356. isSuccess = ConfigurationStatus_Rejected;
  6357. }
  6358. }
  6359. if(strcmp(key, "BlinkRepeat") == 0)
  6360. {
  6361. //Charger.BlinkRepeat = Integer.parseInt(value);
  6362. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  6363. {
  6364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  6365. isSuccess = ConfigurationStatus_Accepted;
  6366. }
  6367. else
  6368. {
  6369. isSuccess = ConfigurationStatus_Rejected;
  6370. }
  6371. }
  6372. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  6373. {
  6374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  6375. {
  6376. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  6377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value)*1000 );
  6378. isSuccess = ConfigurationStatus_Accepted;
  6379. }
  6380. else
  6381. {
  6382. isSuccess = ConfigurationStatus_Rejected;
  6383. }
  6384. }
  6385. if(strcmp(key, "ConnectionTimeOut") == 0 )
  6386. {
  6387. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  6388. {
  6389. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  6390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value)*1000 );
  6391. isSuccess = ConfigurationStatus_Accepted;
  6392. }
  6393. else
  6394. {
  6395. isSuccess = ConfigurationStatus_Rejected;
  6396. }
  6397. }
  6398. if(strcmp(key, "HeartbeatInterval") == 0)
  6399. {
  6400. printf("HeartbeatInterval ItemAccessibility: %d\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility);
  6401. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  6402. {
  6403. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  6404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value)/*atoi(value)*1000*/ );
  6405. HeartBeatWaitTime = atoi(value);
  6406. printf("set HeartbeatInterval value \n");
  6407. isSuccess = ConfigurationStatus_Accepted;
  6408. }
  6409. else
  6410. {
  6411. isSuccess = ConfigurationStatus_Rejected;
  6412. }
  6413. }
  6414. if(strcmp(key, "LightIntensity") == 0)
  6415. {
  6416. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  6417. {
  6418. //Charger.LightIntensity = Integer.parseInt(value);
  6419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  6420. isSuccess = ConfigurationStatus_Accepted;
  6421. }
  6422. else
  6423. {
  6424. isSuccess = ConfigurationStatus_Rejected;
  6425. }
  6426. }
  6427. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  6428. {
  6429. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  6430. {
  6431. //Charger.LocalAuthorizeOffline = (value.toLowerCase().equals("true")?true:false);
  6432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6433. isSuccess = ConfigurationStatus_Accepted;
  6434. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  6435. }
  6436. else
  6437. {
  6438. isSuccess = ConfigurationStatus_Rejected;
  6439. }
  6440. }
  6441. if(strcmp(key, "LocalPreAuthorize") == 0)
  6442. {
  6443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  6444. {
  6445. //Charger.LocalPreAuthorize = (value.toLowerCase().equals("true")?true:false);
  6446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6447. isSuccess = ConfigurationStatus_Accepted;
  6448. }
  6449. else
  6450. {
  6451. isSuccess = ConfigurationStatus_Rejected;
  6452. }
  6453. }
  6454. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  6455. {
  6456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  6457. {
  6458. //Charger.MaxEnergyOnInvalidId = Integer.parseInt(value);
  6459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  6460. isSuccess = ConfigurationStatus_Accepted;
  6461. }
  6462. else
  6463. {
  6464. isSuccess = ConfigurationStatus_Rejected;
  6465. }
  6466. }
  6467. if(strcmp(key, "MeterValuesAlignedData") == 0)
  6468. {
  6469. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  6470. {
  6471. //Charger.MeterValuesAlignedData = value.toLowerCase();
  6472. int valueLength = strlen(value);
  6473. for(int i = 0; value[i]; i++){
  6474. value[i] = tolower(value[i]);
  6475. }
  6476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  6477. isSuccess = ConfigurationStatus_Accepted;
  6478. }
  6479. else
  6480. {
  6481. isSuccess = ConfigurationStatus_Rejected;
  6482. }
  6483. }
  6484. if(strcmp(key, "MeterValuesSampledData") == 0 )
  6485. {
  6486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  6487. {
  6488. //Charger.MeterValuesSampledData = value.toLowerCase();
  6489. int valueLength = strlen(value);
  6490. for(int i = 0; value[i]; i++){
  6491. value[i] = tolower(value[i]);
  6492. }
  6493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  6494. isSuccess = ConfigurationStatus_Accepted;
  6495. }
  6496. else
  6497. {
  6498. isSuccess = ConfigurationStatus_Rejected;
  6499. }
  6500. }
  6501. if(strcmp(key, "MeterValueSampleInterval") == 0)
  6502. {
  6503. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  6504. {
  6505. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  6506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value)*1000 );
  6507. isSuccess = ConfigurationStatus_Accepted;
  6508. }
  6509. else
  6510. {
  6511. isSuccess = ConfigurationStatus_Rejected;
  6512. }
  6513. }
  6514. if(strcmp(key, "MinimumStatusDuration") == 0)
  6515. {
  6516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  6517. {
  6518. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  6519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  6520. isSuccess = ConfigurationStatus_Accepted;
  6521. }
  6522. else
  6523. {
  6524. isSuccess = ConfigurationStatus_Rejected;
  6525. }
  6526. }
  6527. if(strcmp(key, "ResetRetries") == 0)
  6528. {
  6529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  6530. {
  6531. //Charger.ResetRetries = Integer.parseInt(value);
  6532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  6533. isSuccess = ConfigurationStatus_Accepted;
  6534. }
  6535. else
  6536. {
  6537. isSuccess = ConfigurationStatus_Rejected;
  6538. }
  6539. }
  6540. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  6541. {
  6542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  6543. {
  6544. //Charger.ConnectorPhaseRotation = value.toLowerCase();
  6545. int valueLength = strlen(value);
  6546. for(int i = 0; value[i]; i++){
  6547. value[i] = tolower(value[i]);
  6548. }
  6549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  6550. isSuccess = ConfigurationStatus_Accepted;
  6551. }
  6552. else
  6553. {
  6554. isSuccess = ConfigurationStatus_Rejected;
  6555. }
  6556. }
  6557. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  6558. {
  6559. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  6560. {
  6561. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  6562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6563. isSuccess = ConfigurationStatus_Accepted;
  6564. }
  6565. else
  6566. {
  6567. isSuccess = ConfigurationStatus_Rejected;
  6568. }
  6569. }
  6570. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  6571. {
  6572. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  6573. {
  6574. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  6575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6576. isSuccess = ConfigurationStatus_Accepted;
  6577. }
  6578. else
  6579. {
  6580. isSuccess = ConfigurationStatus_Rejected;
  6581. }
  6582. }
  6583. if(strcmp(key, "StopTxnAlignedData") == 0)
  6584. {
  6585. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  6586. {
  6587. //Charger.StopTxnAlignedData = value.toLowerCase();
  6588. int valueLength = strlen(value);
  6589. for(int i = 0; value[i]; i++){
  6590. value[i] = tolower(value[i]);
  6591. }
  6592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  6593. isSuccess = ConfigurationStatus_Accepted;
  6594. }
  6595. else
  6596. {
  6597. isSuccess = ConfigurationStatus_Rejected;
  6598. }
  6599. }
  6600. if(strcmp(key, "StopTxnSampledData") == 0)
  6601. {
  6602. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  6603. {
  6604. //Charger.StopTxnSampledData = value.toLowerCase();
  6605. int valueLength = strlen(value);
  6606. for(int i = 0; value[i]; i++){
  6607. value[i] = tolower(value[i]);
  6608. }
  6609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  6610. isSuccess = ConfigurationStatus_Accepted;
  6611. }
  6612. else
  6613. {
  6614. isSuccess = ConfigurationStatus_Rejected;
  6615. }
  6616. }
  6617. if(strcmp(key, "TransactionMessageAttempts") == 0)
  6618. {
  6619. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  6620. {
  6621. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  6622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  6623. isSuccess = ConfigurationStatus_Accepted;
  6624. }
  6625. else
  6626. {
  6627. isSuccess = ConfigurationStatus_Rejected;
  6628. }
  6629. }
  6630. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  6631. {
  6632. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  6633. {
  6634. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  6635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value)*1000 );
  6636. isSuccess = ConfigurationStatus_Accepted;
  6637. }
  6638. else
  6639. {
  6640. isSuccess = ConfigurationStatus_Rejected;
  6641. }
  6642. }
  6643. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  6644. {
  6645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  6646. {
  6647. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  6648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6649. isSuccess = ConfigurationStatus_Accepted;
  6650. }
  6651. else
  6652. {
  6653. isSuccess = ConfigurationStatus_Rejected;
  6654. }
  6655. }
  6656. if(strcmp(key, "WebSocketPingInterval") == 0)
  6657. {
  6658. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  6659. {
  6660. //Charger.WebSocketPingInterval = Integer.parseInt(value)*1000;
  6661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value)*1000 );
  6662. isSuccess = ConfigurationStatus_Accepted;
  6663. }
  6664. else
  6665. {
  6666. isSuccess = ConfigurationStatus_Rejected;
  6667. }
  6668. }
  6669. if(strcmp(key, "LocalAuthListEnabled") == 0)
  6670. {
  6671. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  6672. {
  6673. //Charger.LocalAuthListEnabled = (value.toLowerCase().equals("true")?true:false);
  6674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%d", (strcmp(value, "true")==0) ?TRUE:FALSE );
  6675. isSuccess = ConfigurationStatus_Accepted;
  6676. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  6677. }
  6678. else
  6679. {
  6680. isSuccess = ConfigurationStatus_Rejected;
  6681. }
  6682. }
  6683. return isSuccess;
  6684. }
  6685. int updateSetting(char *key, char *value)
  6686. {
  6687. int isSuccess = FALSE;
  6688. json_object *json_obj = NULL;
  6689. json_object *tmp_obj = NULL;
  6690. //new a base object
  6691. json_obj = json_object_new_object();
  6692. tmp_obj = json_object_new_string(value);
  6693. json_object_object_add(json_obj, key, tmp_obj);
  6694. json_object_to_file("/var/www/settings", json_obj);
  6695. isSuccess = TRUE;
  6696. return isSuccess;
  6697. }
  6698. json_object * getJSONfromFile(char *filename)
  6699. {
  6700. FILE *fptr;
  6701. char str[] = "{}";
  6702. json_object * obj ;
  6703. fptr = fopen(filename, "rw+");
  6704. if(fptr == NULL) //if file does not exist, create it
  6705. {
  6706. fptr = fopen(filename, "w");
  6707. fwrite(str , 1 , sizeof(str) , fptr );
  6708. }
  6709. fclose(fptr);
  6710. //obj = new JSONObject(new JSONTokener((new URI("file:///" + filename)).toURL().openStream()));
  6711. obj = json_object_from_file(filename);
  6712. return obj;
  6713. }
  6714. #define SA struct sockaddr
  6715. #define MAXBUF 1024
  6716. static char m_send_buffer[1024];
  6717. static char m_recv_buffer[1024];
  6718. static int m_socket_data;
  6719. static int sockfd;
  6720. int ReadHttpStatus(int sock){
  6721. char c;
  6722. char buff[1024]="",*ptr=buff+1;
  6723. int bytes_received, status;
  6724. printf("Begin Response ..\n");
  6725. while(bytes_received = recv(sock, ptr, 1, 0)){
  6726. if(bytes_received==-1){
  6727. perror("ReadHttpStatus");
  6728. exit(1);
  6729. }
  6730. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  6731. ptr++;
  6732. }
  6733. *ptr=0;
  6734. ptr=buff+1;
  6735. sscanf(ptr,"%*s %d ", &status);
  6736. printf("%s\n",ptr);
  6737. printf("status=%d\n",status);
  6738. printf("End Response ..\n");
  6739. return (bytes_received>0)?status:0;
  6740. }
  6741. //the only filed that it parsed is 'Content-Length'
  6742. int ParseHeader(int sock){
  6743. char c;
  6744. char buff[1024]="",*ptr=buff+4;
  6745. int bytes_received, status;
  6746. printf("Begin HEADER ..\n");
  6747. while(bytes_received = recv(sock, ptr, 1, 0)){
  6748. if(bytes_received==-1){
  6749. perror("Parse Header");
  6750. exit(1);
  6751. }
  6752. if(
  6753. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  6754. (ptr[-1]=='\r') && (*ptr=='\n' )
  6755. ) break;
  6756. ptr++;
  6757. }
  6758. *ptr=0;
  6759. ptr=buff+4;
  6760. //printf("%s",ptr);
  6761. if(bytes_received){
  6762. ptr=strstr(ptr,"Content-Length:");
  6763. if(ptr){
  6764. sscanf(ptr,"%*s %d",&bytes_received);
  6765. }else
  6766. bytes_received=-1; //unknown size
  6767. printf("Content-Length: %d\n",bytes_received);
  6768. }
  6769. printf("End HEADER ..\n");
  6770. return bytes_received ;
  6771. }
  6772. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  6773. {
  6774. //char domain[] = "sstatic.net", path[]="stackexchange/img/logos/so/so-logo-med.png";
  6775. int sock, bytes_received;
  6776. char send_data[1024],recv_data[1024], *p;
  6777. struct sockaddr_in server_addr;
  6778. struct hostent *he;
  6779. char ftpbuf[200];
  6780. int systemresult;
  6781. char temp[100];
  6782. memset(ftpbuf, 0, sizeof(ftpbuf));
  6783. sprintf(ftpbuf, "wget --tries=3 -o %s -cb %s ",filename, url);
  6784. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  6785. systemresult = system(ftpbuf);
  6786. printf("systemresult=%d\n",systemresult);
  6787. if(systemresult != 0)
  6788. {
  6789. printf("ftpget error!\n");
  6790. return FALSE;
  6791. }
  6792. return TRUE;
  6793. }
  6794. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename)
  6795. {
  6796. //int sockfd;
  6797. static int ret= 0;
  6798. int reclen=0, off;
  6799. int n, fileSize;
  6800. char fname[40];
  6801. char fileSizeBuffer[256];
  6802. int len;
  6803. int k, size, status;
  6804. struct sockaddr_in servaddr,cliaddr;
  6805. struct sockaddr_in servaddr_data;
  6806. struct hostent* server;
  6807. char bufferTemp[500000];
  6808. char *IPbuffer;
  6809. char ftpbuf[200];
  6810. int systemresult;
  6811. char temp[100];
  6812. server = gethostbyname(location);
  6813. // To convert an Internet network
  6814. // address into ASCII string
  6815. IPbuffer = inet_ntoa(*((struct in_addr*)
  6816. server->h_addr_list[0]));
  6817. memset(ftpbuf, 0, sizeof(ftpbuf));
  6818. sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename);
  6819. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  6820. systemresult = system(ftpbuf);
  6821. printf("systemresult=%d\n",systemresult);
  6822. if(systemresult != 0)
  6823. {
  6824. printf("ftpget error!\n");
  6825. return FALSE;
  6826. }
  6827. return TRUE;
  6828. }
  6829. int ftpFile(char *location, char *user, char *password, int port, char *path, char *filename)
  6830. {
  6831. //int sockfd;
  6832. static int ret= 0;
  6833. int reclen=0, off;
  6834. int n, fileSize;
  6835. char fname[40];
  6836. char fileSizeBuffer[256];
  6837. int len;
  6838. int k, size, status;
  6839. struct sockaddr_in servaddr,cliaddr;
  6840. struct sockaddr_in servaddr_data;
  6841. struct hostent* server;
  6842. char *IPbuffer;
  6843. char ftpbuf[200];
  6844. int systemresult;
  6845. printf("ftpFile -1\n");
  6846. // To retrieve host information
  6847. server = gethostbyname(location);
  6848. // To convert an Internet network
  6849. // address into ASCII string
  6850. IPbuffer = inet_ntoa(*((struct in_addr*)
  6851. server->h_addr_list[0]));
  6852. memset(ftpbuf, 0, sizeof(ftpbuf));
  6853. /* format : ftpput -u username -p passwd IP target source*/
  6854. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,filename);
  6855. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  6856. systemresult = system(ftpbuf);
  6857. printf("systemresult=%d\n",systemresult);
  6858. if(systemresult != 0)
  6859. {
  6860. printf("ftpput error!\n");
  6861. return FALSE;
  6862. }
  6863. return TRUE;
  6864. }
  6865. int SettingChargingRecord(int target, int transactionId)
  6866. {
  6867. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6868. {
  6869. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '4'))
  6870. {
  6871. addBuff(target, transactionId, 0);
  6872. return TRUE;
  6873. }
  6874. }
  6875. for (int index = 0; index < CCS_QUANTITY; index++)
  6876. {
  6877. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == '4'))
  6878. {
  6879. addBuff(target, transactionId, 0);
  6880. return TRUE;
  6881. }
  6882. }
  6883. for (int index = 0; index < GB_QUANTITY; index++)
  6884. {
  6885. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4'))
  6886. {
  6887. addBuff(target, transactionId, 0);
  6888. return TRUE;
  6889. }
  6890. }
  6891. return FALSE;
  6892. }
  6893. int addBuff(int gun_idx, int user_id, int cmd_sn)
  6894. {
  6895. int isSuccess = FALSE;
  6896. char *query = NULL;
  6897. sqlite3_stmt *stmt;
  6898. int rc; // return code
  6899. char str[20];
  6900. sprintf(str,"%d",user_id);
  6901. 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 */
  6902. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  6903. rc = sqlite3_step(stmt); /* 3 */
  6904. if (rc != SQLITE_DONE) {
  6905. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  6906. goto out;
  6907. }
  6908. sqlite3_finalize(stmt);
  6909. free(query);
  6910. out:
  6911. /*
  6912. * close SQLite database
  6913. */
  6914. sqlite3_close(db);
  6915. printf("database closed.\n");
  6916. return isSuccess;
  6917. }
  6918. /**
  6919. * Place the contents of the specified file into a memory buffer
  6920. *
  6921. * @param[in] filename The path and name of the file to read
  6922. * @param[out] filebuffer A pointer to the contents in memory
  6923. * @return status 0 success, 1 on failure
  6924. */
  6925. int get_file_contents(const char* filename, char** outbuffer) {
  6926. FILE* file = NULL;
  6927. long filesize;
  6928. const int blocksize = 1;
  6929. size_t readsize;
  6930. char* filebuffer;
  6931. // Open the file
  6932. file = fopen(filename, "r");
  6933. if (NULL == file)
  6934. {
  6935. printf("'%s' not opened\n", filename);
  6936. exit(EXIT_FAILURE);
  6937. }
  6938. // Determine the file size
  6939. fseek(file, 0, SEEK_END);
  6940. filesize = ftell(file);
  6941. rewind (file);
  6942. // Allocate memory for the file contents
  6943. filebuffer = (char*) malloc(sizeof(char) * filesize);
  6944. *outbuffer = filebuffer;
  6945. if (filebuffer == NULL)
  6946. {
  6947. fputs ("malloc out-of-memory", stderr);
  6948. exit(EXIT_FAILURE);
  6949. }
  6950. // Read in the file
  6951. readsize = fread(filebuffer, blocksize, filesize, file);
  6952. if (readsize != filesize)
  6953. {
  6954. fputs ("didn't read file completely",stderr);
  6955. exit(EXIT_FAILURE);
  6956. }
  6957. // Clean exit
  6958. fclose(file);
  6959. return EXIT_SUCCESS;
  6960. }
  6961. //Command Port, Receive Answer
  6962. static int ftp_recv_respond(int m_socket_cmd, char *resp, int len)
  6963. {
  6964. int ret;
  6965. int off;
  6966. len -= 1;
  6967. for(off=0; off<len; off+=ret)
  6968. {
  6969. ret = recv(m_socket_cmd, &resp[off], 1 ,0);
  6970. // ret = socket_recv(m_socket_cmd, &resp[off], 1);
  6971. if(ret < 0)
  6972. {
  6973. printf("recv respond error(ret=%d)!\r\n", ret);
  6974. return 0;
  6975. }
  6976. if(resp[off] == '\n')
  6977. {
  6978. break;
  6979. }
  6980. }
  6981. resp[off+1] = 0;
  6982. printf("respond:%s", resp);
  6983. return atoi(resp);
  6984. }
  6985. static int selectSqlCount = 0;
  6986. void getMemory(char** s, int num)
  6987. {
  6988. *s = (char*)malloc(sizeof(char) * num);
  6989. printf("s = %p\n", s);
  6990. printf("*s = %p\n", *s);
  6991. }
  6992. static int callback(void *data, int argc, char **argv, char **azColName){
  6993. int i;
  6994. printf("%s: ", (const char*)data);
  6995. selectSqlCount = argc;
  6996. for(i = 0; i<argc; i++){
  6997. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  6998. }
  6999. printf("\n");
  7000. return 0;
  7001. }
  7002. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  7003. int i;
  7004. //printf("%s:\n", (const char*)data);
  7005. localversion = argv[5] ? atoi(argv[5]) : 0;
  7006. printf("localversion=%d\n", localversion);
  7007. return 0;
  7008. }
  7009. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  7010. int i;
  7011. //printf("%s:\n", (const char*)data);
  7012. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  7013. printf("IdTag=%s\n", idTagAuthorization);
  7014. return 0;
  7015. }
  7016. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  7017. int i;
  7018. //printf("%s:\n", (const char*)data);
  7019. #if 1
  7020. for(i=0; i<argc; i++){
  7021. printf("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  7022. }
  7023. printf("");
  7024. #endif
  7025. // localversion = argv[5] ? atoi(argv[5]) : 0;
  7026. // printf("localversion=%d\n", localversion);
  7027. return 0;
  7028. }
  7029. void OCPP_getListVerion()
  7030. {
  7031. int ver = 0;
  7032. int isSuccess = FALSE;
  7033. int rc = 0;
  7034. // const char* data = "Callback function called";
  7035. char sql[100];
  7036. char zErrMsg[100];
  7037. memset(sql, 0, 100);
  7038. memset(zErrMsg, 0, 100);
  7039. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  7040. /* Execute SQL statement */
  7041. printf("OCPP_getListVerion -1\n");
  7042. rc = sqlite3_exec(db, sql, versioncallback, 0, &zErrMsg);
  7043. printf("OCPP_getListVerion -2\n");
  7044. printf("rc=%d\n",rc);
  7045. if( rc != SQLITE_OK ){
  7046. printf("SQL error: %s", zErrMsg);
  7047. //sqlite3_free(zErrMsg);
  7048. }else{
  7049. printf("Operation done successfully");
  7050. }
  7051. printf("OCPP_getListVerion -3\n");
  7052. //return ver;
  7053. }
  7054. void OCPP_getIdTag(char *idTag)
  7055. {
  7056. int ver = 0;
  7057. int isSuccess = FALSE;
  7058. int rc = 0;
  7059. // const char* data = "Callback function called";
  7060. char sql[100];
  7061. char zErrMsg[100];
  7062. memset(sql, 0, 100);
  7063. memset(zErrMsg, 0, 100);
  7064. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  7065. /* Execute SQL statement */
  7066. printf("OCPP_getIdTag -1\n");
  7067. rc = sqlite3_exec(db, sql, versioncallback, 0, &zErrMsg);
  7068. printf("OCPP_getIdTag -2\n");
  7069. printf("rc=%d\n",rc);
  7070. if( rc != SQLITE_OK ){
  7071. printf("SQL error: %s", zErrMsg);
  7072. //sqlite3_free(zErrMsg);
  7073. }else{
  7074. printf("Operation done successfully");
  7075. }
  7076. printf("OCPP_getIdTag -3\n");
  7077. //return ver;
  7078. }
  7079. int OCPP_cleanLocalList()
  7080. {
  7081. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  7082. char *errMsg = 0;
  7083. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  7084. if (SQLITE_OK != rc)
  7085. {
  7086. printf("%s\n",errMsg);
  7087. return FALSE;
  7088. }
  7089. else
  7090. {
  7091. printf("delete ocpp_auth_local table successfully\n");
  7092. }
  7093. return TRUE;
  7094. }
  7095. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  7096. {
  7097. int isSuccess = FALSE;
  7098. int ret = 0;
  7099. const char* data = "Callback function called";
  7100. char sql[200];
  7101. char zErrMsg[100];
  7102. // char* sql = NULL;
  7103. // char* zErrMsg = NULL;
  7104. // sql = (char*)malloc(sizeof(char)*200); // getMemory(&sql, 200);
  7105. // zErrMsg = (char*)malloc(sizeof(char)*100); // getMemory(&zErrMsg, 100);
  7106. memset(sql, 0, 200);
  7107. memset(zErrMsg, 0, 100);
  7108. 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);
  7109. printf("sql:%s\n", sql);
  7110. printf("OCPP_addLocalList -5\n");
  7111. /* Execute SQL statement */
  7112. //zErrMsg = 0;
  7113. ret = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
  7114. printf("OCPP_addLocalList -6\n");
  7115. if( ret != SQLITE_OK ){
  7116. printf("SQL error: %s\n", zErrMsg);
  7117. // free(zErrMsg);
  7118. // free(sql);
  7119. return isSuccess;
  7120. }
  7121. printf("successfully Insert records created\n");
  7122. isSuccess = TRUE;
  7123. return isSuccess;
  7124. }
  7125. void OCPP_deleteIdTag(char *idTag)
  7126. {
  7127. int ver = 0;
  7128. int isSuccess = FALSE;
  7129. int rc = 0;
  7130. char sql[100];
  7131. char zErrMsg[100];
  7132. memset(sql, 0, 100);
  7133. memset(zErrMsg, 0, 100);
  7134. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  7135. /* Execute SQL statement */
  7136. printf("OCPP_getIdTag -1\n");
  7137. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0, &zErrMsg);
  7138. printf("OCPP_getIdTag -2\n");
  7139. printf("rc=%d\n",rc);
  7140. if( rc != SQLITE_OK ){
  7141. printf("SQL error: %s", zErrMsg);
  7142. //sqlite3_free(zErrMsg);
  7143. }else{
  7144. printf("Operation done successfully");
  7145. }
  7146. printf("OCPP_getIdTag -3\n");
  7147. }
  7148. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  7149. {
  7150. int isSuccess = FALSE;
  7151. int ret = 0;
  7152. const char* data = "Callback function called";
  7153. char sql[200];
  7154. char zErrMsg[100];
  7155. memset(sql, 0, 200);
  7156. memset(zErrMsg, 0, 100);
  7157. /* selectFromTable */
  7158. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  7159. printf("OCPP_addLocalList -1\n");
  7160. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  7161. printf("OCPP_addLocalList -2\n");
  7162. /* Execute SQL statement */
  7163. selectSqlCount = 0;
  7164. ret = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
  7165. printf("OCPP_addLocalList -3\n");
  7166. if( ret != SQLITE_OK ){
  7167. printf("Error SQL: %s\n", zErrMsg);
  7168. }
  7169. printf("successfully select operation done\n");
  7170. memset(sql, 0, 200);
  7171. memset(zErrMsg, 0, 100);
  7172. if(selectSqlCount == 0)
  7173. {
  7174. printf("OCPP_addLocalList -4\n");
  7175. //Insert
  7176. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ?�Paul?? 32, ?�California?? 20000.00 ); ";
  7177. 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);
  7178. printf("sql:%s\n", sql);
  7179. printf("OCPP_addLocalList -5\n");
  7180. /* Execute SQL statement */
  7181. //zErrMsg = 0;
  7182. ret = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
  7183. printf("OCPP_addLocalList -6\n");
  7184. if( ret != SQLITE_OK ){
  7185. printf("SQL error: %s\n", zErrMsg);
  7186. return isSuccess;
  7187. }
  7188. printf("successfully Insert records created\n");
  7189. isSuccess = TRUE;
  7190. }
  7191. else
  7192. {
  7193. printf("OCPP_addLocalList -7\n");
  7194. //Update
  7195. /* Create merged SQL statement */
  7196. 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);
  7197. printf("OCPP_addLocalList -8\n");
  7198. /* Execute SQL statement */
  7199. ret = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
  7200. printf("OCPP_addLocalList -9\n");
  7201. if( ret != SQLITE_OK ){
  7202. printf("SQL error: %s\n", zErrMsg);
  7203. //sqlite3_free(zErrMsg);
  7204. //sqlite3_free(sql);
  7205. return isSuccess;
  7206. }
  7207. printf("Successfully operation done \n");
  7208. isSuccess = TRUE;
  7209. }
  7210. return isSuccess;
  7211. }
  7212. char *GetOcppServerURL()
  7213. {
  7214. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  7215. memset(OcppHost, 0, sizeof(OcppHost));
  7216. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  7217. sscanf(ShmOCPP16Data->OcppServerURL,
  7218. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  7219. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  7220. printf("OcppProtocol =%s\n",OcppProtocol);
  7221. printf("OcppHost =%s\n",OcppHost);
  7222. printf("OcppPort =%d\n",OcppPort);
  7223. printf("OcppTempPath =%s\n",OcppTempPath);
  7224. return OcppHost;
  7225. }
  7226. char *GetOcppPath()
  7227. {
  7228. if(OcppTempPath == NULL)
  7229. {
  7230. sprintf(OcppPath,"/%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  7231. }
  7232. else
  7233. {
  7234. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  7235. }
  7236. printf("OcppPath=%s\n",OcppPath);
  7237. return OcppPath;
  7238. }
  7239. int GetOcppPort()
  7240. {
  7241. return OcppPort;
  7242. }
  7243. void Send(struct json_object *message)
  7244. {
  7245. printf("Send -1 \n");
  7246. printf("message=%s\n",json_object_to_json_string(message));
  7247. LWS_Send(json_object_to_json_string(message));
  7248. }
  7249. void LWS_Send(char * str)
  7250. {
  7251. pthread_mutex_lock(&lock);
  7252. printf("LWS_Send -1-1 \n");
  7253. printf("message=%s\n",str);
  7254. memset(SendBuffer,0,SendBufLen);
  7255. sprintf((char *)SendBuffer, "%s", str);
  7256. printf("LWS_Send -2 \n");
  7257. pthread_mutex_unlock(&lock);
  7258. lws_callback_on_writable(wsi_client);
  7259. lws_service(context, 10000);//timeout_ms
  7260. //usleep(10000); // 等�??��?微�?
  7261. printf("Send message\n");
  7262. }