Module_CCS.c 651 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280
  1. /*
  2. * Module_CCS.c
  3. *
  4. * Created on: 2020/03/16
  5. * Author: foluswen
  6. */
  7. #include "Module_CCS.h"
  8. #include "define_ccs.h"
  9. #include "main.h"
  10. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  11. struct StatusCodeData *ShmStatusCodeData;
  12. struct CcsData *ShmCcsData;
  13. struct InternalComm *ShmInternalComm;
  14. struct Charger *ShmCharger;
  15. struct appHandEXIDocument ccs_handshake;
  16. struct dinEXIDocument ccs_exi_doc_DIN;
  17. struct iso1EXIDocument ccs_exi_doc_ISO1;
  18. struct iso2EXIDocument ccs_exi_doc_ISO2;
  19. unsigned char V2GTP_Tx_buf[V2GTP_MSG_TX_BUFFER_SIZE]; //64*1024 = 65,536 = 65.5KB
  20. unsigned char buf_log_evcomm[SIZE_OF_LOG_BUFFER];
  21. unsigned char buf_log_evcomm_fork1[SIZE_OF_LOG_BUFFER];
  22. unsigned char buf_log_evcomm_fork2[SIZE_OF_LOG_BUFFER];
  23. unsigned char buf_log_evcomm_fork3[SIZE_OF_LOG_BUFFER];
  24. pid_t CP_Detection_Pid = 0;
  25. pid_t PP_Detection_Pid = 0;
  26. pid_t Error_Monitor_Pid = 0;
  27. int TcpAcceptFd;
  28. enum MsgFlowStatus V2gFlowStatus;
  29. int RawSock,UdpSock,TcpSock;
  30. unsigned char V2gtpMsgRxBuf[V2GTP_MSG_RX_BUFFER_SIZE] = {0};
  31. unsigned char V2gtpMsgTxBuf[V2GTP_MSG_TX_BUFFER_SIZE] = {0};
  32. unsigned short Aag[64];
  33. struct MmeHeader SendMmePacket;
  34. int SendMmePacketSize;
  35. unsigned char CsuMac[6],QcaMac[6],EvMac[6],SlacRunId[8];
  36. struct sockaddr_ll DestSocketAddress;
  37. struct ifreq Req;
  38. unsigned int PwmStartTime=0;
  39. struct timeb SeqStartTime, SeqEndTime;
  40. unsigned char AagGroupsNum, MnbcSoundNum, AttenProfileCnt;
  41. unsigned char NewNmkKey[16], Nid[7];
  42. uint8_t get_V2G_Status_Name(uint8_t statusCode, char *statusName)
  43. {
  44. int result = PASS;
  45. switch(statusCode)
  46. {
  47. case IDLE:
  48. sprintf(statusName, "IDLE");
  49. break;
  50. case CM_SLAC_PARM_REQ:
  51. sprintf(statusName, "CM_SLAC_PARM_REQ");
  52. break;
  53. case CM_SLAC_PARM_CONF:
  54. sprintf(statusName, "CM_SLAC_PARM_CONF");
  55. break;
  56. case CM_START_ATTEN_CHAR_IND:
  57. sprintf(statusName, "CM_START_ATTEN_CHAR_IND");
  58. break;
  59. case CM_MNBC_SOUND_IND:
  60. sprintf(statusName, "CM_MNBC_SOUND_IND");
  61. break;
  62. case CM_ATTEN_CHAR_IND:
  63. sprintf(statusName, "CM_ATTEN_CHAR_IND");
  64. break;
  65. case CM_ATTEN_CHAR_RSP:
  66. sprintf(statusName, "CM_ATTEN_CHAR_RSP");
  67. break;
  68. case CM_VALIDATE_REQ:
  69. sprintf(statusName, "CM_VALIDATE_REQ");
  70. break;
  71. case CM_VALIDATE_CNF:
  72. sprintf(statusName, "CM_VALIDATE_CNF");
  73. break;
  74. case CM_SLAC_MATCH_REQ:
  75. sprintf(statusName, "CM_SLAC_MATCH_REQ");
  76. break;
  77. case CM_SLAC_MATCH_CNF:
  78. sprintf(statusName, "CM_SLAC_MATCH_CNF");
  79. break;
  80. case CM_AMP_MAP_REQ:
  81. sprintf(statusName, "CM_AMP_MAP_REQ");
  82. break;
  83. case CM_AMP_MAP_CNF:
  84. sprintf(statusName, "CM_AMP_MAP_CNF");
  85. break;
  86. case CM_SET_KEY_REQ:
  87. sprintf(statusName, "CM_SET_KEY_REQ");
  88. break;
  89. case CM_SET_KEY_CNF:
  90. sprintf(statusName, "CM_SET_KEY_CNF");
  91. break;
  92. case SLACC_SDP_UDP_Connection:
  93. sprintf(statusName, "SLACC_SDP_UDP_Connection");
  94. break;
  95. case SLACC_SDP_TCP_Connection:
  96. sprintf(statusName, "SLACC_SDP_TCP_Connection");
  97. break;
  98. case SupportedAppProtocolRequest:
  99. sprintf(statusName, "SupportedAppProtocolRequest");
  100. break;
  101. case SupportedAppProtocolResponse:
  102. sprintf(statusName, "SupportedAppProtocolResponse");
  103. break;
  104. case SessionSetupRequest:
  105. sprintf(statusName, "SessionSetupRequest");
  106. break;
  107. case SessionSetupResponse:
  108. sprintf(statusName, "UnSessionSetupResponseknown");
  109. break;
  110. case ServiceDiscoveryRequest:
  111. sprintf(statusName, "ServiceDiscoveryRequest");
  112. break;
  113. case ServiceDiscoveryResponse:
  114. sprintf(statusName, "ServiceDiscoveryResponse");
  115. break;
  116. case ServiceDetailRequest:
  117. sprintf(statusName, "ServiceDetailRequest");
  118. break;
  119. case ServiceDetailResponse:
  120. sprintf(statusName, "ServiceDetailResponse");
  121. break;
  122. case ServiceAndPaymentSelectionRequest:
  123. sprintf(statusName, "ServiceAndPaymentSelectionRequest");
  124. break;
  125. case ServiceAndPaymentSelectionResponse:
  126. sprintf(statusName, "ServiceAndPaymentSelectionResponse");
  127. break;
  128. case PaymentDetailsRequest:
  129. sprintf(statusName, "PaymentDetailsRequest");
  130. break;
  131. case PaymentDetailsResponse:
  132. sprintf(statusName, "PaymentDetailsResponse");
  133. break;
  134. case AuthorizationRequest:
  135. sprintf(statusName, "AuthorizationRequest");
  136. break;
  137. case AuthorizationResponse:
  138. sprintf(statusName, "AuthorizationResponse");
  139. break;
  140. case CertificateUpdateRequest:
  141. sprintf(statusName, "CertificateUpdateRequest");
  142. break;
  143. case CertificateUpdateResponse:
  144. sprintf(statusName, "CertificateUpdateResponse");
  145. break;
  146. case CertificateInstallationRequest:
  147. sprintf(statusName, "CertificateInstallationRequest");
  148. break;
  149. case CertificateInstallationResponse:
  150. sprintf(statusName, "CertificateInstallationResponse");
  151. break;
  152. case ChargeParameterDiscoveryRequest:
  153. sprintf(statusName, "ChargeParameterDiscoveryRequest");
  154. break;
  155. case ChargeParameterDiscoveryResponse:
  156. sprintf(statusName, "ChargeParameterDiscoveryResponse");
  157. break;
  158. case CableCheckRequest:
  159. sprintf(statusName, "CableCheckRequest");
  160. break;
  161. case CableCheckResponse:
  162. sprintf(statusName, "CableCheckResponse");
  163. break;
  164. case PreChargeRequest:
  165. sprintf(statusName, "PreChargeRequest");
  166. break;
  167. case PreChargeResponse:
  168. sprintf(statusName, "PreChargeResponse");
  169. break;
  170. case PowerDeliveryRequestStart:
  171. sprintf(statusName, "PowerDeliveryRequestStart");
  172. break;
  173. case PowerDeliveryResponsetStart:
  174. sprintf(statusName, "PowerDeliveryResponsetStart");
  175. break;
  176. case ChargingStatusRequest:
  177. sprintf(statusName, "ChargingStatusRequest");
  178. break;
  179. case ChargingStatusResponse:
  180. sprintf(statusName, "ChargingStatusResponse");
  181. break;
  182. case CurrentDemandRequest:
  183. sprintf(statusName, "CurrentDemandRequest");
  184. break;
  185. case CurrentDemandResponse:
  186. sprintf(statusName, "CurrentDemandResponse");
  187. break;
  188. case MeteringReceiptRequest:
  189. sprintf(statusName, "MeteringReceiptRequest");
  190. break;
  191. case MeteringReceiptResponse:
  192. sprintf(statusName, "MeteringReceiptResponse");
  193. break;
  194. case PowerDeliveryRequestStop:
  195. sprintf(statusName, "PowerDeliveryRequestStop");
  196. break;
  197. case PowerDeliveryResponseStop:
  198. sprintf(statusName, "PowerDeliveryResponseStop");
  199. break;
  200. case WeldingDetectionRequest:
  201. sprintf(statusName, "WeldingDetectionRequest");
  202. break;
  203. case WeldingDetectionResponse:
  204. sprintf(statusName, "WeldingDetectionResponse");
  205. break;
  206. case SessionStopRequest:
  207. sprintf(statusName, "SessionStopRequest");
  208. break;
  209. case SessionStopResponse:
  210. sprintf(statusName, "SessionStopResponse");
  211. break;
  212. case Performance_Timeout:
  213. sprintf(statusName, "Performance_Timeout");
  214. break;
  215. case Sequence_Timeout:
  216. sprintf(statusName, "Sequence_Timeout");
  217. break;
  218. case Other_Fault:
  219. sprintf(statusName, "Other_Fault");
  220. break;
  221. default:
  222. sprintf(statusName, "Unknown");
  223. result = FAIL;
  224. break;
  225. }
  226. return result;
  227. }
  228. /*===========================================================================
  229. FUNCTION: Check_V2G_Flow_Status
  230. DESCRIPTION:
  231. PRE-CONDITION:
  232. INPUT:
  233. OUTPUT:
  234. GLOBAL VARIABLES:
  235. =============================================================================*/
  236. unsigned char Check_V2G_Flow_Status()
  237. {
  238. unsigned char result = 0;
  239. switch (ShmCcsData->CommProtocol)
  240. {
  241. case V2GT_MSG_PROTOCOL_DIN70121: //0
  242. {
  243. result = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus;
  244. break;
  245. }
  246. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  247. {
  248. result = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus;
  249. break;
  250. }
  251. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  252. {
  253. result = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus;
  254. break;
  255. }
  256. default:
  257. break;
  258. }
  259. return result;
  260. }
  261. /*===========================================================================
  262. FUNCTION: CAN_Tx_MSG
  263. DESCRIPTION:
  264. PRE-CONDITION:
  265. INPUT:
  266. OUTPUT:
  267. GLOBAL VARIABLES:
  268. =============================================================================*/
  269. int CAN_Tx_MSG(int Fd, unsigned int MsgId, unsigned char SlaveAddress, unsigned char DataLength, unsigned char *SendData)
  270. {
  271. #if 0
  272. struct can_frame frame;
  273. struct timeb StartTime, EndTime;
  274. unsigned int tmp = 0;
  275. int nbytes = 0;
  276. int i = 0;
  277. //Protection: To avoid unexpected length for CAN bus payload.
  278. if (DataLength > 8)
  279. {
  280. DataLength = 8;
  281. }
  282. memset(&frame, 0, sizeof(struct can_frame));
  283. frame.can_id = 0x80000000 | CAN_SEND_DIRECTION | MsgId | SlaveAddress; //0x80000000: extension ID format
  284. frame.can_dlc = DataLength;
  285. memcpy(frame.data, SendData, DataLength);
  286. nbytes = write(Fd, &frame, sizeof(struct can_frame));
  287. #if 0
  288. DEBUG_PRINTF_EVCOMM_DETAIL("[SeccComm][CAN_Tx_MSG] <%X> ", frame.can_id);
  289. for (i = 0; i < frame.can_dlc; i++)
  290. {
  291. DEBUG_PRINTF_EVCOMM_DETAIL("%02X ", frame.data[i]);
  292. }
  293. DEBUG_PRINTF_EVCOMM_DETAIL("(%d Bytes)\n", frame.can_dlc);
  294. #endif
  295. return nbytes;
  296. #else
  297. return -1;
  298. #endif
  299. }
  300. /*===========================================================================
  301. FUNCTION: Proc_EVStopRes
  302. DESCRIPTION:
  303. PRE-CONDITION:
  304. INPUT:
  305. OUTPUT:
  306. GLOBAL VARIABLES:
  307. =============================================================================*/
  308. int Proc_EVStopRes(int Fd)
  309. {
  310. int nbytes;
  311. unsigned char Buffer[8];
  312. memset(Buffer, 0, sizeof(Buffer));
  313. if (CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency == TRUE)
  314. {
  315. Buffer[0] = EV_EMERGENCY_STOP; //2
  316. }
  317. else
  318. {
  319. Buffer[0] = EV_NORMAL_STOP; //1
  320. }
  321. /*
  322. if(strlen(ShmStatusCodeData->PresentStatusCode[0]) > 0)
  323. {
  324. memcpy(Buffer + 2, ShmStatusCodeData->PresentStatusCode[0], 6);
  325. }
  326. */
  327. Buffer[1] = ShmStatusCodeData->PresentStatusCode[0][0];
  328. Buffer[2] = ShmStatusCodeData->PresentStatusCode[0][1];
  329. Buffer[3] = ShmStatusCodeData->PresentStatusCode[0][2];
  330. Buffer[4] = ShmStatusCodeData->PresentStatusCode[0][3];
  331. Buffer[5] = ShmStatusCodeData->PresentStatusCode[0][4];
  332. Buffer[6] = ShmStatusCodeData->PresentStatusCode[0][5];
  333. nbytes = CAN_Tx_MSG(Fd, CAN_CMD_EV_STOP_EVENT, ShmInternalComm->SlaveAddress, 7, Buffer);
  334. //system("echo 1000000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle"); //for test only
  335. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  336. SAVE_SYS_LOG_MSG_EVCOMM("Sending STOP Command to CSU\n");
  337. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = FALSE;
  338. return nbytes;
  339. }
  340. /*===========================================================================
  341. FUNCTION: Sniffer_Candump
  342. DESCRIPTION:
  343. 1. Only used in End_Process(), which is in fork2 of SeccComm task.
  344. PRE-CONDITION:
  345. INPUT:
  346. OUTPUT:
  347. 0: accept
  348. -1: invalid
  349. GLOBAL VARIABLES:
  350. =============================================================================*/
  351. int Sniffer_Candump(char cmd)
  352. {
  353. #if (CANDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  354. if (cmd == ENABLE)
  355. {
  356. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[candump]init");
  357. system("cd /mnt/;rm -rf candump/");
  358. system("cd /mnt/;mkdir candump");
  359. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[candump]on");
  360. system("cd /mnt/candump;candump -l can0 &");
  361. return 0;
  362. }
  363. else if (cmd == DISABLE)
  364. {
  365. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[candump]off");
  366. system("killall candump");
  367. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[candump]save");
  368. system("cd /;cp -rfv /mnt/candump /Storage/SystemLog/");
  369. return 0;
  370. }
  371. else
  372. {
  373. sprintf((char*)buf_log_evcomm_fork2, "[candump]unexpected cmd(%d)", cmd);
  374. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm_fork2);
  375. return -1;
  376. }
  377. #endif
  378. return 0;
  379. }
  380. /*===========================================================================
  381. FUNCTION: Sniffer_Tcpdump
  382. DESCRIPTION:
  383. PRE-CONDITION:
  384. INPUT:
  385. OUTPUT:
  386. GLOBAL VARIABLES:
  387. =============================================================================*/
  388. int Sniffer_Tcpdump(char cmd)
  389. {
  390. #if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  391. if (cmd == ENABLE)
  392. {
  393. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]init...");
  394. system("cd /mnt/;rm -rf tcpdump/");
  395. system("cd /mnt/;mkdir tcpdump");
  396. unsigned char buf[256];
  397. time_t CurrentTime;
  398. struct tm *tm;
  399. struct timeval tv;
  400. memset(buf, 0, sizeof(buf));
  401. CurrentTime = time(NULL);
  402. tm = localtime(&CurrentTime);
  403. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  404. sprintf((char*)buf,
  405. "tcpdump -i eth1 -w /mnt/tcpdump/[%s][%04d%02d%02d-%02d:%02d:%02d.%06d]packets.pcap&",
  406. FIRMWARE_VERSION,
  407. tm->tm_year + 1900,
  408. tm->tm_mon + 1,
  409. tm->tm_mday,
  410. tm->tm_hour,
  411. tm->tm_min,
  412. tm->tm_sec,
  413. tv.tv_usec
  414. );
  415. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]on");
  416. system(buf);
  417. return 0;
  418. }
  419. else if (cmd == DISABLE)
  420. {
  421. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]off");
  422. system("killall tcpdump");
  423. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]wait: 2s");
  424. sleep(1);
  425. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]wait: 1s");
  426. sleep(1);
  427. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[tcpdump]save");
  428. system("cd /;cp -rfv /mnt/tcpdump /Storage/SystemLog/");
  429. return 0;
  430. }
  431. else
  432. {
  433. sprintf((char*)buf_log_evcomm, "[tcpdump]unexpected cmd(%d)", cmd);
  434. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  435. return -1;
  436. }
  437. #endif
  438. return 0;
  439. }
  440. /*===========================================================================
  441. FUNCTION: Check_V2G_Flow_Status_pre
  442. DESCRIPTION:
  443. PRE-CONDITION:
  444. INPUT:
  445. OUTPUT:
  446. GLOBAL VARIABLES:
  447. =============================================================================*/
  448. unsigned char Check_V2G_Flow_Status_pre()
  449. {
  450. unsigned char result = 0;
  451. switch (ShmCcsData->CommProtocol)
  452. {
  453. case V2GT_MSG_PROTOCOL_DIN70121: //0
  454. {
  455. result = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus_pre;
  456. break;
  457. }
  458. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  459. {
  460. result = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus_pre;
  461. break;
  462. }
  463. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  464. {
  465. result = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus_pre;
  466. break;
  467. }
  468. default:
  469. break;
  470. }
  471. return result;
  472. }
  473. /*===========================================================================
  474. FUNCTION: Update_V2G_Flow_Status
  475. DESCRIPTION:
  476. PRE-CONDITION:
  477. INPUT:
  478. OUTPUT:
  479. 1. V2gFlowStatus
  480. GLOBAL VARIABLES:
  481. 1. V2gFlowStatus
  482. =============================================================================*/
  483. int Update_V2G_Flow_Status(unsigned int state_new)
  484. {
  485. unsigned char state_now;
  486. char nameNow[64], nameNew[64];
  487. state_now = Check_V2G_Flow_Status();
  488. get_V2G_Status_Name(state_now, nameNow);
  489. get_V2G_Status_Name(state_new, nameNew);
  490. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE ||
  491. CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused == TRUE)
  492. {
  493. if (state_now != Performance_Timeout && //253
  494. state_now != Sequence_Timeout && //254
  495. state_now != Other_Fault) //255
  496. {
  497. SAVE_SYS_LOG_MSG_EVCOMM("[Warning]state-%s(%d) change: ignored (End_Process_inused:%d, FW_Update_Task_inused:%d)\n",
  498. nameNew, state_new,
  499. EVCOMM_SYS_INFO.End_Process_inused,
  500. CSUCOMMDC_TASK_FLAG.FW_Update_Task_inused);
  501. return -1;
  502. }
  503. }
  504. if (state_now != state_new)
  505. {
  506. //Step 1: Check if Error Occours
  507. if (state_now == Performance_Timeout || //253
  508. state_now == Sequence_Timeout || //254
  509. state_now == Other_Fault) //255
  510. {
  511. if (state_new != IDLE)
  512. {
  513. if (EVCOMM_SYS_INFO.State_Change_Ignored_Notice == FALSE)
  514. {
  515. EVCOMM_SYS_INFO.State_Change_Ignored_Notice = TRUE;
  516. SAVE_SYS_LOG_MSG_EVCOMM("[Warning]state-%s(%d) change: ignored(now in error state-%s(%d))\n",
  517. nameNow, state_new,
  518. nameNew, state_now);
  519. }
  520. return -1;
  521. }
  522. }
  523. //Updating the state formally.
  524. SAVE_SYS_LOG_MSG_EVCOMM("%s(%02d) >> %s(%02d)\n",
  525. nameNow, state_now,
  526. nameNew, state_new);
  527. V2gFlowStatus = state_new;
  528. state_now = state_new;
  529. switch (ShmCcsData->CommProtocol)
  530. {
  531. case V2GT_MSG_PROTOCOL_DIN70121: //0
  532. {
  533. ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus;
  534. ShmCcsData->V2GMessage_DIN70121.PresentMsgFlowStatus = V2gFlowStatus;
  535. break;
  536. }
  537. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  538. {
  539. ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus;
  540. ShmCcsData->V2GMessage_ISO15118_2014.PresentMsgFlowStatus = V2gFlowStatus;
  541. break;
  542. }
  543. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  544. {
  545. ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus_pre = ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus;
  546. ShmCcsData->V2GMessage_ISO15118_2018.PresentMsgFlowStatus = V2gFlowStatus;
  547. break;
  548. }
  549. default:
  550. break;
  551. }
  552. }
  553. return 0;
  554. }
  555. double DiffTimeb(struct timeb ST, struct timeb ET)
  556. {
  557. //return milli-second
  558. double StartTime, EndTime;
  559. double t_diff;
  560. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  561. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  562. t_diff = EndTime - StartTime;
  563. if (t_diff < 0)
  564. {
  565. return -1;
  566. }
  567. return t_diff;
  568. }
  569. double DiffTimeb_fork1_Error_Monitor(struct timeb ST, struct timeb ET)
  570. {
  571. //return milli-second
  572. static double StartTime, EndTime;
  573. static double t_diff;
  574. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  575. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  576. t_diff = EndTime - StartTime;
  577. if (t_diff < 0)
  578. {
  579. return -1;
  580. }
  581. return t_diff;
  582. }
  583. double DiffTimeb_fork2_Error_Monitor(struct timeb ST, struct timeb ET)
  584. {
  585. //return milli-second
  586. static double StartTime, EndTime;
  587. static double t_diff;
  588. StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
  589. EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
  590. t_diff = EndTime - StartTime;
  591. if (t_diff < 0)
  592. {
  593. return -1;
  594. }
  595. return t_diff;
  596. }
  597. /*===========================================================================
  598. FUNCTION: ShareMemory_Init
  599. DESCRIPTION:
  600. PRE-CONDITION:
  601. INPUT:
  602. OUTPUT:
  603. GLOBAL VARIABLES:
  604. =============================================================================*/
  605. int ShareMemory_Init()
  606. {
  607. int MeterSMId;
  608. //create ShmSysConfigAndInfo
  609. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
  610. {
  611. DEBUG_ERROR("ShareMemory_Init:shmget ShmSysConfigAndInfo NG");
  612. return 0;
  613. }
  614. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  615. {
  616. DEBUG_ERROR("ShareMemory_Init:shmat ShmSysConfigAndInfo NG\n");
  617. return 0;
  618. }
  619. //create ShmStatusCodeData
  620. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
  621. {
  622. DEBUG_ERROR("ShareMemory_Init:shmget ShmStatusCodeData NG");
  623. return 0;
  624. }
  625. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  626. {
  627. DEBUG_ERROR("ShareMemory_Init:shmat ShmStatusCodeData NG");
  628. return 0;
  629. }
  630. //create ShmCcsData
  631. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
  632. {
  633. DEBUG_ERROR("ShareMemory_Init:shmget ShmCcsData NG");
  634. return 0;
  635. }
  636. else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  637. {
  638. DEBUG_ERROR("ShareMemory_Init:shmat ShmCcsData NG");
  639. return 0;
  640. }
  641. //create ShmInternalComm
  642. if ((MeterSMId = shmget(ShmInternalCommKey, sizeof(struct InternalComm), IPC_CREAT | 0777)) < 0)
  643. {
  644. DEBUG_ERROR("ShareMemory_Init:shmget ShmInternalComm NG");
  645. return 0;
  646. }
  647. else if ((ShmInternalComm = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  648. {
  649. DEBUG_ERROR("ShareMemory_Init:shmat ShmInternalComm NG");
  650. return 0;
  651. }
  652. //Initial ShmCharger
  653. if ((MeterSMId = shmget(ShmChargerKey, sizeof(struct Charger), 0777)) < 0)
  654. {
  655. DEBUG_ERROR("shmget ShmChargerKey NG\r\n");
  656. return 0;
  657. }
  658. else if ((ShmCharger = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  659. {
  660. DEBUG_ERROR("shmat ShmChargerKey NG\r\n");
  661. return 0;
  662. }
  663. //[To-Do] The initialization here is reduntant and should be removed partially.
  664. //SHM_Init_supportedAppProtocolRes(ShmCcsData);
  665. //SHM_Init_din_SessionSetupRes(ShmCcsData);
  666. //SHM_Init_din_ServiceDiscoveryRes(ShmCcsData);
  667. //SHM_Init_din_ServiceAndPaymentSelectionRes(ShmCcsData);
  668. //SHM_Init_din_ContractAuthenticationRes(ShmCcsData);
  669. SHM_Init_din_ChargeParameterDiscoveryRes(ShmCcsData);
  670. SHM_Init_din_CableCheckRes(ShmCcsData);
  671. SHM_Init_din_PreChargeRes(ShmCcsData);
  672. SHM_Init_din_PowerDeliveryRes(ShmCcsData);
  673. SHM_Init_din_CurrentDemandRes(ShmCcsData);
  674. SHM_Init_din_WeldingDetectionRes(ShmCcsData);
  675. SHM_Init_din_SessionStopRes(ShmCcsData);
  676. return 1;
  677. }
  678. /*===========================================================================
  679. FUNCTION: GetEthMac
  680. DESCRIPTION:
  681. 1. Accessing current CsuMac address, if Eth = eth1
  682. 2. The address of eth1(for QCA7000) is a random number, which will be modified
  683. after each time of booting up system.
  684. PRE-CONDITION:
  685. INPUT:
  686. OUTPUT:
  687. GLOBAL VARIABLES:
  688. =============================================================================*/
  689. int GetEthMac(unsigned char *Eth, unsigned char *mac)
  690. {
  691. //Parameters:MAC,IP,Mask,Gateway
  692. int fd;
  693. unsigned char addr[18], Buffer[128];
  694. memset(Buffer, 0, sizeof(Buffer));
  695. sprintf((char*)Buffer, "cat /sys/class/net/%s/address > /mnt/GetEthInfo", Eth); //CsuMac (Eth = eth1)
  696. system((char*)Buffer);
  697. fd = open("/mnt/GetEthInfo", O_RDONLY);
  698. if(fd < 0)
  699. {
  700. system("rm -f /mnt/GetEthInfo");
  701. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "GetEthMac: MAC Address open error");
  702. return 0;
  703. }
  704. memset(mac, 0, 6);
  705. memset(addr, 0, sizeof(addr));
  706. read(fd, addr, 17);
  707. close(fd);
  708. system("rm -f /mnt/GetEthInfo");
  709. sscanf((char*)addr, "%02x:%02x:%02x:%02x:%02x:%02x", (uint32_t *)&mac[0], (uint32_t *)&mac[1], (uint32_t *)&mac[2], (uint32_t *)&mac[3], (uint32_t *)&mac[4], (uint32_t *)&mac[5]); //CsuMac (Eth = eth1)
  710. SAVE_SYS_LOG_MSG_EVCOMM("EVSE MACAddr(CsuMac): %02x:%02x:%02x:%02x:%02x:%02x\n",
  711. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  712. return 1;
  713. }
  714. /*===========================================================================
  715. FUNCTION: ReadAdcVolt
  716. DESCRIPTION:
  717. 1. fork1
  718. PRE-CONDITION:
  719. INPUT:
  720. OUTPUT:
  721. GLOBAL VARIABLES:
  722. =============================================================================*/
  723. float ReadAdcVolt(unsigned char AdcChannel)
  724. {
  725. //AIN0=CCS GUN Temp 1
  726. //AIN1=CCS GUN Temp 2
  727. //AIN2=CCS_Proximity/2
  728. //AIN3=pilot voltage
  729. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  730. return 0;
  731. #else
  732. if(AdcChannel == 3)
  733. {
  734. int fd,count,AvgTimes;
  735. unsigned char SampleBuf[4];
  736. float TmpVolt, MinSample, AvgSample = 0;
  737. fd = open("/sys/bus/iio/devices/iio\\:device0/in_voltage3_raw", O_RDONLY);
  738. if(fd > 0)
  739. {
  740. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  741. for(AvgTimes = 0; AvgTimes < 3; AvgTimes++) //period = 60~91 ms(renice -10, , CurrentDemand()) /*+++ 20200909, vern, extend detection time for interference ---*/
  742. {
  743. count = 0;
  744. MinSample = 2306;
  745. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  746. while(count < 40) //period = 21~42ms (renice -10, CurrentDemand()) /*+++ 20200909, vern, extend detection time for interference ---*/
  747. {
  748. //re-sampling period = 3~13ms (renice -10, SLAC())
  749. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  750. read(fd, SampleBuf, 4); //period = 3.2~10ms (renice -10, SLAC())
  751. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  752. TmpVolt = atoi((char*)SampleBuf);
  753. if((TmpVolt < 2306) && (TmpVolt > 0))//positive voltage
  754. {
  755. if(TmpVolt < MinSample)
  756. {
  757. MinSample = TmpVolt;
  758. }
  759. count++;
  760. }
  761. lseek(fd, 0, SEEK_SET);
  762. }
  763. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  764. AvgSample += MinSample;
  765. }
  766. AvgSample /= AvgTimes;
  767. close(fd);
  768. //system("echo 0 > /sys/class/gpio/gpio89/value"); //for test
  769. return ((0.954-(1.8*AvgSample/4095))/0.06);
  770. }
  771. else
  772. {
  773. return -1;
  774. }
  775. }
  776. else
  777. {
  778. FILE *fp;
  779. unsigned char str[64];
  780. unsigned char AdcValue[8];
  781. if(AdcChannel > 7)
  782. {
  783. return -1;
  784. }
  785. memset(str,0,sizeof(str));
  786. memset(AdcValue,0,sizeof(AdcValue));
  787. sprintf((char*)str, "cat /sys/bus/iio/devices/iio\\:device0/in_voltage%d_raw", AdcChannel);
  788. fp=popen((char*)str, "r");
  789. if(fgets((char*)AdcValue,sizeof(AdcValue),fp) == NULL)
  790. {
  791. pclose(fp);
  792. return -1;
  793. }
  794. pclose(fp);
  795. //Vin = Vref *D / (2^n - 1)
  796. return ((float)1.8*(float)atoi((char*)AdcValue))/4095;
  797. }
  798. #endif
  799. }
  800. /*===========================================================================
  801. FUNCTION: ReadAdcVolt
  802. DESCRIPTION:
  803. //AIN0=CCS GUN Temp 1
  804. //AIN1=CCS GUN Temp 2
  805. //AIN2=CCS_Proximity/2
  806. //AIN3=pilot voltage
  807. PRE-CONDITION:
  808. INPUT:
  809. OUTPUT:
  810. GLOBAL VARIABLES:
  811. =============================================================================*/
  812. float ReadAdcVolt_PP_fork3()
  813. {
  814. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  815. return 0;
  816. #else
  817. int fd, AvgTimes;
  818. unsigned char SampleBuf[4];
  819. float TmpVolt = 0;
  820. float AvgSample = 0;
  821. float V_pp = 0;
  822. fd = open("/sys/bus/iio/devices/iio\\:device0/in_voltage2_raw", O_RDONLY); //PP
  823. if(fd > 0)
  824. {
  825. for(AvgTimes = 0; AvgTimes < 5; AvgTimes++) //get 5 samples
  826. {
  827. read(fd, SampleBuf, 4);
  828. TmpVolt = atoi((char*)SampleBuf);
  829. lseek(fd, 0, SEEK_SET);
  830. AvgSample += TmpVolt;
  831. }
  832. close(fd);
  833. AvgSample /= AvgTimes;
  834. V_pp = (3.6*AvgSample)/4095; //PP
  835. #if 0
  836. printf("PP_adc = %.02f, PP_v = %.02f\n", AvgSample, V_pp);
  837. usleep(3000000); //300ms
  838. #endif
  839. usleep(20000); //20ms
  840. return V_pp;
  841. }
  842. else
  843. {
  844. return -1;
  845. }
  846. #endif
  847. }
  848. /*===========================================================================
  849. FUNCTION: Qca7kPowerReset
  850. DESCRIPTION:
  851. PRE-CONDITION:
  852. INPUT:
  853. OUTPUT:
  854. GLOBAL VARIABLES:
  855. =============================================================================*/
  856. void Qca7kPowerReset()
  857. {
  858. SAVE_SYS_LOG_MSG_EVCOMM("QCA7000 reset...\n");
  859. system("ifconfig eth1 down");
  860. usleep(500000);
  861. system("echo 0 > /sys/class/gpio/gpio115/value");
  862. usleep(500000);
  863. system("echo 1 > /sys/class/gpio/gpio115/value");
  864. usleep(500000);
  865. system("ifconfig eth1 up");
  866. usleep(500000);
  867. }
  868. /*===========================================================================
  869. FUNCTION: SwitchCpStateE
  870. DESCRIPTION:
  871. PRE-CONDITION:
  872. INPUT:
  873. OUTPUT:
  874. GLOBAL VARIABLES:
  875. =============================================================================*/
  876. int SwitchCpStateE(unsigned char OnOff)
  877. {
  878. /*
  879. * TODO: Request CP change to state E
  880. */
  881. if((OnOff != ENABLE) && (OnOff != DISABLE))
  882. {
  883. return -1;
  884. }
  885. struct ChargingInfoData *ccs;
  886. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  887. ccs->SwitchCpStateE_status = OnOff;
  888. //OnOff = 1 => switch State to E
  889. //OnOff = 0 => return noraml
  890. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  891. {
  892. if(OnOff == DISABLE)
  893. {
  894. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SwitchCpStateE: released\n");
  895. CSUCOMMAC_SHM.CpSetStateE = DISABLE;
  896. }
  897. else
  898. {
  899. OutputCpPwmDuty(100); //set CP duty as 100, firstly.
  900. CSUCOMMAC_SHM.CpSetStateE = ENABLE;
  901. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SwitchCpStateE: enabled!\n");
  902. }
  903. }
  904. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  905. {
  906. if(OnOff == DISABLE)
  907. {
  908. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SwitchCpStateE: released\n");
  909. system("echo 0 > /sys/class/gpio/gpio86/value");
  910. }
  911. else
  912. {
  913. OutputCpPwmDuty(100); //set CP duty as 100, firstly.
  914. system("echo 1 > /sys/class/gpio/gpio86/value");
  915. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SwitchCpStateE: enabled!\n");
  916. }
  917. }
  918. #endif
  919. if (ccs->SwitchCpStateE_status_pre != ccs->SwitchCpStateE_status)
  920. {
  921. SAVE_SYS_LOG_MSG_EVCOMM("SwitchCpStateE: %d >> %d\n",
  922. ccs->SwitchCpStateE_status_pre,
  923. ccs->SwitchCpStateE_status);
  924. ccs->SwitchCpStateE_status_pre = ccs->SwitchCpStateE_status;
  925. }
  926. return 0;
  927. }
  928. /*===========================================================================
  929. FUNCTION: OutputCpPwmDuty
  930. DESCRIPTION:
  931. PRE-CONDITION:
  932. INPUT:
  933. OUTPUT:
  934. GLOBAL VARIABLES:
  935. =============================================================================*/
  936. int OutputCpPwmDuty(unsigned char Duty)
  937. {
  938. #if ((CCS_ENERGY_TRANSFER_MODE != MODE_AC_SINGLE_PHASE_CORE) && (CCS_ENERGY_TRANSFER_MODE != MODE_AC_THREE_PHASE_CORE))
  939. int DutyInNanoSec;
  940. #endif
  941. struct ChargingInfoData *ccs;
  942. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  943. if((Duty < 0)||(Duty > 100))
  944. {
  945. return -1;
  946. }
  947. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  948. {
  949. CSUCOMMAC_SHM.CpSetPWMDuty = Duty;
  950. }
  951. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  952. {
  953. DutyInNanoSec = 10000 * Duty;
  954. sprintf((char*)buf_log_evcomm, "echo %d > /sys/class/pwm/pwmchip0/pwm0/duty_cycle", DutyInNanoSec);//nanoseconds
  955. system((char*)buf_log_evcomm);
  956. }
  957. #endif
  958. ccs->CpDuty = Duty;
  959. //CP Duty
  960. if (ccs->CpDuty != ccs->CpDuty_pre)
  961. {
  962. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  963. SAVE_SYS_LOG_MSG_EVCOMM("CP Duty: %d%% >> %d%%\n", ccs->CpDuty_pre, ccs->CpDuty);
  964. ccs->CpDuty_pre = ccs->CpDuty;
  965. }
  966. return 0;
  967. }
  968. /*===========================================================================
  969. FUNCTION: Check_Plugin_Status_Update_fork1
  970. DESCRIPTION:
  971. PRE-CONDITION:
  972. INPUT:
  973. OUTPUT:
  974. GLOBAL VARIABLES:
  975. =============================================================================*/
  976. //#if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  977. void Check_Plugin_Status_Update_fork1(struct ChargingInfoData *ccs)
  978. {
  979. if (ccs->ConnectorPlugIn != ccs->ConnectorPlugIn_new)
  980. {
  981. SAVE_SYS_LOG_MSG_EVCOMM("Plugin: %d >> %d (CP=%.2fV, PP=%.2fV)\n",
  982. ccs->ConnectorPlugIn,
  983. ccs->ConnectorPlugIn_new,
  984. ccs->CpVoltage,
  985. ccs->PpVoltage);
  986. ccs->ConnectorPlugIn_pre = ccs->ConnectorPlugIn;
  987. ccs->ConnectorPlugIn = ccs->ConnectorPlugIn_new;
  988. //ccs->CpVoltage_pre = ccs->CpVoltage;
  989. }
  990. }
  991. //#endif
  992. /*===========================================================================
  993. FUNCTION: ConnectorPlugIn
  994. DESCRIPTION:
  995. PRE-CONDITION:
  996. INPUT:
  997. OUTPUT:
  998. 0: Unplug
  999. 1: Plug-in
  1000. GLOBAL VARIABLES:
  1001. =============================================================================*/
  1002. int CheckConnectorPlugIn()
  1003. {
  1004. /*
  1005. * TODO: Return connector status depedon CP
  1006. */
  1007. static struct ChargingInfoData *ccs;
  1008. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1009. #if (CP_PROTECTION_MECHANISM == ENABLE)
  1010. return (int)ccs->ConnectorPlugIn;
  1011. #else
  1012. return TRUE;
  1013. #endif
  1014. }
  1015. /*===========================================================================
  1016. FUNCTION: Check_CP_State_Error_fork1
  1017. DESCRIPTION:
  1018. PRE-CONDITION:
  1019. INPUT:
  1020. OUTPUT:
  1021. GLOBAL VARIABLES:
  1022. =============================================================================*/
  1023. int Check_CP_State_Error_fork1(struct ChargingInfoData *ccs)
  1024. {
  1025. #if (CP_PROTECTION_MECHANISM == DISABLE)
  1026. {
  1027. return -1;
  1028. }
  1029. #endif
  1030. unsigned char state = 0;
  1031. #if ((CCS_ENERGY_TRANSFER_MODE != MODE_AC_SINGLE_PHASE_CORE) && (CCS_ENERGY_TRANSFER_MODE != MODE_AC_THREE_PHASE_CORE))
  1032. double time_diff = 0;
  1033. #endif
  1034. state = Check_V2G_Flow_Status();
  1035. //SLAC, SLAAC, SDP, ..., ChargeParameterDiscovery
  1036. if (state >= CM_SLAC_PARM_CONF && //by considering 15118(SLAC first)
  1037. state < ChargeParameterDiscoveryRequest &&
  1038. state != IDLE &&
  1039. state != CM_SET_KEY_REQ &&
  1040. state != CM_SET_KEY_CNF &&
  1041. state != CM_VALIDATE_REQ &&
  1042. state != CM_VALIDATE_CNF)
  1043. {
  1044. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  1045. {
  1046. if((ccs->CpState != 2) && (ccs->CpState != 3))
  1047. {
  1048. if (ccs->CpState_err == FALSE)
  1049. {
  1050. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][CP][Error]before CPD\n"); //CPD: ChargeParameterDiscoveryRequest
  1051. //CPD: ChargeParameterDiscovery
  1052. }
  1053. ccs->CpState_err = TRUE;
  1054. }
  1055. }
  1056. #else
  1057. {
  1058. if(ccs->CpState != 3)
  1059. {
  1060. if (ccs->CpState_err == FALSE)
  1061. {
  1062. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][CP][Error]before CPD\n"); //CPD: ChargeParameterDiscoveryRequest
  1063. //CPD: ChargeParameterDiscovery
  1064. }
  1065. ccs->CpState_err = TRUE;
  1066. }
  1067. }
  1068. #endif
  1069. }
  1070. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  1071. {
  1072. //ChargeParameterDiscovery
  1073. if(state >= ChargeParameterDiscoveryRequest && //35
  1074. state <= ChargeParameterDiscoveryResponse) //36
  1075. {
  1076. if(ccs->CpState != 3)
  1077. {
  1078. if (ccs->CpState_err == FALSE)
  1079. {
  1080. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CPD\n");
  1081. //PRC: Precharge
  1082. //CUD: CurrentDemand
  1083. }
  1084. ccs->CpState_err = TRUE;
  1085. }
  1086. }
  1087. //ChargingStatus
  1088. if(state >= ChargingStatusRequest && //43
  1089. state <= ChargingStatusResponse) //44
  1090. {
  1091. if(ccs->CpState != 4 && ccs->CpState != 5)
  1092. {
  1093. if (ccs->CpState_err == FALSE)
  1094. {
  1095. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CGS\n");
  1096. //PRC: Precharge
  1097. //CUD: CurrentDemand
  1098. }
  1099. ccs->CpState_err = TRUE;
  1100. }
  1101. }
  1102. }
  1103. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  1104. {
  1105. //ChargeParameterDiscovery, CableCheck
  1106. if (state >= ChargeParameterDiscoveryRequest && //35
  1107. state <= CableCheckResponse) //38
  1108. {
  1109. if(ccs->CableCheckPreCountDownDone == FALSE &&
  1110. state >= CableCheckRequest)
  1111. {
  1112. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  1113. time_diff = DiffTimeb_fork1_Error_Monitor(EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start, EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  1114. if(time_diff >= V2G_SECC_CP_Timeout_CableCheck) //2 sec
  1115. {
  1116. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][CP]check C(4),D(5): ON (%.02lf of %dms)\n",
  1117. time_diff,
  1118. V2G_SECC_CP_Timeout_CableCheck);
  1119. ccs->CableCheckPreCountDownDone = TRUE;
  1120. }
  1121. }
  1122. if(ccs->CableCheckPreCountDownDone == TRUE)
  1123. {
  1124. if(ccs->CpState != 4 && ccs->CpState != 5)
  1125. {
  1126. if (ccs->CpState_err == FALSE)
  1127. {
  1128. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CPD and CCK (after CNT)\n");
  1129. //CPD: ChargeParameterDiscovery
  1130. //CCK: CableCheck
  1131. //CNT: count down
  1132. }
  1133. ccs->CpState_err = TRUE;
  1134. }
  1135. }
  1136. else
  1137. {
  1138. if(ccs->CpState != 3 && ccs->CpState != 4 && ccs->CpState != 5)
  1139. {
  1140. if (ccs->CpState_err == FALSE)
  1141. {
  1142. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]CPD and CCK (before CNT)\n");
  1143. //CPD: ChargeParameterDiscovery
  1144. //CCK: CableCheck
  1145. //CNT: count down
  1146. }
  1147. ccs->CpState_err = TRUE;
  1148. }
  1149. }
  1150. }
  1151. //Precharge, CurrentDemand
  1152. if(state >= PreChargeRequest && //39
  1153. state <= CurrentDemandResponse) //46
  1154. {
  1155. if(ccs->CpState != 4 && ccs->CpState != 5)
  1156. {
  1157. if (ccs->CpState_err == FALSE)
  1158. {
  1159. SAVE_SYS_LOG_MSG_EVCOMM("[CP][Error]PRC and CUD\n");
  1160. //PRC: Precharge
  1161. //CUD: CurrentDemand
  1162. }
  1163. ccs->CpState_err = TRUE;
  1164. }
  1165. }
  1166. }
  1167. #endif
  1168. if(ccs->CpState_err == TRUE && ccs->CpState_err_logged == FALSE)
  1169. {
  1170. OutputCpPwmDuty(100);
  1171. //system("echo 1 > /sys/class/gpio/gpio89/value"); //for test
  1172. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1173. //CCS_SECC_CP_State_Error (023889)
  1174. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1175. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1176. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1177. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1178. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1179. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1180. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1181. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1182. SAVE_SYS_LOG_MSG_EVCOMM("[fork1][Error]CP(%d) Error in state %d(%d)\n",
  1183. ccs->CpState,
  1184. state,
  1185. ccs->CableCheckPreCountDownDone);
  1186. ccs->CpState_err_logged = TRUE;
  1187. }
  1188. return 0;
  1189. }
  1190. /*===========================================================================
  1191. FUNCTION: Check_CP_State_Update_fork1
  1192. DESCRIPTION:
  1193. PRE-CONDITION:
  1194. INPUT:
  1195. OUTPUT:
  1196. GLOBAL VARIABLES:
  1197. =============================================================================*/
  1198. //#if SAVE_SYS_LOG_MSG_EVCOMM_SWITCH == ENABLE
  1199. void Check_CP_State_Update_fork1(struct ChargingInfoData *ccs)
  1200. {
  1201. //CP State
  1202. if (ccs->CpState != ccs->CpState_pre)
  1203. {
  1204. SAVE_SYS_LOG_MSG_EVCOMM("CP State: %d >> %d (%.2fV)\n",
  1205. ccs->CpState_pre,
  1206. ccs->CpState,
  1207. ccs->CpVoltage);
  1208. ccs->CpState_pre = ccs->CpState;
  1209. }
  1210. }
  1211. //#endif
  1212. /*===========================================================================
  1213. FUNCTION: CP_Detection
  1214. DESCRIPTION:
  1215. 1. In order to detect CP in efficient response time, we creat an independent
  1216. thead for this procedure.
  1217. 2. The priority of this thread is set as the same as other tasks.
  1218. 3. fork1
  1219. PRE-CONDITION:
  1220. INPUT:
  1221. OUTPUT:
  1222. GLOBAL VARIABLES:
  1223. =============================================================================*/
  1224. void CP_Detection()
  1225. {
  1226. pid_t tmp = 0;
  1227. // struct timeb StartTime, EndTime;
  1228. #if ((CCS_ENERGY_TRANSFER_MODE != MODE_AC_SINGLE_PHASE_CORE) && (CCS_ENERGY_TRANSFER_MODE != MODE_AC_THREE_PHASE_CORE))
  1229. unsigned char Statetmp;
  1230. float TotalTmpVolt;
  1231. #endif
  1232. struct ChargingInfoData *ccs;
  1233. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1234. if(CP_Detection_Pid == 0)
  1235. {
  1236. tmp = fork();
  1237. if(tmp > 0)
  1238. {
  1239. CP_Detection_Pid = tmp;
  1240. #if 1
  1241. unsigned char buf[64];
  1242. memset(buf, 0, sizeof(buf));
  1243. //sprintf((char*)buf, "renice -20 -p %d", tmp);
  1244. sprintf((char*)buf, "renice -10 -p %d", tmp);
  1245. system((char*)buf);
  1246. #endif
  1247. return;
  1248. }
  1249. }
  1250. while(1)
  1251. {
  1252. //ADC_Voltage = (1+RE62/RE63)*0.9 - (RE62/RE63)*Pilot_Voltage, RE62/RE63=0.06
  1253. //=>Pilot_Voltage=(0.954-ADC_Voltage)/0.06
  1254. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_AC_SINGLE_PHASE_CORE) || (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE))
  1255. {
  1256. ccs->CpVoltage = ShmInternalComm->AC_CpPositiveVoltage;
  1257. ccs->CpState = ShmInternalComm->AC_CpPresentState;
  1258. }
  1259. #else //CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED
  1260. {
  1261. TotalTmpVolt = ReadAdcVolt(3);
  1262. ccs->CpVoltage = TotalTmpVolt;
  1263. if (ccs->CpVoltage_pre != ccs->CpVoltage)
  1264. {
  1265. ccs->CpVoltage_pre = ccs->CpVoltage;
  1266. }
  1267. //printf("TotalTmpVolt = %.02f\n", TotalTmpVolt);
  1268. //If CP voltage is higer than 13.5V
  1269. if(TotalTmpVolt >= 13.5)
  1270. {
  1271. //Pilot Error
  1272. if((ccs->CpState == 1) &&
  1273. (TotalTmpVolt < 13.75))
  1274. {
  1275. //V_cp = 13.5 ~ 13.75
  1276. Statetmp = 1;
  1277. }
  1278. else
  1279. {
  1280. //V_cp = 13.5 ~
  1281. Statetmp = 8;
  1282. }
  1283. }
  1284. else if((TotalTmpVolt >= 10.5) && (TotalTmpVolt < 13.5)) //V_cp = 10.5 ~ 13.5
  1285. {
  1286. //State A (12V)
  1287. if((ccs->CpState >= 2) &&
  1288. (ccs->CpState <= 3) &&
  1289. (TotalTmpVolt < 10.75))
  1290. {
  1291. if((ccs->CpDuty >= 5) &&
  1292. (ccs->CpDuty < 100))
  1293. {
  1294. Statetmp = 3;
  1295. }
  1296. else
  1297. {
  1298. Statetmp = 2;
  1299. }
  1300. }
  1301. else if((ccs->CpState == 8) &&
  1302. (TotalTmpVolt >= 13.25))
  1303. {
  1304. Statetmp = 8;
  1305. }
  1306. else
  1307. {
  1308. Statetmp = 1;
  1309. }
  1310. }
  1311. else if((TotalTmpVolt >= 7.5) && (TotalTmpVolt < 10.5))
  1312. {
  1313. //State B (9V)
  1314. if((ccs->CpState == 4) && (TotalTmpVolt < 7.75))
  1315. {
  1316. Statetmp = 4;
  1317. }
  1318. else if((ccs->CpState == 1) && (TotalTmpVolt >= 10.25))
  1319. {
  1320. Statetmp = 1;
  1321. }
  1322. else
  1323. {
  1324. if((ccs->CpDuty >= 5) && (ccs->CpDuty < 100))
  1325. {
  1326. Statetmp = 3;
  1327. }
  1328. else
  1329. {
  1330. Statetmp = 2;
  1331. }
  1332. }
  1333. }
  1334. else if((TotalTmpVolt >= 4.5) && (TotalTmpVolt < 7.5))
  1335. {
  1336. //State C (6V)
  1337. if((ccs->CpState == 5) && (TotalTmpVolt < 4.75))
  1338. {
  1339. Statetmp = 5;
  1340. }
  1341. else if((ccs->CpState >= 2) && (ccs->CpState <= 3) && (TotalTmpVolt >= 7.25))
  1342. {
  1343. if((ccs->CpDuty >= 5)&&(ccs->CpDuty < 100))
  1344. {
  1345. Statetmp = 3;
  1346. }
  1347. else
  1348. {
  1349. Statetmp = 2;
  1350. }
  1351. }
  1352. else
  1353. {
  1354. Statetmp = 4;
  1355. }
  1356. }
  1357. else if((TotalTmpVolt >= 1.5) && (TotalTmpVolt < 4.5))
  1358. {
  1359. //State D (3V)
  1360. if((ccs->CpState == 6)&&(TotalTmpVolt < 1.75))
  1361. {
  1362. Statetmp = 6;
  1363. }
  1364. else if((ccs->CpState == 4)&&(TotalTmpVolt >= 4.25))
  1365. {
  1366. Statetmp = 4;
  1367. }
  1368. else
  1369. {
  1370. Statetmp = 5;
  1371. }
  1372. }
  1373. else if((TotalTmpVolt >= -1.5) && (TotalTmpVolt < 1.5)) //V_cp = -1.5V ~ 1.5V
  1374. {
  1375. //State E (0V)
  1376. if((ccs->CpState == 8) &&
  1377. (TotalTmpVolt < -1.25))
  1378. {
  1379. Statetmp = 8;
  1380. }
  1381. else if((ccs->CpState == 5) &&
  1382. (TotalTmpVolt >= 1.25))
  1383. {
  1384. Statetmp = 5;
  1385. }
  1386. else
  1387. {
  1388. Statetmp = 6;
  1389. }
  1390. }
  1391. else if((TotalTmpVolt >= -13.5) && (TotalTmpVolt < -10.5)) //V_cp = -10.5V ~ -13.5V
  1392. {
  1393. //State F (-12V)
  1394. if((ccs->CpState == 8) &&
  1395. (TotalTmpVolt >= -10.75))
  1396. {
  1397. Statetmp = 8;
  1398. }
  1399. else
  1400. {
  1401. Statetmp = 7;
  1402. }
  1403. }
  1404. else
  1405. {
  1406. //null
  1407. }
  1408. ccs->CpState = Statetmp;
  1409. }
  1410. #endif
  1411. Check_CP_State_Update_fork1(ccs);
  1412. Check_CP_State_Error_fork1(ccs);
  1413. //Updating Plugin status
  1414. #if (PP_PROTECTION_MECHANISM == ENABLE)
  1415. if((ccs->CpState >= 2 ) && (ccs->CpState <= 5 ) && (ccs->PpVoltage >= 1.0)) //PP >= 1.0V
  1416. #else
  1417. if((ccs->CpState >= 2 ) && (ccs->CpState <= 5 ))
  1418. #endif
  1419. {
  1420. ccs->ConnectorPlugIn_new = TRUE;
  1421. }
  1422. else
  1423. {
  1424. ccs->ConnectorPlugIn_new = FALSE;
  1425. OutputCpPwmDuty(100);
  1426. }
  1427. Check_Plugin_Status_Update_fork1(ccs);
  1428. //ftime(&EndTime);
  1429. //DEBUG_PRINTF_EVCOMM_DETAIL("duration:%.02lf\n", DiffTimeb(StartTime, EndTime));
  1430. usleep(1000);
  1431. }//while
  1432. }
  1433. /*===========================================================================
  1434. FUNCTION: PP_Detection
  1435. DESCRIPTION:
  1436. 0. SeccComm fork3
  1437. 1. In order to detect CP in efficient response time, we creat an independent
  1438. thead for this procedure.
  1439. 2. The priority of this thread is set as the same as other tasks.
  1440. PRE-CONDITION:
  1441. INPUT:
  1442. OUTPUT:
  1443. GLOBAL VARIABLES:
  1444. =============================================================================*/
  1445. void PP_Detection()
  1446. {
  1447. pid_t tmp = 0;
  1448. // struct timeb StartTime, EndTime;
  1449. #if ((CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED))
  1450. //unsigned char Statetmp;
  1451. #endif
  1452. float TotalTmpVolt;
  1453. if(PP_Detection_Pid == 0)
  1454. {
  1455. tmp = fork();
  1456. if(tmp > 0)
  1457. {
  1458. PP_Detection_Pid = tmp;
  1459. #if 0
  1460. unsigned char buf[64];
  1461. memset(buf, 0, sizeof(buf));
  1462. sprintf((char*)buf, "renice -20 -p %d", tmp);
  1463. system(buf);
  1464. #endif
  1465. return;
  1466. }
  1467. }
  1468. while(1)
  1469. {
  1470. TotalTmpVolt = ReadAdcVolt_PP_fork3();
  1471. EVCOMM_SYS_INFO.PpVoltage = TotalTmpVolt;
  1472. if (EVCOMM_SYS_INFO.PpVoltage_pre != EVCOMM_SYS_INFO.PpVoltage)
  1473. {
  1474. if ((EVCOMM_SYS_INFO.PpVoltage_pre < 0.5 && EVCOMM_SYS_INFO.PpVoltage >= 1.0) ||
  1475. (EVCOMM_SYS_INFO.PpVoltage_pre >= 1.0 && EVCOMM_SYS_INFO.PpVoltage < 0.5))
  1476. {
  1477. SAVE_SYS_LOG_MSG_EVCOMM("[fork3]PP(%.2f >> %.2fV)\n",
  1478. EVCOMM_SYS_INFO.PpVoltage_pre,
  1479. EVCOMM_SYS_INFO.PpVoltage);
  1480. EVCOMM_SYS_INFO.PpVoltage_pre = EVCOMM_SYS_INFO.PpVoltage;
  1481. }
  1482. }
  1483. #if 0
  1484. sleep(5);
  1485. printf("V_pp = %.02f\n", TotalTmpVolt);
  1486. #endif
  1487. usleep(1000);
  1488. }//while
  1489. }
  1490. /*===========================================================================
  1491. FUNCTION: Error_Monitor
  1492. DESCRIPTION:
  1493. 1. This function only works in SeccComm fork2.
  1494. PRE-CONDITION:
  1495. INPUT:
  1496. OUTPUT:
  1497. GLOBAL VARIABLES:
  1498. =============================================================================*/
  1499. void Error_Monitor()
  1500. {
  1501. pid_t tmp = 0;
  1502. double time_diff = 0;
  1503. unsigned char status = 0;
  1504. struct ChargingInfoData *ccs;
  1505. ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  1506. if(Error_Monitor_Pid == 0)
  1507. {
  1508. tmp = fork(); //SeccComm fork2
  1509. if(tmp > 0)
  1510. {
  1511. Error_Monitor_Pid = tmp;
  1512. #if 0
  1513. unsigned char buf[64];
  1514. memset(buf, 0, sizeof(buf));
  1515. sprintf((char*)buf, "renice -20 -p %d", tmp);
  1516. system(buf);
  1517. #endif
  1518. return;
  1519. }
  1520. }
  1521. while(1)
  1522. {
  1523. //Step 0
  1524. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  1525. {
  1526. //If the End_Process is in processing, disable Error_Monitor.
  1527. continue;
  1528. }
  1529. //Step1 1: Check and Response to Plugin Status
  1530. if(CheckConnectorPlugIn() == FALSE)
  1531. {
  1532. status = Check_V2G_Flow_Status();
  1533. if (status > IDLE &&
  1534. status < Performance_Timeout &&
  1535. status != CM_SET_KEY_REQ &&
  1536. status != CM_SET_KEY_CNF &&
  1537. EVCOMM_SYS_INFO.End_Process_inused == FALSE)
  1538. {
  1539. #if (CP_PROTECTION_MECHANISM == ENABLE)
  1540. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[fork2] Emergency Stop (due to Connector is plugged out during communication.)");
  1541. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Plug out Error => End_Process\n");
  1542. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1543. //CCS_SECC_CP_State_Error (023889)
  1544. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1545. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1546. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1547. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1548. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1549. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1550. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1551. End_Process();
  1552. #else
  1553. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "CP_PROTECTION_MECHANISM is disabled. Emergency Stop: skipped" );
  1554. #endif
  1555. }
  1556. }
  1557. //Step 2: Check for V2G_SECC_Sequence_Timeout
  1558. //#if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  1559. #if 1
  1560. status = Check_V2G_Flow_Status();
  1561. if (status >= SupportedAppProtocolRequest &&
  1562. status < SessionStopRequest)
  1563. {
  1564. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_End);
  1565. time_diff = DiffTimeb_fork2_Error_Monitor(EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start, EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_End);
  1566. if(time_diff > V2G_SECC_Sequence_Timeout) //60s
  1567. {
  1568. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]V2G_SECC_Sequence_Timeout in state %d - (%.02lf of %d ms)\n",
  1569. status,
  1570. time_diff,
  1571. V2G_SECC_Sequence_Timeout);
  1572. Update_V2G_Flow_Status(Sequence_Timeout);
  1573. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1574. //CCS_SECC_TIMEOUT_V2G_Sequence_Time (023844)
  1575. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1576. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1577. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1578. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1579. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  1580. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  1581. End_Process();
  1582. break;
  1583. }
  1584. else if (time_diff > 4000) //4s
  1585. {
  1586. //Check for CSU command of "Stop by EVSE"
  1587. if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_Shutdown)
  1588. {
  1589. SAVE_SYS_LOG_MSG_EVCOMM("[Error_Monitor]EVSE_Shutdown\n");
  1590. Update_V2G_Flow_Status(Other_Fault);
  1591. }
  1592. else if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_EmergencyShutdown)
  1593. {
  1594. SAVE_SYS_LOG_MSG_EVCOMM("[Error_Monitor]EVSE_EmergencyShutdown\n");
  1595. Update_V2G_Flow_Status(Other_Fault);
  1596. }
  1597. else if (ShmInternalComm->ChargingPermission == FALSE)
  1598. {
  1599. if (status >= ChargeParameterDiscoveryRequest) //&& status < SessionStopRequest
  1600. {
  1601. SAVE_SYS_LOG_MSG_EVCOMM("[Error_Monitor]ChargingPermission = FALSE\n");
  1602. Update_V2G_Flow_Status(Other_Fault);
  1603. }
  1604. }
  1605. else
  1606. {
  1607. //null
  1608. }
  1609. }
  1610. else
  1611. {
  1612. //null
  1613. }
  1614. }
  1615. #endif
  1616. //Step 3: Check and Response to Error V2gFlowStatus
  1617. status = Check_V2G_Flow_Status();
  1618. if (status == Performance_Timeout ||
  1619. status == Sequence_Timeout ||
  1620. status == Other_Fault)
  1621. {
  1622. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Timeout or Fault State(%d) => End_Process\n", status);
  1623. //Normal Stop
  1624. //alarm and duty to 100%
  1625. //OutputCpPwmDuty(100);
  1626. //SwitchCpStateE(ENABLE); //Set CP duty as 100% and set CP state as E (0V).
  1627. //[Joseph/ To-Do] Set State E (0V) via GPIO setting
  1628. End_Process();
  1629. }
  1630. //Step 4: Check and Response to CP State Error
  1631. if(ccs->CpState_err == TRUE)
  1632. {
  1633. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]CP Error => End_Process\n");
  1634. Update_V2G_Flow_Status(Other_Fault);
  1635. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1636. //CCS_SECC_CP_State_Error (023889)
  1637. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1638. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1639. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1640. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1641. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  1642. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1643. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1644. End_Process();
  1645. }
  1646. //Step 5: Check and Response to Shutdown Commnad from CSU
  1647. if (EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_Shutdown ||
  1648. EVCOMM_SYS_INFO.DC_EVSEStatus == EVSE_EmergencyShutdown)
  1649. {
  1650. if (Check_V2G_Flow_Status() <= SLACC_SDP_TCP_Connection)
  1651. {
  1652. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]EVSE Shutdown(%d) => End_Process\n", EVCOMM_SYS_INFO.DC_EVSEStatus);
  1653. Update_V2G_Flow_Status(Other_Fault);
  1654. End_Process();
  1655. }
  1656. }
  1657. //Step 6: Check and Response to SessionStop
  1658. status = Check_V2G_Flow_Status();
  1659. if (status == SessionStopResponse)
  1660. {
  1661. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]SessionStopResponse => End_Process\n");
  1662. End_Process();
  1663. }
  1664. //Step 7: Check for ChargingPermission from TRUE to FALSE before V2G Messages
  1665. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  1666. if ((ShmInternalComm->ChargingPermission == FALSE) &&
  1667. (ShmInternalComm->ChargingPermission_pre >= 1) &&
  1668. (ccs->CpState >= 3) && (ccs->CpState <=5))
  1669. {
  1670. if (status >= CM_SLAC_PARM_REQ &&
  1671. status != CM_SET_KEY_REQ &&
  1672. status != CM_SET_KEY_CNF &&
  1673. status <= SLACC_SDP_TCP_Connection)
  1674. {
  1675. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Permission OFF before V2G msg(%d) => End_Process\n", ShmInternalComm->ChargingPermission);
  1676. Update_V2G_Flow_Status(Other_Fault);
  1677. End_Process();
  1678. }
  1679. }
  1680. //Step 8: DC OVP Protection
  1681. if (CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED &&
  1682. status > CableCheckResponse &&
  1683. status <= SessionStopRequest &&
  1684. status != ChargingStatusRequest &&
  1685. status != ChargingStatusResponse &&
  1686. EVCOMM_SYS_INFO.EvBatteryMaxVoltage != 0)
  1687. {
  1688. //Part A: OVP Protection
  1689. if (EVCOMM_SYS_INFO.PresentChargingVoltage >= (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02)) // 2%
  1690. {
  1691. SAVE_SYS_LOG_MSG_EVCOMM("[fork2][Error]OVP => End_Process (%.02f > %.02f)\n",
  1692. EVCOMM_SYS_INFO.PresentChargingVoltage,
  1693. (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02));
  1694. Update_V2G_Flow_Status(Other_Fault);
  1695. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1696. //System CCS output OVP (012219)
  1697. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1698. ShmStatusCodeData->PresentStatusCode[0][1] = 1;
  1699. ShmStatusCodeData->PresentStatusCode[0][2] = 2;
  1700. ShmStatusCodeData->PresentStatusCode[0][3] = 2;
  1701. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  1702. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1703. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1704. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1705. End_Process();
  1706. }
  1707. //Part B: Over Voltage Request Protection
  1708. if (EVCOMM_SYS_INFO.EvBatterytargetVoltage >= (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02))
  1709. {
  1710. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Over V Req => End_Process (%.02f > %.02f)\n",
  1711. EVCOMM_SYS_INFO.EvBatterytargetVoltage,
  1712. (EVCOMM_SYS_INFO.EvBatteryMaxVoltage * 1.02));
  1713. Update_V2G_Flow_Status(Other_Fault);
  1714. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1715. //System CCS output OVP (012219)
  1716. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1717. ShmStatusCodeData->PresentStatusCode[0][1] = 1;
  1718. ShmStatusCodeData->PresentStatusCode[0][2] = 2;
  1719. ShmStatusCodeData->PresentStatusCode[0][3] = 2;
  1720. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  1721. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  1722. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1723. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1724. End_Process();
  1725. }
  1726. }
  1727. //Step 9: Check 60V
  1728. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  1729. if (CCS_ENERGY_TRANSFER_MODE == MODE_DC_EXTENDED &&
  1730. ShmInternalComm->ChargingPermission >= 1 &&
  1731. status < CableCheckRequest)
  1732. {
  1733. if (EVCOMM_SYS_INFO.PresentChargingVoltage >= 60) //60V
  1734. {
  1735. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]DC Output Voltage is over 60V => End_Process\n");
  1736. Update_V2G_Flow_Status(Other_Fault);
  1737. //Update_ShmStatusCode(); //[To-Do] to be implemented
  1738. //CCS_SECC_Unexpected_60V_Before_Charing_Error (023890)
  1739. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  1740. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  1741. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  1742. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  1743. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  1744. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  1745. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  1746. //Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  1747. End_Process();
  1748. }
  1749. }
  1750. //Step 10: Check if the connector is unplug from plugin
  1751. if (EVCOMM_SYS_INFO.ConnectorPlugIn_pre == TRUE && EVCOMM_SYS_INFO.ConnectorPlugIn == FALSE)
  1752. {
  1753. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Unplug Reset => End_Process\n");
  1754. Update_V2G_Flow_Status(Other_Fault);
  1755. End_Process();
  1756. }
  1757. usleep(1000);
  1758. }//while
  1759. }
  1760. /*===========================================================================
  1761. FUNCTION: SendSetKey
  1762. DESCRIPTION:
  1763. PRE-CONDITION:
  1764. INPUT:
  1765. OUTPUT:
  1766. GLOBAL VARIABLES:
  1767. =============================================================================*/
  1768. int SendSetKey()
  1769. {
  1770. int i = 0;
  1771. unsigned char nRandValue = 0x0;
  1772. unsigned char ConstString[16] = "PhihongKey000000";
  1773. memset(&SendMmePacket,0,sizeof(struct MmeHeader));
  1774. memcpy(SendMmePacket.ODA,QcaMac,6);
  1775. memcpy(SendMmePacket.OSA,CsuMac,6);
  1776. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  1777. SendMmePacket.MMV = 0x01;
  1778. SendMmePacket.MMTYPE = MMTYPE_CM_SET_KEY_REQ;
  1779. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  1780. SendMmePacketSize = 0;
  1781. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01;//Fixed value (0x01) to indicate ��NMK��
  1782. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,4);//My Nonce, Fixed value(0x00000000), encrypted payload not used
  1783. SendMmePacketSize+=4;
  1784. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,4);//Your Nonce, Fixed value(0x00000000), encrypted payload not used
  1785. SendMmePacketSize+=4;
  1786. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x04;//PID, Fixed value (0x04) to indicate ��HLE protocol��
  1787. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,2);//PRN, Fixed value(0x00), encrypted payload not used
  1788. SendMmePacketSize+=2;
  1789. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00;//PMN, Fixed value(0x00) encrypted payload not used
  1790. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01;//CCo Capablility
  1791. srand(time(NULL));
  1792. for (i = 10; i < 16; i++)
  1793. {
  1794. nRandValue = (rand()%62) + 1;
  1795. if((nRandValue>=0)&&(nRandValue<=9)) // 0 ~ 9
  1796. {
  1797. ConstString[i]= nRandValue + 0x30;
  1798. }
  1799. else if((nRandValue>=10)&&(nRandValue<=35)) // A ~ Z
  1800. {
  1801. ConstString[i]= nRandValue -10 + 0x41;
  1802. }
  1803. else if((nRandValue>=36)&&(nRandValue<=61)) // a ~ z
  1804. {
  1805. ConstString[i]= nRandValue -37 + 0x61;
  1806. }
  1807. else
  1808. {
  1809. ConstString[i]= 0x30;
  1810. }
  1811. }
  1812. memset(NewNmkKey, 0, sizeof(NewNmkKey));
  1813. memset(Nid, 0, sizeof(Nid));
  1814. HPAVKeyNMK(NewNmkKey, (char*)ConstString);
  1815. HPAVKeyNID(Nid, NewNmkKey, DEFAULT_LEVEL);
  1816. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize, Nid, sizeof(Nid)); //NID, 54 LSBs contain the NID 2 MSBs = 0b00
  1817. SendMmePacketSize += sizeof(Nid);
  1818. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01;//NewEKS,Fixed value (0x01)to indicate ��NMK��
  1819. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,NewNmkKey,sizeof(NewNmkKey));//NewKey
  1820. SendMmePacketSize += sizeof(NewNmkKey);
  1821. SendMmePacketSize += 19; //the size before MMENTRY
  1822. SAVE_SYS_LOG_MSG_EVCOMM("QCA7000 [TX]CM_SET_KEY_REQ\n");
  1823. i = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  1824. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  1825. DEBUG_PRINTF_EVCOMM_DETAIL("SendSetKey: send size: %d\n",i);
  1826. return 0;
  1827. }
  1828. /*===========================================================================
  1829. FUNCTION: GetQca7kMac
  1830. DESCRIPTION:
  1831. PRE-CONDITION:
  1832. INPUT:
  1833. OUTPUT:
  1834. GLOBAL VARIABLES:
  1835. =============================================================================*/
  1836. int GetQca7kMac()
  1837. {
  1838. struct QcaVendorMmeHeader SendPacket;
  1839. SAVE_SYS_LOG_MSG_EVCOMM("Req for QCA7K MacAddr\n");
  1840. memset(&SendPacket, 0, sizeof(struct QcaVendorMmeHeader));
  1841. memset(SendPacket.ODA, 0xFF, 6); //broadcast
  1842. memcpy(SendPacket.OSA, CsuMac, 6);
  1843. SendPacket.MTYPE = htons(EtherType_HomePlug);
  1844. SendPacket.MMV = 0x00;
  1845. SendPacket.MMTYPE = MMTYPE_VENDOR_VS_NW_INFO;
  1846. SendPacket.OUI[0] = 0x00;
  1847. SendPacket.OUI[1] = 0xB0;
  1848. SendPacket.OUI[2] = 0x52;
  1849. DEBUG_PRINTF_EVCOMM_DETAIL("GetQca7kMac: send size: %d\n", sendto(RawSock, &SendPacket, 20, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll)));
  1850. return 0;
  1851. }
  1852. /*===========================================================================
  1853. FUNCTION: Array_Check_All_Zero
  1854. DESCRIPTION:
  1855. PRE-CONDITION:
  1856. INPUT:
  1857. OUTPUT:
  1858. result:
  1859. (1) TRUE: all zero
  1860. (2) FALSE: not all zero
  1861. GLOBAL VARIABLES:
  1862. =============================================================================*/
  1863. int Array_Check_All_Zero(unsigned char *ptr, int size)
  1864. {
  1865. int result = TRUE;
  1866. int i = 0;
  1867. for (i = 0; i < size; i++)
  1868. {
  1869. if (ptr[i] != 0)
  1870. {
  1871. result = FALSE;
  1872. break;
  1873. }
  1874. }
  1875. return result;
  1876. }
  1877. /*===========================================================================
  1878. FUNCTION: Array_Compare_Identity
  1879. DESCRIPTION:
  1880. PRE-CONDITION:
  1881. INPUT:
  1882. OUTPUT:
  1883. result = FALSE (not identical)
  1884. result = TRUE (identical)
  1885. GLOBAL VARIABLES:
  1886. =============================================================================*/
  1887. int Array_Compare_Identity(unsigned char *ptrA, unsigned char *ptrB, int size)
  1888. {
  1889. int result = TRUE;
  1890. int i = 0;
  1891. for (i = 0; i < size; i++)
  1892. {
  1893. if (ptrA[i] != ptrB[i])
  1894. {
  1895. result = FALSE;
  1896. #if 0
  1897. sprintf((char*)buf_log_evcomm,
  1898. "[Array_Compare_Identity]%02X%02X%02X%02X%02X%02X,%02X%02X%02X%02X%02X%02X(%d)\n",
  1899. ptrA[0], ptrA[1], ptrA[2], ptrA[3], ptrA[4], ptrA[5],
  1900. ptrB[0], ptrB[1], ptrB[2], ptrB[3], ptrB[4], ptrB[5],
  1901. result);
  1902. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  1903. #endif
  1904. break;
  1905. }
  1906. }
  1907. return result;
  1908. }
  1909. /*===========================================================================
  1910. FUNCTION: SLAC_DB_Search_EvMac_idx
  1911. DESCRIPTION:
  1912. PRE-CONDITION:
  1913. INPUT:
  1914. OUTPUT:
  1915. idx = -1 (not found)
  1916. GLOBAL VARIABLES:
  1917. =============================================================================*/
  1918. int SLAC_DB_Search_EvMac_idx(struct EVCC_SLAC_DATA_TYPE *evcc, unsigned char *EvMac_in)
  1919. {
  1920. int idx = -1;
  1921. int i = 0;
  1922. if (evcc->arrayLen == 0)
  1923. {
  1924. //printf("[SLAC_DB_Search_EvMac_idx]arrayLen is empty (%d)\n", evcc->arrayLen);
  1925. //no need to search
  1926. }
  1927. else if (evcc->arrayLen > EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE)
  1928. {
  1929. //error
  1930. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]DB length(%d) > %d\n",
  1931. evcc->arrayLen,
  1932. EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE);
  1933. evcc->arrayLen = 0; //reset
  1934. }
  1935. else
  1936. {
  1937. //start searching
  1938. for (i = 0; i < evcc->arrayLen; i++)
  1939. {
  1940. //printf("[SLAC_DB_Search_EvMac_idx]checking DB[%d]...\n", i);
  1941. if (Array_Compare_Identity(evcc->array[i].EvMac, EvMac_in, SLAC_EVMAC_LENGTH) == TRUE)
  1942. {
  1943. //printf("[SLAC_DB_Search_EvMac_idx]identical at DB[%d]...\n", i);
  1944. idx = i;
  1945. break;
  1946. }
  1947. }
  1948. }
  1949. //printf("[SLAC_DB_Search_EvMac_idx]return = %d\n", idx);
  1950. return idx;
  1951. }
  1952. /*===========================================================================
  1953. FUNCTION: SLAC_DB_Check_EvMac_RunID_Matching
  1954. DESCRIPTION:
  1955. PRE-CONDITION:
  1956. INPUT:
  1957. OUTPUT:
  1958. res = FALSE (unmatched)
  1959. res = TRUE (matched)
  1960. GLOBAL VARIABLES:
  1961. =============================================================================*/
  1962. int SLAC_DB_Check_EvMac_RunID_Matching(struct EVCC_SLAC_DATA_TYPE *evcc, unsigned char *EvMac_in, unsigned char *RunID_in)
  1963. {
  1964. int res = FALSE;
  1965. int idx = -1;
  1966. idx = SLAC_DB_Search_EvMac_idx(evcc, EvMac_in);
  1967. if (idx >= 0)
  1968. {
  1969. res = Array_Compare_Identity(evcc->array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH);
  1970. }
  1971. else
  1972. {
  1973. //not found the EvMac data in DB
  1974. res = FALSE;
  1975. }
  1976. return res;
  1977. }
  1978. /*===========================================================================
  1979. FUNCTION: SLAC_DB_Add
  1980. DESCRIPTION:
  1981. 1. Saving each CM_SLAC_PARM_REQ data into EVCC database if its
  1982. EvMac and RunID data are different, respectively.
  1983. PRE-CONDITION:
  1984. INPUT:
  1985. OUTPUT:
  1986. idx = saved index (must be a positive value)
  1987. GLOBAL VARIABLES:
  1988. =============================================================================*/
  1989. int SLAC_DB_Add(unsigned char *EvMac_in, unsigned char *RunID_in)
  1990. {
  1991. int idx = -1;
  1992. //Search if this EvMac and RunID already exists
  1993. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  1994. if (idx < 0) //not exist, yet.
  1995. {
  1996. if (SLAC_INFO.arrayLen < EVCC_SLAC_DATA_ARRAY_TYPE_ARRAY_SIZE) //20
  1997. {
  1998. DEBUG_PRINTF_EVCOMM_DETAIL("data does not exist => added to %d-th\n", SLAC_INFO.arrayLen);
  1999. if (SLAC_INFO.arrayLen >= 0)
  2000. {
  2001. memset(&SLAC_INFO.array[SLAC_INFO.arrayLen], 0, sizeof(struct EVCC_SLAC_DATA_ARRAY_TYPE));
  2002. memcpy(SLAC_INFO.array[SLAC_INFO.arrayLen].EvMac, EvMac_in, SLAC_EVMAC_LENGTH);
  2003. memcpy(SLAC_INFO.array[SLAC_INFO.arrayLen].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2004. idx = SLAC_INFO.arrayLen;
  2005. SLAC_INFO.arrayLen++;
  2006. }
  2007. else
  2008. {
  2009. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]arrayLen: unexpected(%d)\n", SLAC_INFO.arrayLen);
  2010. SLAC_INFO.arrayLen = 0;
  2011. }
  2012. }
  2013. else
  2014. {
  2015. //DB is full
  2016. DEBUG_PRINTF_EVCOMM_DETAIL("DB is full(%d) => bypass\n", SLAC_INFO.arrayLen);
  2017. }
  2018. }
  2019. else
  2020. {
  2021. #if 0
  2022. sprintf((char*)buf_log_evcomm,
  2023. "[SLAC_DB_Add]EvMac: existed (%d)",
  2024. idx);
  2025. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2026. #endif
  2027. //Check RunID
  2028. if (Array_Compare_Identity(SLAC_INFO.array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH) == TRUE)
  2029. {
  2030. //RunID is the same
  2031. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC_DB_Add]RunID: same");
  2032. }
  2033. else
  2034. {
  2035. SAVE_SYS_LOG_MSG_EVCOMM("RunID: diff\n");
  2036. }
  2037. //Reset all corresponding parameters
  2038. #if 0
  2039. sprintf((char*)buf_log_evcomm,
  2040. "[SLAC_DB_Add]EvMac: reset para(%d)",
  2041. idx);
  2042. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2043. #endif
  2044. memset(&SLAC_INFO.array[idx], 0, sizeof(struct EVCC_SLAC_DATA_ARRAY_TYPE));
  2045. memcpy(SLAC_INFO.array[idx].EvMac, EvMac_in, SLAC_EVMAC_LENGTH);
  2046. memcpy(SLAC_INFO.array[idx].RunID, RunID_in, SLAC_RUNID_LENGTH);
  2047. }
  2048. return idx;
  2049. }
  2050. /*===========================================================================
  2051. FUNCTION: SLAC_DB_Reset
  2052. DESCRIPTION:
  2053. PRE-CONDITION:
  2054. INPUT:
  2055. OUTPUT:
  2056. GLOBAL VARIABLES:
  2057. =============================================================================*/
  2058. int SLAC_DB_Reset()
  2059. {
  2060. memset(&SLAC_INFO, 0, sizeof(struct EVCC_SLAC_DATA_TYPE));
  2061. SAVE_SYS_LOG_MSG_EVCOMM("DONE\n");
  2062. return 0;
  2063. }
  2064. /*===========================================================================
  2065. FUNCTION: MmeProcess
  2066. DESCRIPTION:
  2067. PRE-CONDITION:
  2068. INPUT:
  2069. OUTPUT:
  2070. GLOBAL VARIABLES:
  2071. =============================================================================*/
  2072. int MmeProcess(unsigned char *Buffer, int DataLength)
  2073. {
  2074. //struct ethhdr *EthPacket;
  2075. struct MmeHeader *MmePacket;
  2076. static unsigned char counter;
  2077. unsigned char state = 0;
  2078. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2079. unsigned char tmpBuf[2048]={0};
  2080. #endif
  2081. int Rtn = 0;
  2082. #if(NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2083. int idx = 0;
  2084. unsigned char *EvMac_in;
  2085. unsigned char *RunID_in;
  2086. #endif
  2087. MmePacket = (struct MmeHeader *)Buffer;
  2088. state = Check_V2G_Flow_Status();
  2089. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2090. {
  2091. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  2092. DEBUG_PRINTF_EVCOMM_DETAIL("******* Received MME Packet *******\n");
  2093. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  2094. DEBUG_PRINTF_EVCOMM_DETAIL("DataLength=%d\n",DataLength);
  2095. DEBUG_PRINTF_EVCOMM_DETAIL("ODA: %02x:%02x:%02x:%02x:%02x:%02x\n", //Destination MAC Address
  2096. MmePacket->ODA[0], MmePacket->ODA[1],
  2097. MmePacket->ODA[2], MmePacket->ODA[3],
  2098. MmePacket->ODA[4], MmePacket->ODA[5]);
  2099. DEBUG_PRINTF_EVCOMM_DETAIL("OSA: %02x:%02x:%02x:%02x:%02x:%02x\n", //Source MAC Address (EV MAC)
  2100. MmePacket->OSA[0], MmePacket->OSA[1],
  2101. MmePacket->OSA[2], MmePacket->OSA[3],
  2102. MmePacket->OSA[4], MmePacket->OSA[5]);
  2103. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(MmePacket->MTYPE));
  2104. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", MmePacket->MMV);
  2105. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", MmePacket->MMTYPE);
  2106. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n",
  2107. MmePacket->FMI[0],MmePacket->FMI[1]);
  2108. }
  2109. #endif
  2110. #if (SLAC_FIRST_RESPONSE_METHOD == SET_NO_PWM_IF_NOT_GET_PERMISSION)
  2111. {
  2112. //Check CP as 5%
  2113. if (EVCOMM_SYS_INFO.CpState != 3 &&
  2114. EVCOMM_SYS_INFO.CpState != 4 &&
  2115. MmePacket->MMTYPE != MMTYPE_CM_SET_KEY_CNF &&
  2116. MmePacket->MMTYPE != MMTYPE_VENDOR_VS_HOST_ACTION &&
  2117. MmePacket->MMTYPE != MMTYPE_VENDOR_ATTEN_CHAR &&
  2118. MmePacket->MMTYPE != MMTYPE_VENDOR_VS_NW_INFO_CNF
  2119. )
  2120. {
  2121. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC]ignored(wrong CP state)");
  2122. return 0;
  2123. }
  2124. }
  2125. #endif
  2126. //[To-Do] Adding a pre-check filter mechanism for Source and Destination MAC Address
  2127. //check if the destination address is broadcast or EVSE itself, it can be ignore if not belong to itself.
  2128. switch(MmePacket->MMTYPE)
  2129. {
  2130. case MMTYPE_CM_SET_KEY_CNF:
  2131. {
  2132. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SET_KEY_CNF ---\n");
  2133. DEBUG_PRINTF_EVCOMM_DETAIL("Result: 0x%02x\n", MmePacket->MMENTRY[0]);
  2134. SAVE_SYS_LOG_MSG_EVCOMM("CM_SET_KEY_CNF (SetKey: DONE)\n\n");
  2135. Update_V2G_Flow_Status(CM_SET_KEY_CNF);
  2136. break;
  2137. }
  2138. case MMTYPE_CM_SLAC_PARM_REQ:
  2139. {
  2140. //Check QCA7000 status
  2141. if (EVCOMM_SYS_INFO.QCA7K_SetKeyDone == FALSE)
  2142. {
  2143. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][RX]CM_SLAC_PARM_REQ: ignored(QCA7K init...)");
  2144. break;
  2145. }
  2146. //Check error state
  2147. state = Check_V2G_Flow_Status();
  2148. if (state == Performance_Timeout || //253
  2149. state == Sequence_Timeout || //254
  2150. state == Other_Fault) //255
  2151. {
  2152. SAVE_SYS_LOG_MSG_EVCOMM("CM_SLAC_PARM_REQ: ignored(in error state)\n");
  2153. break;
  2154. }
  2155. //Printing EV MAC Address
  2156. SAVE_SYS_LOG_MSG_EVCOMM("CM_SLAC_PARM_REQ\n");
  2157. //Avoid Coupled SLAC_PARM_REQ
  2158. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2159. {
  2160. #if 0
  2161. sprintf((char*)buf_log_evcomm,
  2162. "[WARNING][SLAC][RX]CM_SLAC_PARM_REQ: ignored(coupled SLAC,%d)",
  2163. CheckConnectorPlugIn());
  2164. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2165. #endif
  2166. break;
  2167. }
  2168. //[TC_SECC_VTB_CmSlacParm_003] SECURITY_TYPE needs to be 0x00 (no security)
  2169. if (MmePacket->MMENTRY[1] != 0)
  2170. {
  2171. SAVE_SYS_LOG_MSG_EVCOMM("CM_SLAC_PARM_REQ: ignored(invalid SECURITY_TYPE,%d)\n", //Source MAC Address (EV MAC)
  2172. MmePacket->MMENTRY[1]);
  2173. break;
  2174. }
  2175. //=================== Legal CM_SLAC_PARM_REQ Zone =================
  2176. Update_V2G_Flow_Status(CM_SLAC_PARM_REQ);
  2177. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_RX_CM_SLAC_PARM_REQ)
  2178. {
  2179. //Once receiving CM_SLAC_PARM_REQ, set PWM as 5%
  2180. SwitchCpStateE(DISABLE);
  2181. OutputCpPwmDuty(5);
  2182. }
  2183. #endif
  2184. //Checking if this SLAC Req comes before 5% PWM (for 15118)
  2185. if(ShmInternalComm->ChargingPermission == FALSE)
  2186. {
  2187. //Sniffer_Tcpdump(ENABLE);
  2188. SAVE_SYS_LOG_MSG_EVCOMM("Check Permission: %d (SLAC first => START)\n", ShmInternalComm->ChargingPermission);
  2189. }
  2190. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2191. {
  2192. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SLAC_PARM_REQ ---\n");
  2193. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2194. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2195. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2196. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2197. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2198. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2199. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2200. DEBUG_PRINTF_EVCOMM_DETAIL("CipherSuiteSetSize: 0x%x\n", MmePacket->MMENTRY[10]);
  2201. DEBUG_PRINTF_EVCOMM_DETAIL("CipherSuite [1]: 0x%x,0x%x\n",
  2202. MmePacket->MMENTRY[11], MmePacket->MMENTRY[12]);
  2203. }
  2204. #endif
  2205. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2206. {
  2207. //Saving each CM_SLAC_PARM_REQ data into EVCC database
  2208. EvMac_in = &MmePacket->OSA[0];
  2209. RunID_in = &MmePacket->MMENTRY[2];
  2210. idx = SLAC_DB_Add(EvMac_in, RunID_in); //(EvMac, RunID)
  2211. if (idx < 0)
  2212. {
  2213. SAVE_SYS_LOG_MSG_EVCOMM("DB is full or errors occour(%d) => ignore\n", idx);
  2214. break;
  2215. }
  2216. //Select the 1st EV MAC address
  2217. if (SLAC_INFO.arrayLen == 1) //1st Req
  2218. {
  2219. #if 1
  2220. SAVE_SYS_LOG_MSG_EVCOMM("CM_SLAC_PARM_REQ[%d](%02X:%02X:%02X:%02X:%02X:%02X, %02X%02X%02X%02X%02X%02X%02X%02X):selected\n",
  2221. (idx + 1),
  2222. MmePacket->OSA[0], MmePacket->OSA[1], MmePacket->OSA[2], MmePacket->OSA[3], MmePacket->OSA[4], MmePacket->OSA[5],
  2223. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3], MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2224. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7], MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2225. #endif
  2226. /*
  2227. sprintf((char*)buf_log_evcomm,
  2228. "[SLAC][EVMAC][%d-th]%02X:%02X:%02X:%02X:%02X:%02X (selected)", //Source MAC Address (EV MAC)
  2229. SLAC_INFO.arrayLen,
  2230. MmePacket->OSA[0], MmePacket->OSA[1],
  2231. MmePacket->OSA[2], MmePacket->OSA[3],
  2232. MmePacket->OSA[4], MmePacket->OSA[5]);
  2233. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2234. sprintf((char*)buf_log_evcomm,
  2235. "[SLAC][RunID][%d-th]%02X%02X%02X%02X%02X%02X%02X%02X (selected)", //RunID (from EVCC)
  2236. SLAC_INFO.arrayLen,
  2237. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2238. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2239. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2240. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2241. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2242. */
  2243. }
  2244. else //2nd Req
  2245. {
  2246. #if 1
  2247. SAVE_SYS_LOG_MSG_EVCOMM("CM_SLAC_PARM_REQ[%d](%02X:%02X:%02X:%02X:%02X:%02X, %02X%02X%02X%02X%02X%02X%02X%02X):not selected\n",
  2248. (idx + 1),
  2249. MmePacket->OSA[0], MmePacket->OSA[1], MmePacket->OSA[2], MmePacket->OSA[3], MmePacket->OSA[4], MmePacket->OSA[5],
  2250. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3], MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2251. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7], MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2252. #endif
  2253. /*
  2254. sprintf((char*)buf_log_evcomm,
  2255. "[SLAC][EVMAC][%d-th]%02X:%02X:%02X:%02X:%02X:%02X (not selected)", //Source MAC Address (EV MAC)
  2256. SLAC_INFO.arrayLen,
  2257. MmePacket->OSA[0], MmePacket->OSA[1],
  2258. MmePacket->OSA[2], MmePacket->OSA[3],
  2259. MmePacket->OSA[4], MmePacket->OSA[5]);
  2260. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2261. sprintf((char*)buf_log_evcomm,
  2262. "[SLAC][RunID][%d-th]%02X%02X%02X%02X%02X%02X%02X%02X (not selected)", //RunID (from EVCC)
  2263. SLAC_INFO.arrayLen,
  2264. MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2265. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5],
  2266. MmePacket->MMENTRY[6], MmePacket->MMENTRY[7],
  2267. MmePacket->MMENTRY[8], MmePacket->MMENTRY[9]);
  2268. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2269. */
  2270. }
  2271. memcpy(EvMac, MmePacket->OSA, sizeof(EvMac));
  2272. memcpy(DestSocketAddress.sll_addr, MmePacket->OSA, SLAC_EVMAC_LENGTH);
  2273. memcpy(SlacRunId, MmePacket->MMENTRY + 2, SLAC_RUNID_LENGTH);
  2274. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2275. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  2276. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2277. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2278. SendMmePacket.MMV = MmePacket->MMV;
  2279. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_PARM_CNF;
  2280. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2281. SendMmePacketSize = 0;
  2282. memset(SendMmePacket.MMENTRY, 0xFF, 6); //M-SOUND_TARGET(6-byte:0xFFFFFFFFFFFF): Fixed value indicating that M-Sounds to be sent as Ethernet broadcast
  2283. SendMmePacketSize += 6;
  2284. SendMmePacket.MMENTRY[SendMmePacketSize++] = C_EV_match_MNBC; //NUM_SOUNDS(0x0A): Number of M-Sounds to be transmitted by the EV GP Station during the SLAC process
  2285. SendMmePacket.MMENTRY[SendMmePacketSize++] = 6; //Time_Out(0x06): unit = 100ms
  2286. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01; //RESP_TYPE(0x01): Fixed value indicating ��Other GP station��, 0x00 �V HLE of the STA, 0x01 �V Another GP STA, 0x02 �V 0xFF �V Reserved
  2287. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SLAC_INFO.array[idx].EvMac, 6); //FORWARDING_STA(MAC Address of the EV HLE)
  2288. SendMmePacketSize += 6;
  2289. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00): 0x00(PEV-EVSE Association), 0x01-0xFF(Reserved)
  2290. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00): 0x00(No Security), 0x01(Public Key Signature), 0x02-0xFF(Reserved)
  2291. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SlacRunId, SLAC_RUNID_LENGTH); //RunID (8-byte)
  2292. SendMmePacketSize += SLAC_RUNID_LENGTH;
  2293. SendMmePacketSize += 19; //the size before MMENTRY
  2294. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2295. {
  2296. DEBUG_PRINTF_EVCOMM_DETAIL("***** Response MME Packet *****\n");
  2297. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2298. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  2299. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2300. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  2301. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  2302. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  2303. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  2304. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  2305. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_PARM_CNF ---\n");
  2306. DEBUG_PRINTF_EVCOMM_DETAIL("M-SOUND_TARGET: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2307. SendMmePacket.MMENTRY[0],SendMmePacket.MMENTRY[1],SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],
  2308. SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5]);
  2309. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", SendMmePacket.MMENTRY[6]);
  2310. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out: 0x%x\n", SendMmePacket.MMENTRY[7]);
  2311. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE: 0x%x\n", SendMmePacket.MMENTRY[8]);
  2312. DEBUG_PRINTF_EVCOMM_DETAIL("M-FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2313. SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],SendMmePacket.MMENTRY[12],
  2314. SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14]);
  2315. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[15]);
  2316. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[16]);
  2317. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2318. SendMmePacket.MMENTRY[17],SendMmePacket.MMENTRY[18],SendMmePacket.MMENTRY[19],SendMmePacket.MMENTRY[20],
  2319. SendMmePacket.MMENTRY[21],SendMmePacket.MMENTRY[22],SendMmePacket.MMENTRY[23],SendMmePacket.MMENTRY[24]);
  2320. }
  2321. #endif
  2322. Update_V2G_Flow_Status(CM_SLAC_PARM_CONF);
  2323. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2324. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d, Rtn=%d\n",SendMmePacketSize,Rtn);
  2325. ftime(&SeqStartTime);
  2326. counter = 0;
  2327. break;
  2328. }
  2329. #else
  2330. {
  2331. memcpy(EvMac, MmePacket->OSA, sizeof(EvMac));
  2332. memcpy(DestSocketAddress.sll_addr, MmePacket->OSA, sizeof(EvMac));
  2333. memcpy(SlacRunId,MmePacket->MMENTRY + 2, sizeof(SlacRunId));
  2334. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2335. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  2336. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2337. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2338. SendMmePacket.MMV = MmePacket->MMV;
  2339. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_PARM_CNF;
  2340. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2341. SendMmePacketSize = 0;
  2342. memset(SendMmePacket.MMENTRY, 0xFF, 6); //M-SOUND_TARGET(6-byte:0xFFFFFFFFFFFF): Fixed value indicating that M-Sounds to be sent as Ethernet broadcast
  2343. SendMmePacketSize += 6;
  2344. SendMmePacket.MMENTRY[SendMmePacketSize++] = C_EV_match_MNBC; //NUM_SOUNDS(0x0A): Number of M-Sounds to be transmitted by the EV GP Station during the SLAC process
  2345. SendMmePacket.MMENTRY[SendMmePacketSize++] = 6; //Time_Out(0x06): unit = 100ms
  2346. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x01; //RESP_TYPE(0x01): Fixed value indicating ��Other GP station��, 0x00 �V HLE of the STA, 0x01 �V Another GP STA, 0x02 �V 0xFF �V Reserved
  2347. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac, 6); //FORWARDING_STA(MAC Address of the EV HLE)
  2348. SendMmePacketSize += 6;
  2349. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00): 0x00(PEV-EVSE Association), 0x01-0xFF(Reserved)
  2350. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00): 0x00(No Security), 0x01(Public Key Signature), 0x02-0xFF(Reserved)
  2351. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, SlacRunId, sizeof(SlacRunId)); //RunID (8-byte)
  2352. SendMmePacketSize += sizeof(SlacRunId);
  2353. SendMmePacketSize += 19; //the size before MMENTRY
  2354. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2355. {
  2356. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  2357. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2358. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  2359. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2360. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  2361. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  2362. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  2363. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  2364. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  2365. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_PARM_CNF ---\n");
  2366. DEBUG_PRINTF_EVCOMM_DETAIL("M-SOUND_TARGET: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2367. SendMmePacket.MMENTRY[0],SendMmePacket.MMENTRY[1],SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],
  2368. SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5]);
  2369. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", SendMmePacket.MMENTRY[6]);
  2370. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out: 0x%x\n", SendMmePacket.MMENTRY[7]);
  2371. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE: 0x%x\n", SendMmePacket.MMENTRY[8]);
  2372. DEBUG_PRINTF_EVCOMM_DETAIL("M-FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  2373. SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],SendMmePacket.MMENTRY[12],
  2374. SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14]);
  2375. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[15]);
  2376. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[16]);
  2377. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2378. SendMmePacket.MMENTRY[17],SendMmePacket.MMENTRY[18],SendMmePacket.MMENTRY[19],SendMmePacket.MMENTRY[20],
  2379. SendMmePacket.MMENTRY[21],SendMmePacket.MMENTRY[22],SendMmePacket.MMENTRY[23],SendMmePacket.MMENTRY[24]);
  2380. }
  2381. #endif
  2382. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2383. Update_V2G_Flow_Status(CM_SLAC_PARM_CONF);
  2384. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  2385. ftime(&SeqStartTime);
  2386. counter = 0;
  2387. break;
  2388. }
  2389. #endif
  2390. }
  2391. case MMTYPE_CM_START_ATTEN_CHAR_IND:
  2392. {
  2393. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2394. {
  2395. SAVE_SYS_LOG_MSG_EVCOMM("CM_START_ATTEN_CHAR_IND: ignored(time up)\n");
  2396. break;
  2397. }
  2398. //Avoid Coupled CM_START_ATTEN_CHAR_IND
  2399. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2400. {
  2401. SAVE_SYS_LOG_MSG_EVCOMM("CM_START_ATTEN_CHAR_IND: ignored(coupled SLAC,%d)\n", CheckConnectorPlugIn());
  2402. break;
  2403. }
  2404. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2405. {
  2406. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_START_ATTEN_CHAR_IND (counter : %d/3 ) ---\n", counter);
  2407. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2408. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2409. DEBUG_PRINTF_EVCOMM_DETAIL("NUM_SOUNDS: 0x%x\n", MmePacket->MMENTRY[2]);
  2410. DEBUG_PRINTF_EVCOMM_DETAIL("Time_Out 0x%x\n", MmePacket->MMENTRY[3]);
  2411. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_TYPE 0x%x\n", MmePacket->MMENTRY[4]); //Fixed value (0x01) indicating ��other Green PHY station��
  2412. DEBUG_PRINTF_EVCOMM_DETAIL("FORWARDING_STA: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2413. MmePacket->MMENTRY[5],MmePacket->MMENTRY[6],MmePacket->MMENTRY[7],MmePacket->MMENTRY[8],
  2414. MmePacket->MMENTRY[9],MmePacket->MMENTRY[10]);
  2415. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2416. MmePacket->MMENTRY[11],MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],MmePacket->MMENTRY[14],
  2417. MmePacket->MMENTRY[15],MmePacket->MMENTRY[16],MmePacket->MMENTRY[17],MmePacket->MMENTRY[18]);
  2418. }
  2419. #endif
  2420. //New SLAC architecture designed by Joseph
  2421. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2422. {
  2423. EvMac_in = &MmePacket->OSA[0];
  2424. RunID_in = &MmePacket->MMENTRY[11];
  2425. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2426. if (idx >= 0)
  2427. {
  2428. Update_V2G_Flow_Status(CM_START_ATTEN_CHAR_IND);
  2429. counter++;
  2430. //[TC_SECC_VTB_AttenuationCharacterization_013]
  2431. if (MmePacket->MMENTRY[0] != 0) //APPLICATION_TYPE must be 0x00(EV-EVSE Matching)
  2432. {
  2433. sprintf((char*)buf_log_evcomm,
  2434. "[CM_START_ATTEN_CHAR_IND]APPLICATION_TYPE(%d): invalid => ignore Req",
  2435. MmePacket->MMENTRY[0]);
  2436. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2437. break;
  2438. }
  2439. //[TC_SECC_VTB_AttenuationCharacterization_014]
  2440. if (MmePacket->MMENTRY[1] != 0) //SECURITY_TYPE must be 0x00(No Security)
  2441. {
  2442. sprintf((char*)buf_log_evcomm,
  2443. "[CM_START_ATTEN_CHAR_IND]SECURITY_TYPE(%d): invalid => ignore Req",
  2444. MmePacket->MMENTRY[1]);
  2445. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2446. break;
  2447. }
  2448. //[TC_SECC_VTB_AttenuationCharacterization_017]
  2449. if (MmePacket->MMENTRY[4] != 0x01) //RESP_TYPE must be 0x01(Send to another GP STA(EV))
  2450. {
  2451. sprintf((char*)buf_log_evcomm,
  2452. "[CM_START_ATTEN_CHAR_IND]RESP_TYPE(%d): invalid => ignore Req",
  2453. MmePacket->MMENTRY[4]);
  2454. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2455. break;
  2456. }
  2457. //[TC_SECC_VTB_AttenuationCharacterization_021]
  2458. //FORWARDING_STA: MAC Address of the EV HLE (station which the measurement results shall be sent to)
  2459. if (Array_Compare_Identity(EvMac_in, &MmePacket->MMENTRY[5], SLAC_EVMAC_LENGTH) == FALSE)
  2460. {
  2461. sprintf((char*)buf_log_evcomm,
  2462. "[CM_START_ATTEN_CHAR_IND]FORWARDING_STA(%02X:%02X:%02X:%02X:%02X:%02X): invalid => ignore Req",
  2463. MmePacket->MMENTRY[5], MmePacket->MMENTRY[6],
  2464. MmePacket->MMENTRY[7], MmePacket->MMENTRY[8],
  2465. MmePacket->MMENTRY[9], MmePacket->MMENTRY[10]);
  2466. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2467. SLAC_INFO.array[idx].StartAttenCharErr = TRUE;
  2468. break;
  2469. }
  2470. //Check RunID
  2471. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE)
  2472. {
  2473. SLAC_INFO.array[idx].MnbcSoundNum = MmePacket->MMENTRY[2];
  2474. SLAC_INFO.array[idx].StartAttenCharCnt++;
  2475. #if 0
  2476. sprintf((char*)buf_log_evcomm,
  2477. "[SLAC][RX]CM_START_ATTEN_CHAR_IND[%d]:%d-th",
  2478. (idx + 1),
  2479. SLAC_INFO.array[idx].StartAttenCharCnt);
  2480. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2481. #endif
  2482. if (SLAC_INFO.array[idx].StartAttenCharCnt == 1)
  2483. {
  2484. memset(SLAC_INFO.array[idx].AAG, 0, sizeof(SLAC_INFO.array[idx].AAG));
  2485. SLAC_INFO.array[idx].AttenProfileCnt = 0;
  2486. ftime(&SeqStartTime); //start TT_EVSE_match_MNBC
  2487. }
  2488. else if (SLAC_INFO.array[idx].StartAttenCharCnt >= 3)
  2489. {
  2490. sprintf((char*)buf_log_evcomm,
  2491. "[CM_START_ATTEN_CHAR_IND]counter(%d): unexpected",
  2492. SLAC_INFO.array[idx].StartAttenCharCnt);
  2493. }
  2494. else
  2495. {
  2496. //null
  2497. }
  2498. }
  2499. else
  2500. {
  2501. //This RunID is not matched with this EvMac,
  2502. //or this RunID is not found in DB.
  2503. sprintf((char*)buf_log_evcomm,
  2504. "[CM_START_ATTEN_CHAR_IND]EvMac-RunID: unmatched => ignore Req");
  2505. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2506. //Response: ignore
  2507. }
  2508. }
  2509. else
  2510. {
  2511. //this msg source is not in database
  2512. //ignore
  2513. }
  2514. break;
  2515. }
  2516. #else //Old SLAC architecture designed by Vern
  2517. {
  2518. MnbcSoundNum = MmePacket->MMENTRY[2];
  2519. Update_V2G_Flow_Status(CM_START_ATTEN_CHAR_IND);
  2520. counter++;
  2521. if(counter == 1)
  2522. {
  2523. memset(Aag, 0, sizeof(Aag));
  2524. AttenProfileCnt = 0;
  2525. ftime(&SeqStartTime); //start TT_EVSE_match_MNBC
  2526. }
  2527. else if(counter >= 3)
  2528. {
  2529. counter = 0;
  2530. }
  2531. break;
  2532. }
  2533. #endif
  2534. }
  2535. case MMTYPE_CM_MNBC_SOUND_IND:
  2536. {
  2537. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2538. {
  2539. SAVE_SYS_LOG_MSG_EVCOMM("CM_MNBC_SOUND_IND: ignored(timeup)\n");
  2540. break;
  2541. }
  2542. //Avoid Coupled CM_MNBC_SOUND_IND
  2543. if (CheckConnectorPlugIn() == FALSE) //12V(State 1)
  2544. {
  2545. sprintf((char*)buf_log_evcomm,
  2546. "CM_MNBC_SOUND_IND: ignored(coupled SLAC,%d)",
  2547. CheckConnectorPlugIn());
  2548. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2549. break;
  2550. }
  2551. if(V2gFlowStatus == CM_START_ATTEN_CHAR_IND)
  2552. {
  2553. counter = 0;
  2554. }
  2555. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2556. {
  2557. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_MNBC_SOUND_IND (counter : %d/%d) ---\n", counter, SLAC_INFO.array[idx].MnbcSoundNum);
  2558. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2559. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2560. DEBUG_PRINTF_EVCOMM_DETAIL("SenderID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2561. MmePacket->MMENTRY[2],MmePacket->MMENTRY[3],MmePacket->MMENTRY[4],MmePacket->MMENTRY[5],
  2562. MmePacket->MMENTRY[6],MmePacket->MMENTRY[7],MmePacket->MMENTRY[8],MmePacket->MMENTRY[9],
  2563. MmePacket->MMENTRY[10],MmePacket->MMENTRY[11],MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],
  2564. MmePacket->MMENTRY[14],MmePacket->MMENTRY[15],MmePacket->MMENTRY[16],MmePacket->MMENTRY[17],
  2565. MmePacket->MMENTRY[18]);
  2566. DEBUG_PRINTF_EVCOMM_DETAIL("Cnt: 0x%x\n", MmePacket->MMENTRY[19]);
  2567. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2568. MmePacket->MMENTRY[20],MmePacket->MMENTRY[21],MmePacket->MMENTRY[22],MmePacket->MMENTRY[23],
  2569. MmePacket->MMENTRY[24],MmePacket->MMENTRY[25],MmePacket->MMENTRY[26],MmePacket->MMENTRY[27]);
  2570. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2571. MmePacket->MMENTRY[28],MmePacket->MMENTRY[29],MmePacket->MMENTRY[30],MmePacket->MMENTRY[31],
  2572. MmePacket->MMENTRY[32],MmePacket->MMENTRY[33],MmePacket->MMENTRY[34],MmePacket->MMENTRY[35]);
  2573. DEBUG_PRINTF_EVCOMM_DETAIL("Rnd: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2574. MmePacket->MMENTRY[36],MmePacket->MMENTRY[37],MmePacket->MMENTRY[38],MmePacket->MMENTRY[39],
  2575. MmePacket->MMENTRY[40],MmePacket->MMENTRY[41],MmePacket->MMENTRY[42],MmePacket->MMENTRY[43],
  2576. MmePacket->MMENTRY[44],MmePacket->MMENTRY[45],MmePacket->MMENTRY[46],MmePacket->MMENTRY[47],
  2577. MmePacket->MMENTRY[48],MmePacket->MMENTRY[49],MmePacket->MMENTRY[50],MmePacket->MMENTRY[51]);
  2578. }
  2579. #endif
  2580. //New SLAC architecture designed by Joseph
  2581. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2582. {
  2583. EvMac_in = &MmePacket->OSA[0];
  2584. RunID_in = &MmePacket->MMENTRY[20];
  2585. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2586. if (idx >= 0)
  2587. {
  2588. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2589. counter++;
  2590. //Check for RunID
  2591. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE)
  2592. {
  2593. SLAC_INFO.array[idx].MnbcSoundCnt++;
  2594. /*
  2595. sprintf((char*)buf_log_evcomm,
  2596. "[SLAC][RX]CM_MNBC_SOUND_IND[%d]:%d-th",
  2597. (idx + 1),
  2598. SLAC_INFO.array[idx].MnbcSoundCnt);
  2599. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2600. */
  2601. }
  2602. else
  2603. {
  2604. //RunID is not matched or does not exist.
  2605. sprintf((char*)buf_log_evcomm,
  2606. "CM_MNBC_SOUND_IND]EvMac-RunID: unmatched");
  2607. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2608. }
  2609. }
  2610. else
  2611. {
  2612. //ignore
  2613. sprintf((char*)buf_log_evcomm,
  2614. "CM_MNBC_SOUND_IND]EvMac does not exist");
  2615. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2616. }
  2617. break;
  2618. }
  2619. #else //Old SLAC architecture designed by Vern
  2620. {
  2621. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2622. counter++;
  2623. break;
  2624. }
  2625. #endif
  2626. }
  2627. case MMTYPE_CM_ATTEN_PROFILE_IND:
  2628. {
  2629. if(V2gFlowStatus >= CM_ATTEN_CHAR_IND)
  2630. {
  2631. SAVE_SYS_LOG_MSG_EVCOMM("CM_ATTEN_PROFILE_IND: ignore(timeup)\n");
  2632. break;
  2633. }
  2634. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2635. {
  2636. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_ATTEN_PROFILE_IND (counter : %d/%d) ---\n", counter, SLAC_INFO.array[idx].MnbcSoundNum);
  2637. DEBUG_PRINTF_EVCOMM_DETAIL("EV MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2638. MmePacket->MMENTRY[0], MmePacket->MMENTRY[1], MmePacket->MMENTRY[2], MmePacket->MMENTRY[3],
  2639. MmePacket->MMENTRY[4], MmePacket->MMENTRY[5]);
  2640. DEBUG_PRINTF_EVCOMM_DETAIL("NumGroups: 0x%x\n", MmePacket->MMENTRY[6]); //NumGroups, Number of AAG Groups (ex: 0x3A = 58)
  2641. //NumGroups: Number of OFDM carrier groups used for the SLAC signal characterization.
  2642. //AAG[i]: Average Attenuation of Group i (i = 1 ~ 58)
  2643. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", MmePacket->MMENTRY[7]);
  2644. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  2645. for(Rtn = 0; Rtn < MmePacket->MMENTRY[6]; Rtn++)
  2646. {
  2647. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, MmePacket->MMENTRY[8 + Rtn]);
  2648. }
  2649. DEBUG_PRINTF_EVCOMM_DETAIL("AAG: %s\n", tmpBuf);
  2650. }
  2651. #endif
  2652. //New SLAC architecture designed by Joseph
  2653. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2654. {
  2655. EvMac_in = &MmePacket->MMENTRY[0]; //[CAUTION] The EvMac address is not &MmePacket->OSA[0]
  2656. //[CAUTION] There is no RunID information of CM_ATTEN_PROFILE_IND
  2657. // packet, which means SECC cannot use the RunID to
  2658. // distinguish those SLAC request with identical EvMac
  2659. // but with different RunID.
  2660. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2661. /*
  2662. printf("%d, %d, %d, %d\n",
  2663. idx,
  2664. SLAC_INFO.array[idx].AagGroupsNum,
  2665. MmePacket->MMENTRY[6],
  2666. SLAC_INFO.array[idx].AttenProfileCnt);
  2667. */
  2668. if (idx >= 0)
  2669. {
  2670. SLAC_INFO.array[idx].AttenProfileCnt++;
  2671. /*
  2672. sprintf((char*)buf_log_evcomm,
  2673. "[SLAC][RX]CM_ATTEN_PROFILE_IND[%d]:%d-th",
  2674. (idx + 1),
  2675. SLAC_INFO.array[idx].AttenProfileCnt);
  2676. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2677. */
  2678. //printf("%d, %d\n", SLAC_INFO.array[idx].AagGroupsNum, MmePacket->MMENTRY[6]);
  2679. SLAC_INFO.array[idx].AagGroupsNum = MmePacket->MMENTRY[6];
  2680. ////NumGroups, Number of AAG Groups (ex: 0x3A = 58)
  2681. for(Rtn = 0; Rtn < SLAC_INFO.array[idx].AagGroupsNum; Rtn++) //ex:58
  2682. {
  2683. SLAC_INFO.array[idx].AAG[Rtn] += MmePacket->MMENTRY[8 + Rtn];
  2684. }
  2685. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2686. break;
  2687. }
  2688. else
  2689. {
  2690. //The EvMac is not in the database
  2691. //ignore
  2692. sprintf((char*)buf_log_evcomm,
  2693. "[CM_ATTEN_PROFILE_IND]EvMac(%02X%02X%02X%02X%02X%02X): not exist => ignore",
  2694. EvMac_in[0], EvMac_in[1], EvMac_in[2], EvMac_in[3], EvMac_in[4], EvMac_in[5]);
  2695. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2696. break;
  2697. }
  2698. }
  2699. #else //Old SLAC architecture designed by Vern
  2700. {
  2701. AagGroupsNum = MmePacket->MMENTRY[6];
  2702. for(Rtn = 0; Rtn < MmePacket->MMENTRY[6]; Rtn++)
  2703. {
  2704. Aag[Rtn] += MmePacket->MMENTRY[8 + Rtn];
  2705. }
  2706. AttenProfileCnt++;
  2707. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2708. break;
  2709. }
  2710. #endif
  2711. }
  2712. case MMTYPE_CM_ATTEN_CHAR_RSP:
  2713. {
  2714. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2715. {
  2716. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_ATTEN_CHAR_RSP ---\n");
  2717. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  2718. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  2719. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  2720. MmePacket->MMENTRY[2],MmePacket->MMENTRY[3],MmePacket->MMENTRY[4],MmePacket->MMENTRY[5],
  2721. MmePacket->MMENTRY[6],MmePacket->MMENTRY[7]);
  2722. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  2723. MmePacket->MMENTRY[8],MmePacket->MMENTRY[9],MmePacket->MMENTRY[10],MmePacket->MMENTRY[11],
  2724. MmePacket->MMENTRY[12],MmePacket->MMENTRY[13],MmePacket->MMENTRY[14],MmePacket->MMENTRY[15]);
  2725. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  2726. for(Rtn = 0; Rtn < 17; Rtn++)
  2727. {
  2728. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, MmePacket->MMENTRY[16 + Rtn]);
  2729. }
  2730. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: %s\n", tmpBuf);
  2731. ;
  2732. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  2733. for(Rtn = 0; Rtn < 17; Rtn++)
  2734. {
  2735. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, MmePacket->MMENTRY[33 + Rtn]);
  2736. }
  2737. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: %s\n", tmpBuf);
  2738. DEBUG_PRINTF_EVCOMM_DETAIL("Result: 0x%x\n", MmePacket->MMENTRY[50]); //Fixed value of 0x00 indicates a successful SLAC process
  2739. }
  2740. #endif
  2741. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2742. {
  2743. //Check ODA (Destination Address)
  2744. if (Array_Compare_Identity(CsuMac, MmePacket->ODA, SLAC_EVSE_MAC_LENGTH) == FALSE)
  2745. {
  2746. SAVE_SYS_LOG_MSG_EVCOMM("[CM_ATTEN_CHAR_RSP]wrong ODA: ignore\n");
  2747. break;
  2748. }
  2749. EvMac_in = &MmePacket->OSA[0];
  2750. RunID_in = &MmePacket->MMENTRY[8];
  2751. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2752. //Check Parameters
  2753. if ((MmePacket->MMENTRY[0] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_005] applicationType must be 0x00
  2754. (MmePacket->MMENTRY[1] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_006] securityType must be 0x00
  2755. (SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in) < 0) || //[TC_SECC_VTB_AttenuationCharacterization_007] sourceAddress cannot not be all zero
  2756. (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_008] check for invalid runID
  2757. (Array_Check_All_Zero(&MmePacket->MMENTRY[16], 17) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_009] SourceID(17 bytes) must be all zero.
  2758. (Array_Check_All_Zero(&MmePacket->MMENTRY[33], 17) == FALSE) || //[TC_SECC_VTB_AttenuationCharacterization_009] RESP_ID (17 bytes) must be all zero.
  2759. (MmePacket->MMENTRY[50] != 0) //Result: must be 0x00(Success)
  2760. )
  2761. {
  2762. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry++;
  2763. sprintf((char*)buf_log_evcomm,
  2764. "[WARNING][SLAC][RX]CM_ATTEN_CHAR_RSP:invalid para(%d,%d,%d,%d,%d) => %d-th retry",
  2765. MmePacket->MMENTRY[0], //applicationType must be 0x00
  2766. MmePacket->MMENTRY[1], //securityType must be 0x00
  2767. SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in),
  2768. SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in),
  2769. MmePacket->MMENTRY[50],
  2770. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry
  2771. );
  2772. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2773. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry <= 2) //limited to 2 retries
  2774. {
  2775. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2776. ftime(&SeqStartTime);
  2777. break;
  2778. }
  2779. else
  2780. {
  2781. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR][SLAC][RX]CM_ATTEN_CHAR_RSP:invalid para => 2-retry fail => End_Process");
  2782. Update_V2G_Flow_Status(Other_Fault);
  2783. break;
  2784. }
  2785. }
  2786. else
  2787. {
  2788. //The CM_ATTEN_CHAR_IND is legal
  2789. SLAC_INFO.array[idx].AttenCharRspCnt++;
  2790. sprintf((char*)buf_log_evcomm,
  2791. "[SLAC][RX]CM_ATTEN_CHAR_RSP[%d]:%d-th",
  2792. (idx + 1),
  2793. SLAC_INFO.array[idx].AttenCharRspCnt);
  2794. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2795. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry = 0;
  2796. Update_V2G_Flow_Status(CM_ATTEN_CHAR_RSP);
  2797. ftime(&SeqStartTime);
  2798. break;
  2799. }
  2800. }
  2801. #else
  2802. {
  2803. //Check Parameters
  2804. if ((MmePacket->MMENTRY[0] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_005] applicationType must be 0x00
  2805. (MmePacket->MMENTRY[1] != 0) || //[TC_SECC_VTB_AttenuationCharacterization_006] securityType must be 0x00
  2806. (Array_Compare_Identity(SLAC_INFO.array[0].EvMac, &MmePacket->MMENTRY[2], 6) == TRUE) || //[TC_SECC_VTB_AttenuationCharacterization_007] sourceAddress cannot not be all zero
  2807. (Array_Compare_Identity(SLAC_INFO.array[0].RunID, &MmePacket->MMENTRY[8], 8) == TRUE) //[TC_SECC_VTB_AttenuationCharacterization_008] check for invalid runID
  2808. )
  2809. {
  2810. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry++;
  2811. sprintf((char*)buf_log_evcomm,
  2812. "[WARNING][SLAC][RX]CM_ATTEN_CHAR_RSP: invalid parameters(%d-th)",
  2813. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  2814. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2815. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry <= 2) //limited to 2 retries
  2816. {
  2817. Update_V2G_Flow_Status(CM_MNBC_SOUND_IND);
  2818. ftime(&SeqStartTime);
  2819. break;
  2820. }
  2821. else
  2822. {
  2823. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]CM_ATTEN_CHAR_RSP: invalid parameters => End_Process");
  2824. Update_V2G_Flow_Status(Other_Fault);
  2825. ftime(&SeqStartTime);
  2826. break;
  2827. }
  2828. }
  2829. else
  2830. {
  2831. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry = 0;
  2832. Update_V2G_Flow_Status(CM_ATTEN_CHAR_RSP);
  2833. ftime(&SeqStartTime);
  2834. break;
  2835. }
  2836. }
  2837. #endif
  2838. }
  2839. case MMTYPE_CM_VALIDATE_REQ: //BCB Toggle
  2840. {
  2841. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2842. {
  2843. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_VALIDATE_REQ ---\n");
  2844. DEBUG_PRINTF_EVCOMM_DETAIL("Signal Type: 0x%x\n", MmePacket->MMENTRY[0]); //Fixed value (0x00) to indicate ��PEV S2 toggles on control pilot line��
  2845. DEBUG_PRINTF_EVCOMM_DETAIL("Timer: 0x%x\n", MmePacket->MMENTRY[1]); //Fixed value In the first VALIDATE Request-Response exchange, the Timer field shall be set to zero.
  2846. DEBUG_PRINTF_EVCOMM_DETAIL("Result: 0x%x\n", MmePacket->MMENTRY[2]); //Fixed value In the first VALIDATE Request-Response exchange, the Result field shall be set to 0x01 = ��ready��.
  2847. }
  2848. #endif
  2849. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  2850. {
  2851. counter = 0;
  2852. EvMac_in = &MmePacket->OSA[0];
  2853. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  2854. if (idx >= 0)
  2855. {
  2856. Update_V2G_Flow_Status(CM_VALIDATE_CNF);
  2857. SLAC_INFO.array[idx].ValidateReqCnt++;
  2858. sprintf((char*)buf_log_evcomm,
  2859. "[SLAC][RX]CM_VALIDATE_REQ[%d]:%d-th",
  2860. (idx + 1),
  2861. SLAC_INFO.array[idx].ValidateReqCnt);
  2862. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  2863. //[To-Do] Protection
  2864. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2865. memcpy(SendMmePacket.ODA, EvMac_in, SLAC_EVMAC_LENGTH);
  2866. memcpy(SendMmePacket.OSA, CsuMac, 6);
  2867. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2868. SendMmePacket.MMV = 0x01;
  2869. SendMmePacket.MMTYPE = MMTYPE_CM_VALIDATE_CNF;
  2870. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2871. SendMmePacketSize = 0;
  2872. if(counter == 0)
  2873. {
  2874. //The First MMTYPE_CM_VALIDATE_REQ because Unicast
  2875. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SignalType(0x00): Fixed value to indicate "EV S2 toggles on control pilot line"
  2876. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //ToggleNum(0x00): Fixed value. In the first VALIDATE Request-Response exchange, the ToggleNum field shall be set to zero.
  2877. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  2878. SendMmePacket.MMENTRY[SendMmePacketSize++] = 1; //0x01 = Ready
  2879. #else
  2880. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  2881. #endif
  2882. }
  2883. else
  2884. {
  2885. //The Second MMTYPE_CM_VALIDATE_REQ because Broadcast
  2886. unsigned char PreStatus = 3;
  2887. unsigned char ToggleNum = 0;
  2888. ftime(&SeqStartTime);
  2889. while(1)
  2890. {
  2891. if((EVCOMM_SYS_INFO.CpState == 4) && (PreStatus == 3))
  2892. {
  2893. ToggleNum++;
  2894. PreStatus = 4;
  2895. }
  2896. else
  2897. {
  2898. PreStatus = 3;
  2899. }
  2900. ftime(&SeqEndTime);
  2901. if(DiffTimeb(SeqStartTime, SeqEndTime) >= (SendMmePacket.MMENTRY[1]*100 + 100))
  2902. {
  2903. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate "PEV S2 toggles on control pilot line"
  2904. SendMmePacket.MMENTRY[SendMmePacketSize++] = ToggleNum;
  2905. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  2906. SendMmePacket.MMENTRY[SendMmePacketSize++] = 2; //0x02 = Success
  2907. #else
  2908. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  2909. #endif
  2910. break;
  2911. }
  2912. usleep(1000);
  2913. }
  2914. }
  2915. SendMmePacketSize += 19; //the size before MMENTRY
  2916. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2917. ftime(&SeqStartTime);
  2918. }
  2919. else
  2920. {
  2921. //EvMac does not exist.
  2922. //ignore
  2923. }
  2924. break;
  2925. }
  2926. #else
  2927. {
  2928. counter = 0;
  2929. for(Rtn = 0; Rtn < 6; Rtn++)
  2930. {
  2931. if(MmePacket->ODA[Rtn] != CsuMac[Rtn])
  2932. {
  2933. counter = 1;
  2934. break;
  2935. }
  2936. }
  2937. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  2938. memcpy(SendMmePacket.ODA, EvMac,6);
  2939. memcpy(SendMmePacket.OSA, CsuMac,6);
  2940. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  2941. SendMmePacket.MMV = 0x01;
  2942. SendMmePacket.MMTYPE = MMTYPE_CM_VALIDATE_CNF;
  2943. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  2944. SendMmePacketSize = 0;
  2945. if(counter == 0)
  2946. {
  2947. //The First MMTYPE_CM_VALIDATE_REQ because Unicast
  2948. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate ��PEV S2 toggles on control pilot line��
  2949. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value In the first VALIDATE Request-Response exchange, the ToggleNum field shall be set to zero.
  2950. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  2951. SendMmePacket.MMENTRY[SendMmePacketSize++] = 1; //0x01 = Ready
  2952. #else
  2953. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  2954. #endif
  2955. }
  2956. else
  2957. {
  2958. //The Second MMTYPE_CM_VALIDATE_REQ because Broadcast
  2959. unsigned char PreStatus = 3, ToggleNum = 0;
  2960. ftime(&SeqStartTime);
  2961. while(1)
  2962. {
  2963. ftime(&SeqEndTime);
  2964. if((EVCOMM_SYS_INFO.CpState == 4) && (PreStatus == 3))
  2965. {
  2966. ToggleNum++;
  2967. PreStatus = 4;
  2968. }
  2969. else
  2970. {
  2971. PreStatus = 3;
  2972. }
  2973. if(DiffTimeb(SeqStartTime, SeqEndTime) >= (SendMmePacket.MMENTRY[1]*100 + 100))
  2974. {
  2975. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //Fixed value to indicate ��PEV S2 toggles on control pilot line��
  2976. SendMmePacket.MMENTRY[SendMmePacketSize++] = ToggleNum;
  2977. #if (SUPPORT_BCB_TOGGLE_FUNCTION == ENABLE)
  2978. SendMmePacket.MMENTRY[SendMmePacketSize++] = 2; //0x02 = Success
  2979. #else
  2980. SendMmePacket.MMENTRY[SendMmePacketSize++] = 4; //0x04 = Not Required
  2981. #endif
  2982. break;
  2983. }
  2984. usleep(1000);
  2985. }
  2986. }
  2987. SendMmePacketSize += 19; //the size before MMENTRY
  2988. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  2989. Update_V2G_Flow_Status(CM_VALIDATE_CNF);
  2990. ftime(&SeqStartTime);
  2991. break;
  2992. }
  2993. #endif
  2994. }
  2995. case MMTYPE_CM_SLAC_MATCH_REQ:
  2996. {
  2997. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  2998. {
  2999. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_CM_SLAC_MATCH_REQ ---\n");
  3000. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", MmePacket->MMENTRY[0]);
  3001. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", MmePacket->MMENTRY[1]);
  3002. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", MmePacket->MMENTRY[2],MmePacket->MMENTRY[3]); //Fixed value (0x3E) for matching
  3003. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3004. for(Rtn=0; Rtn<17; Rtn++)
  3005. {
  3006. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[4+Rtn]);
  3007. }
  3008. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3009. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3010. for(Rtn=0; Rtn<6; Rtn++)
  3011. {
  3012. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[21+Rtn]);
  3013. }
  3014. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3015. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3016. for(Rtn=0; Rtn<17; Rtn++)
  3017. {
  3018. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[27+Rtn]);
  3019. }
  3020. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3021. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3022. for(Rtn=0; Rtn<6; Rtn++)
  3023. {
  3024. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[44+Rtn]);
  3025. }
  3026. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3027. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3028. for(Rtn=0; Rtn<8; Rtn++)
  3029. {
  3030. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[50+Rtn]);
  3031. }
  3032. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3033. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3034. for(Rtn=0; Rtn<8; Rtn++)
  3035. {
  3036. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",MmePacket->MMENTRY[58+Rtn]);
  3037. }
  3038. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3039. }
  3040. #endif
  3041. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  3042. {
  3043. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][RX]CM_SLAC_MATCH_REQ");
  3044. //Check ODA (Destination Address)
  3045. if (Array_Compare_Identity(CsuMac, MmePacket->ODA, SLAC_EVSE_MAC_LENGTH) == FALSE)
  3046. {
  3047. SAVE_SYS_LOG_MSG_EVCOMM("[CM_SLAC_MATCH_REQ]wrong ODA: ignore");
  3048. //break; //patch for DEKRA I2SE EVCC (another EVSE MAC Address protection comes as below.)
  3049. }
  3050. EvMac_in = &MmePacket->OSA[0];
  3051. RunID_in = &MmePacket->MMENTRY[50];
  3052. idx = SLAC_DB_Search_EvMac_idx(&SLAC_INFO, EvMac_in);
  3053. if (idx >= 0)
  3054. {
  3055. Update_V2G_Flow_Status(CM_SLAC_MATCH_REQ);
  3056. SLAC_INFO.array[idx].MatchReqNum++;
  3057. sprintf((char*)buf_log_evcomm,
  3058. "CM_SLAC_MATCH_REQ[%d]:%d-th",
  3059. (idx + 1),
  3060. SLAC_INFO.array[idx].MatchReqNum);
  3061. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3062. //[TC_SECC_VTB_CmSlacMatch_007] APPLICATION_TYPE must be 0x00(EV-EVSE Matching)
  3063. //[TC_SECC_VTB_CmSlacMatch_008]
  3064. if (MmePacket->MMENTRY[0] != 0)
  3065. {
  3066. sprintf((char*)buf_log_evcomm,
  3067. "CM_SLAC_MATCH_REQ[%d]:wrong APPLICATION_TYPE(%d)",
  3068. (idx + 1),
  3069. MmePacket->MMENTRY[0]);
  3070. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3071. break;
  3072. }
  3073. //[TC_SECC_VTB_CmSlacMatch_009] SECURITY_TYPE must be 0x00(No Security)
  3074. //[TC_SECC_VTB_CmSlacMatch_010]
  3075. if (MmePacket->MMENTRY[1] != 0)
  3076. {
  3077. sprintf((char*)buf_log_evcomm,
  3078. "CM_SLAC_MATCH_REQ[%d]:wrong SECURITY_TYPE(%d)",
  3079. (idx + 1),
  3080. MmePacket->MMENTRY[1]);
  3081. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3082. break;
  3083. }
  3084. //[TC_SECC_VTB_CmSlacMatch_011] MVFLength must be 0x3E(MatchVarField Length)
  3085. //[TC_SECC_VTB_CmSlacMatch_012]
  3086. if (MmePacket->MMENTRY[2] != 0x3E || MmePacket->MMENTRY[3] != 0x00)
  3087. {
  3088. sprintf((char*)buf_log_evcomm,
  3089. "CM_SLAC_MATCH_REQ[%d]:wrong MVFLength(%d,%d)",
  3090. (idx + 1),
  3091. MmePacket->MMENTRY[2],
  3092. MmePacket->MMENTRY[3]);
  3093. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3094. break;
  3095. }
  3096. //[TC_SECC_VTB_CmSlacMatch_013] EV ID (muxt be all zero)
  3097. //[TC_SECC_VTB_CmSlacMatch_014]
  3098. if (Array_Check_All_Zero(&MmePacket->MMENTRY[4], 17) == FALSE)
  3099. {
  3100. sprintf((char*)buf_log_evcomm,
  3101. "CM_SLAC_MATCH_REQ[%d]: wrong EV ID",
  3102. (idx + 1));
  3103. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3104. break;
  3105. }
  3106. //[TC_SECC_VTB_CmSlacMatch_015] EV MAC
  3107. //[TC_SECC_VTB_CmSlacMatch_016]
  3108. if (Array_Compare_Identity(EvMac_in, &MmePacket->MMENTRY[21], SLAC_EVMAC_LENGTH) == FALSE)
  3109. {
  3110. sprintf((char*)buf_log_evcomm,
  3111. "CM_SLAC_MATCH_REQ[%d]: wrong EV MAC(%02X:%02X:%02X:%02X:%02X:%02X)",
  3112. (idx + 1),
  3113. MmePacket->MMENTRY[21], MmePacket->MMENTRY[22], MmePacket->MMENTRY[23],
  3114. MmePacket->MMENTRY[24], MmePacket->MMENTRY[25], MmePacket->MMENTRY[26]);
  3115. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3116. break;
  3117. }
  3118. //[TC_SECC_VTB_CmSlacMatch_017] EVSE ID should be all zero
  3119. //[TC_SECC_VTB_CmSlacMatch_018]
  3120. if (Array_Check_All_Zero(&MmePacket->MMENTRY[27], 17) == FALSE)
  3121. {
  3122. sprintf((char*)buf_log_evcomm,
  3123. "CM_SLAC_MATCH_REQ[%d]: wrong EVSE ID",
  3124. (idx + 1));
  3125. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3126. break;
  3127. }
  3128. //[TC_SECC_VTB_CmSlacMatch_019] EVSE MAC
  3129. //[TC_SECC_VTB_CmSlacMatch_020]
  3130. if (Array_Compare_Identity(CsuMac, &MmePacket->MMENTRY[44], SLAC_EVSE_MAC_LENGTH) == FALSE)
  3131. {
  3132. sprintf((char*)buf_log_evcomm,
  3133. "CM_SLAC_MATCH_REQ[%d]: wrong EVSE MAC(%02X:%02X:%02X:%02X:%02X:%02X)",
  3134. (idx + 1),
  3135. MmePacket->MMENTRY[44], MmePacket->MMENTRY[45], MmePacket->MMENTRY[46],
  3136. MmePacket->MMENTRY[47], MmePacket->MMENTRY[48], MmePacket->MMENTRY[49]);
  3137. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3138. break;
  3139. }
  3140. //[TC_SECC_VTB_CmSlacMatch_021]runID: Check RunID
  3141. //[TC_SECC_VTB_CmSlacMatch_022]
  3142. if (SLAC_DB_Check_EvMac_RunID_Matching(&SLAC_INFO, EvMac_in, RunID_in) == TRUE &&
  3143. (idx == 0)) //only setup a successful link establishment with the first SLAC Req instance
  3144. {
  3145. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3146. memcpy(SendMmePacket.ODA, MmePacket->OSA, 6);
  3147. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3148. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3149. SendMmePacket.MMV = MmePacket->MMV;
  3150. SendMmePacket.MMTYPE = MMTYPE_CM_SLAC_MATCH_CNF;
  3151. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3152. SendMmePacketSize = 0;
  3153. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //APPLICATION_TYPE: Fixed value (0x00: EV-EVSE matching)
  3154. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //SECURITY_TYPE: Fixed value (0x00: No Security)
  3155. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x56; //MVFLength: MatchVarField Length (Fixed value: 0x0056)
  3156. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //MVFLength: MatchVarField Length (Fixed value: 0x0056)
  3157. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //EV ID
  3158. SendMmePacketSize += 17;
  3159. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac_in, SLAC_EVMAC_LENGTH); //EV MAC
  3160. SendMmePacketSize += 6;
  3161. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //EVSE ID
  3162. SendMmePacketSize += 17;
  3163. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, CsuMac, 6); //EVSE MAC
  3164. SendMmePacketSize += 6;
  3165. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, RunID_in, SLAC_RUNID_LENGTH);
  3166. SendMmePacketSize += SLAC_RUNID_LENGTH;
  3167. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 8); //RSVD
  3168. SendMmePacketSize += 8;
  3169. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, Nid, sizeof(Nid)); //NID: Network ID given by the CCo(EVSE)
  3170. SendMmePacketSize += sizeof(Nid); //NID caculated from the random NMK that will be set.
  3171. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0x00; //RSVD
  3172. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, NewNmkKey, sizeof(NewNmkKey)); //NMK: Random value
  3173. SendMmePacketSize += sizeof(NewNmkKey); //NMK: Private NMK of the EVSE (random value)
  3174. SendMmePacketSize += 19; //the size before MMENTRY
  3175. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3176. {
  3177. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  3178. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3179. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3180. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3181. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3182. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3183. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3184. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3185. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3186. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_MATCH_CNF ---\n");
  3187. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3188. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3189. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3]);
  3190. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3191. for(Rtn=0; Rtn<17; Rtn++)
  3192. {
  3193. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[4+Rtn]);
  3194. }
  3195. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3196. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3197. for(Rtn=0; Rtn<6; Rtn++)
  3198. {
  3199. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[21+Rtn]);
  3200. }
  3201. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3202. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3203. for(Rtn=0; Rtn<17; Rtn++)
  3204. {
  3205. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[27+Rtn]);
  3206. }
  3207. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3208. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3209. for(Rtn=0; Rtn<6; Rtn++)
  3210. {
  3211. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[44+Rtn]);
  3212. }
  3213. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3214. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3215. for(Rtn=0; Rtn<8; Rtn++)
  3216. {
  3217. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[50+Rtn]);
  3218. }
  3219. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3220. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3221. for(Rtn=0; Rtn<8; Rtn++)
  3222. {
  3223. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[58+Rtn]);
  3224. }
  3225. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3226. DEBUG_PRINTF_EVCOMM_DETAIL("NID: \n");
  3227. for(Rtn=0; Rtn<7; Rtn++)
  3228. {
  3229. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[66+Rtn]);
  3230. }
  3231. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3232. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", SendMmePacket.MMENTRY[73]);
  3233. DEBUG_PRINTF_EVCOMM_DETAIL("NMK: \n");
  3234. for(Rtn=0; Rtn<16; Rtn++)
  3235. {
  3236. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[74+Rtn]);
  3237. }
  3238. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3239. }
  3240. #endif
  3241. Update_V2G_Flow_Status(CM_SLAC_MATCH_CNF);
  3242. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3243. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  3244. sprintf((char*)buf_log_evcomm,
  3245. "CM_SLAC_MATCH_CNF[%d]",
  3246. (idx + 1));
  3247. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3248. ftime(&SeqStartTime);
  3249. }
  3250. else
  3251. {
  3252. //RunID does not match and it's not the first SLAC request
  3253. //Reset the SLAC database to embrace SLAC retry
  3254. SAVE_SYS_LOG_MSG_EVCOMM("[CM_SLAC_MATCH_REQ]No Real MATCH_REQ\n");
  3255. SLAC_DB_Reset();
  3256. }
  3257. }
  3258. else
  3259. {
  3260. //OSA(EvMac) does not exist
  3261. }
  3262. break;
  3263. }
  3264. #else
  3265. {
  3266. Update_V2G_Flow_Status(CM_SLAC_MATCH_REQ);
  3267. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][RX]CM_SLAC_MATCH_REQ");
  3268. memset(&SendMmePacket,0,sizeof(struct MmeHeader));
  3269. memcpy(SendMmePacket.ODA,MmePacket->OSA,6);
  3270. memcpy(SendMmePacket.OSA,CsuMac,6);
  3271. SendMmePacket.MTYPE=htons(EtherType_HomePlug);
  3272. SendMmePacket.MMV=MmePacket->MMV;
  3273. SendMmePacket.MMTYPE=MMTYPE_CM_SLAC_MATCH_CNF;
  3274. SendMmePacket.FMI[0]=SendMmePacket.FMI[1]=0;
  3275. SendMmePacketSize=0;
  3276. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x00) indicating ��PEV-EVSE matching��
  3277. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x00) indicating ��No Security��
  3278. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x56; //Fixed value (0x0056) for matching
  3279. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //Fixed value (0x0056) for matching
  3280. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,17); //PEV ID
  3281. SendMmePacketSize+=17;
  3282. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,EvMac,6);
  3283. SendMmePacketSize+=6;
  3284. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,17); //EVSE ID
  3285. SendMmePacketSize+=17;
  3286. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,CsuMac,6);
  3287. SendMmePacketSize+=6;
  3288. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,SlacRunId,sizeof(SlacRunId));
  3289. SendMmePacketSize+=sizeof(SlacRunId);
  3290. memset(SendMmePacket.MMENTRY+SendMmePacketSize,0,8); //RSVD
  3291. SendMmePacketSize+=8;
  3292. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,Nid,sizeof(Nid));
  3293. SendMmePacketSize+=sizeof(Nid);
  3294. SendMmePacket.MMENTRY[SendMmePacketSize++]=0x00; //RSVD
  3295. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize,NewNmkKey,sizeof(NewNmkKey));
  3296. SendMmePacketSize+=sizeof(NewNmkKey);
  3297. SendMmePacketSize+=19; //the size before MMENTRY
  3298. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3299. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response MME Packet *****\n");
  3300. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3301. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3302. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3303. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3304. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3305. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3306. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3307. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3308. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_SLAC_MATCH_CNF ---\n");
  3309. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3310. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3311. DEBUG_PRINTF_EVCOMM_DETAIL("MVFLength: 0x%x, 0x%x\n", SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3]);
  3312. DEBUG_PRINTF_EVCOMM_DETAIL("PEV ID: \n");
  3313. for(Rtn=0; Rtn<17; Rtn++)
  3314. {
  3315. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[4+Rtn]);
  3316. }
  3317. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3318. DEBUG_PRINTF_EVCOMM_DETAIL("PEV MAC: \n");
  3319. for(Rtn=0; Rtn<6; Rtn++)
  3320. {
  3321. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[21+Rtn]);
  3322. }
  3323. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3324. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE ID: \n");
  3325. for(Rtn=0; Rtn<17; Rtn++)
  3326. {
  3327. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[27+Rtn]);
  3328. }
  3329. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3330. DEBUG_PRINTF_EVCOMM_DETAIL("EVSE MAC: \n");
  3331. for(Rtn=0; Rtn<6; Rtn++)
  3332. {
  3333. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[44+Rtn]);
  3334. }
  3335. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3336. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: \n");
  3337. for(Rtn=0; Rtn<8; Rtn++)
  3338. {
  3339. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[50+Rtn]);
  3340. }
  3341. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3342. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: \n");
  3343. for(Rtn=0; Rtn<8; Rtn++)
  3344. {
  3345. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[58+Rtn]);
  3346. }
  3347. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3348. DEBUG_PRINTF_EVCOMM_DETAIL("NID: \n");
  3349. for(Rtn=0; Rtn<7; Rtn++)
  3350. {
  3351. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[66+Rtn]);
  3352. }
  3353. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3354. DEBUG_PRINTF_EVCOMM_DETAIL("RSVD: 0x%x\n", SendMmePacket.MMENTRY[73]);
  3355. DEBUG_PRINTF_EVCOMM_DETAIL("NMK: \n");
  3356. for(Rtn=0; Rtn<16; Rtn++)
  3357. {
  3358. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ",SendMmePacket.MMENTRY[74+Rtn]);
  3359. }
  3360. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  3361. #endif
  3362. Update_V2G_Flow_Status(CM_SLAC_MATCH_CNF);
  3363. Rtn = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3364. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n",SendMmePacketSize,Rtn);
  3365. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[SLAC][TX]CM_SLAC_MATCH_CNF");
  3366. ftime(&SeqStartTime);
  3367. break;
  3368. }
  3369. #endif
  3370. }
  3371. case MMTYPE_VENDOR_VS_HOST_ACTION:
  3372. {
  3373. struct QcaVendorMmeHeader *RecvPacket;
  3374. RecvPacket = (struct QcaVendorMmeHeader *)Buffer;
  3375. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_VS_HOST_ACTION ---\n");
  3376. switch (RecvPacket->MBODY[0])
  3377. {
  3378. case 0x00:
  3379. //Loader (Device Softloader or Bootloader) ready
  3380. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Loader Ready\n");
  3381. break;
  3382. case 0x01:
  3383. //Firmware Upgrade Ready
  3384. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Firmware Upgrade Ready\n");
  3385. break;
  3386. case 0x02:
  3387. //PIB Update Ready
  3388. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: PIB Update Ready\n");
  3389. break;
  3390. case 0x03:
  3391. //Firmware Upgrade and PIB Update ready
  3392. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Firmware Upgrade and PIB Update ready\n");
  3393. break;
  3394. case 0x04:
  3395. //Loader (Bootloader) ready to receive SDRAM configuration.
  3396. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Loader ready to receive SDRAM configuration\n");
  3397. break;
  3398. case 0x05:
  3399. //Reset to Factory Defaults.
  3400. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Reset to Factory Defaults\n");
  3401. break;
  3402. default:
  3403. //Reserved
  3404. DEBUG_PRINTF_EVCOMM_DETAIL("QCA7K: Reserved\n");
  3405. break;
  3406. }
  3407. break;
  3408. }
  3409. case MMTYPE_VENDOR_ATTEN_CHAR:
  3410. {
  3411. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_ATTEN_CHAR ---\n");
  3412. break;
  3413. }
  3414. case MMTYPE_VENDOR_VS_NW_INFO_CNF:
  3415. {
  3416. // Only Set key for local QCA7000
  3417. if((MmePacket->OSA[0] == MmePacket->MMENTRY[12]) &&
  3418. (MmePacket->OSA[1] == MmePacket->MMENTRY[13]) &&
  3419. (MmePacket->OSA[2] == MmePacket->MMENTRY[14]) &&
  3420. (MmePacket->OSA[3] == MmePacket->MMENTRY[15]) &&
  3421. (MmePacket->OSA[4] == MmePacket->MMENTRY[16]) &&
  3422. (MmePacket->OSA[5] == MmePacket->MMENTRY[17]))
  3423. {
  3424. memcpy(QcaMac, MmePacket->OSA, 6);
  3425. DEBUG_PRINTF_EVCOMM_DETAIL("--- MMTYPE_VENDOR_VS_NW_INFO_CNF ---\n");
  3426. SAVE_SYS_LOG_MSG_EVCOMM("Got QCA7K MacAddr:%02X:%02X:%02X:%02X:%02X:%02X (comm:OK)\n",
  3427. QcaMac[0], QcaMac[1], QcaMac[2], QcaMac[3], QcaMac[4], QcaMac[5]);
  3428. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  3429. ftime(&SeqStartTime);
  3430. }
  3431. break;
  3432. }
  3433. case MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF:
  3434. {
  3435. struct QcaVendorMmeHeader *RecvPacket;
  3436. RecvPacket = (struct QcaVendorMmeHeader *)Buffer;
  3437. if(RecvPacket->MBODY[1]==0)
  3438. {
  3439. //PLC disconnected
  3440. sprintf((char*)buf_log_evcomm,
  3441. "[MMTYPE_VENDOR_VS_PL_LNK_STATUS_CNF]Got PLC Link Status:%d",
  3442. RecvPacket->MBODY[1]);
  3443. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  3444. Update_V2G_Flow_Status(Other_Fault);
  3445. }
  3446. else
  3447. Update_V2G_Flow_Status(CM_SET_KEY_REQ);
  3448. ftime(&SeqStartTime);
  3449. break;
  3450. }
  3451. default:
  3452. {
  3453. break;
  3454. }
  3455. }
  3456. return 0;
  3457. }
  3458. /*===========================================================================
  3459. FUNCTION: SlacComm
  3460. DESCRIPTION:
  3461. PRE-CONDITION:
  3462. INPUT:
  3463. OUTPUT:
  3464. GLOBAL VARIABLES:
  3465. =============================================================================*/
  3466. int SlacComm()
  3467. {
  3468. static unsigned char qca7k_comm_retry = 0;
  3469. double t_diff = 0;
  3470. int packet_size = 0;
  3471. int count = 0;
  3472. //int idx = 0;
  3473. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3474. unsigned char tmpBuf[2048]={0};
  3475. #endif
  3476. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  3477. unsigned char *EvMac_in;
  3478. unsigned char *RunID_in;
  3479. int i = 0;
  3480. #endif
  3481. if(RawSock >= 0)
  3482. {
  3483. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  3484. packet_size = recvfrom(RawSock, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, 0, NULL, NULL);
  3485. if(packet_size > 0)
  3486. {
  3487. MmeProcess(V2gtpMsgRxBuf, packet_size);
  3488. }
  3489. }
  3490. switch(Check_V2G_Flow_Status())
  3491. {
  3492. case IDLE:
  3493. {
  3494. if(RawSock < 0)
  3495. {
  3496. RawSock = socket(PF_PACKET, SOCK_RAW, htons(EtherType_HomePlug));
  3497. SAVE_SYS_LOG_MSG_EVCOMM("[RawSock]opened(%d)\n", RawSock);
  3498. if(RawSock == -1)
  3499. {
  3500. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm:Failed to create socket");
  3501. Update_V2G_Flow_Status(Other_Fault);
  3502. return -1;
  3503. }
  3504. if (setsockopt(RawSock, SOL_SOCKET, SO_BINDTODEVICE, QcaInterface, 4) < 0)
  3505. {
  3506. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm:Set SO_BINDTODEVICE NG");
  3507. Update_V2G_Flow_Status(Other_Fault);
  3508. return -1;
  3509. }
  3510. struct timeval tv;
  3511. tv.tv_sec = 0;
  3512. tv.tv_usec = 100000; //100ms (Rx timeout)
  3513. if (setsockopt(RawSock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
  3514. {
  3515. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm:Set SO_RCVTIMEO NG");
  3516. Update_V2G_Flow_Status(Other_Fault);
  3517. return -1;
  3518. }
  3519. tv.tv_usec = 100000; //100ms (Tx timeout)
  3520. if (setsockopt(RawSock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)) < 0)
  3521. {
  3522. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm:Set SO_SNDTIMEO NG");
  3523. Update_V2G_Flow_Status(Other_Fault);
  3524. return -1;
  3525. }
  3526. memset(&Req, 0, sizeof(struct ifreq));
  3527. strcpy( (char*)Req.ifr_name, QcaInterface);
  3528. if (ioctl(RawSock, SIOCGIFINDEX, &Req) < 0)
  3529. {
  3530. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SlacComm: ioctl NG");
  3531. Update_V2G_Flow_Status(Other_Fault);
  3532. return -1;
  3533. }
  3534. memset( &DestSocketAddress, 0, sizeof(struct sockaddr_ll));
  3535. DestSocketAddress.sll_ifindex = Req.ifr_ifindex;
  3536. DestSocketAddress.sll_halen = ETH_ALEN;
  3537. PwmStartTime = 0;
  3538. EVCOMM_SYS_INFO.QCA7K_SetKeyDone = FALSE;
  3539. SAVE_SYS_LOG_MSG_EVCOMM("QCA7000 connecting...\n");
  3540. //Get QCA7K MAC address
  3541. GetQca7kMac();
  3542. ftime(&SeqStartTime);
  3543. break;
  3544. }
  3545. else //RawSock: opened
  3546. {
  3547. if(EVCOMM_SYS_INFO.QCA7K_SetKeyDone == FALSE)
  3548. {
  3549. ftime(&SeqEndTime);
  3550. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3551. if (t_diff > V2G_SECC_QCA7000_GET_MAC_ADDR_REQ_RETRY_PERIOD) //3 secs
  3552. {
  3553. qca7k_comm_retry++;
  3554. SAVE_SYS_LOG_MSG_EVCOMM("Re-try connecting...(%.02lf/%dms)\n", t_diff, V2G_SECC_QCA7000_GET_MAC_ADDR_REQ_RETRY_PERIOD);
  3555. GetQca7kMac(); //re-send req
  3556. ftime(&SeqStartTime);
  3557. break;
  3558. }
  3559. else
  3560. {
  3561. //null
  3562. }
  3563. //Retry by 3 times
  3564. if (qca7k_comm_retry >= 3)
  3565. {
  3566. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Comm: fail (retry by %d times)\n", qca7k_comm_retry);
  3567. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3568. //CCS_SECCC_TIMEOUT_QCA7000_COMM (023892): The firmware code of QCA7000 may not be installed, yet
  3569. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3570. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3571. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3572. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3573. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  3574. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  3575. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3576. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3577. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  3578. Update_V2G_Flow_Status(Sequence_Timeout);
  3579. qca7k_comm_retry = 0;
  3580. break;
  3581. }
  3582. }
  3583. else //RawSock: opened; Set Key: DONE
  3584. {
  3585. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  3586. if((CheckConnectorPlugIn() == TRUE) && (ShmInternalComm->ChargingPermission >= 1))
  3587. {
  3588. if(PwmStartTime <= 0)
  3589. {
  3590. //Sniffer_Tcpdump(ENABLE);
  3591. //#if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  3592. //sleep(1); //wait for tcpdump to be ready.
  3593. //#endif
  3594. SwitchCpStateE(DISABLE);
  3595. OutputCpPwmDuty(5);
  3596. PwmStartTime = time(NULL);
  3597. }
  3598. else
  3599. {
  3600. if((time(NULL) - PwmStartTime) > TT_EVSE_SLAC_init)
  3601. {
  3602. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: Wait CM_SLAC_PARM_REQ Timeout - TT_EVSE_SLAC_init, NowTime(%ld)-PwmStartTime(%d)>%d (sec)\n", time(NULL), PwmStartTime, TT_EVSE_SLAC_init);
  3603. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3604. //CCS_SECC_TIMEOUT_SLAC_TT_EVSE_SLAC_init (023809)
  3605. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3606. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3607. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3608. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3609. ShmStatusCodeData->PresentStatusCode[0][4] = 0;
  3610. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  3611. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  3612. Update_V2G_Flow_Status(Sequence_Timeout);
  3613. PwmStartTime = 0;
  3614. return -1;
  3615. }
  3616. else
  3617. {
  3618. //waiting for CM_SLAC_PARM_REQ
  3619. }
  3620. }
  3621. }
  3622. else
  3623. {
  3624. PwmStartTime = 0;
  3625. }
  3626. }
  3627. }
  3628. break;
  3629. }
  3630. case CM_SET_KEY_REQ: //13
  3631. {
  3632. //CM_SET_KEY_REQ
  3633. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "QCA7000 [RX]CM_SET_KEY_REQ");
  3634. ftime(&SeqEndTime);
  3635. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3636. if (t_diff > V2G_SECC_QCA7000_COMM_TIMEOUT) //10 seconds
  3637. {
  3638. SAVE_SYS_LOG_MSG_EVCOMM("QCA7000 Failed on SetKey => End_Process (%.02lf/%dms)\n", t_diff, V2G_SECC_QCA7000_COMM_TIMEOUT);
  3639. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3640. //CCS_SECCC_TIMEOUT_QCA7000_COMM (023892): The firmware code of QCA7000 may not be installed, yet
  3641. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3642. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3643. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3644. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3645. ShmStatusCodeData->PresentStatusCode[0][4] = 9;
  3646. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  3647. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3648. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3649. Update_V2G_Flow_Status(Sequence_Timeout);
  3650. }
  3651. else if (t_diff > V2G_SECC_QCA7000_SEND_SET_KEY_PERIOD) //2 seconds
  3652. {
  3653. SAVE_SYS_LOG_MSG_EVCOMM("QCA7000 SetKey: proceed (%.02lf/%dms)\n", t_diff, V2G_SECC_QCA7000_SEND_SET_KEY_PERIOD);
  3654. SendSetKey();
  3655. ftime(&SeqStartTime);
  3656. }
  3657. else
  3658. {
  3659. //null
  3660. }
  3661. break;
  3662. }
  3663. case CM_SET_KEY_CNF: //14
  3664. {
  3665. SAVE_SYS_LOG_MSG_EVCOMM("Wait: plugin(%d), matached(%d), permission(%d)...\n", CheckConnectorPlugIn(), CSUCOMMDC_TASK_FLAG.matched, ShmInternalComm->ChargingPermission);
  3666. EVCOMM_SYS_INFO.QCA7K_SetKeyDone = TRUE;
  3667. PwmStartTime = 0;
  3668. Update_V2G_Flow_Status(IDLE);
  3669. break;
  3670. }
  3671. case CM_SLAC_PARM_CONF:
  3672. {
  3673. ftime(&SeqEndTime);
  3674. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_sequence)
  3675. {
  3676. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: Wait CM_START_ATTEN_CHAR_IND Timeout - TT_match_sequence (%.02lf of %dms)\n", DiffTimeb(SeqStartTime, SeqEndTime), TT_match_sequence);
  3677. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3678. //CCS_SECC_TIMEOUT_CM_START_ATTEN_CHAR_IND (023811):
  3679. //[Possible Reason] CCS Board image might not be updated properly. The 2nd reboot process is not finished.
  3680. //[Verification Method] By tying reboot command to the terminal and see if it could be executed immediately.
  3681. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3682. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3683. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3684. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3685. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  3686. ShmStatusCodeData->PresentStatusCode[0][5] = 1;
  3687. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3688. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3689. Update_V2G_Flow_Status(Sequence_Timeout);
  3690. return -1;
  3691. }
  3692. break;
  3693. }
  3694. case CM_START_ATTEN_CHAR_IND:
  3695. {
  3696. ftime(&SeqEndTime);
  3697. if(DiffTimeb(SeqStartTime, SeqEndTime) > (TP_EV_batch_msg_interval)) //one more time interval for tolerance
  3698. {
  3699. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: Wait CM_MNBC_SOUND_IND Timeout - TP_EV_batch_msg_interval (%.02lf of %dms)\n", DiffTimeb(SeqStartTime, SeqEndTime), TP_EV_batch_msg_interval);
  3700. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3701. //CCS_SECC_TIMEOUT_SLAC_CM_MNBC_SOUND_IND (023818):
  3702. //[Possible Reason] CCS Board image might not be updated properly. The 2nd reboot process is not finished.
  3703. //[Verification Method] By tying reboot command to the terminal and see if it could be executed immediately.
  3704. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3705. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3706. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  3707. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  3708. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  3709. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  3710. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  3711. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  3712. Update_V2G_Flow_Status(Sequence_Timeout);
  3713. return -1;
  3714. }
  3715. break;
  3716. }
  3717. case CM_MNBC_SOUND_IND:
  3718. {
  3719. #if (NEW_SLAC_ARCHITECTURE_SWITCH == ENABLE)
  3720. {
  3721. ftime(&SeqEndTime);
  3722. t_diff = DiffTimeb(SeqStartTime, SeqEndTime);
  3723. //printf("time:%.02lf, profilNum:%d\n",DiffTimeb(SeqStartTime, SeqEndTime),AttenProfileCnt); //added by Vern
  3724. if(t_diff > TT_EVSE_match_MNBC ||
  3725. (SLAC_INFO.array[0].AttenProfileCnt >= SLAC_INFO.array[0].MnbcSoundNum) ||
  3726. (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)) //TC_SECC_VTB_AttenuationCharacterization_003
  3727. {
  3728. //Wait for other SLAC Req sets
  3729. if ((SLAC_INFO.arrayLen >= 2) &&
  3730. (t_diff < TT_EVSE_match_MNBC) &&
  3731. (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry == 0)) //not a retry
  3732. {
  3733. break;
  3734. }
  3735. //Check if it is a timeup response
  3736. if (t_diff > TT_EVSE_match_MNBC)
  3737. {
  3738. SAVE_SYS_LOG_MSG_EVCOMM("[WARNING][SLAC][TX]CM_ATTEN_CHAR_IND[%d]: timeup(%.2f/%dms) => send\n", (i + 1), t_diff, TT_EVSE_match_MNBC);
  3739. }
  3740. //Sending all CM_ATTEN_CHAR_IND according to all corresponding SLAC Req sets
  3741. for (i = 0; i < SLAC_INFO.arrayLen; i++)
  3742. {
  3743. if ((SLAC_INFO.array[i].AttenProfileCnt == 0) ||
  3744. (SLAC_INFO.array[i].AagGroupsNum == 0) ||
  3745. (SLAC_INFO.array[i].StartAttenCharCnt == 0) ||
  3746. (SLAC_INFO.array[i].MnbcSoundNum != 10) || //received in CM_START_ATTEN_CHAR_IND
  3747. (SLAC_INFO.array[i].StartAttenCharErr == TRUE)
  3748. )
  3749. {
  3750. //Ignoring those SLAC request sets without sending CM_MNBC_SOUND_IND(CM_ATTEN_PROFILE_IND)
  3751. SAVE_SYS_LOG_MSG_EVCOMM("[WARNING][SLAC][TX]CM_ATTEN_CHAR_IND[%d]: para err(%d,%d,%d,%d,%d) => canceled\n",
  3752. (i + 1), SLAC_INFO.array[i].AttenProfileCnt, SLAC_INFO.array[i].AagGroupsNum, SLAC_INFO.array[i].StartAttenCharCnt, SLAC_INFO.array[i].MnbcSoundNum, SLAC_INFO.array[i].StartAttenCharErr);
  3753. continue;
  3754. }
  3755. //In CM_ATTEN_CHAR_IND retry process, here only re-send this message according to the 1st coming SLAC request
  3756. if ((EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0) && (i != 0))
  3757. {
  3758. SAVE_SYS_LOG_MSG_EVCOMM("[NOTE][SLAC][TX]CM_ATTEN_CHAR_IND[%d]: canceled\n", (i + 1));
  3759. break;
  3760. }
  3761. EvMac_in = SLAC_INFO.array[i].EvMac;
  3762. RunID_in = SLAC_INFO.array[i].RunID;
  3763. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3764. memcpy(SendMmePacket.ODA, EvMac_in, SLAC_EVMAC_LENGTH);
  3765. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3766. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3767. SendMmePacket.MMV = 0x01;
  3768. SendMmePacket.MMTYPE = MMTYPE_CM_ATTEN_CHAR_IND;
  3769. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3770. SendMmePacketSize = 0;
  3771. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00: EV-EVSE Matching)
  3772. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00: No Security)
  3773. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac_in, SLAC_EVMAC_LENGTH); //SOURCE_ADDRESS, MAC address of the EV Host
  3774. SendMmePacketSize += SLAC_EVMAC_LENGTH;
  3775. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, RunID_in, SLAC_RUNID_LENGTH);
  3776. SendMmePacketSize += SLAC_RUNID_LENGTH;
  3777. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //SOURCE_ID(0x00)
  3778. SendMmePacketSize += 17;
  3779. memset(SendMmePacket.MMENTRY + SendMmePacketSize, 0, 17); //RESP_ID(0x00)
  3780. SendMmePacketSize += 17;
  3781. SendMmePacket.MMENTRY[SendMmePacketSize++] = SLAC_INFO.array[i].AttenProfileCnt; //NumSounds: Number of M-Sounds used for generation of the ATTEN_PROFILE
  3782. SendMmePacket.MMENTRY[SendMmePacketSize++] = SLAC_INFO.array[i].AagGroupsNum; //NumGroups
  3783. for(count = 0; count < SLAC_INFO.array[i].AagGroupsNum; count++)
  3784. {
  3785. unsigned char TmpAag;
  3786. TmpAag = ((SLAC_INFO.array[i].AAG[count] / SLAC_INFO.array[i].AttenProfileCnt) & 0xFF);
  3787. SLAC_INFO.array[i].AAG_quality_ori += (float) TmpAag; //original signal quality
  3788. #if (SUDO_PSD_PARAMETER_MECHANISM == ENABLE) //default: ENABLE
  3789. #if 1
  3790. //TC_SECC_VTB_AttenuationCharacterization_019
  3791. TmpAag = TmpAag >> 1; //new method proposed by Joseph (divided by 2)
  3792. #else
  3793. if(TmpAag >= 39) //original method proposed by Vern
  3794. {
  3795. TmpAag = 37;
  3796. }
  3797. #endif
  3798. #endif
  3799. SendMmePacket.MMENTRY[SendMmePacketSize++] = TmpAag;
  3800. SLAC_INFO.array[i].AAG_quality_refined += (float) TmpAag; //refined signal quality
  3801. }
  3802. SendMmePacketSize += 19; //the size before MMENTRY
  3803. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3804. {
  3805. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Send MME Packet *****\n");
  3806. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3807. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3808. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3809. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3810. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3811. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3812. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3813. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3814. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_ATTEN_CHAR_IND ---\n");
  3815. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3816. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3817. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  3818. SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5],
  3819. SendMmePacket.MMENTRY[6],SendMmePacket.MMENTRY[7]);
  3820. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  3821. SendMmePacket.MMENTRY[8],SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],
  3822. SendMmePacket.MMENTRY[12],SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14],SendMmePacket.MMENTRY[15]);
  3823. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  3824. for(count=0; count<17; count++)
  3825. {
  3826. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[16+count]);
  3827. }
  3828. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: %s\n", tmpBuf);
  3829. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  3830. for(count=0; count<17; count++)
  3831. {
  3832. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[33+count]);
  3833. }
  3834. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: %s\n", tmpBuf);
  3835. DEBUG_PRINTF_EVCOMM_DETAIL("NumSounds: 0x%x\n", SendMmePacket.MMENTRY[50]);
  3836. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  3837. for(count=0; count<AagGroupsNum; count++)
  3838. {
  3839. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[51+count]);
  3840. }
  3841. DEBUG_PRINTF_EVCOMM_DETAIL("ATTEN_PROFILE: %s\n", tmpBuf);
  3842. }
  3843. #endif
  3844. count = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3845. SLAC_INFO.array[i].AAG_quality_ori /= SLAC_INFO.array[i].AagGroupsNum;
  3846. SLAC_INFO.array[i].AAG_quality_refined /= SLAC_INFO.array[i].AagGroupsNum;
  3847. //Print log if this CM_ATTEN_CHAR_IND belongs to RETRY Tx message.
  3848. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)
  3849. {
  3850. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][TX]CM_ATTEN_CHAR_IND[%d]: %d-th resend (Q=%.2f/%.2f)(%d/%d)\n",
  3851. (i + 1),
  3852. EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry,
  3853. SLAC_INFO.array[i].AAG_quality_refined,
  3854. SLAC_INFO.array[i].AAG_quality_ori,
  3855. SLAC_INFO.array[i].AttenProfileCnt,
  3856. SLAC_INFO.array[i].MnbcSoundNum);
  3857. }
  3858. else if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry == 0)
  3859. {
  3860. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][TX]CM_ATTEN_CHAR_IND[%d]: Q=%.2f/%.2f(%d/%d)\n",
  3861. (i + 1),
  3862. SLAC_INFO.array[i].AAG_quality_refined,
  3863. SLAC_INFO.array[i].AAG_quality_ori,
  3864. SLAC_INFO.array[i].AttenProfileCnt,
  3865. SLAC_INFO.array[i].MnbcSoundNum);
  3866. }
  3867. else
  3868. {
  3869. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][TX]CM_ATTEN_CHAR_IND[%d]: unexpected CM_ATTEN_CHAR_IND_retry(%d))\n", i, EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  3870. }
  3871. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n", SendMmePacketSize,count);
  3872. } //end of for loop
  3873. Update_V2G_Flow_Status(CM_ATTEN_CHAR_IND);
  3874. ftime(&SeqStartTime);
  3875. }
  3876. break;
  3877. }
  3878. #else
  3879. {
  3880. ftime(&SeqEndTime);
  3881. //printf("time:%.02lf, profilNum:%d\n",DiffTimeb(SeqStartTime, SeqEndTime),AttenProfileCnt); //added by Vern
  3882. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_EVSE_match_MNBC || (AttenProfileCnt >= MnbcSoundNum) || (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0))
  3883. {
  3884. memset(&SendMmePacket, 0, sizeof(struct MmeHeader));
  3885. memcpy(SendMmePacket.ODA, EvMac, 6);
  3886. memcpy(SendMmePacket.OSA, CsuMac, 6);
  3887. SendMmePacket.MTYPE = htons(EtherType_HomePlug);
  3888. SendMmePacket.MMV = 0x01;
  3889. SendMmePacket.MMTYPE = MMTYPE_CM_ATTEN_CHAR_IND;
  3890. SendMmePacket.FMI[0] = SendMmePacket.FMI[1] = 0;
  3891. SendMmePacketSize = 0;
  3892. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //APPLICATION_TYPE(0x00: EV-EVSE Matching)
  3893. SendMmePacket.MMENTRY[SendMmePacketSize++] = 0; //SECURITY_TYPE(0x00: No Security)
  3894. memcpy(SendMmePacket.MMENTRY + SendMmePacketSize, EvMac, 6); //SOURCE_ADDRESS, MAC address of the EV Host
  3895. SendMmePacketSize += 6;
  3896. memcpy(SendMmePacket.MMENTRY+SendMmePacketSize, SlacRunId, sizeof(SlacRunId));
  3897. SendMmePacketSize += sizeof(SlacRunId);
  3898. memset(SendMmePacket.MMENTRY+SendMmePacketSize, 0, 17); //SOURCE_ID
  3899. SendMmePacketSize += 17;
  3900. memset(SendMmePacket.MMENTRY+SendMmePacketSize, 0, 17); //RESP_ID
  3901. SendMmePacketSize += 17;
  3902. SendMmePacket.MMENTRY[SendMmePacketSize++] = AttenProfileCnt; //NumSounds
  3903. SendMmePacket.MMENTRY[SendMmePacketSize++] = AagGroupsNum; //NumGroups
  3904. for(count=0; count < AagGroupsNum; count++)
  3905. {
  3906. unsigned char TmpAag;
  3907. TmpAag = ((Aag[count] / AttenProfileCnt) & 0xFF);
  3908. #if (SUDO_PSD_PARAMETER_MECHANISM == ENABLE) //default: ENABLE
  3909. #if 1
  3910. //TC_SECC_VTB_AttenuationCharacterization_019
  3911. TmpAag = TmpAag >> 1; //new method proposed by Joseph (divided by 2)
  3912. #else
  3913. if(TmpAag >= 39) //original method proposed by Vern
  3914. {
  3915. /*
  3916. // [To-do] If this statement is enabled, SLAC will fail due to timeout.
  3917. {
  3918. unsigned char TmpBuf[64];
  3919. memset(TmpBuf,0,sizeof(TmpBuf));
  3920. sprintf((char*)TmpBuf,"SlacComm: bad Aag[%d]=%d",count,TmpAag);
  3921. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", TmpBuf);
  3922. }
  3923. */
  3924. printf("%d,", TmpAag);
  3925. TmpAag = 37;
  3926. }
  3927. #endif
  3928. #endif
  3929. SendMmePacket.MMENTRY[SendMmePacketSize++] = TmpAag;
  3930. }
  3931. SendMmePacketSize += 19; //the size before MMENTRY
  3932. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  3933. {
  3934. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Send MME Packet *****\n");
  3935. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.ODA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3936. SendMmePacket.ODA[0],SendMmePacket.ODA[1],SendMmePacket.ODA[2],SendMmePacket.ODA[3],SendMmePacket.ODA[4],SendMmePacket.ODA[5]);
  3937. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacket.OSA: %02x:%02x:%02x:%02x:%02x:%02x:\n",
  3938. SendMmePacket.OSA[0],SendMmePacket.OSA[1],SendMmePacket.OSA[2],SendMmePacket.OSA[3],SendMmePacket.OSA[4],SendMmePacket.OSA[5]);
  3939. DEBUG_PRINTF_EVCOMM_DETAIL("MTYPE: 0x%x\n", htons(SendMmePacket.MTYPE));
  3940. DEBUG_PRINTF_EVCOMM_DETAIL("MMV: 0x%x\n", SendMmePacket.MMV);
  3941. DEBUG_PRINTF_EVCOMM_DETAIL("MMTYPE: 0x%x\n", SendMmePacket.MMTYPE);
  3942. DEBUG_PRINTF_EVCOMM_DETAIL("FMI 0x%x, 0x%x\n", SendMmePacket.FMI[0],SendMmePacket.FMI[1]);
  3943. DEBUG_PRINTF_EVCOMM_DETAIL("--- CM_ATTEN_CHAR_IND ---\n");
  3944. DEBUG_PRINTF_EVCOMM_DETAIL("APPLICATION_TYPE: 0x%x\n", SendMmePacket.MMENTRY[0]);
  3945. DEBUG_PRINTF_EVCOMM_DETAIL("SECURITY_TYPE: 0x%x\n", SendMmePacket.MMENTRY[1]);
  3946. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ADDRESS: %02x:%02x:%02x:%02x:%02x:%02x\n",
  3947. SendMmePacket.MMENTRY[2],SendMmePacket.MMENTRY[3],SendMmePacket.MMENTRY[4],SendMmePacket.MMENTRY[5],
  3948. SendMmePacket.MMENTRY[6],SendMmePacket.MMENTRY[7]);
  3949. DEBUG_PRINTF_EVCOMM_DETAIL("RunID: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x\n",
  3950. SendMmePacket.MMENTRY[8],SendMmePacket.MMENTRY[9],SendMmePacket.MMENTRY[10],SendMmePacket.MMENTRY[11],
  3951. SendMmePacket.MMENTRY[12],SendMmePacket.MMENTRY[13],SendMmePacket.MMENTRY[14],SendMmePacket.MMENTRY[15]);
  3952. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  3953. for(count=0; count<17; count++)
  3954. {
  3955. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[16+count]);
  3956. }
  3957. DEBUG_PRINTF_EVCOMM_DETAIL("SOURCE_ID: %s\n", tmpBuf);
  3958. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));;
  3959. for(count=0; count<17; count++)
  3960. {
  3961. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[33+count]);
  3962. }
  3963. DEBUG_PRINTF_EVCOMM_DETAIL("RESP_ID: %s\n", tmpBuf);
  3964. DEBUG_PRINTF_EVCOMM_DETAIL("NumSounds: 0x%x\n", SendMmePacket.MMENTRY[50]);
  3965. memset(tmpBuf, 0x00, ARRAY_SIZE(tmpBuf));
  3966. for(count=0; count<AagGroupsNum; count++)
  3967. {
  3968. sprintf((char*)tmpBuf, "%s%02x,", tmpBuf, SendMmePacket.MMENTRY[51+count]);
  3969. }
  3970. DEBUG_PRINTF_EVCOMM_DETAIL("ATTEN_PROFILE: %s\n", tmpBuf);
  3971. }
  3972. #endif
  3973. Update_V2G_Flow_Status(CM_ATTEN_CHAR_IND);
  3974. count = sendto(RawSock, &SendMmePacket, SendMmePacketSize, 0, (struct sockaddr*)&DestSocketAddress, sizeof(struct sockaddr_ll));
  3975. //Print log if this CM_ATTEN_CHAR_IND belongs to RETRY Tx message.
  3976. if (EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry > 0)
  3977. {
  3978. SAVE_SYS_LOG_MSG_EVCOMM("[SLAC][TX]CM_ATTEN_CHAR_IND: resend(%d-th)\n", EVCOMM_SYS_INFO.CM_ATTEN_CHAR_IND_retry);
  3979. }
  3980. DEBUG_PRINTF_EVCOMM_DETAIL("SendMmePacketSize=%d,Rtn=%d\n", SendMmePacketSize,count);
  3981. ftime(&SeqStartTime);
  3982. }
  3983. break;
  3984. }
  3985. #endif
  3986. }
  3987. case CM_ATTEN_CHAR_IND:
  3988. {
  3989. ftime(&SeqEndTime);
  3990. //if(DiffTimeb(SeqStartTime, SeqEndTime)>TT_match_response)
  3991. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_response) //extended to 400ms due to the response of CM_ATTEN_CHAR.RSP of some EVCC is slower than 200ms.
  3992. {
  3993. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: Wait CM_ATTEN_CHAR_RSP Timeout - TT_match_response (%.02lf of %dms)\n", DiffTimeb(SeqStartTime, SeqEndTime), TT_match_response);
  3994. //Update_ShmStatusCode(); //[To-Do] to be implemented
  3995. //CCS_SECC_TIMEOUT_SLAC_CM_ATTEN_CHAR_RSP (023814):
  3996. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  3997. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  3998. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  3999. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4000. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4001. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4002. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  4003. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  4004. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4005. Update_V2G_Flow_Status(Sequence_Timeout);
  4006. return -1;
  4007. }
  4008. break;
  4009. }
  4010. case CM_ATTEN_CHAR_RSP:
  4011. {
  4012. ftime(&SeqEndTime);
  4013. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_EVSE_match_session)
  4014. {
  4015. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: Wait CM_VALIDATE_REQ_1ST or CM_SLAC_MATCH_REQ Timeout - TT_EVSE_match_session (%.02lf of %dms)\n", DiffTimeb(SeqStartTime, SeqEndTime), TT_EVSE_match_session);
  4016. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4017. //CCS_SECC_TIMEOUT_SLAC_CM_VALIDATE_REQ_1ST__CM_SLAC_MATCH_REQ (023815):
  4018. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4019. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4020. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4021. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4022. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4023. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4024. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  4025. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  4026. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4027. Update_V2G_Flow_Status(Sequence_Timeout);
  4028. return -1;
  4029. }
  4030. break;
  4031. }
  4032. case CM_VALIDATE_CNF:
  4033. {
  4034. ftime(&SeqEndTime);
  4035. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_sequence)
  4036. {
  4037. SAVE_SYS_LOG_MSG_EVCOMM("SlacComm: Wait CM_VALIDATE_REQ_2ND or CM_SLAC_MATCH_REQ Timeout - TT_match_sequence (%.02lf of %dms)\n", DiffTimeb(SeqStartTime, SeqEndTime), TT_match_sequence);
  4038. //Update_ShmStatusCode(); //[To-Do] to be implemented
  4039. //CCS_SECC_TIMEOUT_SLAC_CM_VALIDATE_REQ_2ND__CM_SLAC_MATCH_REQ (023819):
  4040. //[Possible Reason] Frequent on BMW i3, need to drive the EV a bit.
  4041. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  4042. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  4043. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  4044. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  4045. ShmStatusCodeData->PresentStatusCode[0][4] = 1;
  4046. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  4047. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = FALSE;
  4048. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4049. Update_V2G_Flow_Status(Sequence_Timeout);
  4050. return -1;
  4051. }
  4052. break;
  4053. }
  4054. case CM_SLAC_MATCH_CNF:
  4055. {
  4056. if(UdpSock > 0)
  4057. {
  4058. close(UdpSock);
  4059. UdpSock = -1;
  4060. }
  4061. if(TcpSock > 0)
  4062. {
  4063. close(TcpSock);
  4064. TcpSock = -1;
  4065. }
  4066. ftime(&SeqStartTime);
  4067. V2gTcpConnected();
  4068. Update_V2G_Flow_Status(SLACC_SDP_UDP_Connection);
  4069. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SLAAC,SDP,UDP: connecting...");
  4070. break;
  4071. }
  4072. default:
  4073. {
  4074. break;
  4075. }
  4076. }
  4077. return 0;
  4078. }
  4079. /*===========================================================================
  4080. FUNCTION: V2gMsgDecoder
  4081. DESCRIPTION:
  4082. 1. Decode the V2GTP messages inside "msg" and save the decoded
  4083. messages in ccs_exi_doc_DIN, ccs_exi_doc_ISO1, and ccs_exi_doc_ISO2,
  4084. respectively.
  4085. 2. After decoding, V2gMsg_Process() could then use
  4086. ccs_exi_doc_DIN, ccs_exi_doc_ISO1, or ccs_exi_doc_ISO2
  4087. to deal with the corresponding Response messages, respectively.
  4088. PRE-CONDITION:
  4089. 1. msg_length > 0
  4090. INPUT:
  4091. 1. msg
  4092. 2. msg_length
  4093. OUTPUT:
  4094. 1. ccs_exi_doc_DIN //global variable
  4095. ccs_exi_doc_ISO1
  4096. ccs_exi_doc_ISO2
  4097. 2. v2g_state //Status Flag
  4098. //indicating the V2gMsg_Process_din to proceed
  4099. the next process.
  4100. 3. return value // < 0: ERROR
  4101. // > 0: Message Type
  4102. GLOBAL VARIABLES:
  4103. =============================================================================*/
  4104. int V2gMsgDecoder(unsigned char *msg, unsigned int msg_length, unsigned int v2g_state)
  4105. {
  4106. int errn = 0;
  4107. //Checking the minimum Header size requirement
  4108. if(msg_length < V2GTP_MSG_HEADER_LENGTH) //The minimum requirement should be 8-byte header.
  4109. {
  4110. errn = -1;
  4111. return errn;
  4112. }
  4113. //Decode the 1st V2GMSG: AppProtocol
  4114. if(v2g_state == SupportedAppProtocolRequest) //17
  4115. {
  4116. if ((errn = API_V2GMSG_EXI_Decoder_AppProtocol(msg, msg_length, &ccs_handshake)) < 0)
  4117. {
  4118. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR = %d (DEC)]V2gMsgDecoder: SupportedAppProtocolRequest()\n", errn);
  4119. }
  4120. else //decoded successfully.
  4121. {
  4122. //PRINT_XML_DOC_supportedAppProtocolReq(&ccs_handshake);
  4123. }
  4124. }
  4125. //Decode the subsequent V2GMSG (DIN 70121, ISO 15118-2, ISO 15118-20)
  4126. else if(v2g_state > SupportedAppProtocolRequest && v2g_state <= SessionStopResponse)
  4127. {
  4128. //Decoding according to its own protocol
  4129. switch (ShmCcsData->CommProtocol)
  4130. {
  4131. case V2GT_MSG_PROTOCOL_DIN70121: //0
  4132. {
  4133. //DIN
  4134. if((errn = API_V2GMSG_EXI_Decoder_DIN(msg, msg_length, &ccs_exi_doc_DIN)) < 0)
  4135. {
  4136. sprintf((char*)buf_log_evcomm,
  4137. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_DIN()",
  4138. errn);
  4139. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4140. }
  4141. break;
  4142. }
  4143. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  4144. {
  4145. //ISO1
  4146. if((errn = API_V2GMSG_EXI_Decoder_ISO1(msg, msg_length, &ccs_exi_doc_ISO1)) < 0)
  4147. {
  4148. sprintf((char*)buf_log_evcomm,
  4149. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_ISO1()",
  4150. errn);
  4151. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4152. }
  4153. break;
  4154. }
  4155. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  4156. {
  4157. //ISO2
  4158. if((errn = API_V2GMSG_EXI_Decoder_ISO2(msg, msg_length, &ccs_exi_doc_ISO2)) < 0)
  4159. {
  4160. sprintf((char*)buf_log_evcomm,
  4161. "[ERROR = %d (DEC)]V2gMsgDecoder: API_V2GMSG_EXI_Decoder_ISO2()",
  4162. errn);
  4163. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4164. }
  4165. break;
  4166. }
  4167. default:
  4168. break;
  4169. }
  4170. }
  4171. else
  4172. {
  4173. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR = %d (DEC)]V2gMsgDecoder: Unexpected v2g_state\n", errn);
  4174. errn = -1;
  4175. }
  4176. return errn;
  4177. }
  4178. /*===========================================================================
  4179. FUNCTION: encode_din_V2GTP_stream
  4180. DESCRIPTION:
  4181. PRE-CONDITION:
  4182. INPUT:
  4183. OUTPUT:
  4184. GLOBAL VARIABLES:
  4185. =============================================================================*/
  4186. int encode_din_V2GTP_stream(bitstream_t *v2g_tx_stream, struct dinEXIDocument *ccs_exi_doc_DIN)
  4187. {
  4188. int errn = 0;
  4189. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4190. errn = encode_dinExiDocument(v2g_tx_stream, ccs_exi_doc_DIN);
  4191. if (errn == 0)
  4192. {
  4193. //successfully encoded
  4194. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4195. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4196. if (errn != 0)
  4197. {
  4198. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_din_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4199. }
  4200. }
  4201. else
  4202. {
  4203. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_din_V2GTP_stream]encode_dinExiDocument(): %d (DEC)\n", errn);
  4204. }
  4205. return errn;
  4206. }
  4207. /*===========================================================================
  4208. FUNCTION: encode_iso1_V2GTP_stream
  4209. DESCRIPTION:
  4210. PRE-CONDITION:
  4211. INPUT:
  4212. OUTPUT:
  4213. GLOBAL VARIABLES:
  4214. =============================================================================*/
  4215. int encode_iso1_V2GTP_stream(bitstream_t *v2g_tx_stream, struct iso1EXIDocument *ccs_exi_doc_ISO1)
  4216. {
  4217. int errn = 0;
  4218. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4219. errn = encode_iso1ExiDocument(v2g_tx_stream, ccs_exi_doc_ISO1);
  4220. if (errn == 0)
  4221. {
  4222. //successfully encoded
  4223. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4224. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4225. if (errn != 0)
  4226. {
  4227. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso1_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4228. }
  4229. }
  4230. else
  4231. {
  4232. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso1_V2GTP_stream]encode_iso1ExiDocument(): %d (DEC)\n", errn);
  4233. }
  4234. return errn;
  4235. }
  4236. /*===========================================================================
  4237. FUNCTION: encode_iso2_V2GTP_stream
  4238. DESCRIPTION:
  4239. PRE-CONDITION:
  4240. INPUT:
  4241. OUTPUT:
  4242. GLOBAL VARIABLES:
  4243. =============================================================================*/
  4244. int encode_iso2_V2GTP_stream(bitstream_t *v2g_tx_stream, struct iso2EXIDocument *ccs_exi_doc_ISO2)
  4245. {
  4246. int errn = 0;
  4247. *v2g_tx_stream->pos = V2GTP_HEADER_LENGTH;
  4248. errn = encode_iso2ExiDocument(v2g_tx_stream, ccs_exi_doc_ISO2);
  4249. if (errn == 0)
  4250. {
  4251. //successfully encoded
  4252. errn = write_v2gtpHeader(v2g_tx_stream->data, (*v2g_tx_stream->pos) - V2GTP_HEADER_LENGTH, V2GTP_EXI_TYPE);
  4253. v2g_tx_stream->size = *v2g_tx_stream->pos; //total length of the encoded V2GMSG.
  4254. if (errn != 0)
  4255. {
  4256. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso2_V2GTP_stream]write_v2gtpHeader(): %d (DEC)\n", errn);
  4257. }
  4258. }
  4259. else
  4260. {
  4261. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR][SeccComm][encode_iso2_V2GTP_stream]encode_iso2ExiDocument(): %d (DEC)\n", errn);
  4262. }
  4263. return errn;
  4264. }
  4265. /*===========================================================================
  4266. FUNCTION: send_encoded_din_V2GTP_Stream
  4267. DESCRIPTION:
  4268. PRE-CONDITION:
  4269. INPUT:
  4270. OUTPUT:
  4271. GLOBAL VARIABLES:
  4272. =============================================================================*/
  4273. int send_encoded_din_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct dinEXIDocument *ccs_exi_doc_DIN)
  4274. {
  4275. int errn = 0;
  4276. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4277. errn = encode_din_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_DIN);
  4278. // STEP 2: =========== Send Response Packet ===========
  4279. int rtn = 0;
  4280. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4281. if (rtn == v2g_tx_stream->size)
  4282. {
  4283. /*
  4284. DEBUG_PRINTF_EVCOMM_DETAIL("Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4285. rtn, v2g_tx_stream->size);
  4286. */
  4287. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4288. }
  4289. else if (rtn >= 0)
  4290. {
  4291. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]Incomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n", rtn, v2g_tx_stream->size);
  4292. }
  4293. else
  4294. {
  4295. errn = rtn;
  4296. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]send(): %d (DEC)\n", errn);
  4297. }
  4298. //STEP 3: ========= Reset V2G MSG Flags ==========
  4299. init_dinBodyType(&ccs_exi_doc_DIN->V2G_Message.Body);
  4300. return errn;
  4301. }
  4302. /*===========================================================================
  4303. FUNCTION: send_encoded_iso1_V2GTP_Stream
  4304. DESCRIPTION:
  4305. PRE-CONDITION:
  4306. INPUT:
  4307. OUTPUT:
  4308. GLOBAL VARIABLES:
  4309. =============================================================================*/
  4310. int send_encoded_iso1_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct iso1EXIDocument *ccs_exi_doc_ISO1)
  4311. {
  4312. int errn = 0;
  4313. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4314. errn = encode_iso1_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_ISO1);
  4315. // STEP 2: =========== Send Response Packet ===========
  4316. int rtn = 0;
  4317. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4318. if (rtn == v2g_tx_stream->size)
  4319. {
  4320. //DEBUG_PRINTF_EVCOMM_DETAIL("Response message sent (%d/%d)(Bytes, DEC): OK\n", rtn, v2g_tx_stream->size);
  4321. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4322. }
  4323. else if (rtn >= 0)
  4324. {
  4325. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]Incomplete Tx (%d/%d)(Bytes, DEC): FAIL\n", rtn, v2g_tx_stream->size);
  4326. }
  4327. else
  4328. {
  4329. errn = rtn;
  4330. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]send(): %d(DEC)\n", errn);
  4331. }
  4332. //STEP 3: ========= Reset V2G MSG Flags ==========
  4333. init_iso1BodyType(&ccs_exi_doc_ISO1->V2G_Message.Body);
  4334. return errn;
  4335. }
  4336. /*===========================================================================
  4337. FUNCTION: send_encoded_iso2_V2GTP_Stream
  4338. DESCRIPTION:
  4339. PRE-CONDITION:
  4340. INPUT:
  4341. OUTPUT:
  4342. GLOBAL VARIABLES:
  4343. =============================================================================*/
  4344. int send_encoded_iso2_V2GTP_Stream(int AcceptFd, bitstream_t *v2g_tx_stream, struct iso2EXIDocument *ccs_exi_doc_ISO2)
  4345. {
  4346. int errn = 0;
  4347. // STEP 1: =========== Encoding into EXI and Composing into V2GTP Stream ==========
  4348. errn = encode_iso2_V2GTP_stream(v2g_tx_stream, ccs_exi_doc_ISO2);
  4349. // STEP 2: =========== Send Response Packet ===========
  4350. int rtn = 0;
  4351. rtn = send(AcceptFd, v2g_tx_stream->data, v2g_tx_stream->size, 0);
  4352. if (rtn == v2g_tx_stream->size)
  4353. {
  4354. /*
  4355. DEBUG_PRINTF_EVCOMM_DETAIL("Response Message is sent ( %d / %d ). (Bytes, DEC): OK\n",
  4356. rtn, v2g_tx_stream->size);
  4357. */
  4358. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4359. }
  4360. else if (rtn >= 0)
  4361. {
  4362. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]Incomplete Tx ( %d / %d ). (Bytes, DEC): FAIL\n",
  4363. rtn, v2g_tx_stream->size);
  4364. }
  4365. else
  4366. {
  4367. errn = rtn;
  4368. DEBUG_PRINTF_EVCOMM_DETAIL("[ERROR]send(): %d (DEC)\n", errn);
  4369. }
  4370. //STEP 3: ========= Reset V2G MSG Flags ==========
  4371. init_iso2BodyType(&ccs_exi_doc_ISO2->V2G_Message.Body);
  4372. return errn;
  4373. }
  4374. /*===========================================================================
  4375. FUNCTION: Check_din_V2G_Rx_MSG_SessionID
  4376. DESCRIPTION:
  4377. PRE-CONDITION:
  4378. INPUT:
  4379. OUTPUT:
  4380. GLOBAL VARIABLES:
  4381. =============================================================================*/
  4382. int Check_din_V2G_Rx_MSG_SessionID(struct dinEXIDocument *exi_doc_DIN)
  4383. {
  4384. int i = 0;
  4385. int leng = 0;
  4386. int errn = 0;
  4387. leng = exi_doc_DIN->V2G_Message.Header.SessionID.bytesLen;
  4388. //Step 1: Check SessionID Length
  4389. if (leng != 8) //8-byte
  4390. {
  4391. sprintf((char*)buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4392. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4393. errn = -1;
  4394. }
  4395. else
  4396. {
  4397. //Step 2-1: Check SessionID content
  4398. for (i = 0; i < leng; i++)
  4399. {
  4400. if (exi_doc_DIN->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4401. {
  4402. errn = -2;
  4403. break;
  4404. }
  4405. }
  4406. }
  4407. //Step 2-2: Print Incorrect ID
  4408. if (errn == -2) //incorrect ID
  4409. {
  4410. sprintf((char*)buf_log_evcomm,
  4411. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4412. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[0],
  4413. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[1],
  4414. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[2],
  4415. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[3],
  4416. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[4],
  4417. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[5],
  4418. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[6],
  4419. exi_doc_DIN->V2G_Message.Header.SessionID.bytes[7],
  4420. EVCOMM_SYS_INFO.SessionID[0],
  4421. EVCOMM_SYS_INFO.SessionID[1],
  4422. EVCOMM_SYS_INFO.SessionID[2],
  4423. EVCOMM_SYS_INFO.SessionID[3],
  4424. EVCOMM_SYS_INFO.SessionID[4],
  4425. EVCOMM_SYS_INFO.SessionID[5],
  4426. EVCOMM_SYS_INFO.SessionID[6],
  4427. EVCOMM_SYS_INFO.SessionID[7]
  4428. );
  4429. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4430. }
  4431. //Step 3: Correct SessionID for Res Message
  4432. if (errn != 0)
  4433. {
  4434. exi_doc_DIN->V2G_Message.Header.SessionID.bytesLen = 8;
  4435. memset(exi_doc_DIN->V2G_Message.Header.SessionID.bytes, 0, 8);
  4436. memcpy(exi_doc_DIN->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4437. }
  4438. return errn;
  4439. }
  4440. /*===========================================================================
  4441. FUNCTION: Check_iso1_V2G_Rx_MSG_SessionID
  4442. DESCRIPTION:
  4443. PRE-CONDITION:
  4444. INPUT:
  4445. OUTPUT:
  4446. GLOBAL VARIABLES:
  4447. =============================================================================*/
  4448. int Check_iso1_V2G_Rx_MSG_SessionID(struct iso1EXIDocument *exi_doc_ISO1)
  4449. {
  4450. int i = 0;
  4451. int leng = 0;
  4452. int errn = 0;
  4453. leng = exi_doc_ISO1->V2G_Message.Header.SessionID.bytesLen;
  4454. //Step 1: Check SessionID Length
  4455. if (leng != 8) //8-byte
  4456. {
  4457. sprintf((char*)buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4458. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4459. errn = -1;
  4460. }
  4461. else
  4462. {
  4463. //Step 2-1: Check SessionID content
  4464. for (i = 0; i < leng; i++)
  4465. {
  4466. if (exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4467. {
  4468. errn = -2;
  4469. break;
  4470. }
  4471. }
  4472. }
  4473. //Step 2-2: Print Incorrect ID
  4474. if (errn == -2) //incorrect ID
  4475. {
  4476. sprintf((char*)buf_log_evcomm,
  4477. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4478. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[0],
  4479. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[1],
  4480. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[2],
  4481. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[3],
  4482. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[4],
  4483. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[5],
  4484. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[6],
  4485. exi_doc_ISO1->V2G_Message.Header.SessionID.bytes[7],
  4486. EVCOMM_SYS_INFO.SessionID[0],
  4487. EVCOMM_SYS_INFO.SessionID[1],
  4488. EVCOMM_SYS_INFO.SessionID[2],
  4489. EVCOMM_SYS_INFO.SessionID[3],
  4490. EVCOMM_SYS_INFO.SessionID[4],
  4491. EVCOMM_SYS_INFO.SessionID[5],
  4492. EVCOMM_SYS_INFO.SessionID[6],
  4493. EVCOMM_SYS_INFO.SessionID[7]
  4494. );
  4495. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4496. }
  4497. //Step 3: Correct SessionID for Res Message
  4498. if (errn != 0)
  4499. {
  4500. exi_doc_ISO1->V2G_Message.Header.SessionID.bytesLen = 8;
  4501. memset(exi_doc_ISO1->V2G_Message.Header.SessionID.bytes, 0, 8);
  4502. memcpy(exi_doc_ISO1->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4503. }
  4504. return errn;
  4505. }
  4506. /*===========================================================================
  4507. FUNCTION: Check_iso2_V2G_Rx_MSG_SessionID
  4508. DESCRIPTION:
  4509. PRE-CONDITION:
  4510. INPUT:
  4511. OUTPUT:
  4512. GLOBAL VARIABLES:
  4513. =============================================================================*/
  4514. int Check_iso2_V2G_Rx_MSG_SessionID(struct iso2EXIDocument *exi_doc_ISO2)
  4515. {
  4516. int i = 0;
  4517. int leng = 0;
  4518. int errn = 0;
  4519. leng = exi_doc_ISO2->V2G_Message.Header.SessionID.bytesLen;
  4520. //Step 1: Check SessionID Length
  4521. if (leng != 8) //8-byte
  4522. {
  4523. sprintf((char*)buf_log_evcomm, "[ERROR]SessionID: incorrect length(%d)", leng);
  4524. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4525. errn = -1;
  4526. }
  4527. else
  4528. {
  4529. //Step 2-1: Check SessionID content
  4530. for (i = 0; i < leng; i++)
  4531. {
  4532. if (exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[i] != EVCOMM_SYS_INFO.SessionID[i])
  4533. {
  4534. errn = -2;
  4535. break;
  4536. }
  4537. }
  4538. }
  4539. //Step 2-2: Print Incorrect ID
  4540. if (errn == -2) //incorrect ID
  4541. {
  4542. sprintf((char*)buf_log_evcomm,
  4543. "[ERROR]SessionID: incorrect ID(RX:%02X%02X%02X%02X%02X%02X%02X%02X, ORI:%02X%02X%02X%02X%02X%02X%02X%02X)",
  4544. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[0],
  4545. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[1],
  4546. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[2],
  4547. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[3],
  4548. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[4],
  4549. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[5],
  4550. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[6],
  4551. exi_doc_ISO2->V2G_Message.Header.SessionID.bytes[7],
  4552. EVCOMM_SYS_INFO.SessionID[0],
  4553. EVCOMM_SYS_INFO.SessionID[1],
  4554. EVCOMM_SYS_INFO.SessionID[2],
  4555. EVCOMM_SYS_INFO.SessionID[3],
  4556. EVCOMM_SYS_INFO.SessionID[4],
  4557. EVCOMM_SYS_INFO.SessionID[5],
  4558. EVCOMM_SYS_INFO.SessionID[6],
  4559. EVCOMM_SYS_INFO.SessionID[7]
  4560. );
  4561. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4562. }
  4563. //Step 3: Correct SessionID for Res Message
  4564. if (errn != 0)
  4565. {
  4566. exi_doc_ISO2->V2G_Message.Header.SessionID.bytesLen = 8;
  4567. memset(exi_doc_ISO2->V2G_Message.Header.SessionID.bytes, 0, 8);
  4568. memcpy(exi_doc_ISO2->V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  4569. }
  4570. return errn;
  4571. }
  4572. /*===========================================================================
  4573. FUNCTION: GetSchemaID_of_Protocol
  4574. DESCRIPTION:
  4575. 1. Get the SchemaID accroding to the input target
  4576. *V2GT_MSG_PROTOCOL_DIN70121: choose DIN 70121
  4577. *V2GT_MSG_PROTOCOL_ISO15118_2014: choose ISO 15118-2 (ed1)
  4578. *V2GT_MSG_PROTOCOL_ISO15118_2018: choose ISO 15118-20 (ed2)
  4579. *V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY: choose the one with the highest priority
  4580. 2. [To-do] Checking Major and Minor version
  4581. 3. The parsing method will not support those private protocols,
  4582. such as "usr:tesla...," since "tesla" is 5 bytes but "din" and "iso" are 3 bytes.
  4583. 4. [To-do] If the target is selected as DIN," but there is no DIN.
  4584. However, if EV and EVSE all support ISO, how to use ISO instead?
  4585. PRE-CONDITION:
  4586. INPUT:
  4587. 1. target: target protocol
  4588. OUTPUT:
  4589. 1. id: SchemaID of selected protocol by EVSE
  4590. 2. ShmCcsData->CommProtocol (selected protocol)
  4591. 3. SupportedAppProtocol_result
  4592. (1) appHandresponseCodeType_OK_SuccessfulNegotiation = 0,
  4593. (2) appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation = 1,
  4594. (3) appHandresponseCodeType_Failed_NoNegotiation = 2
  4595. GLOBAL VARIABLES:
  4596. 1. ccs_handshake
  4597. 2. ShmCcsData
  4598. =============================================================================*/
  4599. int GetSchemaID_of_Protocol(unsigned char target)
  4600. {
  4601. int i = 0;
  4602. int ii = 0;
  4603. int id = 0;
  4604. //unsigned char tmp = 0;
  4605. unsigned char pri = 20; //priority = 1(highest)~20(lowerest)
  4606. char num[10];
  4607. //struct CCS_ProtocolNamespacestructCharacters pro;
  4608. //Choose the 1st protocol as default.
  4609. //id = CCS_HANDSHAKE_PROTOCOLS.array[0].SchemaID;
  4610. id = -1;
  4611. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4612. for(i = 0; i < CCS_HANDSHAKE_PROTOCOLS.arrayLen; i++)
  4613. {
  4614. //Checking for <ProtocolNamespace>urn:din:70121:2012:MsgDef</ProtocolNamespace>
  4615. //[To-Do] Ignoring the priority from EV and force DIN 70121 as our only option. (for temp)
  4616. //[CAUTION] The parsing method will not support those private protocols, such as "usr:tesla..."
  4617. num[0] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[8];
  4618. num[1] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[9];
  4619. num[2] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[10];
  4620. num[3] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[11];
  4621. num[4] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[12];
  4622. num[5] = '\0';
  4623. if (atoi(num) == 70121)
  4624. {
  4625. sprintf((char*)buf_log_evcomm,
  4626. "supported(%d-th/%d): DIN 70121(%d:v%d.%d;id=%d,pri=%d)",
  4627. (i+1),
  4628. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4629. atoi(num),
  4630. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4631. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4632. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4633. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4634. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4635. if (target == V2GT_MSG_PROTOCOL_DIN70121)
  4636. {
  4637. sprintf((char*)buf_log_evcomm,
  4638. "selected(%d-th/%d): DIN 70121(%d:v%d.%d;id=%d,pri=%d)",
  4639. (i+1),
  4640. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4641. atoi(num),
  4642. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4643. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4644. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4645. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4646. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4647. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == DIN_SPEC_70121_2012_VersionNumberMajor)
  4648. {
  4649. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == DIN_SPEC_70121_2012_VersionNumberMinor)
  4650. {
  4651. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4652. }
  4653. else
  4654. { //[TC_SECC_VTB_SupportedAppProtocol_005]
  4655. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  4656. }
  4657. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4658. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4659. return id;
  4660. }
  4661. else
  4662. {
  4663. //keep looking for the suitable protocol
  4664. }
  4665. }
  4666. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  4667. {
  4668. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  4669. {
  4670. ii = i;
  4671. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4672. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  4673. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_DIN70121;
  4674. }
  4675. else
  4676. {
  4677. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  4678. }
  4679. }
  4680. else
  4681. {
  4682. //null
  4683. }
  4684. }
  4685. else if (atoi(num) == 15118)
  4686. {
  4687. //urn:din:70121:2012:MsgDef
  4688. //urn:iso:15118:2:2013:MsgDef
  4689. memset(num, 0, sizeof(num));
  4690. num[0] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[16];
  4691. num[1] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[17];
  4692. num[2] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[18];
  4693. num[3] = CCS_HANDSHAKE_PROTOCOLS.array[i].ProtocolNamespace.characters[19];
  4694. num[4] = '\0';
  4695. if (atoi(num) < 2018 && atoi(num) >= 2010)
  4696. {
  4697. sprintf((char*)buf_log_evcomm,
  4698. "supported(%d-th/%d): ISO 15118-2(ed1,%d:v%d.%d;id=%d,pri=%d)",
  4699. (i+1),
  4700. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4701. atoi(num),
  4702. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4703. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4704. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4705. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4706. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4707. if (target == V2GT_MSG_PROTOCOL_ISO15118_2014)
  4708. {
  4709. sprintf((char*)buf_log_evcomm,
  4710. "selected(%d-th/%d): ISO 15118-2,ed1(%d:v%d.%d;id=%d,pri=%d)",
  4711. (i+1),
  4712. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4713. atoi(num),
  4714. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4715. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4716. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4717. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4718. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4719. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == ISO1_15118_2013_VersionNumberMajor)
  4720. {
  4721. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == ISO1_15118_2013_VersionNumberMinor)
  4722. {
  4723. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4724. }
  4725. else
  4726. {
  4727. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  4728. }
  4729. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4730. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2014;
  4731. return id;
  4732. }
  4733. else
  4734. {
  4735. //keep looking for the suitable protocol
  4736. }
  4737. }
  4738. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  4739. {
  4740. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  4741. {
  4742. ii = i;
  4743. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4744. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  4745. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2014;
  4746. }
  4747. else
  4748. {
  4749. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  4750. }
  4751. }
  4752. else
  4753. {
  4754. //null
  4755. }
  4756. }
  4757. else if (atoi(num) >= 2018 && atoi(num) <= 2100) // >= 2018
  4758. {
  4759. sprintf((char*)buf_log_evcomm,
  4760. "supported(%d-th/%d): ISO 15118-20(ed2,%d:v%d.%d;id=%d,pri=%d)",
  4761. (i+1),
  4762. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4763. atoi(num),
  4764. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4765. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4766. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4767. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4768. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4769. if (target == V2GT_MSG_PROTOCOL_ISO15118_2018)
  4770. {
  4771. sprintf((char*)buf_log_evcomm,
  4772. "selected(%d-th/%d): ISO 15118-20,ed2(%d:v%d.%d;id=%d,pri=%d)",
  4773. (i+1),
  4774. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4775. atoi(num),
  4776. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4777. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4778. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4779. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4780. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4781. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor == ISO2_15118_2018_VersionNumberMajor)
  4782. {
  4783. if (CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor == ISO2_15118_2018_VersionNumberMinor)
  4784. {
  4785. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4786. }
  4787. else
  4788. {
  4789. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_OK_SuccessfulNegotiationWithMinorDeviation;
  4790. }
  4791. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4792. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2018;
  4793. return id;
  4794. }
  4795. else
  4796. {
  4797. //keep looking for the suitable protocol
  4798. }
  4799. }
  4800. else if (target == V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY)
  4801. {
  4802. if (pri > CCS_HANDSHAKE_PROTOCOLS.array[i].Priority)
  4803. {
  4804. ii = i;
  4805. id = CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID;
  4806. pri = CCS_HANDSHAKE_PROTOCOLS.array[i].Priority;
  4807. ShmCcsData->CommProtocol = V2GT_MSG_PROTOCOL_ISO15118_2018;
  4808. }
  4809. else
  4810. {
  4811. //not using this SchemaID, and keep looking for that SchemaID with higer priority
  4812. }
  4813. }
  4814. else
  4815. {
  4816. //null
  4817. }
  4818. }
  4819. else
  4820. {
  4821. //Unexpected Year
  4822. sprintf((char*)buf_log_evcomm,
  4823. "unsupported(%d-th/%d): ISO 15118-X(unexpected year:%d,v%d.%d),id=%d,pri=%d",
  4824. (i+1),
  4825. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4826. atoi(num),
  4827. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4828. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4829. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4830. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4831. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4832. //return -1;
  4833. }
  4834. }
  4835. else
  4836. {
  4837. sprintf((char*)buf_log_evcomm,
  4838. "unsupported protocol(%d-th/%d)(%d:v%d.%d;id=%d,pri=%d)",
  4839. (i+1),
  4840. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4841. atoi(num),
  4842. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMajor,
  4843. CCS_HANDSHAKE_PROTOCOLS.array[i].VersionNumberMinor,
  4844. CCS_HANDSHAKE_PROTOCOLS.array[i].SchemaID,
  4845. CCS_HANDSHAKE_PROTOCOLS.array[i].Priority);
  4846. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4847. //return -1;
  4848. }
  4849. }
  4850. //The final result of highest priority protocol
  4851. sprintf((char*)buf_log_evcomm,
  4852. "selected(%d-th/%d): pro=%d(0:DIN,1:ISO1,2:ISO2);id=%d,pri=%d",
  4853. (ii+1),
  4854. CCS_HANDSHAKE_PROTOCOLS.arrayLen,
  4855. ShmCcsData->CommProtocol,
  4856. id,
  4857. pri);
  4858. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4859. if (id < 0)
  4860. {
  4861. EVCOMM_SYS_INFO.SupportedAppProtocol_result = appHandresponseCodeType_Failed_NoNegotiation;
  4862. }
  4863. return id;
  4864. }
  4865. /*===========================================================================
  4866. FUNCTION: Proc_supportedAppProtocolRes
  4867. DESCRIPTION:
  4868. PRE-CONDITION:
  4869. INPUT:
  4870. OUTPUT:
  4871. GLOBAL VARIABLES:
  4872. =============================================================================*/
  4873. int Proc_supportedAppProtocolRes(int AcceptFd)
  4874. {
  4875. int errn = 0;
  4876. bitstream_t v2g_tx_stream;
  4877. static struct ChargingInfoData *sys;
  4878. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  4879. //STEP 1: =========== Setting the Response Message ===========
  4880. init_appHandEXIDocument(&ccs_handshake);
  4881. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_OK_SuccessfulNegotiation;
  4882. ccs_handshake.supportedAppProtocolRes_isUsed = 1u;
  4883. //select the 1st one as the default
  4884. ccs_handshake.supportedAppProtocolRes.SchemaID = CCS_HANDSHAKE_PROTOCOLS.array[0].SchemaID;
  4885. ccs_handshake.supportedAppProtocolRes.SchemaID_isUsed = 1u;
  4886. int id = 0;
  4887. /*+++ 20200808, vern, support both DIN and ISO +++*/
  4888. //id = GetSchemaID_of_Protocol(V2GT_MSG_PROTOCOL_PREFERENCE); //output: EVCOMM_SYS_INFO.SupportedAppProtocol_result
  4889. id = GetSchemaID_of_Protocol(V2GT_MSG_PROTOCOL_HIGHEST_PRIORITY); //output: EVCOMM_SYS_INFO.SupportedAppProtocol_result
  4890. /*--- 20200808, vern, support both DIN and ISO ---*/
  4891. ccs_handshake.supportedAppProtocolRes.ResponseCode = EVCOMM_SYS_INFO.SupportedAppProtocol_result; //updating the response code
  4892. if (id < 0)
  4893. {
  4894. sprintf((char*)buf_log_evcomm,
  4895. "[Error]No avalible CCS protocol (id = %d, preference = %d)",
  4896. id,
  4897. V2GT_MSG_PROTOCOL_PREFERENCE);
  4898. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4899. }
  4900. else
  4901. {
  4902. //selected SchemaID
  4903. ccs_handshake.supportedAppProtocolRes.SchemaID = (unsigned char) id;
  4904. }
  4905. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  4906. {
  4907. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_supportedAppProtocolRes]EVSE_Shutdown => End_Process");
  4908. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  4909. errn = -1;
  4910. }
  4911. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  4912. {
  4913. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_supportedAppProtocolRes]EVSE_EmergencyShutdown => End_Process");
  4914. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  4915. errn = -1;
  4916. }
  4917. else
  4918. {
  4919. //null
  4920. }
  4921. //Check for Permission Changing from TRUE to FALSE
  4922. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  4923. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  4924. ShmInternalComm->ChargingPermission == FALSE)
  4925. {
  4926. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][DIN][supportedAppProtocolRes]Permission OFF");
  4927. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  4928. //errn = -1;
  4929. }
  4930. #if (CP_PROTECTION_MECHANISM == ENABLE)
  4931. {
  4932. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  4933. {
  4934. //Detect for CP State should be 9V with 5% PWM or 100%PWM (State B1, B2)
  4935. if (sys->CpState != 2 && sys->CpState != 3) //State B1, B2
  4936. {
  4937. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  4938. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4939. Update_V2G_Flow_Status(Other_Fault);
  4940. sprintf((char*)buf_log_evcomm,
  4941. "[Proc_supportedAppProtocolRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  4942. sys->CpState,
  4943. sys->CpVoltage);
  4944. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4945. }
  4946. }
  4947. #else
  4948. {
  4949. //Detect for CP State should be 9V (State B)
  4950. if (sys->CpState != 3) //B2
  4951. {
  4952. ccs_handshake.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_Failed_NoNegotiation;
  4953. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  4954. Update_V2G_Flow_Status(Other_Fault);
  4955. sprintf((char*)buf_log_evcomm,
  4956. "[Proc_supportedAppProtocolRes]Emergency Stop by CP Error (%d, %.02f V)\n",
  4957. sys->CpState,
  4958. sys->CpVoltage);
  4959. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  4960. }
  4961. }
  4962. #endif
  4963. }
  4964. #endif
  4965. //STEP 2: =========== Encode into EXI ===========
  4966. if ((errn = API_V2GMSG_EXI_Encoder_AppProtocol(&ccs_handshake, &v2g_tx_stream)) !=0)
  4967. {
  4968. DEBUG_PRINTF_EVCOMM_DETAIL("\n[Error]API_V2GMSG_EXI_Encoder_AppProtocol\n");
  4969. return errn;
  4970. }
  4971. //STEP 3: =========== Send Response Packet ===========
  4972. int Rtn = 0;
  4973. Rtn = send(AcceptFd, v2g_tx_stream.data, v2g_tx_stream.size, 0);
  4974. //Rtn = send(6, v2g_tx_stream.data, v2g_tx_stream.size, 0);
  4975. DEBUG_PRINTF_EVCOMM_DETAIL("Send V2GTP Packet Size = %d, Rtn = %d (Bytes, DEC)\n", v2g_tx_stream.size, Rtn);
  4976. if (Rtn < 0)
  4977. {
  4978. return Rtn;
  4979. }
  4980. //STEP 4: =========== Save into Share Memory =========
  4981. //[Joseph, To-Do] Adding a mechanism to choose DIN 70121 as our 1st priority. (for multiple protocols)
  4982. //STEP 5: =========== Updating the Flow State Flag =========
  4983. if (id < 0)
  4984. {
  4985. errn = -1;
  4986. }
  4987. //STEP 6: =========== Reset Flags ============
  4988. //Reset all EXI doc Req/Res _isUsed Flags after each Res Tx
  4989. init_appHandEXIDocument(&ccs_handshake);
  4990. return errn;
  4991. }
  4992. /*===========================================================================
  4993. FUNCTION: Proc_supportedAppProtocolReq
  4994. DESCRIPTION:
  4995. PRE-CONDITION:
  4996. INPUT:
  4997. OUTPUT:
  4998. GLOBAL VARIABLES:
  4999. =============================================================================*/
  5000. int Proc_supportedAppProtocolReq(int AcceptFd)
  5001. {
  5002. //[Joseph, To-Do] analysis on Req message and choose the prefered protocol
  5003. //Default: DIN 70121 (find SchemaID)
  5004. int errn = 0;
  5005. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]supportedAppProtocolReq\n");
  5006. SHM_Save_din_supportedAppProtocolReq(ShmCcsData, &ccs_handshake, ShmSysConfigAndInfo);
  5007. errn = Proc_supportedAppProtocolRes(AcceptFd);
  5008. if (errn == 0)
  5009. {
  5010. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]supportedAppProtocolRes\n");
  5011. }
  5012. else
  5013. {
  5014. DEBUG_PRINTF_EVCOMM_DETAIL("[Error]Proc_supportedAppProtocolRes(): %d (DEC)\n", errn);
  5015. }
  5016. return errn;
  5017. }
  5018. /*===========================================================================
  5019. FUNCTION: Proc_din_SessionSetupRes
  5020. DESCRIPTION:
  5021. PRE-CONDITION:
  5022. INPUT:
  5023. OUTPUT:
  5024. GLOBAL VARIABLES:
  5025. =============================================================================*/
  5026. int Proc_din_SessionSetupRes(int AcceptFd)
  5027. {
  5028. //int i = 0;
  5029. int errn = 0;
  5030. bitstream_t v2g_tx_stream;
  5031. static struct ChargingInfoData *sys;
  5032. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5033. size_t pos = 0;
  5034. v2g_tx_stream.pos = &pos;
  5035. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5036. v2g_tx_stream.data = V2GTP_Tx_buf;
  5037. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5038. init_dinSessionSetupResType(&ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes);
  5039. // ====== [BODY (1/2) ResponseCode ======
  5040. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5041. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_OK_NewSessionEstablished;
  5042. //[HEADER] Assign Res SessionID
  5043. ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytesLen = 8;
  5044. memset(ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytes, 0, 8);
  5045. memcpy(ccs_exi_doc_DIN.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5046. //Check for SequenceError
  5047. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5048. {
  5049. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError;
  5050. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5051. errn = -1;
  5052. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5053. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5054. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5055. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5056. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5057. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5058. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5059. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5060. }
  5061. //#if PARAMETER_NORMAL_MODE == ENABLE
  5062. //SHM_Read_din_V2GMSG_Header(&ccs_exi_doc_DIN, ShmCcsData);
  5063. //#endif
  5064. //Detect for CP State should be 9V (State B)
  5065. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5066. {
  5067. #if CP_PROTECTION_MECHANISM == ENABLE
  5068. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5069. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5070. Update_V2G_Flow_Status(Other_Fault);
  5071. errn = -1;
  5072. sprintf((char*)buf_log_evcomm,
  5073. "[Proc_din_SessionSetupRes]Emergency Stop by CP Error (%d)\n",
  5074. sys->CpState);
  5075. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5076. #else
  5077. sprintf((char*)buf_log_evcomm,
  5078. "[Proc_din_SessionSetupRes]Emergency Stop by CP Error (%d): ignored\n",
  5079. sys->CpState);
  5080. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5081. #endif
  5082. }
  5083. //Check for shutdown commands from EVSE(DC Main Board)
  5084. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5085. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5086. {
  5087. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5088. sprintf((char*)buf_log_evcomm, "[Proc_din_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5089. EVSE_Shutdown,
  5090. EVSE_EmergencyShutdown,
  5091. sys->DC_EVSEStatus);
  5092. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5093. errn = -1;
  5094. }
  5095. //Check for Permission Changing from TRUE to FALSE
  5096. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5097. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  5098. ShmInternalComm->ChargingPermission == FALSE)
  5099. {
  5100. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][DIN][SessionSetupRes]Permission OFF");
  5101. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_FAILED;
  5102. errn = -1;
  5103. }
  5104. // ====== [BODY (2/3) EVSEID ======
  5105. //EVSEID = all zero
  5106. memset(ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytes, 0, sizeof(ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytes));
  5107. //vern, should be encode by SN
  5108. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.EVSEID.bytesLen = 1; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5109. // ====== [BODY (3/3) DateTimeNow ======
  5110. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.DateTimeNow_isUsed = 1u;
  5111. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.DateTimeNow = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5112. #if PARAMETER_NORMAL_MODE == ENABLE
  5113. ///////////SHM_Read_din_SessionSetupRes(&ccs_exi_doc_DIN, ShmCcsData);
  5114. #endif
  5115. // ============ Encode and Send Response Message ===========
  5116. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  5117. {
  5118. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_SessionSetupRes][Error]Tx encoded msg error");
  5119. errn = -1;
  5120. }
  5121. return errn;
  5122. }
  5123. /*===========================================================================
  5124. FUNCTION: Proc_iso1_SessionSetupRes
  5125. DESCRIPTION:
  5126. PRE-CONDITION:
  5127. INPUT:
  5128. OUTPUT:
  5129. GLOBAL VARIABLES:
  5130. =============================================================================*/
  5131. int Proc_iso1_SessionSetupRes(int AcceptFd)
  5132. {
  5133. //int i = 0;
  5134. int errn = 0;
  5135. bitstream_t v2g_tx_stream;
  5136. static struct ChargingInfoData *sys;
  5137. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5138. size_t pos = 0;
  5139. v2g_tx_stream.pos = &pos;
  5140. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5141. v2g_tx_stream.data = V2GTP_Tx_buf;
  5142. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  5143. init_iso1SessionSetupResType(&ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes);
  5144. // ====== [BODY (1/2) ResponseCode ======
  5145. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5146. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_OK_NewSessionEstablished;
  5147. //[HEADER] Assign Res SessionID
  5148. ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytesLen = 8;
  5149. memset(ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytes, 0, 8);
  5150. memcpy(ccs_exi_doc_ISO1.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5151. //Check for SequenceError
  5152. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5153. {
  5154. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5155. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5156. errn = -1;
  5157. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5158. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5159. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5160. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5161. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5162. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5163. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5164. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5165. }
  5166. //#if PARAMETER_NORMAL_MODE == ENABLE
  5167. //SHM_Read_iso1_V2GMSG_Header(&ccs_exi_doc_ISO1, ShmCcsData);
  5168. //#endif
  5169. //Detect for CP State should be 9V (State B)
  5170. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5171. {
  5172. #if CP_PROTECTION_MECHANISM == ENABLE
  5173. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5174. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5175. Update_V2G_Flow_Status(Other_Fault);
  5176. errn = -1;
  5177. sprintf((char*)buf_log_evcomm,
  5178. "[Proc_iso1_SessionSetupRes]Emergency Stop by CP Error (%d)\n",
  5179. sys->CpState);
  5180. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5181. #else
  5182. sprintf((char*)buf_log_evcomm,
  5183. "[Proc_iso1_SessionSetupRes]Emergency Stop by CP Error (%d): ignored\n",
  5184. sys->CpState);
  5185. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5186. #endif
  5187. }
  5188. //Check for shutdown commands from EVSE(DC Main Board)
  5189. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5190. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5191. {
  5192. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5193. sprintf((char*)buf_log_evcomm, "[Proc_iso1_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5194. EVSE_Shutdown,
  5195. EVSE_EmergencyShutdown,
  5196. sys->DC_EVSEStatus);
  5197. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5198. errn = -1;
  5199. }
  5200. //Check for Permission Changing from TRUE to FALSE
  5201. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  5202. ShmInternalComm->ChargingPermission == FALSE)
  5203. {
  5204. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][SessionSetupRes]Permission OFF");
  5205. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED;
  5206. errn = -1;
  5207. }
  5208. // ====== [BODY (2/3) EVSEID ======
  5209. //EVSEID = all zero
  5210. memset(ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters, 0, sizeof(ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters));
  5211. /*+++ 20200808, vern, set default EVSEID +++*/
  5212. //vern, should be encoded by SN
  5213. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[0]='Z';
  5214. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[1]='Z';
  5215. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[2]='0';
  5216. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[3]='0';
  5217. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[4]='0';
  5218. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[5]='0';
  5219. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.characters[6]='0';
  5220. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSEID.charactersLen = 7; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5221. /*--- 20200808, vern, set default EVSEID ---*/
  5222. // ====== [BODY (3/3) DateTimeNow ======
  5223. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 1u;
  5224. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.EVSETimeStamp = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5225. #if PARAMETER_NORMAL_MODE == ENABLE
  5226. ///////////SHM_Read_iso1_SessionSetupRes(&ccs_exi_doc_ISO1, ShmCcsData);
  5227. #endif
  5228. // ============ Encode and Send Response Message ===========
  5229. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  5230. {
  5231. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_SessionSetupRes][Error]Tx encoded msg error");
  5232. errn = -1;
  5233. }
  5234. return errn;
  5235. }
  5236. /*===========================================================================
  5237. FUNCTION: Proc_iso2_SessionSetupRes
  5238. DESCRIPTION:
  5239. PRE-CONDITION:
  5240. INPUT:
  5241. OUTPUT:
  5242. GLOBAL VARIABLES:
  5243. =============================================================================*/
  5244. int Proc_iso2_SessionSetupRes(int AcceptFd)
  5245. {
  5246. //int i = 0;
  5247. int errn = 0;
  5248. bitstream_t v2g_tx_stream;
  5249. static struct ChargingInfoData *sys;
  5250. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5251. size_t pos = 0;
  5252. v2g_tx_stream.pos = &pos;
  5253. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5254. v2g_tx_stream.data = V2GTP_Tx_buf;
  5255. init_iso2BodyType(&ccs_exi_doc_ISO2.V2G_Message.Body);
  5256. init_iso2SessionSetupResType(&ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes);
  5257. // ====== [BODY (1/2) ResponseCode ======
  5258. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
  5259. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_OK_NewSessionEstablished;
  5260. //[HEADER] Assign Res SessionID
  5261. ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytesLen = 8;
  5262. memset(ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytes, 0, 8);
  5263. memcpy(ccs_exi_doc_ISO2.V2G_Message.Header.SessionID.bytes, EVCOMM_SYS_INFO.SessionID, 8);
  5264. //Check for SequenceError
  5265. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5266. {
  5267. ccs_exi_doc_ISO1.V2G_Message.Body.SessionSetupRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5268. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5269. errn = -1;
  5270. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5271. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5272. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5273. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5274. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5275. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5276. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5277. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5278. }
  5279. //#if PARAMETER_NORMAL_MODE == ENABLE
  5280. //SHM_Read_iso2_V2GMSG_Header(&ccs_exi_doc_ISO2, ShmCcsData);
  5281. //#endif
  5282. //Detect for CP State should be 9V (State B)
  5283. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5284. {
  5285. #if CP_PROTECTION_MECHANISM == ENABLE
  5286. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5287. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5288. Update_V2G_Flow_Status(Other_Fault);
  5289. errn = -1;
  5290. sprintf((char*)buf_log_evcomm,
  5291. "[Proc_iso2_SessionSetupRes]Emergency Stop by CP Error (%d)",
  5292. sys->CpState);
  5293. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5294. #else
  5295. sprintf((char*)buf_log_evcomm,
  5296. "[Proc_iso2_SessionSetupRes]Emergency Stop by CP Error (%d): ignored",
  5297. sys->CpState);
  5298. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5299. #endif
  5300. }
  5301. //Check for shutdown commands from EVSE(DC Main Board)
  5302. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5303. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5304. {
  5305. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5306. sprintf((char*)buf_log_evcomm, "[Proc_iso2_SessionSetupRes]Stop by EVSE(%d:normal, %d:emergency): (%d)\n",
  5307. EVSE_Shutdown,
  5308. EVSE_EmergencyShutdown,
  5309. sys->DC_EVSEStatus);
  5310. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5311. errn = -1;
  5312. }
  5313. //Check for Permission Changing from TRUE to FALSE
  5314. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5315. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  5316. ShmInternalComm->ChargingPermission == FALSE)
  5317. {
  5318. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][ISO2][SessionSetupRes]Permission OFF");
  5319. ccs_exi_doc_DIN.V2G_Message.Body.SessionSetupRes.ResponseCode = iso2responseCodeType_FAILED;
  5320. errn = -1;
  5321. }
  5322. // ====== [BODY (2/3) EVSEID ======
  5323. //EVSEID = all zero
  5324. memset(ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.characters, 0, sizeof(ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.characters));
  5325. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSEID.charactersLen = 15; //max: DIN = 32, ISO1/ISO2 = 37 bytes
  5326. // ====== [BODY (3/3) DateTimeNow ======
  5327. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 1u;
  5328. ccs_exi_doc_ISO2.V2G_Message.Body.SessionSetupRes.EVSETimeStamp = (int64_t)time(NULL); //[Joseph] Format: Unix Time Stamp
  5329. #if PARAMETER_NORMAL_MODE == ENABLE
  5330. ///////////SHM_Read_iso2_SessionSetupRes(&ccs_exi_doc_ISO2, ShmCcsData);
  5331. #endif
  5332. // ============ Encode and Send Response Message ===========
  5333. if (send_encoded_iso2_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO2) != 0)
  5334. {
  5335. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso2_SessionSetupRes][Error]Tx encoded msg error");
  5336. errn = -1;
  5337. }
  5338. return errn;
  5339. }
  5340. /*===========================================================================
  5341. FUNCTION: Proc_din_SessionSetupReq
  5342. DESCRIPTION:
  5343. PRE-CONDITION:
  5344. INPUT:
  5345. OUTPUT:
  5346. GLOBAL VARIABLES:
  5347. 2. ccs_exi_doc_DIN
  5348. =============================================================================*/
  5349. int Proc_din_SessionSetupReq(int AcceptFd)
  5350. {
  5351. int errn = 0;
  5352. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]SessionSetupReq\n");
  5353. //Print the decoded XML Document
  5354. PRINT_XML_DOC_DIN_SessionSetupReq(&ccs_exi_doc_DIN);
  5355. //Save into Share Memory
  5356. SHM_Save_din_SessionSetupReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  5357. errn = Proc_din_SessionSetupRes(AcceptFd);
  5358. if (errn == 0)
  5359. {
  5360. //successfully send response.
  5361. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]SessionSetupRes\n");
  5362. }
  5363. else
  5364. {
  5365. sprintf((char*)buf_log_evcomm,
  5366. "[Error]Proc_din_SessionSetupRes(): %d (DEC)",
  5367. errn);
  5368. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5369. }
  5370. return errn;
  5371. }
  5372. /*===========================================================================
  5373. FUNCTION: Proc_iso1_SessionSetupReq
  5374. DESCRIPTION:
  5375. PRE-CONDITION:
  5376. INPUT:
  5377. OUTPUT:
  5378. GLOBAL VARIABLES:
  5379. 2. ccs_exi_doc_ISO1
  5380. =============================================================================*/
  5381. int Proc_iso1_SessionSetupReq(int AcceptFd)
  5382. {
  5383. int errn = 0;
  5384. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]SessionSetupReq\n");
  5385. //Print the decoded XML Document
  5386. PRINT_XML_DOC_ISO1_SessionSetupReq(&ccs_exi_doc_ISO1);
  5387. //Save into Share Memory
  5388. SHM_Save_iso1_SessionSetupReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  5389. errn = Proc_iso1_SessionSetupRes(AcceptFd);
  5390. if (errn == 0)
  5391. {
  5392. //successfully send response.
  5393. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]SessionSetupRes");
  5394. }
  5395. else
  5396. {
  5397. sprintf((char*)buf_log_evcomm,
  5398. "[Error]Proc_iso1_SessionSetupRes(): %d (DEC)",
  5399. errn);
  5400. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5401. }
  5402. return errn;
  5403. }
  5404. /*===========================================================================
  5405. FUNCTION: Proc_iso2_SessionSetupReq
  5406. DESCRIPTION:
  5407. PRE-CONDITION:
  5408. INPUT:
  5409. OUTPUT:
  5410. GLOBAL VARIABLES:
  5411. 2. ccs_exi_doc_ISO2
  5412. =============================================================================*/
  5413. int Proc_iso2_SessionSetupReq(int AcceptFd)
  5414. {
  5415. int errn = 0;
  5416. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]SessionSetupReq\n");
  5417. //Print the decoded XML Document
  5418. PRINT_XML_DOC_ISO2_SessionSetupReq(&ccs_exi_doc_ISO2);
  5419. //Save into Share Memory
  5420. SHM_Save_iso2_SessionSetupReq(ShmCcsData, &ccs_exi_doc_ISO2, ShmSysConfigAndInfo);
  5421. errn = Proc_iso2_SessionSetupRes(AcceptFd);
  5422. if (errn == 0)
  5423. {
  5424. //successfully send response.
  5425. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]SessionSetupRes");
  5426. }
  5427. else
  5428. {
  5429. sprintf((char*)buf_log_evcomm,
  5430. "[Error]Proc_iso2_SessionSetupRes(): %d (DEC)",
  5431. errn);
  5432. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5433. }
  5434. return errn;
  5435. }
  5436. /*===========================================================================
  5437. FUNCTION: Proc_din_ServiceDiscoveryRes
  5438. DESCRIPTION:
  5439. PRE-CONDITION:
  5440. INPUT:
  5441. OUTPUT:
  5442. GLOBAL VARIABLES:
  5443. =============================================================================*/
  5444. int Proc_din_ServiceDiscoveryRes(int AcceptFd)
  5445. {
  5446. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5447. //if it is not the same, the packet should be ignored.
  5448. //int i = 0;
  5449. int errn = 0;
  5450. bitstream_t v2g_tx_stream;
  5451. struct ChargingInfoData *sys;
  5452. //struct ServiceDiscoveryRequest_DIN70121 *req;
  5453. struct ServiceDiscoveryResponse_DIN70121 *res;
  5454. size_t pos = 0;
  5455. v2g_tx_stream.pos = &pos;
  5456. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5457. v2g_tx_stream.data = V2GTP_Tx_buf;
  5458. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5459. //req = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryRequest;
  5460. res = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryResponse;
  5461. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5462. init_dinServiceDiscoveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes);
  5463. //[1/4] Response Code
  5464. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes_isUsed = 1u;
  5465. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_OK;
  5466. //[HEADER] Check Req SessionID
  5467. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  5468. {
  5469. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  5470. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  5471. errn = -1;
  5472. }
  5473. //Check for SequenceError
  5474. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5475. {
  5476. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  5477. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5478. errn = -1;
  5479. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5480. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5481. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5482. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5483. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5484. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5485. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5486. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5487. }
  5488. //Detect for CP State should be 9V (State B)
  5489. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5490. {
  5491. #if CP_PROTECTION_MECHANISM == ENABLE
  5492. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5493. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5494. Update_V2G_Flow_Status(Other_Fault);
  5495. errn = -1;
  5496. sprintf((char*)buf_log_evcomm, "[Proc_din_ServiceDiscoveryRes]Emergency Stop by CP Error (%d)", sys->CpState);
  5497. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5498. #else
  5499. sprintf((char*)buf_log_evcomm,
  5500. "[Proc_din_ServiceDiscoveryRes]Emergency Stop by CP Error (%d): ignored",
  5501. sys->CpState);
  5502. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5503. #endif
  5504. }
  5505. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5506. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5507. {
  5508. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5509. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_ServiceDiscoveryRes]shutdown by EVSE");
  5510. errn = -1;
  5511. }
  5512. //Check for Permission Changing from TRUE to FALSE
  5513. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5514. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  5515. ShmInternalComm->ChargingPermission == FALSE)
  5516. {
  5517. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][DIN][ServiceDiscoveryRes]Permission OFF");
  5518. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_FAILED;
  5519. errn = -1;
  5520. }
  5521. //[2/4] PaymentOptions
  5522. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptions.PaymentOption.arrayLen = 1u;
  5523. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptions.PaymentOption.array[0] = dinpaymentOptionType_ExternalPayment; //1
  5524. //[3/4] Charge Service
  5525. res->ChargeService_DIN70121.Services.ServiceTag.ServiceID = 1;
  5526. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceID = (unsigned short) res->ChargeService_DIN70121.Services.ServiceTag.ServiceID;
  5527. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceCategory = dinserviceCategoryType_EVCharging;
  5528. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.FreeService = 1; //[Joseph] for test
  5529. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.EnergyTransferType = dinEVSESupportedEnergyTransferType_DC_extended;
  5530. //[4/4] Service List (null, not be uesed for now.)
  5531. //#if PARAMETER_NORMAL_MODE == ENABLE
  5532. ///////////////SHM_Read_din_ServiceDiscoveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  5533. //#endif
  5534. // ============ Encode and Send Response Message ===========
  5535. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  5536. {
  5537. errn = -1;
  5538. }
  5539. return errn;
  5540. }
  5541. /*===========================================================================
  5542. FUNCTION: Proc_iso1_ServiceDiscoveryRes
  5543. DESCRIPTION:
  5544. PRE-CONDITION:
  5545. INPUT:
  5546. OUTPUT:
  5547. GLOBAL VARIABLES:
  5548. =============================================================================*/
  5549. int Proc_iso1_ServiceDiscoveryRes(int AcceptFd)
  5550. {
  5551. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5552. //if it is not the same, the packet should be ignored.
  5553. //int i = 0;
  5554. int errn = 0;
  5555. bitstream_t v2g_tx_stream;
  5556. struct ChargingInfoData *sys;
  5557. //struct ServiceDiscoveryRequest_ISO15118_2014 *req;
  5558. struct ServiceDiscoveryResponse_ISO15118_2014 *res;
  5559. size_t pos = 0;
  5560. v2g_tx_stream.pos = &pos;
  5561. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5562. v2g_tx_stream.data = V2GTP_Tx_buf;
  5563. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5564. //req = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryRequest;
  5565. res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryResponse;
  5566. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  5567. init_iso1ServiceDiscoveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes);
  5568. //[1/4] Response Code
  5569. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes_isUsed = 1u;
  5570. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_OK;
  5571. //[HEADER] Check Req SessionID
  5572. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  5573. {
  5574. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  5575. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  5576. errn = -1;
  5577. }
  5578. //Check for SequenceError
  5579. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5580. {
  5581. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5582. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5583. errn = -1;
  5584. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5585. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5586. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5587. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5588. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5589. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5590. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5591. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5592. }
  5593. //Detect for CP State should be 9V (State B)
  5594. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5595. {
  5596. #if CP_PROTECTION_MECHANISM == ENABLE
  5597. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  5598. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5599. Update_V2G_Flow_Status(Other_Fault);
  5600. errn = -1;
  5601. sprintf((char*)buf_log_evcomm,
  5602. "[Proc_iso1_ServiceDiscoveryRes]Emergency Stop by CP Error (%d)",
  5603. sys->CpState);
  5604. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5605. #else
  5606. sprintf((char*)buf_log_evcomm,
  5607. "[Proc_iso1_ServiceDiscoveryRes]Emergency Stop by CP Error (%d): ignored",
  5608. sys->CpState);
  5609. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5610. #endif
  5611. }
  5612. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5613. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5614. {
  5615. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  5616. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ServiceDiscoveryRes]shutdown by EVSE");
  5617. errn = -1;
  5618. }
  5619. //Check for Permission Changing from TRUE to FALSE
  5620. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5621. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  5622. ShmInternalComm->ChargingPermission == FALSE)
  5623. {
  5624. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][ServiceDiscoveryRes]Permission OFF");
  5625. ccs_exi_doc_DIN.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = iso1responseCodeType_FAILED;
  5626. errn = -1;
  5627. }
  5628. //[2/4] PaymentOptionList
  5629. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.arrayLen = 1u;
  5630. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptionList.PaymentOption.array[0] = iso1paymentOptionType_ExternalPayment; //1
  5631. //[3/4] Charge Service
  5632. res->ChargeService.Services.ServiceID = 1;
  5633. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceID = (unsigned short) res->ChargeService.Services.ServiceID;
  5634. //ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName_isUsed = 1; //new in ISO1, not be used, yet.
  5635. //ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName.charactersLen = xxx;
  5636. //ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceName.characters[i] = xxx;
  5637. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceCategory = iso1serviceCategoryType_EVCharging;
  5638. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.FreeService = 1; //[Joseph] for test
  5639. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.arrayLen = 1u; // max = 6
  5640. switch (ShmCcsData->EnergyTransferMode)
  5641. {
  5642. case DC_extended:
  5643. {
  5644. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_DC_extended;
  5645. break;
  5646. }
  5647. case AC_single_phase_core:
  5648. {
  5649. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_AC_single_phase_core;
  5650. break;
  5651. }
  5652. case AC_three_phase_core:
  5653. {
  5654. ccs_exi_doc_ISO1.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.SupportedEnergyTransferMode.EnergyTransferMode.array[0] = iso1EnergyTransferModeType_AC_three_phase_core;
  5655. break;
  5656. }
  5657. default:
  5658. {
  5659. SAVE_SYS_LOG_MSG_EVCOMM("[Warning]unexpected EnergyTransferMode(%d)\n", ShmCcsData->EnergyTransferMode);
  5660. break;
  5661. }
  5662. }
  5663. //[4/4] Service List (null, not be uesed for now.)
  5664. //#if PARAMETER_NORMAL_MODE == ENABLE
  5665. ///////////////SHM_Read_iso1_ServiceDiscoveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  5666. //#endif
  5667. // ============ Encode and Send Response Message ===========
  5668. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  5669. {
  5670. errn = -1;
  5671. }
  5672. return errn;
  5673. }
  5674. /*===========================================================================
  5675. FUNCTION: Proc_din_ServiceDiscoveryReq
  5676. DESCRIPTION:
  5677. PRE-CONDITION:
  5678. INPUT:
  5679. OUTPUT:
  5680. GLOBAL VARIABLES:
  5681. =============================================================================*/
  5682. int Proc_din_ServiceDiscoveryReq(int AcceptFd)
  5683. {
  5684. int errn = 0;
  5685. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]ServiceDiscoveryReq\n");
  5686. //Print the decoded XML Document
  5687. PRINT_XML_DOC_DIN_ServiceDiscoveryReq(&ccs_exi_doc_DIN);
  5688. //Save into Share Memory
  5689. SHM_Save_din_ServiceDiscoveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  5690. errn = Proc_din_ServiceDiscoveryRes(AcceptFd);
  5691. if (errn == 0)
  5692. {
  5693. //send response successfully.
  5694. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]ServiceDiscoveryRes");
  5695. }
  5696. else
  5697. {
  5698. sprintf((char*)buf_log_evcomm,
  5699. "[Error]Proc_din_ServiceDiscoveryRes(): %d (DEC)",
  5700. errn
  5701. );
  5702. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5703. }
  5704. return errn;
  5705. }
  5706. /*===========================================================================
  5707. FUNCTION: Proc_iso1_ServiceDiscoveryReq
  5708. DESCRIPTION:
  5709. PRE-CONDITION:
  5710. INPUT:
  5711. OUTPUT:
  5712. GLOBAL VARIABLES:
  5713. =============================================================================*/
  5714. int Proc_iso1_ServiceDiscoveryReq(int AcceptFd)
  5715. {
  5716. int errn = 0;
  5717. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]ServiceDiscoveryReq\n");
  5718. //Print the decoded XML Document
  5719. PRINT_XML_DOC_ISO1_ServiceDiscoveryReq(&ccs_exi_doc_ISO1);
  5720. //Save into Share Memory
  5721. SHM_Save_iso1_ServiceDiscoveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  5722. errn = Proc_iso1_ServiceDiscoveryRes(AcceptFd);
  5723. if (errn == 0)
  5724. {
  5725. //send response successfully.
  5726. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ServiceDiscoveryRes\n");
  5727. }
  5728. else
  5729. {
  5730. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Proc_iso1_ServiceDiscoveryRes(): %d (DEC)\n", errn);
  5731. }
  5732. return errn;
  5733. }
  5734. /*===========================================================================
  5735. FUNCTION: Proc_din_ServiceAndPaymentSelectionRes
  5736. DESCRIPTION:
  5737. PRE-CONDITION:
  5738. INPUT:
  5739. OUTPUT:
  5740. GLOBAL VARIABLES:
  5741. =============================================================================*/
  5742. int Proc_din_ServiceAndPaymentSelectionRes(int AcceptFd)
  5743. {
  5744. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5745. //if it is not the same, the packet should be ignored.
  5746. //int i = 0;
  5747. int errn = 0;
  5748. bitstream_t v2g_tx_stream;
  5749. struct ServiceAndPaymentSelectionRequest_DIN70121 *req;
  5750. //struct ServiceAndPaymentSelectionResponse_DIN70121 *res;
  5751. struct ServiceDiscoveryResponse_DIN70121 *sd_res;
  5752. struct ChargingInfoData *sys;
  5753. size_t pos = 0;
  5754. v2g_tx_stream.pos = &pos;
  5755. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5756. v2g_tx_stream.data = V2GTP_Tx_buf;
  5757. req = &ShmCcsData->V2GMessage_DIN70121.ServiceAndPaymentSelectionRequest;
  5758. //res = &ShmCcsData->V2GMessage_DIN70121.ServiceAndPaymentSelectionResponse;
  5759. sd_res = &ShmCcsData->V2GMessage_DIN70121.ServiceDiscoveryResponse;
  5760. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5761. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  5762. init_dinServicePaymentSelectionResType(&ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes);
  5763. //[1/1] Response Code
  5764. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes_isUsed = 1u;
  5765. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_OK;
  5766. //[HEADER] Check Req SessionID
  5767. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  5768. {
  5769. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  5770. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  5771. errn = -1;
  5772. }
  5773. //Check for SequenceError
  5774. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5775. {
  5776. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  5777. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5778. errn = -1;
  5779. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5780. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5781. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5782. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5783. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5784. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5785. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5786. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5787. }
  5788. //Check for SelectedPaymentOption (TC_SECC_VTB_ServicePaymentSelection_007)
  5789. if (req->SelectedPaymentOption != ExternalPayment) //1
  5790. {
  5791. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_PaymentSelectionInvalid;
  5792. sprintf((char*)buf_log_evcomm,
  5793. "[ERROR]unexpected SelectedPaymentOption(%d) => End_Process (EIM only, no PnC, yet.)",
  5794. req->SelectedPaymentOption);
  5795. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5796. errn = -1;
  5797. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5798. //CCS_SECC_ResponseCode_FAILED_Payment SelectionInvalid (023762)
  5799. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5800. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5801. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5802. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5803. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  5804. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  5805. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5806. }
  5807. //Check for ServiceID (TC_SECC_VTB_ServicePaymentSelection_004)
  5808. if (req->SelectedServiceList.SelectedService[0].ServiceID != sd_res->ChargeService_DIN70121.Services.ServiceTag.ServiceID)
  5809. {
  5810. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED_ServiceSelectionInvalid; //8
  5811. sprintf((char*)buf_log_evcomm,
  5812. "[ERROR]Wrong selected ServiceID(%d) => End_Process",
  5813. req->SelectedServiceList.SelectedService[0].ServiceID);
  5814. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5815. errn = -1;
  5816. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5817. //CCS_SECC_ResponseCode_FAILED_ServiceSelectionInvalid (023764)
  5818. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5819. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5820. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5821. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5822. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  5823. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  5824. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5825. }
  5826. //Detect for CP State should be 9V (State B)
  5827. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5828. {
  5829. #if CP_PROTECTION_MECHANISM == ENABLE
  5830. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  5831. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5832. Update_V2G_Flow_Status(Other_Fault);
  5833. errn = -1;
  5834. sprintf((char*)buf_log_evcomm,
  5835. "Emergency Stop by CP Error (%d)",
  5836. sys->CpState);
  5837. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5838. #else
  5839. sprintf((char*)buf_log_evcomm,
  5840. "Emergency Stop by CP Error (%d): ignored due to function is disabled",
  5841. sys->CpState);
  5842. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5843. #endif
  5844. }
  5845. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5846. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5847. {
  5848. SAVE_SYS_LOG_MSG_EVCOMM("shutdown by EVSE\n");
  5849. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  5850. errn = -1;
  5851. }
  5852. //Check for Permission Changing from TRUE to FALSE
  5853. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5854. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  5855. ShmInternalComm->ChargingPermission == FALSE)
  5856. {
  5857. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Permission OFF\n");
  5858. ccs_exi_doc_DIN.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode = dinresponseCodeType_FAILED;
  5859. errn = -1;
  5860. }
  5861. // ============ Encode and Send Response Message ===========
  5862. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  5863. {
  5864. SAVE_SYS_LOG_MSG_EVCOMM("Tx encoded msg error\n");
  5865. errn = -1;
  5866. }
  5867. return errn;
  5868. }
  5869. /*===========================================================================
  5870. FUNCTION: Proc_iso1_ServiceAndPaymentSelectionRes
  5871. DESCRIPTION:
  5872. PRE-CONDITION:
  5873. INPUT:
  5874. OUTPUT:
  5875. GLOBAL VARIABLES:
  5876. =============================================================================*/
  5877. int Proc_iso1_ServiceAndPaymentSelectionRes(int AcceptFd)
  5878. {
  5879. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  5880. //if it is not the same, the packet should be ignored.
  5881. //int i = 0;
  5882. int errn = 0;
  5883. bitstream_t v2g_tx_stream;
  5884. struct ServiceAndPaymentSelectionRequest_ISO15118_2014 *req;
  5885. //struct ServiceAndPaymentSelectionResponse_ISO15118_2014 *res;
  5886. struct ServiceDiscoveryResponse_ISO15118_2014 *sd_res;
  5887. static struct ChargingInfoData *sys;
  5888. size_t pos = 0;
  5889. v2g_tx_stream.pos = &pos;
  5890. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  5891. v2g_tx_stream.data = V2GTP_Tx_buf;
  5892. req = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceAndPaymentSelectionRequest;
  5893. //res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceAndPaymentSelectionResponse;
  5894. sd_res = &ShmCcsData->V2GMessage_ISO15118_2014.ServiceDiscoveryResponse;
  5895. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  5896. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  5897. init_iso1PaymentServiceSelectionResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes);
  5898. //[1/1] Response Code
  5899. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes_isUsed = 1u;
  5900. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_OK;
  5901. //[HEADER] Check Req SessionID
  5902. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  5903. {
  5904. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  5905. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  5906. errn = -1;
  5907. }
  5908. //Check for SequenceError
  5909. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  5910. {
  5911. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  5912. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  5913. errn = -1;
  5914. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5915. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  5916. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5917. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5918. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5919. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5920. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  5921. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  5922. }
  5923. //Check for SelectedPaymentOption (TC_SECC_VTB_ServicePaymentSelection_007)
  5924. if (req->SelectedPaymentOption != ExternalPayment) //1
  5925. {
  5926. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_PaymentSelectionInvalid;
  5927. sprintf((char*)buf_log_evcomm,
  5928. "[ERROR]unexpected SelectedPaymentOption(%d) => End_Process (EIM only, no PnC, yet.)",
  5929. req->SelectedPaymentOption);
  5930. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5931. errn = -1;
  5932. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5933. //CCS_SECC_ResponseCode_FAILED_Payment SelectionInvalid (023762)
  5934. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5935. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5936. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5937. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5938. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  5939. ShmStatusCodeData->PresentStatusCode[0][5] = 2;
  5940. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5941. }
  5942. //Check for ServiceID (TC_SECC_VTB_ServicePaymentSelection_004)
  5943. if (req->SelectedServiceList.SelectedService[0].ServiceID != sd_res->ChargeService.Services.ServiceID)
  5944. {
  5945. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED_ServiceSelectionInvalid; //8
  5946. sprintf((char*)buf_log_evcomm,
  5947. "[ERROR]Wrong selected ServiceID(%d) => End_Process",
  5948. req->SelectedServiceList.SelectedService[0].ServiceID);
  5949. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5950. errn = -1;
  5951. //Update_ShmStatusCode(); //[To-Do] to be implemented
  5952. //CCS_SECC_ResponseCode_FAILED_ServiceSelectionInvalid (023764)
  5953. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  5954. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  5955. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  5956. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  5957. ShmStatusCodeData->PresentStatusCode[0][4] = 6;
  5958. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  5959. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5960. }
  5961. //Detect for CP State should be 9V (State B)
  5962. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  5963. {
  5964. #if CP_PROTECTION_MECHANISM == ENABLE
  5965. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  5966. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  5967. Update_V2G_Flow_Status(Other_Fault);
  5968. errn = -1;
  5969. sprintf((char*)buf_log_evcomm,
  5970. "Emergency Stop by CP Error (%d)",
  5971. sys->CpState);
  5972. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5973. #else
  5974. sprintf((char*)buf_log_evcomm,
  5975. "Emergency Stop by CP Error (%d): ignored due to function is disabled",
  5976. sys->CpState);
  5977. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  5978. #endif
  5979. }
  5980. if (sys->DC_EVSEStatus == EVSE_Shutdown ||
  5981. sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  5982. {
  5983. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_iso1_ServiceAndPaymentSelectionRes]shutdown by EVSE\n");
  5984. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  5985. errn = -1;
  5986. }
  5987. //Check for Permission Changing from TRUE to FALSE
  5988. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  5989. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  5990. ShmInternalComm->ChargingPermission == FALSE)
  5991. {
  5992. SAVE_SYS_LOG_MSG_EVCOMM("[Error][PaymentServiceSelectionRes]Permission OFF\n");
  5993. ccs_exi_doc_ISO1.V2G_Message.Body.PaymentServiceSelectionRes.ResponseCode = iso1responseCodeType_FAILED;
  5994. errn = -1;
  5995. }
  5996. // ============ Encode and Send Response Message ===========
  5997. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  5998. {
  5999. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_ServiceAndPaymentSelectionRes]Tx encoded msg error");
  6000. errn = -1;
  6001. }
  6002. return errn;
  6003. }
  6004. /*===========================================================================
  6005. FUNCTION: Proc_din_ServiceAndPaymentSelectionReq
  6006. DESCRIPTION:
  6007. PRE-CONDITION:
  6008. INPUT:
  6009. OUTPUT:
  6010. GLOBAL VARIABLES:
  6011. =============================================================================*/
  6012. int Proc_din_ServiceAndPaymentSelectionReq(int AcceptFd)
  6013. {
  6014. int errn = 0;
  6015. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]ServiceAndPaymentSelectionReq");
  6016. //Print the decoded XML Document
  6017. PRINT_XML_DOC_DIN_ServiceAndPaymentSelectionReq(&ccs_exi_doc_DIN);
  6018. //Save into Share Memory
  6019. SHM_Save_din_ServiceAndPaymentSelectionReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  6020. errn = Proc_din_ServiceAndPaymentSelectionRes(AcceptFd);
  6021. if (errn == 0)
  6022. {
  6023. //send response successfully.
  6024. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ServiceAndPaymentSelectionRes\n");
  6025. }
  6026. else
  6027. {
  6028. SAVE_SYS_LOG_MSG_EVCOMM("[Error][Proc_iso1_ServiceAndPaymentSelectionReq]Proc_iso1_ServiceAndPaymentSelectionRes(): %d (DEC)\n", errn);
  6029. }
  6030. return errn;
  6031. }
  6032. /*===========================================================================
  6033. FUNCTION: Proc_iso1_ServiceAndPaymentSelectionReq
  6034. DESCRIPTION:
  6035. PRE-CONDITION:
  6036. INPUT:
  6037. OUTPUT:
  6038. GLOBAL VARIABLES:
  6039. =============================================================================*/
  6040. int Proc_iso1_ServiceAndPaymentSelectionReq(int AcceptFd)
  6041. {
  6042. int errn = 0;
  6043. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]ServiceAndPaymentSelectionReq\n");
  6044. //Print the decoded XML Document
  6045. PRINT_XML_DOC_ISO1_ServiceAndPaymentSelectionReq(&ccs_exi_doc_ISO1);
  6046. //Save into Share Memory
  6047. SHM_Save_iso1_ServiceAndPaymentSelectionReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  6048. errn = Proc_iso1_ServiceAndPaymentSelectionRes(AcceptFd);
  6049. if (errn == 0)
  6050. {
  6051. //send response successfully.
  6052. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ServiceAndPaymentSelectionRes.\n");
  6053. }
  6054. else
  6055. {
  6056. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Proc_iso1_ServiceAndPaymentSelectionRes(): %d (DEC)\n", errn);
  6057. }
  6058. return errn;
  6059. }
  6060. /*===========================================================================
  6061. FUNCTION: Proc_din_ContractAuthenticationRes
  6062. DESCRIPTION:
  6063. PRE-CONDITION:
  6064. INPUT:
  6065. OUTPUT:
  6066. GLOBAL VARIABLES:
  6067. =============================================================================*/
  6068. int Proc_din_ContractAuthenticationRes(int AcceptFd)
  6069. {
  6070. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6071. //if it is not the same, the packet should be ignored.
  6072. //int i = 0;
  6073. int errn = 0;
  6074. bitstream_t v2g_tx_stream;
  6075. static struct ChargingInfoData *sys;
  6076. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6077. size_t pos = 0;
  6078. v2g_tx_stream.pos = &pos;
  6079. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6080. v2g_tx_stream.data = V2GTP_Tx_buf;
  6081. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  6082. init_dinContractAuthenticationResType(&ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes);
  6083. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes_isUsed = 1u;
  6084. //[BODY (1/2)] ResponseCode
  6085. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_OK;
  6086. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Ongoing; //0
  6087. //[HEADER] Check Req SessionID
  6088. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  6089. {
  6090. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  6091. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  6092. errn = -1;
  6093. }
  6094. //Check for SequenceError
  6095. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6096. {
  6097. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  6098. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  6099. errn = -1;
  6100. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6101. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6102. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6103. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6104. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6105. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6106. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6107. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6108. }
  6109. //Detect for CP State should be 9V (State B)
  6110. #if CP_PROTECTION_MECHANISM == ENABLE
  6111. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6112. {
  6113. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6114. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6115. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6116. Update_V2G_Flow_Status(Other_Fault);
  6117. errn = -1;
  6118. sprintf((char*)buf_log_evcomm,
  6119. "Emergency Stop by CP Error (%d)",
  6120. sys->CpState);
  6121. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6122. }
  6123. #endif
  6124. //Check for CSU command of "Stop by EVSE"
  6125. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6126. {
  6127. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6128. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6129. errn = -1;
  6130. }
  6131. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6132. {
  6133. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6134. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6135. errn = -1;
  6136. }
  6137. //[BODY (2/2)] EVSEProcessing
  6138. if(ShmInternalComm->ChargingPermission == TRUE)
  6139. {
  6140. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished; //0
  6141. SAVE_SYS_LOG_MSG_EVCOMM("CSU Permission: OK\n");
  6142. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  6143. {
  6144. //Set PWM as 5% (for SLAC first case)
  6145. SAVE_SYS_LOG_MSG_EVCOMM("Set PWM as 5%%\n");
  6146. SwitchCpStateE(DISABLE);
  6147. OutputCpPwmDuty(5);
  6148. }
  6149. #endif
  6150. }
  6151. //Check for Permission Changing from TRUE to FALSE
  6152. if (ShmInternalComm->ChargingPermission_pre == TRUE &&
  6153. ShmInternalComm->ChargingPermission == FALSE)
  6154. {
  6155. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Permission OFF\n");
  6156. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.ResponseCode = dinresponseCodeType_FAILED;
  6157. ccs_exi_doc_DIN.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing = dinEVSEProcessingType_Finished;
  6158. errn = -1;
  6159. }
  6160. #if PARAMETER_NORMAL_MODE == ENABLE
  6161. ////////////SHM_Read_din_ContractAuthenticationRes(&ccs_exi_doc_DIN, ShmCcsData);
  6162. #endif
  6163. // ============ Encode and Send Response Message ===========
  6164. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  6165. {
  6166. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Tx encoded msg error\n");
  6167. errn = -1;
  6168. }
  6169. return errn;
  6170. }
  6171. /*===========================================================================
  6172. FUNCTION: Proc_iso1_AuthorizationRes
  6173. DESCRIPTION:
  6174. PRE-CONDITION:
  6175. INPUT:
  6176. OUTPUT:
  6177. GLOBAL VARIABLES:
  6178. =============================================================================*/
  6179. int Proc_iso1_AuthorizationRes(int AcceptFd)
  6180. {
  6181. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6182. //if it is not the same, the packet should be ignored.
  6183. //int i = 0;
  6184. int errn = 0;
  6185. bitstream_t v2g_tx_stream;
  6186. static struct ChargingInfoData *sys;
  6187. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6188. size_t pos = 0;
  6189. v2g_tx_stream.pos = &pos;
  6190. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6191. v2g_tx_stream.data = V2GTP_Tx_buf;
  6192. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6193. init_iso1AuthorizationResType(&ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes);
  6194. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes_isUsed = 1u;
  6195. //[BODY (1/2)] ResponseCode
  6196. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_OK;
  6197. /*+++ 20200808, vern, EVSEProcessing should be waiting for Customer during authrization +++*/
  6198. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Ongoing_WaitingForCustomerInteraction; //0
  6199. /*--- 20200808, vern, should be waiting for Customer during authrization ---*/
  6200. //[HEADER] Check Req SessionID
  6201. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  6202. {
  6203. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  6204. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process\n");
  6205. errn = -1;
  6206. }
  6207. //Check for SequenceError
  6208. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6209. {
  6210. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  6211. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process\n");
  6212. errn = -1;
  6213. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6214. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6215. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6216. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6217. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6218. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6219. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6220. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6221. }
  6222. //Detect for CP State should be 9V (State B)
  6223. #if CP_PROTECTION_MECHANISM == ENABLE
  6224. if ((sys->CpState != 2) && (sys->CpState != 3)) //State B1, B2
  6225. {
  6226. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = iso1responseCodeType_FAILED;
  6227. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6228. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6229. Update_V2G_Flow_Status(Other_Fault);
  6230. errn = -1;
  6231. sprintf((char*)buf_log_evcomm,
  6232. "Emergency Stop by CP Error (%d)",
  6233. sys->CpState);
  6234. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6235. }
  6236. #endif
  6237. //Check for CSU command of "Stop by EVSE"
  6238. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6239. {
  6240. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  6241. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6242. errn = -1;
  6243. }
  6244. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6245. {
  6246. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  6247. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6248. errn = -1;
  6249. }
  6250. //[BODY (2/2)] EVSEProcessing
  6251. //Check for Permission from CSU
  6252. if(ShmInternalComm->ChargingPermission == TRUE)
  6253. {
  6254. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  6255. SAVE_SYS_LOG_MSG_EVCOMM("CSU Permission: OK\n");
  6256. #if (SLAC_FIRST_RESPONSE_METHOD == SET_5_PWM_ONCE_GET_PERMISSION_IN_AUTHORIZATIONRES)
  6257. {
  6258. //Set PWM as 5% (for SLAC first case)
  6259. SAVE_SYS_LOG_MSG_EVCOMM("Set PWM as 5%%\n");
  6260. SwitchCpStateE(DISABLE);
  6261. OutputCpPwmDuty(5);
  6262. }
  6263. #endif
  6264. }
  6265. //Check for Permission Changing from TRUE to FALSE
  6266. /*+++ 20200808, vern, sync with Tesla CHAdeMO adaptor, 2 for start communication(not yet auth), 1 for star charging (authorized) ---*/
  6267. if (ShmInternalComm->ChargingPermission_pre >= 1 &&
  6268. ShmInternalComm->ChargingPermission == FALSE)
  6269. {
  6270. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Permission OFF\n");
  6271. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.ResponseCode = FAILED_ISO15118_2014;
  6272. ccs_exi_doc_ISO1.V2G_Message.Body.AuthorizationRes.EVSEProcessing = iso1EVSEProcessingType_Finished;
  6273. errn = -1;
  6274. }
  6275. #if PARAMETER_NORMAL_MODE == ENABLE
  6276. ////////////SHM_Read_iso1_AuthorizationRes(&ccs_exi_doc_ISO1, ShmCcsData);
  6277. #endif
  6278. // ============ Encode and Send Response Message ===========
  6279. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  6280. {
  6281. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Tx encoded msg error\n");
  6282. errn = -1;
  6283. }
  6284. return errn;
  6285. }
  6286. /*===========================================================================
  6287. FUNCTION: Proc_din_ContractAuthenticationReq
  6288. DESCRIPTION:
  6289. PRE-CONDITION:
  6290. INPUT:
  6291. OUTPUT:
  6292. GLOBAL VARIABLES:
  6293. =============================================================================*/
  6294. int Proc_din_ContractAuthenticationReq(int AcceptFd)
  6295. {
  6296. int errn = 0;
  6297. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]Proc_din_ContractAuthenticationReq\n");
  6298. //Print the decoded XML Document
  6299. PRINT_XML_DOC_DIN_ContractAuthenticationReq(&ccs_exi_doc_DIN);
  6300. //Save into Share Memory
  6301. SHM_Save_din_ContractAuthenticationReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  6302. errn = Proc_din_ContractAuthenticationRes(AcceptFd);
  6303. if (errn == 0)
  6304. {
  6305. //send response successfully.
  6306. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ContractAuthenticationRes\n");
  6307. }
  6308. else
  6309. {
  6310. sprintf((char*)buf_log_evcomm,
  6311. "[Error]Proc_iso1_AuthenticationRes(): %d (DEC)",
  6312. errn);
  6313. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6314. }
  6315. return errn;
  6316. }
  6317. /*===========================================================================
  6318. FUNCTION: Proc_iso1_AuthenticationReq
  6319. DESCRIPTION:
  6320. PRE-CONDITION:
  6321. INPUT:
  6322. OUTPUT:
  6323. GLOBAL VARIABLES:
  6324. =============================================================================*/
  6325. int Proc_iso1_AuthenticationReq(int AcceptFd)
  6326. {
  6327. int errn = 0;
  6328. DEBUG_PRINTF_EVCOMM_DETAIL("[V2G][RX]AuthorizationReq\n");
  6329. //Print the decoded XML Document
  6330. PRINT_XML_DOC_ISO1_AuthorizationReq(&ccs_exi_doc_ISO1);
  6331. //Save into Share Memory
  6332. SHM_Save_iso1_AuthorizationReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  6333. errn = Proc_iso1_AuthorizationRes(AcceptFd);
  6334. if (errn == 0)
  6335. {
  6336. //send response successfully.
  6337. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]AuthorizationRes\n");
  6338. }
  6339. else
  6340. {
  6341. sprintf((char*)buf_log_evcomm,
  6342. "[Error]Proc_iso1_AuthenticationRes(): %d (DEC)",
  6343. errn);
  6344. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6345. }
  6346. return errn;
  6347. }
  6348. /*===========================================================================
  6349. FUNCTION: SHM_Init_dinDC_EVSEStatusType
  6350. DESCRIPTION:
  6351. PRE-CONDITION:
  6352. INPUT:
  6353. 1. in
  6354. OUTPUT:
  6355. 2. out
  6356. GLOBAL VARIABLES:
  6357. =============================================================================*/
  6358. void SHM_Init_dinDC_EVSEStatusType(struct DC_EVSEStatusType_DIN70121 *in)
  6359. {
  6360. in->EVSEIsolationStatus = dinisolationLevelType_Valid;
  6361. // dinisolationLevelType_Invalid = 0,
  6362. // dinisolationLevelType_Valid = 1, (default)
  6363. // dinisolationLevelType_Warning = 2,
  6364. // dinisolationLevelType_Fault = 3
  6365. in->EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  6366. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  6367. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1, (default)
  6368. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  6369. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  6370. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  6371. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  6372. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  6373. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  6374. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  6375. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  6376. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  6377. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  6378. in->EVSENotification = dinEVSENotificationType_None;
  6379. // dinEVSENotificationType_None = 0, (default)
  6380. // dinEVSENotificationType_StopCharging = 1,
  6381. // dinEVSENotificationType_ReNegotiation = 2
  6382. }
  6383. /*===========================================================================
  6384. FUNCTION: SHM_Save_dinPhysicalValueType
  6385. DESCRIPTION:
  6386. PRE-CONDITION:
  6387. INPUT:
  6388. OUTPUT:
  6389. GLOBAL VARIABLES:
  6390. =============================================================================*/
  6391. void SHM_Save_dinPhysicalValueType(struct PhysicalValueType_DIN70121 *obj, short value, int multiplier, unsigned char unit)
  6392. {
  6393. obj->Value = value;
  6394. obj->Multiplier = multiplier;
  6395. obj->Unit =unit;
  6396. }
  6397. /*===========================================================================
  6398. FUNCTION: SHM_Init_din_ChargeParameterDiscoveryRes
  6399. DESCRIPTION:
  6400. PRE-CONDITION:
  6401. INPUT:
  6402. 1. shm_ccs
  6403. OUTPUT:
  6404. 2. shm_ccs
  6405. GLOBAL VARIABLES:
  6406. =============================================================================*/
  6407. void SHM_Init_din_ChargeParameterDiscoveryRes(struct CcsData *shm_ccs)
  6408. {
  6409. struct ChargeParameterDiscoveryResponse_DIN70121 *in;
  6410. in = &shm_ccs->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse;
  6411. //----- [BODY (1/5)] ResponseCode -----
  6412. in->ResponseCode = dinresponseCodeType_OK;
  6413. //----- [BODY (2/5)] EVSEProcessing -----
  6414. in->EVSEProcessing = dinEVSEProcessingType_Ongoing; //0
  6415. // dinEVSEProcessingType_Finished = 0,
  6416. // dinEVSEProcessingType_Ongoing = 1
  6417. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  6418. //be fixed in another function.
  6419. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  6420. //ignore, since DIN doesn't support AC
  6421. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  6422. struct DC_EVSEChargeParameterType_DIN70121 *in_para;
  6423. in_para = &in->DC_EVSEChargeParameter;
  6424. //DC_EVSEStatus
  6425. SHM_Init_dinDC_EVSEStatusType(&in_para->DC_EVSEStatus);
  6426. in_para->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  6427. short value = 0; int multiplier = 0; unsigned char unit = 0;
  6428. //EVSEMaximumCurrentLimit
  6429. value = 600; multiplier = -1; unit = A_DIN70121; //60A
  6430. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumCurrentLimit, value, multiplier, unit);
  6431. //EVSEMaximumPowerLimit
  6432. value = 3000; multiplier = 1; unit = W_DIN70121; //30KW
  6433. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumPowerLimit, value, multiplier, unit);
  6434. //EVSEMaximumVoltageLimit
  6435. value = 7500; multiplier = -1; unit = V_DIN70121; //750V
  6436. SHM_Save_dinPhysicalValueType(&in_para->EVSEMaximumVoltageLimit, value, multiplier, unit);
  6437. //EVSEMinimumVoltageLimit
  6438. value = 1500; multiplier = -1; unit = V_DIN70121; //150V
  6439. SHM_Save_dinPhysicalValueType(&in_para->EVSEMinimumVoltageLimit, value, multiplier, unit);
  6440. //EVSEMinimumCurrentLimit
  6441. value = 10; multiplier = -1; unit = A_DIN70121; //1A
  6442. SHM_Save_dinPhysicalValueType(&in_para->EVSEMinimumCurrentLimit, value, multiplier, unit);
  6443. //EVSECurrentRegulationTolerance
  6444. value = 10; multiplier = -1; unit = A_DIN70121; //1A
  6445. SHM_Save_dinPhysicalValueType(&in_para->EVSECurrentRegulationTolerance, value, multiplier, unit);
  6446. //EVSEPeakCurrentRipple
  6447. value = 2; multiplier = -1; unit = A_DIN70121; //0.2A
  6448. SHM_Save_dinPhysicalValueType(&in_para->EVSEPeakCurrentRipple, value, multiplier, unit);
  6449. //EVSEEnergyToBeDelivered (optional)
  6450. //SHM_Save_dinPhysicalValueType(&out_para->EVSEEnergyToBeDelivered, &in_para->EVSEEnergyToBeDelivered);
  6451. }
  6452. /*===========================================================================
  6453. FUNCTION: Sudo_Parameter_din_ChargeParameterDiscoveryRes
  6454. DESCRIPTION:
  6455. PRE-CONDITION:
  6456. INPUT:
  6457. OUTPUT:
  6458. GLOBAL VARIABLES:
  6459. =============================================================================*/
  6460. void Sudo_Parameter_din_ChargeParameterDiscoveryRes()
  6461. {
  6462. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  6463. init_dinChargeParameterDiscoveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes);
  6464. ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed = 1u;
  6465. //----- [BODY (1/5)] ResponseCode -----
  6466. struct dinChargeParameterDiscoveryResType *res;
  6467. res = &ccs_exi_doc_DIN.V2G_Message.Body.ChargeParameterDiscoveryRes;
  6468. res->ResponseCode = dinresponseCodeType_OK;
  6469. //----- [BODY (2/5)] EVSEProcessing -----
  6470. res->EVSEProcessing = dinEVSEProcessingType_Finished; //0
  6471. // dinEVSEProcessingType_Finished = 0,
  6472. // dinEVSEProcessingType_Ongoing = 1
  6473. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  6474. res->SAScheduleList_isUsed = 1u;
  6475. struct dinSAScheduleListType *list;
  6476. list = &res->SAScheduleList;
  6477. //
  6478. list->SAScheduleTuple.arrayLen = 1;
  6479. list->SAScheduleTuple.array[0].SAScheduleTupleID = 0;
  6480. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleID = 0;
  6481. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.arrayLen = 1;
  6482. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval_isUsed = 1u;
  6483. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.start = 0;
  6484. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration = xxx
  6485. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration_isUsed = 1u;
  6486. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval_isUsed = 0u;
  6487. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval.xxx
  6488. //list->SAScheduleTuple.array[0].SalesTariff.xxx
  6489. //list->SAScheduleTuple.array[0].SalesTariff_isUsed = 0u;
  6490. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  6491. //ignore, since DIN doesn't support AC
  6492. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  6493. res->DC_EVSEChargeParameter_isUsed = 1u;
  6494. struct dinDC_EVSEChargeParameterType *para;
  6495. para = &res->DC_EVSEChargeParameter;
  6496. //DC_EVSEStatus
  6497. para->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  6498. para->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  6499. // dinisolationLevelType_Invalid = 0,
  6500. // dinisolationLevelType_Valid = 1,
  6501. // dinisolationLevelType_Warning = 2,
  6502. // dinisolationLevelType_Fault = 3
  6503. para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  6504. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  6505. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  6506. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  6507. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  6508. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  6509. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  6510. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  6511. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  6512. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  6513. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  6514. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  6515. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  6516. para->DC_EVSEStatus.NotificationMaxDelay = 0u;
  6517. para->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  6518. // dinEVSENotificationType_None = 0,
  6519. // dinEVSENotificationType_StopCharging = 1,
  6520. // dinEVSENotificationType_ReNegotiation = 2
  6521. //EVSEMaximumCurrentLimit
  6522. para->EVSEMaximumCurrentLimit.Value = 2400;
  6523. para->EVSEMaximumCurrentLimit.Multiplier = -1;
  6524. para->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  6525. para->EVSEMaximumCurrentLimit.Unit = dinunitSymbolType_A;
  6526. // dinunitSymbolType_h = 0,
  6527. // dinunitSymbolType_m = 1,
  6528. // dinunitSymbolType_s = 2,
  6529. // dinunitSymbolType_A = 3,
  6530. // dinunitSymbolType_Ah = 4,
  6531. // dinunitSymbolType_V = 5,
  6532. // dinunitSymbolType_VA = 6,
  6533. // dinunitSymbolType_W = 7,
  6534. // dinunitSymbolType_W_s = 8,
  6535. // dinunitSymbolType_Wh = 9
  6536. //EVSEMaximumPowerLimit
  6537. para->EVSEMaximumPowerLimit.Value = 6000;
  6538. para->EVSEMaximumPowerLimit.Multiplier = 1;
  6539. para->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  6540. para->EVSEMaximumPowerLimit.Unit = dinunitSymbolType_W;
  6541. //EVSEMaximumVoltageLimit
  6542. para->EVSEMaximumVoltageLimit.Value = 7500;
  6543. para->EVSEMaximumVoltageLimit.Multiplier = -1;
  6544. para->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  6545. para->EVSEMaximumVoltageLimit.Unit = dinunitSymbolType_V;
  6546. //EVSEMinimumVoltageLimit
  6547. para->EVSEMinimumVoltageLimit.Value = 1500;
  6548. para->EVSEMinimumVoltageLimit.Multiplier = -1;
  6549. para->EVSEMinimumVoltageLimit.Unit_isUsed = 1u;
  6550. para->EVSEMinimumVoltageLimit.Unit = dinunitSymbolType_V;
  6551. //EVSEMinimumCurrentLimit
  6552. para->EVSEMinimumCurrentLimit.Value = 20;
  6553. para->EVSEMinimumCurrentLimit.Multiplier = -1;
  6554. para->EVSEMinimumCurrentLimit.Unit_isUsed = 1u;
  6555. para->EVSEMinimumCurrentLimit.Unit = dinunitSymbolType_A;
  6556. //EVSECurrentRegulationTolerance_isUsed
  6557. para->EVSECurrentRegulationTolerance_isUsed = 1u;
  6558. //EVSECurrentRegulationTolerance
  6559. para->EVSECurrentRegulationTolerance.Value = 10;
  6560. para->EVSECurrentRegulationTolerance.Multiplier = -1;
  6561. para->EVSECurrentRegulationTolerance.Unit_isUsed = 1u;
  6562. para->EVSECurrentRegulationTolerance.Unit = dinunitSymbolType_A;
  6563. //EVSEEnergyToBeDelivered_isUsed
  6564. para->EVSEEnergyToBeDelivered_isUsed = 1u;
  6565. //EVSEPeakCurrentRipple
  6566. para->EVSEPeakCurrentRipple.Value = 2;
  6567. para->EVSEPeakCurrentRipple.Multiplier = -1;
  6568. para->EVSEPeakCurrentRipple.Unit_isUsed = 1u;
  6569. para->EVSEPeakCurrentRipple.Unit = dinunitSymbolType_A;
  6570. //EVSEEnergyToBeDelivered (optional)
  6571. /*
  6572. para->EVSEEnergyToBeDelivered.Value = 360;
  6573. para->EVSEEnergyToBeDelivered.Multiplier = 3;
  6574. para->EVSEEnergyToBeDelivered.Unit_isUsed = 1u;
  6575. para->EVSEEnergyToBeDelivered.Unit = dinunitSymbolType_Wh;
  6576. */
  6577. }
  6578. /*===========================================================================
  6579. FUNCTION: Sudo_Parameter_iso1_ChargeParameterDiscoveryRes
  6580. DESCRIPTION:
  6581. PRE-CONDITION:
  6582. INPUT:
  6583. OUTPUT:
  6584. GLOBAL VARIABLES:
  6585. =============================================================================*/
  6586. void Sudo_Parameter_iso1_ChargeParameterDiscoveryRes()
  6587. {
  6588. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  6589. init_iso1ChargeParameterDiscoveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes);
  6590. ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed = 1u;
  6591. //----- [BODY (1/5)] ResponseCode -----
  6592. struct iso1ChargeParameterDiscoveryResType *res;
  6593. res = &ccs_exi_doc_ISO1.V2G_Message.Body.ChargeParameterDiscoveryRes;
  6594. res->ResponseCode = iso1responseCodeType_OK;
  6595. //----- [BODY (2/5)] EVSEProcessing -----
  6596. res->EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  6597. // iso1EVSEProcessingType_Finished = 0,
  6598. // iso1EVSEProcessingType_Ongoing = 1
  6599. //----- [BODY (3/5)] SAScheduleList of SASchedules -----
  6600. res->SAScheduleList_isUsed = 1u;
  6601. struct iso1SAScheduleListType *list;
  6602. list = &res->SAScheduleList;
  6603. //
  6604. list->SAScheduleTuple.arrayLen = 1;
  6605. list->SAScheduleTuple.array[0].SAScheduleTupleID = 0;
  6606. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.arrayLen = 1;
  6607. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval_isUsed = 1u;
  6608. list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.start = 0;
  6609. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration = xxx
  6610. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].RelativeTimeInterval.duration_isUsed = 1u;
  6611. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval_isUsed = 0u;
  6612. //list->SAScheduleTuple.array[0].PMaxSchedule.PMaxScheduleEntry.array[0].TimeInterval.xxx
  6613. //list->SAScheduleTuple.array[0].SalesTariff.xxx
  6614. //list->SAScheduleTuple.array[0].SalesTariff_isUsed = 0u;
  6615. //----- [BODY (4/5)] AC_EVSEChargeParameter of EVSEChargeParameter -----
  6616. //ignore, since our ISO1 doesn't support AC, yet
  6617. //----- [BODY (5/5)] DC_EVSEChargeParameter of EVSEChargeParameter -----
  6618. res->DC_EVSEChargeParameter_isUsed = 1u;
  6619. struct iso1DC_EVSEChargeParameterType *para;
  6620. para = &res->DC_EVSEChargeParameter;
  6621. //DC_EVSEStatus
  6622. para->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  6623. para->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  6624. // iso1isolationLevelType_Invalid = 0,
  6625. // iso1isolationLevelType_Valid = 1,
  6626. // iso1isolationLevelType_Warning = 2,
  6627. // iso1isolationLevelType_Fault = 3
  6628. para->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  6629. // iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  6630. // iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  6631. // iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  6632. // iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  6633. // iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  6634. // iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  6635. // iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  6636. // iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  6637. // iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  6638. // iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  6639. // iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  6640. // iso1DC_EVSEStatusCodeType_Reserved_C = 11
  6641. para->DC_EVSEStatus.NotificationMaxDelay = 0u;
  6642. para->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  6643. // iso1EVSENotificationType_None = 0,
  6644. // iso1EVSENotificationType_StopCharging = 1,
  6645. // iso1EVSENotificationType_ReNegotiation = 2
  6646. //EVSEMaximumCurrentLimit
  6647. para->EVSEMaximumCurrentLimit.Value = 2400;
  6648. para->EVSEMaximumCurrentLimit.Multiplier = -1;
  6649. //para->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  6650. para->EVSEMaximumCurrentLimit.Unit = iso1unitSymbolType_A;
  6651. //iso1unitSymbolType_h = 0,
  6652. //iso1unitSymbolType_m = 1,
  6653. //iso1unitSymbolType_s = 2,
  6654. //iso1unitSymbolType_A = 3,
  6655. //iso1unitSymbolType_V = 4,
  6656. //iso1unitSymbolType_W = 5,
  6657. //iso1unitSymbolType_Wh = 6
  6658. //EVSEMaximumPowerLimit
  6659. para->EVSEMaximumPowerLimit.Value = 6000;
  6660. para->EVSEMaximumPowerLimit.Multiplier = 1;
  6661. //para->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  6662. para->EVSEMaximumPowerLimit.Unit = iso1unitSymbolType_W;
  6663. //EVSEMaximumVoltageLimit
  6664. para->EVSEMaximumVoltageLimit.Value = 7500;
  6665. para->EVSEMaximumVoltageLimit.Multiplier = -1;
  6666. //para->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  6667. para->EVSEMaximumVoltageLimit.Unit = iso1unitSymbolType_V;
  6668. //EVSEMinimumVoltageLimit
  6669. para->EVSEMinimumVoltageLimit.Value = 1500;
  6670. para->EVSEMinimumVoltageLimit.Multiplier = -1;
  6671. //para->EVSEMinimumVoltageLimit.Unit_isUsed = 1u;
  6672. para->EVSEMinimumVoltageLimit.Unit = iso1unitSymbolType_V;
  6673. //EVSEMinimumCurrentLimit
  6674. para->EVSEMinimumCurrentLimit.Value = 20;
  6675. para->EVSEMinimumCurrentLimit.Multiplier = -1;
  6676. //para->EVSEMinimumCurrentLimit.Unit_isUsed = 1u;
  6677. para->EVSEMinimumCurrentLimit.Unit = iso1unitSymbolType_A;
  6678. //EVSECurrentRegulationTolerance_isUsed
  6679. para->EVSECurrentRegulationTolerance_isUsed = 1u;
  6680. //EVSECurrentRegulationTolerance
  6681. para->EVSECurrentRegulationTolerance.Value = 10;
  6682. para->EVSECurrentRegulationTolerance.Multiplier = -1;
  6683. //para->EVSECurrentRegulationTolerance.Unit_isUsed = 1u;
  6684. para->EVSECurrentRegulationTolerance.Unit = iso1unitSymbolType_A;
  6685. //EVSEEnergyToBeDelivered_isUsed
  6686. para->EVSEEnergyToBeDelivered_isUsed = 1u;
  6687. //EVSEPeakCurrentRipple
  6688. para->EVSEPeakCurrentRipple.Value = 2;
  6689. para->EVSEPeakCurrentRipple.Multiplier = -1;
  6690. //para->EVSEPeakCurrentRipple.Unit_isUsed = 1u;
  6691. para->EVSEPeakCurrentRipple.Unit = iso1unitSymbolType_A;
  6692. //EVSEEnergyToBeDelivered (optional)
  6693. /*
  6694. para->EVSEEnergyToBeDelivered.Value = 360;
  6695. para->EVSEEnergyToBeDelivered.Multiplier = 3;
  6696. para->EVSEEnergyToBeDelivered.Unit_isUsed = 1u;
  6697. para->EVSEEnergyToBeDelivered.Unit = iso1unitSymbolType_Wh;
  6698. */
  6699. }
  6700. /*===========================================================================
  6701. FUNCTION: Proc_din_ChargeParameterDiscoveryRes
  6702. DESCRIPTION:
  6703. PRE-CONDITION:
  6704. INPUT:
  6705. OUTPUT:
  6706. GLOBAL VARIABLES:
  6707. =============================================================================*/
  6708. int Proc_din_ChargeParameterDiscoveryRes(int AcceptFd)
  6709. {
  6710. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6711. //if it is not the same, the packet should be ignored.
  6712. //STEP 1: ============ Initialize ============
  6713. int errn = 0;
  6714. bitstream_t v2g_tx_stream;
  6715. struct ChargeParameterDiscoveryResponse_DIN70121 *res;
  6716. struct ChargeParameterDiscoveryRequest_DIN70121 *req;
  6717. struct DC_EVSEChargeParameterType_DIN70121 *dc_para;
  6718. struct ChargingInfoData *sys;
  6719. size_t pos = 0;
  6720. v2g_tx_stream.pos = &pos;
  6721. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6722. v2g_tx_stream.data = V2GTP_Tx_buf;
  6723. res = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse;
  6724. req = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest;
  6725. dc_para = &ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryResponse.DC_EVSEChargeParameter;
  6726. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6727. res->ResponseCode = OK_DIN70121;
  6728. res->EVSEProcessing = Ongoing_DIN70121;
  6729. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready; //1
  6730. //[HEADER] Check Req SessionID
  6731. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  6732. {
  6733. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  6734. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process\n");
  6735. errn = -1;
  6736. }
  6737. //Check for SequenceError
  6738. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6739. {
  6740. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  6741. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process\n");
  6742. errn = -1;
  6743. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6744. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6745. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6746. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6747. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6748. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6749. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6750. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6751. }
  6752. //[TC_SECC_VTB_ChargeParameterDiscovery_005]
  6753. if (sys->EvBatteryMaxCurrent < 0)
  6754. {
  6755. sprintf((char*)buf_log_evcomm,
  6756. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  6757. sys->EvBatteryMaxCurrent);
  6758. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6759. res->ResponseCode = dinresponseCodeType_FAILED_WrongChargeParameter; //16
  6760. res->EVSEProcessing = Finished_DIN70121;
  6761. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6762. errn = -1;
  6763. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6764. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  6765. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6766. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6767. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6768. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6769. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  6770. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  6771. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6772. }
  6773. //STEP 2: ============ Modify Parameters of ShmCcsData ============
  6774. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_DIN70121);
  6775. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_DIN70121);
  6776. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_DIN70121);
  6777. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMinimumVoltageLimit, 1500, V_DIN70121); //150V
  6778. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMinimumCurrentLimit, 10, A_DIN70121); //1A
  6779. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSECurrentRegulationTolerance, 10, A_DIN70121); //1A
  6780. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEPeakCurrentRipple, 2, A_DIN70121); //0.2A
  6781. //SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEEnergyToBeDelivered, 0, WH_DIN70121); //optional
  6782. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  6783. if (sys->EvBatteryMaxVoltage <= 500)
  6784. {
  6785. SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumVoltageLimit, (int) (500 * 10), V_DIN70121); //500V
  6786. }
  6787. #endif
  6788. //for test with Tesla Model 3, 10A
  6789. //SAVE_PhysicalValueType_DIN70121(&dc_para->EVSEMaximumCurrentLimit, (int) (10 * 10), A_DIN70121); //10A, for testing with Tesla Model 3
  6790. //Check for EnergyTransferMode [TC_SECC_VTB_ChargeParameterDiscovery_004]
  6791. if (req->EVRequestedEnergyTransferType != DC_extended)
  6792. {
  6793. sprintf((char*)buf_log_evcomm,
  6794. "[ERROR]Wrong EVRequestedEnergyTransferType(%d,%d)",
  6795. req->EVRequestedEnergyTransferType,
  6796. dinEVSESupportedEnergyTransferType_DC_extended);
  6797. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6798. res->ResponseCode = FAILED_WrongEnergyTransferType_DIN70121;
  6799. res->EVSEProcessing = Finished_DIN70121;
  6800. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6801. errn = -1;
  6802. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6803. Update_V2G_Flow_Status(Other_Fault);
  6804. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6805. //CCS_SECC_ResponseCode_FAILED_WrongEnergyTransferMode (023774)
  6806. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6807. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6808. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6809. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6810. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  6811. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  6812. }
  6813. //Check for CSU command of "Stop by EVSE"
  6814. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  6815. {
  6816. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryRes]EVSE_Shutdown\n");
  6817. res->ResponseCode = FAILED_DIN70121;
  6818. res->EVSEProcessing = Finished_DIN70121;
  6819. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6820. errn = -1;
  6821. }
  6822. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  6823. {
  6824. SAVE_SYS_LOG_MSG_EVCOMM("[Proc_din_ChargeParameterDiscoveryRes]EVSE_EmergencyShutdown\n");
  6825. res->ResponseCode = FAILED_DIN70121;
  6826. res->EVSEProcessing = Finished_DIN70121;
  6827. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  6828. errn = -1;
  6829. }
  6830. //Detect for CP State should be 9V (State B)
  6831. #if CP_PROTECTION_MECHANISM == ENABLE
  6832. if (sys->CpState != 3) //State B1, B2
  6833. {
  6834. res->ResponseCode = FAILED_DIN70121;
  6835. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  6836. res->EVSEProcessing = Finished_DIN70121;
  6837. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6838. Update_V2G_Flow_Status(Other_Fault);
  6839. errn = -1;
  6840. sprintf((char*)buf_log_evcomm,
  6841. "Emergency Stop by CP Error (%d, %.02f V)\n",
  6842. sys->CpState,
  6843. sys->CpVoltage);
  6844. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6845. }
  6846. #endif
  6847. //Check for Permission from CSU
  6848. if (ShmInternalComm->ChargingPermission == TRUE)
  6849. {
  6850. res->EVSEProcessing = Finished_DIN70121;
  6851. }
  6852. //Check for Permission Off
  6853. if (ShmInternalComm->ChargingPermission == FALSE)
  6854. {
  6855. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Permission OFF\n");
  6856. res->ResponseCode = FAILED_DIN70121;
  6857. res->EVSEProcessing = Finished_DIN70121;
  6858. dc_para->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  6859. errn = -1;
  6860. }
  6861. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  6862. #if PARAMETER_NORMAL_MODE == ENABLE
  6863. SHM_Read_din_ChargeParameterDiscoveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  6864. #else
  6865. Sudo_Parameter_din_ChargeParameterDiscoveryRes();
  6866. #endif
  6867. //STEP 4: ============ Encode and Send Response Message ===========
  6868. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  6869. {
  6870. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Tx encoded msg error\n");
  6871. errn = -1;
  6872. }
  6873. //STPE 5: ============ Update Flags ============
  6874. return errn;
  6875. }
  6876. /*===========================================================================
  6877. FUNCTION: Proc_iso1_ChargeParameterDiscoveryRes
  6878. DESCRIPTION:
  6879. PRE-CONDITION:
  6880. INPUT:
  6881. OUTPUT:
  6882. GLOBAL VARIABLES:
  6883. =============================================================================*/
  6884. int Proc_iso1_ChargeParameterDiscoveryRes(int AcceptFd)
  6885. {
  6886. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  6887. //if it is not the same, the packet should be ignored.
  6888. //STEP 1: ============ Initialize ============
  6889. int errn = 0;
  6890. bitstream_t v2g_tx_stream;
  6891. struct ChargeParameterDiscoveryResponse_ISO15118_2014 *res;
  6892. struct ChargeParameterDiscoveryRequest_ISO15118_2014 *req;
  6893. struct DC_EVSEChargeParameterType_ISO15118_2014 *dc_para;
  6894. struct AC_EVSEChargeParameterType_ISO15118_2014 *ac_para;
  6895. struct ChargingInfoData *sys;
  6896. size_t pos = 0;
  6897. v2g_tx_stream.pos = &pos;
  6898. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  6899. v2g_tx_stream.data = V2GTP_Tx_buf;
  6900. res = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse;
  6901. req = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest;
  6902. dc_para = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse.DC_EVSEChargeParameter;
  6903. ac_para = &ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryResponse.AC_EVSEChargeParameter;
  6904. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  6905. res->ResponseCode = OK_ISO15118_2014;
  6906. /*+++ 20200808, vern, EVSEProcessing should be on-going during ChargeParameterDiscovery +++*/
  6907. res->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  6908. /*--- 20200808, vern, EVSEProcessing should be on-going during ChargeParameterDiscovery ---*/
  6909. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; //1
  6910. ac_para->AC_EVSEStatus.RCD = ShmInternalComm->AC_RcdStatus; //0:no error, 1:error
  6911. ac_para->AC_EVSEStatus.NotificationMaxDelay = 0; //unit: 1s
  6912. ac_para->AC_EVSEStatus.EVSENotification = ShmInternalComm->AC_EVSENotification; //0:none, 1:StopCharging, 2:RenNgotiation
  6913. //[HEADER] Check Req SessionID
  6914. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  6915. {
  6916. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  6917. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process\n");
  6918. errn = -1;
  6919. }
  6920. //Check for SequenceError
  6921. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  6922. {
  6923. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  6924. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process\n");
  6925. errn = -1;
  6926. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6927. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  6928. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6929. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6930. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6931. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6932. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  6933. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  6934. }
  6935. //[TC_SECC_VTB_ChargeParameterDiscovery_005]
  6936. /*+++ 20200808, vern, should check the voltage and current to see if the range of battery parameter is accepted by charger ---*/
  6937. if ((sys->EvBatteryMaxCurrent < 0) ||(sys->EvBatteryMaxVoltage<150))
  6938. {
  6939. sprintf((char*)buf_log_evcomm,
  6940. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  6941. sys->EvBatteryMaxCurrent);
  6942. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  6943. res->ResponseCode = iso1responseCodeType_FAILED_WrongChargeParameter; //16
  6944. res->EVSEProcessing = Finished_ISO15118_2014;
  6945. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  6946. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  6947. errn = -1;
  6948. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6949. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  6950. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6951. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6952. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6953. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6954. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  6955. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  6956. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6957. }
  6958. //STEP 2: ============ Modify Parameters of ShmCcsData ============
  6959. //DC
  6960. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_ISO15118_2014);
  6961. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  6962. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_ISO15118_2014);
  6963. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMinimumVoltageLimit, 1500, V_ISO15118_2014); //150V
  6964. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMinimumCurrentLimit, 10, A_ISO15118_2014); //1A
  6965. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSECurrentRegulationTolerance, 10, A_ISO15118_2014); //1A
  6966. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEPeakCurrentRipple, 2, A_ISO15118_2014); //0.2A
  6967. //SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEEnergyToBeDelivered, 0, Wh_ISO15118_2014); //optional
  6968. //AC
  6969. SAVE_PhysicalValueType_ISO15118_2014(&ac_para->EVSENominalVoltage, (int) (sys->AC_EVSENominalVoltage * 10), V_ISO15118_2014);
  6970. SAVE_PhysicalValueType_ISO15118_2014(&ac_para->EVSEMaxCurrent, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  6971. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  6972. if (sys->EvBatteryMaxVoltage <= 500)
  6973. {
  6974. SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumVoltageLimit, (int) (500 * 10), V_ISO15118_2014); //500V
  6975. }
  6976. #endif
  6977. //for test with Tesla Model 3, 10A
  6978. //SAVE_PhysicalValueType_ISO15118_2014(&dc_para->EVSEMaximumCurrentLimit, (int) (10 * 10), A_ISO15118_2014); //10A, for testing with Tesla Model 3
  6979. //Check for EnergyTransferMode
  6980. if (req->RequestedEnergyTransferMode != ShmCcsData->EnergyTransferMode) //[CAUTION] Their table should be kept as the same.
  6981. {
  6982. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]Unmatched RequestedEnergyTransferMode(%d,%d)\n",
  6983. req->RequestedEnergyTransferMode,
  6984. ShmCcsData->EnergyTransferMode);
  6985. res->ResponseCode = FAILED_WrongEnergyTransferMode_ISO15118_2014;
  6986. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  6987. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  6988. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  6989. errn = -1;
  6990. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  6991. Update_V2G_Flow_Status(Other_Fault);
  6992. //Update_ShmStatusCode(); //[To-Do] to be implemented
  6993. //CCS_SECC_ResponseCode_FAILED_WrongEnergyTransferMode (023774)
  6994. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  6995. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  6996. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  6997. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  6998. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  6999. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  7000. }
  7001. //Check for CSU command of "Stop by EVSE"
  7002. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7003. {
  7004. SAVE_SYS_LOG_MSG_EVCOMM("EVSE_Shutdown\n");
  7005. res->ResponseCode = FAILED_ISO15118_2014;
  7006. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7007. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7008. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7009. errn = -1;
  7010. }
  7011. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7012. {
  7013. SAVE_SYS_LOG_MSG_EVCOMM("EVSE_EmergencyShutdown\n");
  7014. res->ResponseCode = FAILED_ISO15118_2014;
  7015. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7016. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7017. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7018. errn = -1;
  7019. }
  7020. //Detect for CP State should be 9V (State B)
  7021. #if CP_PROTECTION_MECHANISM == ENABLE
  7022. if (sys->CpState != 3) //State B1, B2
  7023. {
  7024. res->ResponseCode = FAILED_ISO15118_2014;
  7025. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7026. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7027. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7028. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7029. Update_V2G_Flow_Status(Other_Fault);
  7030. errn = -1;
  7031. sprintf((char*)buf_log_evcomm,
  7032. "Emergency Stop by CP Error (%d, %.02f V)\n",
  7033. sys->CpState,
  7034. sys->CpVoltage);
  7035. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7036. }
  7037. #endif
  7038. //Check for Permission from CSU
  7039. if(ShmInternalComm->ChargingPermission == TRUE)
  7040. {
  7041. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7042. }
  7043. //Check for Permission Off
  7044. if (ShmInternalComm->ChargingPermission == FALSE)
  7045. {
  7046. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Permission OFF\n");
  7047. res->ResponseCode = FAILED_ISO15118_2014;
  7048. res->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7049. dc_para->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7050. ac_para->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  7051. errn = -1;
  7052. }
  7053. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7054. #if PARAMETER_NORMAL_MODE == ENABLE
  7055. SHM_Read_iso1_ChargeParameterDiscoveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  7056. #else
  7057. Sudo_Parameter_iso1_ChargeParameterDiscoveryRes();
  7058. #endif
  7059. //STEP 4: ============ Encode and Send Response Message ===========
  7060. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  7061. {
  7062. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Tx encoded msg error\n");
  7063. errn = -1;
  7064. }
  7065. //STPE 5: ============ Update Flags ============
  7066. return errn;
  7067. }
  7068. /*===========================================================================
  7069. FUNCTION: Proc_din_ChargeParameterDiscoveryReq
  7070. DESCRIPTION:
  7071. PRE-CONDITION:
  7072. INPUT:
  7073. OUTPUT:
  7074. GLOBAL VARIABLES:
  7075. =============================================================================*/
  7076. int Proc_din_ChargeParameterDiscoveryReq(int AcceptFd)
  7077. {
  7078. int errn = 0;
  7079. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]ChargeParameterDiscoveryReq");
  7080. //ftime(&SeqStartTime);
  7081. //Print the decoded XML Document
  7082. PRINT_XML_DOC_DIN_ChargeParameterDiscoveryReq(&ccs_exi_doc_DIN);
  7083. //Save into Share Memory
  7084. SHM_Save_din_ChargeParameterDiscoveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  7085. //Check for EV Error Code
  7086. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.DC_EVStatus.EVErrorCode);
  7087. errn = Proc_din_ChargeParameterDiscoveryRes(AcceptFd);
  7088. //ftime(&SeqEndTime);
  7089. //DEBUG_PRINTF_EVCOMM_DETAIL("\ndelta = %.02lf ms\n", DiffTimeb(SeqStartTime, SeqEndTime));
  7090. if ( errn == 0)
  7091. {
  7092. //send response successfully.
  7093. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ChargeParameterDiscoveryRes\n");
  7094. }
  7095. else
  7096. {
  7097. sprintf((char*)buf_log_evcomm,
  7098. "[Error]%d (DEC)",
  7099. errn);
  7100. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7101. }
  7102. return errn;
  7103. }
  7104. /*===========================================================================
  7105. FUNCTION: Proc_iso1_ChargeParameterDiscoveryReq
  7106. DESCRIPTION:
  7107. PRE-CONDITION:
  7108. INPUT:
  7109. OUTPUT:
  7110. GLOBAL VARIABLES:
  7111. =============================================================================*/
  7112. int Proc_iso1_ChargeParameterDiscoveryReq(int AcceptFd)
  7113. {
  7114. int errn = 0;
  7115. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]ChargeParameterDiscoveryReq\n");
  7116. //ftime(&SeqStartTime);
  7117. //Print the decoded XML Document
  7118. PRINT_XML_DOC_ISO1_ChargeParameterDiscoveryReq(&ccs_exi_doc_ISO1);
  7119. //Save into Share Memory
  7120. SHM_Save_iso1_ChargeParameterDiscoveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  7121. //Check for EV Error Code
  7122. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.ChargeParameterDiscoveryRequest.DC_EVChargeParameter.DC_EVStatus.EVErrorCode);
  7123. errn = Proc_iso1_ChargeParameterDiscoveryRes(AcceptFd);
  7124. //ftime(&SeqEndTime);
  7125. //DEBUG_PRINTF_EVCOMM_DETAIL("\ndelta = %.02lf ms\n", DiffTimeb(SeqStartTime, SeqEndTime));
  7126. if (errn == 0)
  7127. {
  7128. //send response successfully.
  7129. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ChargeParameterDiscoveryRes\n");
  7130. }
  7131. else
  7132. {
  7133. SAVE_SYS_LOG_MSG_EVCOMM("[Error]%d (DEC)\n", errn);
  7134. }
  7135. return errn;
  7136. }
  7137. /*===========================================================================
  7138. FUNCTION: SHM_Init_din_CableCheckRes
  7139. DESCRIPTION:
  7140. PRE-CONDITION:
  7141. INPUT:
  7142. 1. shm_ccs
  7143. OUTPUT:
  7144. 1. shm_ccs
  7145. GLOBAL VARIABLES:
  7146. =============================================================================*/
  7147. void SHM_Init_din_CableCheckRes(struct CcsData *shm_ccs)
  7148. {
  7149. struct CableCheckResponse_DIN70121 *in;
  7150. in = &shm_ccs->V2GMessage_DIN70121.CableCheckResponse;
  7151. //----- [BODY (1/3)] ResponseCode -----
  7152. in->ResponseCode = dinresponseCodeType_OK;
  7153. //----- [BODY (2/3)] EVSEProcessing -----
  7154. //in->EVSEProcessing = dinEVSEProcessingType_Finished; //for test
  7155. in->EVSEProcessing = dinEVSEProcessingType_Ongoing; //default
  7156. // dinEVSEProcessingType_Finished = 0,
  7157. // dinEVSEProcessingType_Ongoing = 1
  7158. //----- [BODY (3/3)] DC_EVSEStatus -----
  7159. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  7160. in->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0 (default)
  7161. // dinisolationLevelType_Invalid = 0,
  7162. // dinisolationLevelType_Valid = 1, (default)
  7163. // dinisolationLevelType_Warning = 2,
  7164. // dinisolationLevelType_Fault = 3
  7165. }
  7166. /*===========================================================================
  7167. FUNCTION: Sudo_Parameter_din_CableCheckRes
  7168. DESCRIPTION:
  7169. PRE-CONDITION:
  7170. INPUT:
  7171. OUTPUT:
  7172. GLOBAL VARIABLES:
  7173. =============================================================================*/
  7174. void Sudo_Parameter_din_CableCheckRes()
  7175. {
  7176. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  7177. init_dinCableCheckResType(&ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes);
  7178. ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes_isUsed = 1u;
  7179. //----- [BODY (1/3)] ResponseCode -----
  7180. struct dinCableCheckResType *res;
  7181. res = &ccs_exi_doc_DIN.V2G_Message.Body.CableCheckRes;
  7182. res->ResponseCode = dinresponseCodeType_OK;
  7183. //----- [BODY (2/3)] EVSEProcessing -----
  7184. res->EVSEProcessing = dinEVSEProcessingType_Finished; //0
  7185. // dinEVSEProcessingType_Finished = 0,
  7186. // dinEVSEProcessingType_Ongoing = 1
  7187. //----- [BODY (3/3)] DC_EVSEStatus -----
  7188. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7189. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  7190. // dinisolationLevelType_Invalid = 0,
  7191. // dinisolationLevelType_Valid = 1,
  7192. // dinisolationLevelType_Warning = 2,
  7193. // dinisolationLevelType_Fault = 3
  7194. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7195. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7196. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  7197. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7198. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7199. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7200. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7201. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7202. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  7203. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  7204. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  7205. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  7206. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  7207. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7208. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  7209. // dinEVSENotificationType_None = 0,
  7210. // dinEVSENotificationType_StopCharging = 1,
  7211. // dinEVSENotificationType_ReNegotiation = 2
  7212. }
  7213. /*===========================================================================
  7214. FUNCTION: Sudo_Parameter_iso1_CableCheckRes
  7215. DESCRIPTION:
  7216. PRE-CONDITION:
  7217. INPUT:
  7218. OUTPUT:
  7219. GLOBAL VARIABLES:
  7220. =============================================================================*/
  7221. void Sudo_Parameter_iso1_CableCheckRes()
  7222. {
  7223. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  7224. init_iso1CableCheckResType(&ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes);
  7225. ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes_isUsed = 1u;
  7226. //----- [BODY (1/3)] ResponseCode -----
  7227. struct iso1CableCheckResType *res;
  7228. res = &ccs_exi_doc_ISO1.V2G_Message.Body.CableCheckRes;
  7229. res->ResponseCode = iso1responseCodeType_OK;
  7230. //----- [BODY (2/3)] EVSEProcessing -----
  7231. res->EVSEProcessing = iso1EVSEProcessingType_Finished; //0
  7232. //iso1EVSEProcessingType_Finished = 0,
  7233. //iso1EVSEProcessingType_Ongoing = 1,
  7234. //iso1EVSEProcessingType_Ongoing_WaitingForCustomerInteraction = 2
  7235. //----- [BODY (3/3)] DC_EVSEStatus -----
  7236. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7237. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  7238. //iso1isolationLevelType_Invalid = 0,
  7239. //iso1isolationLevelType_Valid = 1,
  7240. //iso1isolationLevelType_Warning = 2,
  7241. //iso1isolationLevelType_Fault = 3,
  7242. //iso1isolationLevelType_No_IMD = 4
  7243. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  7244. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7245. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  7246. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7247. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7248. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7249. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7250. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7251. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  7252. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  7253. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  7254. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  7255. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  7256. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7257. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  7258. //iso1EVSENotificationType_None = 0,
  7259. //iso1EVSENotificationType_StopCharging = 1,
  7260. //iso1EVSENotificationType_ReNegotiation = 2
  7261. }
  7262. /*===========================================================================
  7263. FUNCTION: Proc_din_CableCheckRes
  7264. DESCRIPTION:
  7265. PRE-CONDITION:
  7266. INPUT:
  7267. OUTPUT:
  7268. GLOBAL VARIABLES:
  7269. =============================================================================*/
  7270. int Proc_din_CableCheckRes(int AcceptFd)
  7271. {
  7272. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7273. //if it is not the same, the packet should be ignored.
  7274. //STEP 1: ============ Initialize ============
  7275. //int i = 0;
  7276. int errn = 0;
  7277. bitstream_t v2g_tx_stream;
  7278. static struct CableCheckResponse_DIN70121 *cab;
  7279. static struct ChargingInfoData *sys;
  7280. size_t pos = 0;
  7281. v2g_tx_stream.pos = &pos;
  7282. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7283. v2g_tx_stream.data = V2GTP_Tx_buf;
  7284. cab = &ShmCcsData->V2GMessage_DIN70121.CableCheckResponse;
  7285. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7286. cab->ResponseCode = OK_DIN70121;
  7287. cab->cnt++;
  7288. DEBUG_PRINTF_EVCOMM_DETAIL("CP_State = %d (%.02f V), V_now = %.02f, Isolation Status = %d, EVSEProcessing = %d\n",
  7289. sys->CpState,
  7290. sys->CpVoltage,
  7291. sys->PresentChargingVoltage,
  7292. sys->IsolationStatus,
  7293. cab->EVSEProcessing);
  7294. //[HEADER] Check Req SessionID
  7295. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  7296. {
  7297. cab->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  7298. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process\n");
  7299. errn = -1;
  7300. }
  7301. //Check for SequenceError
  7302. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7303. {
  7304. cab->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  7305. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process\n");
  7306. errn = -1;
  7307. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7308. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7309. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7310. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7311. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7312. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7313. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7314. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7315. }
  7316. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  7317. if (sys->IsolationStatus == GFD_Invalid) //0: on going
  7318. {
  7319. //For PSU
  7320. sys->EvBatterytargetVoltage = CABLECHECK_TARGET_VOLTAGE; //500V //[To-Do] this should be modified to auto decision.
  7321. sys->EvBatterytargetCurrent = CABLECHECK_TARGET_CURRENT; //2A(default), unit: 1A
  7322. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7323. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive; //4
  7324. cab->EVSEProcessing = dinEVSEProcessingType_Ongoing;
  7325. }
  7326. else if ((sys->IsolationStatus == GFD_Valid) || (sys->IsolationStatus == GFD_Warning)) //1: valid, 2: warning
  7327. {
  7328. //For PSU
  7329. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7330. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7331. if (sys->PresentChargingVoltage < 60) // < 60V
  7332. {
  7333. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  7334. sprintf((char*)buf_log_evcomm, "[V2G][CableCheck]Pass (V_now = %.02f, Isolated = %d)",
  7335. sys->PresentChargingVoltage,
  7336. sys->IsolationStatus);
  7337. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7338. //IsolationStatus
  7339. if (sys->IsolationStatus == GFD_Valid)
  7340. {
  7341. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  7342. }
  7343. else if (sys->IsolationStatus == GFD_Warning)
  7344. {
  7345. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning;
  7346. }
  7347. else
  7348. {
  7349. sprintf((char*)buf_log_evcomm,
  7350. "[WARNING]unexpected IsolationStatus(%d)",
  7351. sys->IsolationStatus);
  7352. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7353. }
  7354. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7355. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7356. }
  7357. else
  7358. {
  7359. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7360. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  7361. cab->EVSEProcessing = dinEVSEProcessingType_Ongoing;
  7362. }
  7363. }
  7364. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  7365. {
  7366. //For PSU
  7367. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7368. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7369. cab->ResponseCode = FAILED_DIN70121;
  7370. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7371. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_NotReady;
  7372. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7373. SAVE_SYS_LOG_MSG_EVCOMM("IsolationStatus = 3 (fault)\n");
  7374. errn = -1;
  7375. }
  7376. else
  7377. {
  7378. //For PSU
  7379. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7380. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7381. cab->ResponseCode = FAILED_DIN70121;
  7382. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  7383. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_NotReady;
  7384. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7385. sprintf((char*)buf_log_evcomm,
  7386. "Undefined Isolation Status(%d)",
  7387. sys->IsolationStatus);
  7388. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7389. }
  7390. //Check for CSU command of "Stop by EVSE"
  7391. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7392. {
  7393. cab->ResponseCode = FAILED_DIN70121;
  7394. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7395. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7396. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7397. errn = -1;
  7398. SAVE_SYS_LOG_MSG_EVCOMM("EVSE_Shutdown\n");
  7399. }
  7400. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7401. {
  7402. cab->ResponseCode = FAILED_DIN70121;
  7403. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7404. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7405. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7406. errn = -1;
  7407. SAVE_SYS_LOG_MSG_EVCOMM("EVSE_EmergencyShutdown\n");
  7408. }
  7409. else if (ShmInternalComm->ChargingPermission == FALSE)
  7410. {
  7411. cab->ResponseCode = FAILED_DIN70121;
  7412. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7413. cab->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7414. cab->EVSEProcessing = dinEVSEProcessingType_Finished;
  7415. errn = -1;
  7416. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingPermission = FALSE\n");
  7417. }
  7418. else
  7419. {
  7420. //null
  7421. }
  7422. //Response to CP Error
  7423. #if CP_PROTECTION_MECHANISM == ENABLE
  7424. //#if 1
  7425. if (sys->CableCheckPreCountDownDone == TRUE) //[To-Do] Here should be modified to 2 seconds
  7426. {
  7427. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  7428. {
  7429. cab->ResponseCode = FAILED_DIN70121;
  7430. cab->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7431. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7432. Update_V2G_Flow_Status(Other_Fault);
  7433. errn = -1;
  7434. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7435. //CCS_SECC_CP_State_Error (023889)
  7436. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7437. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7438. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7439. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  7440. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  7441. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  7442. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  7443. sprintf((char*)buf_log_evcomm,
  7444. "[CableCheck]Emergency Stop by CP Error (%d, %.02f V, %d)\n",
  7445. sys->CpState,
  7446. sys->CpVoltage,
  7447. cab->cnt
  7448. );
  7449. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7450. //cab->cnt = 0;
  7451. }
  7452. }
  7453. #endif
  7454. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7455. #if PARAMETER_NORMAL_MODE == ENABLE
  7456. SHM_Read_din_CableCheckRes(&ccs_exi_doc_DIN, ShmCcsData);
  7457. #else
  7458. Sudo_Parameter_din_CableCheckRes();
  7459. #endif
  7460. //STEP 4: ============ Encode and Send Response Message ===========
  7461. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  7462. {
  7463. errn = -1;
  7464. }
  7465. //STEP 5: ============ Update Flags ===========
  7466. sys->ConnectorLocked = TRUE; //Inicating EVSE that the CCS Connector is Locked.
  7467. return errn;
  7468. }
  7469. /*===========================================================================
  7470. FUNCTION: Proc_iso1_CableCheckRes
  7471. DESCRIPTION:
  7472. PRE-CONDITION:
  7473. INPUT:
  7474. OUTPUT:
  7475. GLOBAL VARIABLES:
  7476. =============================================================================*/
  7477. int Proc_iso1_CableCheckRes(int AcceptFd)
  7478. {
  7479. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7480. //if it is not the same, the packet should be ignored.
  7481. //STEP 1: ============ Initialize ============
  7482. //int i = 0;
  7483. int errn = 0;
  7484. bitstream_t v2g_tx_stream;
  7485. static struct CableCheckResponse_ISO15118_2014 *cab;
  7486. static struct ChargingInfoData *sys;
  7487. size_t pos = 0;
  7488. v2g_tx_stream.pos = &pos;
  7489. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7490. v2g_tx_stream.data = V2GTP_Tx_buf;
  7491. cab = &ShmCcsData->V2GMessage_ISO15118_2014.CableCheckResponse;
  7492. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7493. cab->ResponseCode = OK_ISO15118_2014;
  7494. cab->cnt++;
  7495. DEBUG_PRINTF_EVCOMM_DETAIL("CP_State = %d (%.02f V), V_now = %.02f, Isolation Status = %d, EVSEProcessing = %d\n",
  7496. sys->CpState,
  7497. sys->CpVoltage,
  7498. sys->PresentChargingVoltage,
  7499. sys->IsolationStatus,
  7500. cab->EVSEProcessing);
  7501. //[HEADER] Check Req SessionID
  7502. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  7503. {
  7504. cab->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  7505. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process\n");
  7506. errn = -1;
  7507. }
  7508. //Check for SequenceError
  7509. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7510. {
  7511. cab->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  7512. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process\n");
  7513. errn = -1;
  7514. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7515. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7516. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7517. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7518. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7519. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7520. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7521. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7522. }
  7523. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  7524. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  7525. {
  7526. //For PSU
  7527. sys->EvBatterytargetVoltage = CABLECHECK_TARGET_VOLTAGE; //500V //[To-Do] this should be modified to auto decision.
  7528. sys->EvBatterytargetCurrent = CABLECHECK_TARGET_CURRENT; //2A(default), unit: 1A
  7529. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  7530. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  7531. cab->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  7532. }
  7533. else if ((sys->IsolationStatus == GFD_Valid) || (sys->IsolationStatus == GFD_Warning)) //1: valid, 2:waring
  7534. {
  7535. //For PSU
  7536. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7537. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7538. if (sys->PresentChargingVoltage < 60) // < 60V
  7539. {
  7540. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  7541. sprintf((char*)buf_log_evcomm, "[V2G][CableCheck]Pass (V_now = %.02f, Isolated = %d)",
  7542. sys->PresentChargingVoltage,
  7543. sys->IsolationStatus);
  7544. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7545. //IsolationStatus
  7546. if (sys->IsolationStatus == GFD_Valid)
  7547. {
  7548. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  7549. }
  7550. else if (sys->IsolationStatus == GFD_Warning)
  7551. {
  7552. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Warning;
  7553. }
  7554. else
  7555. {
  7556. sprintf((char*)buf_log_evcomm,
  7557. "[WARNING]unexpected IsolationStatus(%d)",
  7558. sys->IsolationStatus);
  7559. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7560. }
  7561. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  7562. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7563. }
  7564. else
  7565. {
  7566. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  7567. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive;
  7568. cab->EVSEProcessing = iso1EVSEProcessingType_Ongoing;
  7569. }
  7570. }
  7571. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  7572. {
  7573. //For PSU
  7574. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7575. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7576. cab->ResponseCode = FAILED_ISO15118_2014;
  7577. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7578. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_NotReady;
  7579. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7580. SAVE_SYS_LOG_MSG_EVCOMM("IsolationStatus = 3 (fault)\n");
  7581. errn = -1;
  7582. }
  7583. //else if (sys->IsolationStatus == GFD_No_IMD){} //only for ISO15118
  7584. else
  7585. {
  7586. //For PSU
  7587. sys->EvBatterytargetVoltage = 0; //0V, asking PSU to discharge to 0V
  7588. sys->EvBatterytargetCurrent = 0; //0A, unit: 1A
  7589. cab->ResponseCode = FAILED_ISO15118_2014;
  7590. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7591. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_NotReady;
  7592. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7593. SAVE_SYS_LOG_MSG_EVCOMM("Undefined Isolation Status.\n");
  7594. }
  7595. //Check for CSU command of "Stop by EVSE"
  7596. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7597. {
  7598. cab->ResponseCode = FAILED_ISO15118_2014;
  7599. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7600. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7601. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7602. errn = -1;
  7603. SAVE_SYS_LOG_MSG_EVCOMM("EVSE_Shutdown\n");
  7604. }
  7605. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7606. {
  7607. cab->ResponseCode = FAILED_ISO15118_2014;
  7608. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7609. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7610. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7611. errn = -1;
  7612. SAVE_SYS_LOG_MSG_EVCOMM("EVSE_EmergencyShutdown\n");
  7613. }
  7614. else if (ShmInternalComm->ChargingPermission == FALSE)
  7615. {
  7616. cab->ResponseCode = FAILED_ISO15118_2014;
  7617. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  7618. cab->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  7619. cab->EVSEProcessing = iso1EVSEProcessingType_Finished;
  7620. errn = -1;
  7621. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingPermission = FALSE\n");
  7622. }
  7623. else
  7624. {
  7625. //null
  7626. }
  7627. //Response to CP Error
  7628. #if CP_PROTECTION_MECHANISM == ENABLE
  7629. if (sys->CableCheckPreCountDownDone == TRUE) //[To-Do] Here should be modified to 2 seconds
  7630. {
  7631. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  7632. {
  7633. cab->ResponseCode = FAILED_ISO15118_2014;
  7634. cab->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7635. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7636. Update_V2G_Flow_Status(Other_Fault);
  7637. errn = -1;
  7638. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7639. //CCS_SECC_CP_State_Error (023889)
  7640. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7641. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7642. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7643. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  7644. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  7645. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  7646. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  7647. sprintf((char*)buf_log_evcomm,
  7648. "[CableCheck]Emergency Stop by CP Error (%d, %.02f V, %d)\n",
  7649. sys->CpState,
  7650. sys->CpVoltage,
  7651. cab->cnt
  7652. );
  7653. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7654. //cab->cnt = 0;
  7655. }
  7656. }
  7657. #endif
  7658. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  7659. #if PARAMETER_NORMAL_MODE == ENABLE
  7660. SHM_Read_iso1_CableCheckRes(&ccs_exi_doc_ISO1, ShmCcsData);
  7661. #else
  7662. Sudo_Parameter_iso1_CableCheckRes();
  7663. #endif
  7664. //STEP 4: ============ Encode and Send Response Message ===========
  7665. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  7666. {
  7667. errn = -1;
  7668. }
  7669. //STEP 5: ============ Update Flags ===========
  7670. sys->ConnectorLocked = TRUE; //Inicating EVSE that the CCS Connector is Locked.
  7671. return errn;
  7672. }
  7673. /*===========================================================================
  7674. FUNCTION: Proc_din_CableCheckReq
  7675. DESCRIPTION:
  7676. PRE-CONDITION:
  7677. INPUT:
  7678. OUTPUT:
  7679. GLOBAL VARIABLES:
  7680. =============================================================================*/
  7681. int Proc_din_CableCheckReq(int AcceptFd)
  7682. {
  7683. int errn = 0;
  7684. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]CableCheckReq\n");
  7685. //Print the decoded XML Document
  7686. PRINT_XML_DOC_DIN_CableCheckReq(&ccs_exi_doc_DIN);
  7687. //Save into Share Memory
  7688. SHM_Save_din_CableCheckReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  7689. //Check for EV Error Code
  7690. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.CableCheckRequest.DC_EVStatus.EVErrorCode);
  7691. errn = Proc_din_CableCheckRes(AcceptFd);
  7692. if (errn == 0)
  7693. {
  7694. //send response successfully.
  7695. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]CableCheckRes\n");
  7696. }
  7697. else
  7698. {
  7699. sprintf((char*)buf_log_evcomm,
  7700. "[Error]Proc_iso1_CableCheckRes(): %d (DEC)",
  7701. errn);
  7702. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7703. }
  7704. return errn;
  7705. }
  7706. /*===========================================================================
  7707. FUNCTION: Proc_iso1_CableCheckReq
  7708. DESCRIPTION:
  7709. PRE-CONDITION:
  7710. INPUT:
  7711. OUTPUT:
  7712. GLOBAL VARIABLES:
  7713. =============================================================================*/
  7714. int Proc_iso1_CableCheckReq(int AcceptFd)
  7715. {
  7716. int errn = 0;
  7717. SAVE_SYS_LOG_MSG_EVCOMM("CableCheckReq\n");
  7718. //Print the decoded XML Document
  7719. PRINT_XML_DOC_ISO1_CableCheckReq(&ccs_exi_doc_ISO1);
  7720. //Save into Share Memory
  7721. SHM_Save_iso1_CableCheckReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  7722. //Check for EV Error Code
  7723. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.CableCheckRequest.DC_EVStatus.EVErrorCode);
  7724. errn = Proc_iso1_CableCheckRes(AcceptFd);
  7725. if (errn == 0)
  7726. {
  7727. //send response successfully.
  7728. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]CableCheckRes\n");
  7729. }
  7730. else
  7731. {
  7732. sprintf((char*)buf_log_evcomm,
  7733. "[Error]Proc_iso1_CableCheckRes(): %d (DEC)",
  7734. errn);
  7735. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7736. }
  7737. return errn;
  7738. }
  7739. /*===========================================================================
  7740. FUNCTION: SHM_Init_din_PreChargeRes
  7741. DESCRIPTION:
  7742. PRE-CONDITION:
  7743. INPUT:
  7744. 1. shm_ccs
  7745. OUTPUT:
  7746. 1. shm_ccs
  7747. GLOBAL VARIABLES:
  7748. =============================================================================*/
  7749. void SHM_Init_din_PreChargeRes(struct CcsData *shm_ccs)
  7750. {
  7751. struct PreChargeResponse_DIN70121 *in;
  7752. in = &shm_ccs->V2GMessage_DIN70121.PreChargeResponse;
  7753. //----- [BODY (1/3)] ResponseCode -----
  7754. in->ResponseCode = dinresponseCodeType_OK;
  7755. //----- [BODY (2/3)] EVSEPresentVoltage -----
  7756. short value = 0; int multiplier = 0; unsigned char unit = 0;
  7757. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for Test
  7758. value = 0; multiplier = 0; unit = V_DIN70121; //waiting for CsuComm to update V to fit EV Target
  7759. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  7760. //----- [BODY (3/3)] DC_EVSEStatus -----
  7761. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  7762. }
  7763. /*===========================================================================
  7764. FUNCTION: Sudo_Parameter_din_PreChargeRes
  7765. DESCRIPTION:
  7766. PRE-CONDITION:
  7767. INPUT:
  7768. OUTPUT:
  7769. GLOBAL VARIABLES:
  7770. =============================================================================*/
  7771. void Sudo_Parameter_din_PreChargeRes()
  7772. {
  7773. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  7774. init_dinPreChargeResType(&ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes);
  7775. ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes_isUsed = 1u;
  7776. //----- [BODY (1/3)] ResponseCode -----
  7777. struct dinPreChargeResType *res;
  7778. res = &ccs_exi_doc_DIN.V2G_Message.Body.PreChargeRes;
  7779. res->ResponseCode = dinresponseCodeType_OK;
  7780. //----- [BODY (2/3)] EVSEPresentVoltage -----
  7781. res->EVSEPresentVoltage.Value = 3820;
  7782. res->EVSEPresentVoltage.Multiplier = -1;
  7783. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  7784. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  7785. // dinunitSymbolType_h = 0,
  7786. // dinunitSymbolType_m = 1,
  7787. // dinunitSymbolType_s = 2,
  7788. // dinunitSymbolType_A = 3,
  7789. // dinunitSymbolType_Ah = 4,
  7790. // dinunitSymbolType_V = 5,
  7791. // dinunitSymbolType_VA = 6,
  7792. // dinunitSymbolType_W = 7,
  7793. // dinunitSymbolType_W_s = 8,
  7794. // dinunitSymbolType_Wh = 9
  7795. //----- [BODY (3/3)] DC_EVSEStatus -----
  7796. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7797. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  7798. // dinisolationLevelType_Invalid = 0,
  7799. // dinisolationLevelType_Valid = 1,
  7800. // dinisolationLevelType_Warning = 2,
  7801. // dinisolationLevelType_Fault = 3
  7802. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7803. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7804. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  7805. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7806. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7807. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7808. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7809. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7810. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  7811. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  7812. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  7813. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  7814. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  7815. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7816. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  7817. // dinEVSENotificationType_None = 0,
  7818. // dinEVSENotificationType_StopCharging = 1,
  7819. // dinEVSENotificationType_ReNegotiation = 2
  7820. }
  7821. /*===========================================================================
  7822. FUNCTION: Sudo_Parameter_iso1_PreChargeRes
  7823. DESCRIPTION:
  7824. PRE-CONDITION:
  7825. INPUT:
  7826. OUTPUT:
  7827. GLOBAL VARIABLES:
  7828. =============================================================================*/
  7829. void Sudo_Parameter_iso1_PreChargeRes()
  7830. {
  7831. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  7832. init_iso1PreChargeResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes);
  7833. ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes_isUsed = 1u;
  7834. //----- [BODY (1/3)] ResponseCode -----
  7835. struct iso1PreChargeResType *res;
  7836. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PreChargeRes;
  7837. res->ResponseCode = iso1responseCodeType_OK;
  7838. //----- [BODY (2/3)] EVSEPresentVoltage -----
  7839. res->EVSEPresentVoltage.Value = 3820;
  7840. res->EVSEPresentVoltage.Multiplier = -1;
  7841. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  7842. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  7843. //iso1unitSymbolType_h = 0,
  7844. //iso1unitSymbolType_m = 1,
  7845. //iso1unitSymbolType_s = 2,
  7846. //iso1unitSymbolType_A = 3,
  7847. //iso1unitSymbolType_V = 4,
  7848. //iso1unitSymbolType_W = 5,
  7849. //iso1unitSymbolType_Wh = 6
  7850. //----- [BODY (3/3)] DC_EVSEStatus -----
  7851. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  7852. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  7853. //iso1isolationLevelType_Invalid = 0,
  7854. //iso1isolationLevelType_Valid = 1,
  7855. //iso1isolationLevelType_Warning = 2,
  7856. //iso1isolationLevelType_Fault = 3,
  7857. //iso1isolationLevelType_No_IMD = 4
  7858. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  7859. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  7860. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  7861. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  7862. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  7863. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  7864. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  7865. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  7866. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  7867. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  7868. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  7869. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  7870. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  7871. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  7872. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  7873. //iso1EVSENotificationType_None = 0,
  7874. //iso1EVSENotificationType_StopCharging = 1,
  7875. //iso1EVSENotificationType_ReNegotiation = 2
  7876. }
  7877. /*===========================================================================
  7878. FUNCTION: Proc_din_PreChargeRes
  7879. DESCRIPTION:
  7880. PRE-CONDITION:
  7881. INPUT:
  7882. OUTPUT:
  7883. GLOBAL VARIABLES:
  7884. =============================================================================*/
  7885. int Proc_din_PreChargeRes(int AcceptFd)
  7886. {
  7887. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  7888. //if it is not the same, the packet should be ignored.
  7889. //STEP 1: ============ Initialize ============
  7890. //int i = 0;
  7891. int errn = 0;
  7892. bitstream_t v2g_tx_stream;
  7893. static struct PreChargeResponse_DIN70121 *pre;
  7894. static struct ChargingInfoData *sys;
  7895. size_t pos = 0;
  7896. v2g_tx_stream.pos = &pos;
  7897. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  7898. v2g_tx_stream.data = V2GTP_Tx_buf;
  7899. pre = &ShmCcsData->V2GMessage_DIN70121.PreChargeResponse;
  7900. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  7901. pre->ResponseCode = OK_DIN70121;
  7902. //EVSE Status Code
  7903. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  7904. //[HEADER] Check Req SessionID
  7905. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  7906. {
  7907. pre->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  7908. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]unmatched SessionID => End_Process\n");
  7909. errn = -1;
  7910. }
  7911. //Check for SequenceError
  7912. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  7913. {
  7914. pre->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  7915. SAVE_SYS_LOG_MSG_EVCOMM("[ERROR]SequenceError => End_Process\n");
  7916. errn = -1;
  7917. //Update_ShmStatusCode(); //[To-Do] to be implemented
  7918. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  7919. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  7920. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  7921. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  7922. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  7923. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  7924. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  7925. }
  7926. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  7927. SAVE_PhysicalValueType_DIN70121(&pre->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  7928. //Isolation Status
  7929. if (sys->IsolationStatus == GFD_Invalid) //0: invalid
  7930. {
  7931. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  7932. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7933. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7934. Update_V2G_Flow_Status(Other_Fault);
  7935. errn = -1;
  7936. sprintf((char*)buf_log_evcomm, "[Error]IsolationStatus = %d", sys->IsolationStatus);
  7937. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7938. }
  7939. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  7940. {
  7941. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  7942. }
  7943. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  7944. {
  7945. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  7946. }
  7947. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  7948. {
  7949. SAVE_SYS_LOG_MSG_EVCOMM("[Error]GFD_Fault => Emergency Shutdown\n");
  7950. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  7951. pre->ResponseCode = FAILED_DIN70121;
  7952. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7953. errn = -1;
  7954. }
  7955. else //GFD_No_IMD or other unexpected status
  7956. {
  7957. pre->ResponseCode = FAILED_DIN70121;
  7958. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  7959. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  7960. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  7961. Update_V2G_Flow_Status(Other_Fault);
  7962. errn = -1;
  7963. sprintf((char*)buf_log_evcomm,
  7964. "[Error]IsolationStatus = %d (undefined)",
  7965. sys->IsolationStatus);
  7966. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  7967. }
  7968. //Check for CSU command of "Stop by EVSE"
  7969. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  7970. {
  7971. //Check for Alarm Code: CCS GFD trip (012235)
  7972. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  7973. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  7974. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  7975. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  7976. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  7977. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  7978. {
  7979. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CCS GFD trip => EVSE_Shutdown\n");
  7980. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  7981. }
  7982. else
  7983. {
  7984. SAVE_SYS_LOG_MSG_EVCOMM("[Error]EVSE_Shutdown\n");
  7985. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  7986. }
  7987. pre->ResponseCode = FAILED_DIN70121;
  7988. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  7989. errn = -1;
  7990. }
  7991. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  7992. {
  7993. //Check for Alarm Code: CCS GFD trip (012235)
  7994. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  7995. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  7996. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  7997. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  7998. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  7999. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8000. {
  8001. SAVE_SYS_LOG_MSG_EVCOMM("[Error]CCS GFD trip => EVSE_EmergencyShutdown\n");
  8002. pre->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  8003. }
  8004. else
  8005. {
  8006. SAVE_SYS_LOG_MSG_EVCOMM("[Error]EVSE_EmergencyShutdown\n");
  8007. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8008. }
  8009. pre->ResponseCode = FAILED_DIN70121;
  8010. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8011. errn = -1;
  8012. }
  8013. else if (ShmInternalComm->ChargingPermission == FALSE)
  8014. {
  8015. SAVE_SYS_LOG_MSG_EVCOMM("[Error]ChargingPermission = FALSE\n");
  8016. pre->ResponseCode = FAILED_DIN70121;
  8017. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8018. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8019. errn = -1;
  8020. }
  8021. else
  8022. {
  8023. //null
  8024. }
  8025. //Response to CP Error
  8026. #if CP_PROTECTION_MECHANISM == ENABLE
  8027. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  8028. {
  8029. pre->ResponseCode = FAILED_DIN70121;
  8030. pre->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8031. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8032. Update_V2G_Flow_Status(Other_Fault);
  8033. errn = -1;
  8034. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8035. //CCS_SECC_CP_State_Error (023889)
  8036. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8037. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8038. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8039. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  8040. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  8041. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  8042. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  8043. sprintf((char*)buf_log_evcomm,
  8044. "[Error]Emergency Stop by CP Error (%d, %.02f V)\n",
  8045. sys->CpState,
  8046. sys->CpVoltage
  8047. );
  8048. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8049. }
  8050. #endif
  8051. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8052. #if PARAMETER_NORMAL_MODE == ENABLE
  8053. SHM_Read_din_PreChargeRes(&ccs_exi_doc_DIN, ShmCcsData);
  8054. #else
  8055. Sudo_Parameter_din_PreChargeRes();
  8056. #endif
  8057. //STEP 4: ============ Encode and Send Response Message ===========
  8058. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  8059. {
  8060. SAVE_SYS_LOG_MSG_EVCOMM("[Error]Tx encoded msg error\n");
  8061. errn = -1;
  8062. }
  8063. //STEP 5: ============ Update Flags ===========
  8064. return errn;
  8065. }
  8066. /*===========================================================================
  8067. FUNCTION: Proc_iso1_PreChargeRes
  8068. DESCRIPTION:
  8069. PRE-CONDITION:
  8070. INPUT:
  8071. OUTPUT:
  8072. GLOBAL VARIABLES:
  8073. =============================================================================*/
  8074. int Proc_iso1_PreChargeRes(int AcceptFd)
  8075. {
  8076. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8077. //if it is not the same, the packet should be ignored.
  8078. //STEP 1: ============ Initialize ============
  8079. //int i = 0;
  8080. int errn = 0;
  8081. bitstream_t v2g_tx_stream;
  8082. static struct PreChargeResponse_ISO15118_2014 *pre;
  8083. static struct ChargingInfoData *sys;
  8084. size_t pos = 0;
  8085. v2g_tx_stream.pos = &pos;
  8086. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8087. v2g_tx_stream.data = V2GTP_Tx_buf;
  8088. pre = &ShmCcsData->V2GMessage_ISO15118_2014.PreChargeResponse;
  8089. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8090. pre->ResponseCode = OK_ISO15118_2014;
  8091. //EVSE Status Code
  8092. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8093. //[HEADER] Check Req SessionID
  8094. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  8095. {
  8096. pre->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  8097. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  8098. errn = -1;
  8099. }
  8100. //Check for SequenceError
  8101. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8102. {
  8103. pre->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  8104. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  8105. errn = -1;
  8106. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8107. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8108. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8109. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8110. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8111. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8112. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8113. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8114. }
  8115. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8116. SAVE_PhysicalValueType_ISO15118_2014(&pre->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  8117. //Isolation Status
  8118. if (sys->IsolationStatus == GFD_Invalid) //0: invalid(on going)
  8119. {
  8120. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  8121. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8122. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8123. Update_V2G_Flow_Status(Other_Fault);
  8124. errn = -1;
  8125. sprintf((char*)buf_log_evcomm, "[Error]IsolationStatus = %d", sys->IsolationStatus);
  8126. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8127. }
  8128. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  8129. {
  8130. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  8131. }
  8132. else if (sys->IsolationStatus == GFD_Warning) //2: waring
  8133. {
  8134. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Warning; //1
  8135. }
  8136. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  8137. {
  8138. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]GFD_Fault => Emergency Shutdown");
  8139. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  8140. pre->ResponseCode = FAILED_ISO15118_2014;
  8141. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8142. errn = -1;
  8143. }
  8144. else
  8145. {
  8146. pre->ResponseCode = FAILED_ISO15118_2014;
  8147. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  8148. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8149. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8150. Update_V2G_Flow_Status(Other_Fault);
  8151. errn = -1;
  8152. sprintf((char*)buf_log_evcomm,
  8153. "[Error][Proc_iso1_PreChargeRes]IsolationStatus = %d (undefined)",
  8154. sys->IsolationStatus);
  8155. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8156. }
  8157. //Check for CSU command of "Stop by EVSE"
  8158. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8159. {
  8160. //Check for Alarm Code: CCS GFD trip (012235)
  8161. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8162. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8163. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8164. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8165. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8166. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8167. {
  8168. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CCS GFD trip => EVSE_Shutdown");
  8169. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8170. }
  8171. else
  8172. {
  8173. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]EVSE_Shutdown");
  8174. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8175. }
  8176. pre->ResponseCode = FAILED_ISO15118_2014;
  8177. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8178. errn = -1;
  8179. }
  8180. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8181. {
  8182. //Check for Alarm Code: CCS GFD trip (012235)
  8183. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  8184. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  8185. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  8186. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  8187. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  8188. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  8189. {
  8190. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CCS GFD trip => EVSE_EmergencyShutdown");
  8191. pre->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  8192. }
  8193. else
  8194. {
  8195. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]EVSE_EmergencyShutdown");
  8196. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8197. }
  8198. pre->ResponseCode = FAILED_ISO15118_2014;
  8199. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8200. errn = -1;
  8201. }
  8202. else if (ShmInternalComm->ChargingPermission == FALSE)
  8203. {
  8204. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargingPermission = FALSE");
  8205. pre->ResponseCode = FAILED_ISO15118_2014;
  8206. pre->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  8207. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8208. errn = -1;
  8209. }
  8210. else
  8211. {
  8212. //null
  8213. }
  8214. //Response to CP Error
  8215. #if CP_PROTECTION_MECHANISM == ENABLE
  8216. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  8217. {
  8218. pre->ResponseCode = FAILED_ISO15118_2014;
  8219. pre->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8220. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8221. Update_V2G_Flow_Status(Other_Fault);
  8222. errn = -1;
  8223. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8224. //CCS_SECC_CP_State_Error (023889)
  8225. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8226. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8227. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8228. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  8229. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  8230. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  8231. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  8232. sprintf((char*)buf_log_evcomm,
  8233. "[Error]Emergency Stop by CP Error (%d, %.02f V)\n",
  8234. sys->CpState,
  8235. sys->CpVoltage
  8236. );
  8237. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8238. }
  8239. #endif
  8240. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8241. #if PARAMETER_NORMAL_MODE == ENABLE
  8242. SHM_Read_iso1_PreChargeRes(&ccs_exi_doc_ISO1, ShmCcsData);
  8243. #else
  8244. Sudo_Parameter_iso1_PreChargeRes();
  8245. #endif
  8246. //STEP 4: ============ Encode and Send Response Message ===========
  8247. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  8248. {
  8249. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]Tx encoded msg error");
  8250. errn = -1;
  8251. }
  8252. //STEP 5: ============ Update Flags ===========
  8253. return errn;
  8254. }
  8255. /*===========================================================================
  8256. FUNCTION: Proc_din_PreChargeReq
  8257. DESCRIPTION:
  8258. PRE-CONDITION:
  8259. INPUT:
  8260. OUTPUT:
  8261. GLOBAL VARIABLES:
  8262. =============================================================================*/
  8263. int Proc_din_PreChargeReq(int AcceptFd)
  8264. {
  8265. int errn = 0;
  8266. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]PreChargeReq\n");
  8267. //Print the decoded XML Document
  8268. PRINT_XML_DOC_DIN_PreChargeReq(&ccs_exi_doc_DIN);
  8269. //Save into Share Memory
  8270. SHM_Save_din_PreChargeReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  8271. //Check for EV Error Code
  8272. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PreChargeRequest.DC_EVStatus.EVErrorCode);
  8273. errn = Proc_din_PreChargeRes(AcceptFd);
  8274. if (errn == 0)
  8275. {
  8276. //send response successfully.
  8277. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]PreChargeRes\n");
  8278. }
  8279. else
  8280. {
  8281. sprintf((char*)buf_log_evcomm,
  8282. "[Error]Proc_iso1_PreChargeRes(): %d (DEC)",
  8283. errn);
  8284. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8285. }
  8286. return errn;
  8287. }
  8288. /*===========================================================================
  8289. FUNCTION: Proc_iso1_PreChargeReq
  8290. DESCRIPTION:
  8291. PRE-CONDITION:
  8292. INPUT:
  8293. OUTPUT:
  8294. GLOBAL VARIABLES:
  8295. =============================================================================*/
  8296. int Proc_iso1_PreChargeReq(int AcceptFd)
  8297. {
  8298. int errn = 0;
  8299. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]PreChargeReq\n");
  8300. //Print the decoded XML Document
  8301. PRINT_XML_DOC_ISO1_PreChargeReq(&ccs_exi_doc_ISO1);
  8302. //Save into Share Memory
  8303. SHM_Save_iso1_PreChargeReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  8304. //Check for EV Error Code
  8305. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PreChargeRequest.DC_EVStatus.EVErrorCode);
  8306. errn = Proc_iso1_PreChargeRes(AcceptFd);
  8307. if (errn == 0)
  8308. {
  8309. //send response successfully.
  8310. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]PreChargeRes\n");
  8311. }
  8312. else
  8313. {
  8314. sprintf((char*)buf_log_evcomm,
  8315. "[Error][SeccComm][Proc_iso1_PreChargeReq]Proc_iso1_PreChargeRes(): %d (DEC)",
  8316. errn);
  8317. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8318. }
  8319. return errn;
  8320. }
  8321. /*===========================================================================
  8322. FUNCTION: SHM_Init_din_PowerDeliveryRes
  8323. DESCRIPTION:
  8324. PRE-CONDITION:
  8325. INPUT:
  8326. 1. shm_ccs
  8327. OUTPUT:
  8328. 1. shm_ccs
  8329. GLOBAL VARIABLES:
  8330. =============================================================================*/
  8331. void SHM_Init_din_PowerDeliveryRes(struct CcsData *shm_ccs)
  8332. {
  8333. struct PowerDeliveryResponse_DIN70121 *in;
  8334. in = &shm_ccs->V2GMessage_DIN70121.PowerDeliveryResponse;
  8335. //----- [BODY (1/3)] ResponseCode -----
  8336. in->ResponseCode = dinresponseCodeType_OK;
  8337. //----- [BODY (2/3)] AC_EVSEStatus -----
  8338. //ignore, since DIN 70121 doesn't support AC, yet.
  8339. //----- [BODY (2/3)] DC_EVSEStatus -----
  8340. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  8341. }
  8342. /*===========================================================================
  8343. FUNCTION: Sudo_Parameter_din_PowerDeliveryRes
  8344. DESCRIPTION:
  8345. PRE-CONDITION:
  8346. INPUT:
  8347. OUTPUT:
  8348. GLOBAL VARIABLES:
  8349. =============================================================================*/
  8350. void Sudo_Parameter_din_PowerDeliveryRes()
  8351. {
  8352. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  8353. init_dinPowerDeliveryResType(&ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes);
  8354. ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes_isUsed = 1u;
  8355. //----- [BODY (1/3)] ResponseCode -----
  8356. struct dinPowerDeliveryResType *res;
  8357. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  8358. res->ResponseCode = dinresponseCodeType_OK;
  8359. //----- [BODY (2/3)] AC_EVSEStatus -----
  8360. //ignore, since DIN 70121 doesn't support AC, yet.
  8361. //----- [BODY (2/3)] DC_EVSEStatus -----
  8362. res->DC_EVSEStatus_isUsed = 1u;
  8363. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8364. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  8365. // dinisolationLevelType_Invalid = 0,
  8366. // dinisolationLevelType_Valid = 1,
  8367. // dinisolationLevelType_Warning = 2,
  8368. // dinisolationLevelType_Fault = 3
  8369. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8370. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8371. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  8372. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8373. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8374. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8375. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8376. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8377. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  8378. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  8379. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  8380. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  8381. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  8382. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8383. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  8384. // dinEVSENotificationType_None = 0,
  8385. // dinEVSENotificationType_StopCharging = 1,
  8386. // dinEVSENotificationType_ReNegotiation = 2
  8387. }
  8388. /*===========================================================================
  8389. FUNCTION: Sudo_Parameter_iso1_PowerDeliveryRes
  8390. DESCRIPTION:
  8391. PRE-CONDITION:
  8392. INPUT:
  8393. OUTPUT:
  8394. GLOBAL VARIABLES:
  8395. =============================================================================*/
  8396. void Sudo_Parameter_iso1_PowerDeliveryRes()
  8397. {
  8398. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8399. init_iso1PowerDeliveryResType(&ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes);
  8400. ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes_isUsed = 1u;
  8401. //----- [BODY (1/3)] ResponseCode -----
  8402. struct iso1PowerDeliveryResType *res;
  8403. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  8404. res->ResponseCode = iso1responseCodeType_OK;
  8405. //----- [BODY (2/3)] AC_EVSEStatus -----
  8406. //ignore, since our ISO1 70121 doesn't support AC, yet.
  8407. //----- [BODY (2/3)] DC_EVSEStatus -----
  8408. res->DC_EVSEStatus_isUsed = 1u;
  8409. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8410. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  8411. //iso1isolationLevelType_Invalid = 0,
  8412. //iso1isolationLevelType_Valid = 1,
  8413. //iso1isolationLevelType_Warning = 2,
  8414. //iso1isolationLevelType_Fault = 3,
  8415. //iso1isolationLevelType_No_IMD = 4
  8416. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8417. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8418. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  8419. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8420. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8421. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8422. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8423. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8424. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  8425. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  8426. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  8427. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  8428. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  8429. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8430. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8431. //iso1EVSENotificationType_None = 0,
  8432. //iso1EVSENotificationType_StopCharging = 1,
  8433. //iso1EVSENotificationType_ReNegotiation = 2
  8434. }
  8435. /*===========================================================================
  8436. FUNCTION: Proc_din_PowerDeliveryStartRes
  8437. DESCRIPTION:
  8438. PRE-CONDITION:
  8439. INPUT:
  8440. OUTPUT:
  8441. GLOBAL VARIABLES:
  8442. =============================================================================*/
  8443. int Proc_din_PowerDeliveryStartRes(int AcceptFd)
  8444. {
  8445. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8446. //if it is not the same, the packet should be ignored.
  8447. //STEP 1: ============ Initialize ============
  8448. //int i = 0;
  8449. int errn = 0;
  8450. bitstream_t v2g_tx_stream;
  8451. struct dinPowerDeliveryResType *res;
  8452. struct ChargingInfoData *sys;
  8453. size_t pos = 0;
  8454. v2g_tx_stream.pos = &pos;
  8455. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8456. v2g_tx_stream.data = V2GTP_Tx_buf;
  8457. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  8458. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8459. res->ResponseCode = OK_DIN70121;
  8460. //[HEADER] Check Req SessionID
  8461. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  8462. {
  8463. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  8464. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  8465. errn = -1;
  8466. }
  8467. //Check for SequenceError
  8468. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8469. {
  8470. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  8471. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  8472. errn = -1;
  8473. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8474. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8475. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8476. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8477. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8478. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8479. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8480. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8481. }
  8482. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8483. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8484. #if PARAMETER_NORMAL_MODE == ENABLE
  8485. SHM_Read_din_PowerDeliveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  8486. #else
  8487. Sudo_Parameter_din_PowerDeliveryRes();
  8488. #endif
  8489. //EVSE Status Code
  8490. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  8491. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8492. //Check for CSU command of "Stop by EVSE"
  8493. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8494. {
  8495. //res->ResponseCode = FAILED_DIN70121;
  8496. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8497. }
  8498. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8499. {
  8500. //res->ResponseCode = FAILED_DIN70121;
  8501. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8502. }
  8503. else if (ShmInternalComm->ChargingPermission == FALSE)
  8504. {
  8505. //res->ResponseCode = FAILED_DIN70121;
  8506. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8507. }
  8508. //STEP 4: ============ Encode and Send Response Message ===========
  8509. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  8510. {
  8511. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_PowerDeliveryStartRes][Error]Tx encoded msg error");
  8512. errn = -1;
  8513. }
  8514. //STEP 5: ============ Update Flags ===========
  8515. return errn;
  8516. }
  8517. /*===========================================================================
  8518. FUNCTION: Proc_iso1_PowerDeliveryStartRes
  8519. DESCRIPTION:
  8520. PRE-CONDITION:
  8521. INPUT:
  8522. OUTPUT:
  8523. GLOBAL VARIABLES:
  8524. =============================================================================*/
  8525. int Proc_iso1_PowerDeliveryStartRes(int AcceptFd)
  8526. {
  8527. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8528. //if it is not the same, the packet should be ignored.
  8529. //STEP 1: ============ Initialize ============
  8530. //int i = 0;
  8531. int errn = 0;
  8532. bitstream_t v2g_tx_stream;
  8533. struct iso1PowerDeliveryResType *res;
  8534. struct ChargingInfoData *sys;
  8535. size_t pos = 0;
  8536. v2g_tx_stream.pos = &pos;
  8537. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8538. v2g_tx_stream.data = V2GTP_Tx_buf;
  8539. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  8540. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8541. res->ResponseCode = OK_ISO15118_2014;
  8542. //[HEADER] Check Req SessionID
  8543. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  8544. {
  8545. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  8546. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  8547. errn = -1;
  8548. }
  8549. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8550. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  8551. #if PARAMETER_NORMAL_MODE == ENABLE
  8552. SHM_Read_iso1_PowerDeliveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  8553. #else
  8554. Sudo_Parameter_iso1_PowerDeliveryRes();
  8555. #endif
  8556. //EVSE Status Code
  8557. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  8558. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8559. //Check for CSU command of "Stop by EVSE"
  8560. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  8561. {
  8562. //res->ResponseCode = FAILED_ISO15118_2014;
  8563. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8564. }
  8565. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  8566. {
  8567. //res->ResponseCode = FAILED_ISO15118_2014;
  8568. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  8569. }
  8570. else if (ShmInternalComm->ChargingPermission == FALSE)
  8571. {
  8572. //res->ResponseCode = FAILED_ISO15118_2014;
  8573. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  8574. }
  8575. //STEP 4: ============ Encode and Send Response Message ===========
  8576. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  8577. {
  8578. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_PowerDeliveryStartRes][Error]Tx encoded msg error");
  8579. errn = -1;
  8580. }
  8581. //STEP 5: ============ Update Flags ===========
  8582. return errn;
  8583. }
  8584. /*===========================================================================
  8585. FUNCTION: Proc_din_PowerDeliveryStartReq
  8586. DESCRIPTION:
  8587. PRE-CONDITION:
  8588. INPUT:
  8589. OUTPUT:
  8590. GLOBAL VARIABLES:
  8591. =============================================================================*/
  8592. int Proc_din_PowerDeliveryStartReq(int AcceptFd)
  8593. {
  8594. int errn = 0;
  8595. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PowerDeliveryStartReq");
  8596. //Print the decoded XML Document
  8597. PRINT_XML_DOC_DIN_PowerDeliveryReq(&ccs_exi_doc_DIN);
  8598. //Save into Share Memory
  8599. SHM_Save_din_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  8600. //Check for EV Error Code
  8601. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  8602. errn = Proc_din_PowerDeliveryStartRes(AcceptFd);
  8603. if (errn == 0)
  8604. {
  8605. //send response successfully.
  8606. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][TX]PowerDeliveryStartRes");
  8607. }
  8608. else
  8609. {
  8610. sprintf((char*)buf_log_evcomm,
  8611. "[Error][Proc_din_PowerDeliveryStartReq]Proc_iso1_PowerDeliveryStartRes(): %d (DEC)",
  8612. errn);
  8613. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8614. }
  8615. return errn;
  8616. }
  8617. /*===========================================================================
  8618. FUNCTION: Proc_iso1_PowerDeliveryStartReq
  8619. DESCRIPTION:
  8620. PRE-CONDITION:
  8621. INPUT:
  8622. OUTPUT:
  8623. GLOBAL VARIABLES:
  8624. =============================================================================*/
  8625. int Proc_iso1_PowerDeliveryStartReq(int AcceptFd)
  8626. {
  8627. int errn = 0;
  8628. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PowerDeliveryStartReq");
  8629. //Print the decoded XML Document
  8630. PRINT_XML_DOC_ISO1_PowerDeliveryReq(&ccs_exi_doc_ISO1);
  8631. //Save into Share Memory
  8632. SHM_Save_iso1_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  8633. //Check for EV Error Code
  8634. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  8635. errn = Proc_iso1_PowerDeliveryStartRes(AcceptFd);
  8636. if (errn == 0)
  8637. {
  8638. //send response successfully.
  8639. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]PowerDeliveryStartRes");
  8640. }
  8641. else
  8642. {
  8643. sprintf((char*)buf_log_evcomm,
  8644. "[Error][Proc_iso1_PowerDeliveryStartReq]Proc_iso1_PowerDeliveryStartRes(): %d (DEC)",
  8645. errn);
  8646. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8647. }
  8648. return errn;
  8649. }
  8650. /*===========================================================================
  8651. FUNCTION: SHM_Init_din_CurrentDemandRes
  8652. DESCRIPTION:
  8653. PRE-CONDITION:
  8654. INPUT:
  8655. 1. shm_ccs
  8656. OUTPUT:
  8657. 1. shm_ccs
  8658. GLOBAL VARIABLES:
  8659. =============================================================================*/
  8660. void SHM_Init_din_CurrentDemandRes(struct CcsData *shm_ccs)
  8661. {
  8662. struct CurrentDemandResponse_DIN70121 *in;
  8663. in = &shm_ccs->V2GMessage_DIN70121.CurrentDemandResponse;
  8664. //----- [BODY (1/10)] ResponseCode -----
  8665. in->ResponseCode = dinresponseCodeType_OK;
  8666. //----- [BODY (2/10)] DC_EVSEStatus -----
  8667. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  8668. //----- [BODY (3/10)] EVSEPresentVoltage -----
  8669. short value = 0; int multiplier = 0; unsigned char unit = 0;
  8670. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for test only.
  8671. value = 0; multiplier = 0; unit = V_DIN70121;
  8672. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  8673. //----- [BODY (4/10)] EVSEPresentCurrent -----
  8674. //value = 600; multiplier = -1; unit = A_DIN70121; //60A, for test only.
  8675. value = 0; multiplier = 0; unit = A_DIN70121;
  8676. SHM_Save_dinPhysicalValueType(&in->EVSEPresentCurrent, value, multiplier, unit);
  8677. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  8678. in->EVSECurrentLimitAchieved = FALSE;
  8679. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  8680. in->EVSEVoltageLimitAchieved = FALSE;
  8681. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  8682. in->EVSEPowerLimitAchieved = FALSE;
  8683. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  8684. //value = 7500; multiplier = -1; unit = V_DIN70121; //750V
  8685. value = 5000; multiplier = -1; unit = V_DIN70121; //500V
  8686. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumVoltageLimit, value, multiplier, unit);
  8687. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  8688. value = 600; multiplier = -1; unit = A_DIN70121; //60A
  8689. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumCurrentLimit, value, multiplier, unit);
  8690. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  8691. value = 3000; multiplier = 1; unit = W_DIN70121; //30KW
  8692. SHM_Save_dinPhysicalValueType(&in->EVSEMaximumPowerLimit, value, multiplier, unit);
  8693. }
  8694. /*===========================================================================
  8695. FUNCTION: Sudo_Parameter_din_CurrentDemandRes
  8696. DESCRIPTION:
  8697. PRE-CONDITION:
  8698. INPUT:
  8699. OUTPUT:
  8700. GLOBAL VARIABLES:
  8701. =============================================================================*/
  8702. void Sudo_Parameter_din_CurrentDemandRes()
  8703. {
  8704. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  8705. init_dinCurrentDemandResType(&ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes);
  8706. ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes_isUsed = 1u;
  8707. //----- [BODY (1/10)] ResponseCode -----
  8708. struct dinCurrentDemandResType *res;
  8709. res = &ccs_exi_doc_DIN.V2G_Message.Body.CurrentDemandRes;
  8710. res->ResponseCode = dinresponseCodeType_OK;
  8711. //----- [BODY (2/10)] DC_EVSEStatus -----
  8712. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8713. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid;
  8714. // dinisolationLevelType_Invalid = 0,
  8715. // dinisolationLevelType_Valid = 1,
  8716. // dinisolationLevelType_Warning = 2,
  8717. // dinisolationLevelType_Fault = 3
  8718. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8719. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8720. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  8721. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8722. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8723. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8724. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8725. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8726. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  8727. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  8728. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  8729. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  8730. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  8731. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8732. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  8733. // dinEVSENotificationType_None = 0,
  8734. // dinEVSENotificationType_StopCharging = 1,
  8735. // dinEVSENotificationType_ReNegotiation = 2
  8736. //----- [BODY (3/10)] EVSEPresentVoltage -----
  8737. res->EVSEPresentVoltage.Value = 3820;
  8738. res->EVSEPresentVoltage.Multiplier = -1;
  8739. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  8740. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  8741. //----- [BODY (4/10)] EVSEPresentCurrent -----
  8742. res->EVSEPresentCurrent.Value = 1200;
  8743. res->EVSEPresentCurrent.Multiplier = -1;
  8744. res->EVSEPresentCurrent.Unit_isUsed = 1u;
  8745. res->EVSEPresentCurrent.Unit = dinunitSymbolType_A;
  8746. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  8747. res->EVSECurrentLimitAchieved = 0;
  8748. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  8749. res->EVSEVoltageLimitAchieved = 0;
  8750. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  8751. res->EVSEPowerLimitAchieved = 0;
  8752. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  8753. res->EVSEMaximumVoltageLimit_isUsed = 1u;
  8754. res->EVSEMaximumVoltageLimit.Value = 7500;
  8755. res->EVSEMaximumVoltageLimit.Multiplier = -1;
  8756. res->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  8757. res->EVSEMaximumVoltageLimit.Unit = dinunitSymbolType_V;
  8758. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  8759. res->EVSEMaximumCurrentLimit_isUsed = 1u;
  8760. res->EVSEMaximumCurrentLimit.Value = 1200;
  8761. res->EVSEMaximumCurrentLimit.Multiplier = -1;
  8762. res->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  8763. res->EVSEMaximumCurrentLimit.Unit = dinunitSymbolType_A;
  8764. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  8765. res->EVSEMaximumPowerLimit_isUsed = 1u;
  8766. res->EVSEMaximumPowerLimit.Value = 6000;
  8767. res->EVSEMaximumPowerLimit.Multiplier = 1;
  8768. res->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  8769. res->EVSEMaximumPowerLimit.Unit = dinunitSymbolType_W;
  8770. }
  8771. /*===========================================================================
  8772. FUNCTION: Sudo_Parameter_iso1_CurrentDemandRes
  8773. DESCRIPTION:
  8774. PRE-CONDITION:
  8775. INPUT:
  8776. OUTPUT:
  8777. GLOBAL VARIABLES:
  8778. =============================================================================*/
  8779. void Sudo_Parameter_iso1_CurrentDemandRes()
  8780. {
  8781. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8782. init_iso1CurrentDemandResType(&ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes);
  8783. ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes_isUsed = 1u;
  8784. //----- [BODY (1/10)] ResponseCode -----
  8785. struct iso1CurrentDemandResType *res;
  8786. res = &ccs_exi_doc_ISO1.V2G_Message.Body.CurrentDemandRes;
  8787. res->ResponseCode = iso1responseCodeType_OK;
  8788. //----- [BODY (2/10)] DC_EVSEStatus -----
  8789. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  8790. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid;
  8791. //iso1isolationLevelType_Invalid = 0,
  8792. //iso1isolationLevelType_Valid = 1,
  8793. //iso1isolationLevelType_Warning = 2,
  8794. //iso1isolationLevelType_Fault = 3,
  8795. //iso1isolationLevelType_No_IMD = 4
  8796. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  8797. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  8798. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  8799. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  8800. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  8801. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  8802. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  8803. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  8804. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  8805. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  8806. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  8807. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  8808. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  8809. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  8810. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8811. //iso1EVSENotificationType_None = 0,
  8812. //iso1EVSENotificationType_StopCharging = 1,
  8813. //iso1EVSENotificationType_ReNegotiation = 2
  8814. //----- [BODY (3/10)] EVSEPresentVoltage -----
  8815. res->EVSEPresentVoltage.Value = 3820;
  8816. res->EVSEPresentVoltage.Multiplier = -1;
  8817. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  8818. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  8819. //----- [BODY (4/10)] EVSEPresentCurrent -----
  8820. res->EVSEPresentCurrent.Value = 1200;
  8821. res->EVSEPresentCurrent.Multiplier = -1;
  8822. //res->EVSEPresentCurrent.Unit_isUsed = 1u;
  8823. res->EVSEPresentCurrent.Unit = iso1unitSymbolType_A;
  8824. //----- [BODY (5/10)] EVSECurrentLimitAchieved -----
  8825. res->EVSECurrentLimitAchieved = 0;
  8826. //----- [BODY (6/10)] EVSEVoltageLimitAchieved -----
  8827. res->EVSEVoltageLimitAchieved = 0;
  8828. //----- [BODY (7/10)] EVSEPowerLimitAchieved -----
  8829. res->EVSEPowerLimitAchieved = 0;
  8830. //----- [BODY (8/10)] EVSEMaximumVoltageLimit -----
  8831. res->EVSEMaximumVoltageLimit_isUsed = 1u;
  8832. res->EVSEMaximumVoltageLimit.Value = 7500;
  8833. res->EVSEMaximumVoltageLimit.Multiplier = -1;
  8834. //res->EVSEMaximumVoltageLimit.Unit_isUsed = 1u;
  8835. res->EVSEMaximumVoltageLimit.Unit = iso1unitSymbolType_V;
  8836. //----- [BODY (9/10)] EVSEMaximumCurrentLimit -----
  8837. res->EVSEMaximumCurrentLimit_isUsed = 1u;
  8838. res->EVSEMaximumCurrentLimit.Value = 1200;
  8839. res->EVSEMaximumCurrentLimit.Multiplier = -1;
  8840. //res->EVSEMaximumCurrentLimit.Unit_isUsed = 1u;
  8841. res->EVSEMaximumCurrentLimit.Unit = iso1unitSymbolType_A;
  8842. //----- [BODY (10/10)] EVSEMaximumPowerLimit -----
  8843. res->EVSEMaximumPowerLimit_isUsed = 1u;
  8844. res->EVSEMaximumPowerLimit.Value = 6000;
  8845. res->EVSEMaximumPowerLimit.Multiplier = 1;
  8846. //res->EVSEMaximumPowerLimit.Unit_isUsed = 1u;
  8847. res->EVSEMaximumPowerLimit.Unit = iso1unitSymbolType_W;
  8848. }
  8849. /*===========================================================================
  8850. FUNCTION: Sudo_Parameter_iso1_ChargingStatusRes
  8851. DESCRIPTION:
  8852. PRE-CONDITION:
  8853. INPUT:
  8854. OUTPUT:
  8855. GLOBAL VARIABLES:
  8856. =============================================================================*/
  8857. void Sudo_Parameter_iso1_ChargingStatusRes()
  8858. {
  8859. //int i = 0;
  8860. struct iso1ChargingStatusResType *res;
  8861. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  8862. init_iso1ChargingStatusResType(&ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes);
  8863. res = &ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes;
  8864. ccs_exi_doc_ISO1.V2G_Message.Body.ChargingStatusRes_isUsed = 1u;
  8865. //----- [BODY (1/10)] ResponseCode -----
  8866. res->ResponseCode = OK_ISO15118_2014;
  8867. //----- [BODY (2/10)] AC_EVSEStatus -----
  8868. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  8869. res->AC_EVSEStatus.NotificationMaxDelay = 0;
  8870. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  8871. // iso1EVSENotificationType_None = 0,
  8872. // iso1EVSENotificationType_StopCharging = 1,
  8873. // iso1EVSENotificationType_ReNegotiation = 2
  8874. //----- [BODY (3/10)] EVSEMaxCurrent -----
  8875. res->EVSEMaxCurrent_isUsed = 1u;
  8876. res->EVSEMaxCurrent.Value = 32;
  8877. res->EVSEMaxCurrent.Multiplier = 0;
  8878. res->EVSEMaxCurrent.Unit = iso1unitSymbolType_A;
  8879. //----- [BODY (4/10)] SAScheduleTupleID -----
  8880. res->SAScheduleTupleID = 0;
  8881. //----- [BODY (5/10)] EVSEID -----
  8882. res->EVSEID.charactersLen = 37;
  8883. memset(res->EVSEID.characters, 0, sizeof(res->EVSEID.characters));
  8884. //sprintf((char*)res->EVSEID.characters, CCS_AC_EVSEID);
  8885. //----- [BODY (6/10)] MeterInfo -----
  8886. res->MeterInfo_isUsed = 1u;
  8887. memset(res->MeterInfo.MeterID.characters, 0, sizeof(res->MeterInfo.MeterID.characters));
  8888. memset(res->MeterInfo.SigMeterReading.bytes, 0, sizeof(res->MeterInfo.SigMeterReading.bytes));
  8889. //[MeterInfo][1/5] MeterID
  8890. //sprintf((char*)res->MeterInfo.MeterID , CCS_AC_METER_ID);
  8891. //[MeterInfo][2/5] SigMeterReading (optional)
  8892. //sprintf((char*)res->MeterInfo.SigMeterReading , CCS_AC_SIG_METER_READING);
  8893. //[MeterInfo][3/5] MeterStatus (optional)
  8894. res->MeterInfo.MeterStatus = 0;
  8895. //[MeterInfo][4/5] MeterReading (optional)
  8896. res->MeterInfo.MeterReading = 12345;
  8897. //[MeterInfo][5/5] TMeter (optional)
  8898. res->MeterInfo.TMeter = 1586243587; //Unix Time Stamp format
  8899. //----- [BODY (7/10)] ReceiptRequired -----
  8900. res->ReceiptRequired_isUsed = 1u;
  8901. res->ReceiptRequired = FALSE; //optional
  8902. }
  8903. /*===========================================================================
  8904. FUNCTION: Check_EVErrorCode
  8905. DESCRIPTION:
  8906. PRE-CONDITION:
  8907. INPUT:
  8908. OUTPUT:
  8909. GLOBAL VARIABLES:
  8910. =============================================================================*/
  8911. void Check_EVErrorCode(int code)
  8912. {
  8913. if (code != NO_ERROR) //NO_ERROR = 0
  8914. {
  8915. //Asking CSU to Stop
  8916. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8917. //Update_V2G_Flow_Status(Other_Fault);
  8918. //memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  8919. sprintf((char*)buf_log_evcomm,
  8920. "Stop by EV (EVErrorCode = %d (DEC))",
  8921. code);
  8922. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8923. }
  8924. }
  8925. /*===========================================================================
  8926. FUNCTION: Proc_din_CurrentDemandRes
  8927. DESCRIPTION:
  8928. PRE-CONDITION:
  8929. INPUT:
  8930. OUTPUT:
  8931. GLOBAL VARIABLES:
  8932. =============================================================================*/
  8933. int Proc_din_CurrentDemandRes(int AcceptFd)
  8934. {
  8935. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  8936. //if it is not the same, the packet should be ignored.
  8937. //STEP 1: ============ Initialize ============
  8938. int errn = 0;
  8939. bitstream_t v2g_tx_stream;
  8940. static struct CurrentDemandResponse_DIN70121 *cur;
  8941. static struct ChargingInfoData *sys;
  8942. // int i = 0;
  8943. // static int EVSE_max_current;
  8944. // int tmp = 0;
  8945. size_t pos = 0;
  8946. v2g_tx_stream.pos = &pos;
  8947. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  8948. v2g_tx_stream.data = V2GTP_Tx_buf;
  8949. cur = &ShmCcsData->V2GMessage_DIN70121.CurrentDemandResponse;
  8950. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  8951. cur->ResponseCode = OK_DIN70121;
  8952. //EVSE Status Code
  8953. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  8954. //[HEADER] Check Req SessionID
  8955. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  8956. {
  8957. cur->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  8958. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  8959. errn = -1;
  8960. }
  8961. //Check for SequenceError
  8962. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  8963. {
  8964. cur->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  8965. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  8966. errn = -1;
  8967. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8968. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  8969. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8970. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8971. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8972. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8973. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  8974. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  8975. }
  8976. //Check for negative EvBatteryMaxCurrent
  8977. if (sys->EvBatteryMaxCurrent < 0)
  8978. {
  8979. sprintf((char*)buf_log_evcomm,
  8980. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  8981. sys->EvBatteryMaxCurrent);
  8982. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  8983. cur->DC_EVSEStatus.EVSEStatusCode = dinresponseCodeType_FAILED_WrongChargeParameter; //16
  8984. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  8985. errn = -1;
  8986. //Update_ShmStatusCode(); //[To-Do] to be implemented
  8987. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  8988. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  8989. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  8990. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  8991. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  8992. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  8993. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  8994. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  8995. }
  8996. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  8997. SAVE_PhysicalValueType_DIN70121(&cur->EVSEPresentCurrent, (int) (sys->PresentChargingCurrent * 10), A_DIN70121);
  8998. SAVE_PhysicalValueType_DIN70121(&cur->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  8999. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == DISABLE
  9000. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_DIN70121);
  9001. #endif
  9002. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_DIN70121);
  9003. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_DIN70121);
  9004. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  9005. if (sys->EvBatteryMaxVoltage <= 500)
  9006. {
  9007. SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumVoltageLimit, (int) (500 * 10), V_DIN70121); //500V
  9008. }
  9009. #endif
  9010. //Limit the EVTargetCurrent should be under EVSEMaximumCurrentLimit
  9011. if (sys->EvBatterytargetCurrent > sys->AvailableChargingCurrent)
  9012. {
  9013. sys->EvBatterytargetCurrent = sys->AvailableChargingCurrent;
  9014. //[To-Do] Limit is achieved flag
  9015. }
  9016. //Isolation Status
  9017. if (sys->IsolationStatus == GFD_Invalid) //0:invalid (on going)
  9018. {
  9019. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  9020. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9021. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9022. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_CurrentDemandRes]IsolationStatus = %d", sys->IsolationStatus);
  9023. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9024. Update_V2G_Flow_Status(Other_Fault);
  9025. errn = -1;
  9026. }
  9027. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  9028. {
  9029. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  9030. }
  9031. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  9032. {
  9033. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  9034. }
  9035. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  9036. {
  9037. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  9038. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9039. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9040. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_CurrentDemandRes]GFD_Fault => Emergency Shutdown");
  9041. Update_V2G_Flow_Status(Other_Fault);
  9042. errn = -1;
  9043. }
  9044. else //GFD_No_IMD or other unexpected status
  9045. {
  9046. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  9047. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9048. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9049. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_CurrentDemandRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  9050. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9051. Update_V2G_Flow_Status(Other_Fault);
  9052. errn = -1;
  9053. }
  9054. //For testing with Tesla Model 3
  9055. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == ENABLE
  9056. //[CAUTION][To-Do] Decresement of Current is not implemented.
  9057. //SAVE_PhysicalValueType_DIN70121(&cur->EVSEMaximumCurrentLimit, 10, A_DIN70121);
  9058. if (sys->EvBatterytargetCurrent <= 0)
  9059. {
  9060. EVSE_max_current = 50; //10A
  9061. cur->EVSEMaximumCurrentLimit.Value = 50; //10A
  9062. /*
  9063. DEBUG_PRINTF_EVCOMM_DETAIL("1PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9064. sys->PresentChargingCurrent,
  9065. sys->EvBatterytargetCurrent,
  9066. EVSE_max_current,
  9067. cur->EVSEMaximumCurrentLimit.Value
  9068. );
  9069. */
  9070. }
  9071. else //1A
  9072. {
  9073. /*
  9074. DEBUG_PRINTF_EVCOMM_DETAIL("2PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9075. sys->PresentChargingCurrent,
  9076. sys->EvBatterytargetCurrent,
  9077. EVSE_max_current,
  9078. cur->EVSEMaximumCurrentLimit.Value
  9079. );
  9080. */
  9081. if ((abs((int)sys->PresentChargingCurrent - (int)sys->EvBatterytargetCurrent) < 3)&&(abs((int)(EVSE_max_current/10) - (int)sys->EvBatterytargetCurrent) < 3))
  9082. {
  9083. tmp = EVSE_max_current + 50; //10A
  9084. if (tmp <= (int)(sys->AvailableChargingCurrent * 10))
  9085. {
  9086. cur->EVSEMaximumCurrentLimit.Value = (int)tmp;
  9087. EVSE_max_current = tmp;
  9088. }
  9089. else
  9090. {
  9091. cur->EVSEMaximumCurrentLimit.Value = (int) (sys->AvailableChargingCurrent * 10); //max is set to 40A
  9092. EVSE_max_current = (int) (sys->AvailableChargingCurrent * 10);
  9093. }
  9094. }
  9095. }
  9096. #endif
  9097. //Check for CSU command of "Stop by EVSE"
  9098. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9099. {
  9100. //Check for Alarm Code: CCS GFD trip (012235)
  9101. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9102. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9103. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9104. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9105. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9106. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9107. {
  9108. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]CCS GFD trip => EVSE_Shutdown");
  9109. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  9110. }
  9111. else
  9112. {
  9113. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]EVSE_Shutdown");
  9114. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9115. }
  9116. //cur->ResponseCode = FAILED_DIN70121;
  9117. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9118. //errn = -1;
  9119. }
  9120. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9121. {
  9122. //Check for Alarm Code: CCS GFD trip (012235)
  9123. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9124. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9125. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9126. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9127. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9128. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9129. {
  9130. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]CCS GFD trip => EVSE_EmergencyShutdown");
  9131. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault;
  9132. }
  9133. else
  9134. {
  9135. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]EVSE_EmergencyShutdown");
  9136. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9137. }
  9138. //cur->ResponseCode = FAILED_DIN70121;
  9139. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9140. //errn = -1;
  9141. }
  9142. else if (ShmInternalComm->ChargingPermission == FALSE)
  9143. {
  9144. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][Error][CurrentDemandRes]Permission OFF");
  9145. //cur->ResponseCode = FAILED_DIN70121;
  9146. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9147. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9148. //errn = -1;
  9149. }
  9150. else
  9151. {
  9152. //null
  9153. }
  9154. //Response to CP Error
  9155. #if CP_PROTECTION_MECHANISM == ENABLE
  9156. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9157. {
  9158. cur->ResponseCode = FAILED_DIN70121;
  9159. cur->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9160. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9161. Update_V2G_Flow_Status(Other_Fault);
  9162. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9163. //CCS_SECC_CP_State_Error (023889)
  9164. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9165. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9166. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9167. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9168. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9169. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9170. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9171. sprintf((char*)buf_log_evcomm,
  9172. "[CurrentDemand]Emergency Stop by CP Error (%d, %.02f V)",
  9173. sys->CpState,
  9174. sys->CpVoltage);
  9175. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9176. }
  9177. #endif
  9178. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9179. #if PARAMETER_NORMAL_MODE == ENABLE
  9180. SHM_Read_din_CurrentDemandRes(&ccs_exi_doc_DIN, ShmCcsData);
  9181. #else
  9182. Sudo_Parameter_din_CurrentDemandRes();
  9183. #endif
  9184. //STEP 4: ============ Encode and Send Response Message ===========
  9185. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  9186. {
  9187. errn = -1;
  9188. }
  9189. //STEP 5: ============ Update Flags ===========
  9190. return errn;
  9191. }
  9192. /*===========================================================================
  9193. FUNCTION: Proc_iso1_CurrentDemandRes
  9194. DESCRIPTION:
  9195. PRE-CONDITION:
  9196. INPUT:
  9197. OUTPUT:
  9198. GLOBAL VARIABLES:
  9199. =============================================================================*/
  9200. int Proc_iso1_CurrentDemandRes(int AcceptFd)
  9201. {
  9202. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9203. //if it is not the same, the packet should be ignored.
  9204. //STEP 1: ============ Initialize ============
  9205. int errn = 0;
  9206. bitstream_t v2g_tx_stream;
  9207. static struct CurrentDemandResponse_ISO15118_2014 *cur;
  9208. static struct ChargingInfoData *sys;
  9209. // int i = 0;
  9210. // static int EVSE_max_current;
  9211. // int tmp = 0;
  9212. size_t pos = 0;
  9213. v2g_tx_stream.pos = &pos;
  9214. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9215. v2g_tx_stream.data = V2GTP_Tx_buf;
  9216. cur = &ShmCcsData->V2GMessage_ISO15118_2014.CurrentDemandResponse;
  9217. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9218. cur->ResponseCode = OK_ISO15118_2014;
  9219. //EVSE Status Code
  9220. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  9221. //[HEADER] Check Req SessionID
  9222. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  9223. {
  9224. cur->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  9225. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  9226. errn = -1;
  9227. }
  9228. //Check for SequenceError
  9229. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9230. {
  9231. cur->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  9232. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  9233. errn = -1;
  9234. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9235. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9236. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9237. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9238. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9239. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9240. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9241. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9242. }
  9243. //Check for negative EvBatteryMaxCurrent
  9244. if (sys->EvBatteryMaxCurrent < 0)
  9245. {
  9246. sprintf((char*)buf_log_evcomm,
  9247. "[ERROR]EvBatteryMaxCurrent is negative(%.02f) => End_Process",
  9248. sys->EvBatteryMaxCurrent);
  9249. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9250. cur->ResponseCode = iso1responseCodeType_FAILED_WrongChargeParameter; //16
  9251. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9252. errn = -1;
  9253. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9254. //CCS_SECC_ResponseCode_FAILED_WrongChargeParameter (023775)
  9255. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9256. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9257. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9258. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9259. ShmStatusCodeData->PresentStatusCode[0][4] = 7;
  9260. ShmStatusCodeData->PresentStatusCode[0][5] = 5;
  9261. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9262. }
  9263. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9264. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEPresentCurrent, (int) (sys->PresentChargingCurrent * 10), A_ISO15118_2014);
  9265. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  9266. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == DISABLE
  9267. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumCurrentLimit, (int) (sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  9268. #endif
  9269. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumPowerLimit, (int) (sys->AvailableChargingPower * 10), W_ISO15118_2014);
  9270. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumVoltageLimit, (int) (sys->MaximumChargingVoltage * 10), V_ISO15118_2014);
  9271. #if PATCH_FOR_BMW_I3_BUG_EVSEMAXIMUMVOLTAGELIMIT_599V == ENABLE
  9272. if (sys->EvBatteryMaxVoltage <= 500)
  9273. {
  9274. SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumVoltageLimit, (int) (500 * 10), V_ISO15118_2014); //500V
  9275. }
  9276. #endif
  9277. //Limit the EVTargetCurrent should be under EVSEMaximumCurrentLimit
  9278. if (sys->EvBatterytargetCurrent > sys->AvailableChargingCurrent)
  9279. {
  9280. sys->EvBatterytargetCurrent = sys->AvailableChargingCurrent;
  9281. //[To-Do] Limit is achieved flag
  9282. }
  9283. //Isolation Status
  9284. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  9285. {
  9286. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  9287. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9288. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9289. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_CurrentDemandRes]IsolationStatus = %d", sys->IsolationStatus);
  9290. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9291. Update_V2G_Flow_Status(Other_Fault);
  9292. errn = -1;
  9293. }
  9294. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  9295. {
  9296. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  9297. }
  9298. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  9299. {
  9300. cur->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  9301. }
  9302. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  9303. {
  9304. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  9305. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9306. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9307. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_CurrentDemandRes]GFD_Fault => EmergencyShutdown");
  9308. Update_V2G_Flow_Status(Other_Fault);
  9309. errn = -1;
  9310. }
  9311. else
  9312. {
  9313. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  9314. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9315. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9316. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_CurrentDemandRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  9317. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9318. Update_V2G_Flow_Status(Other_Fault);
  9319. errn = -1;
  9320. }
  9321. //For testing with Tesla Model 3
  9322. #if TESLA_SLOW_INCREASE_CURRENT_FUNCTION == ENABLE
  9323. //[CAUTION][To-Do] Decresement of Current is not implemented.
  9324. //SAVE_PhysicalValueType_ISO15118_2014(&cur->EVSEMaximumCurrentLimit, 10, A_ISO15118_2014);
  9325. if (sys->EvBatterytargetCurrent <= 0)
  9326. {
  9327. EVSE_max_current = 50; //10A
  9328. cur->EVSEMaximumCurrentLimit.Value = 50; //10A
  9329. /*
  9330. DEBUG_PRINTF_EVCOMM_DETAIL("1PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9331. sys->PresentChargingCurrent,
  9332. sys->EvBatterytargetCurrent,
  9333. EVSE_max_current,
  9334. cur->EVSEMaximumCurrentLimit.Value
  9335. );
  9336. */
  9337. }
  9338. else //1A
  9339. {
  9340. /*
  9341. DEBUG_PRINTF_EVCOMM_DETAIL("2PresentChargingCurrent = %.02f, EvBatterytargetCurrent = %.02f, EVSE_max_current = %d, EVSEMaximumCurrentLimit = %d\n",
  9342. sys->PresentChargingCurrent,
  9343. sys->EvBatterytargetCurrent,
  9344. EVSE_max_current,
  9345. cur->EVSEMaximumCurrentLimit.Value
  9346. );
  9347. */
  9348. if ((abs((int)sys->PresentChargingCurrent - (int)sys->EvBatterytargetCurrent) < 3)&&(abs((int)(EVSE_max_current/10) - (int)sys->EvBatterytargetCurrent) < 3))
  9349. {
  9350. tmp = EVSE_max_current + 50; //10A
  9351. if (tmp <= (int)(sys->AvailableChargingCurrent * 10))
  9352. {
  9353. cur->EVSEMaximumCurrentLimit.Value = (int)tmp;
  9354. EVSE_max_current = tmp;
  9355. }
  9356. else
  9357. {
  9358. cur->EVSEMaximumCurrentLimit.Value = (int) (sys->AvailableChargingCurrent * 10); //max is set to 40A
  9359. EVSE_max_current = (int) (sys->AvailableChargingCurrent * 10);
  9360. }
  9361. }
  9362. }
  9363. #endif
  9364. //Check for CSU command of "Stop by EVSE"
  9365. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9366. {
  9367. //Check for Alarm Code: CCS GFD trip (012235)
  9368. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9369. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9370. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9371. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9372. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9373. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9374. {
  9375. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][CurrentDemandRes]CCS GFD trip => EVSE_Shutdown");
  9376. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  9377. }
  9378. else
  9379. {
  9380. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][CurrentDemandRes]EVSE_Shutdown");
  9381. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9382. }
  9383. //cur->ResponseCode = FAILED_ISO15118_2014;
  9384. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9385. //errn = -1;
  9386. }
  9387. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9388. {
  9389. //Check for Alarm Code: CCS GFD trip (012235)
  9390. if (ShmInternalComm->EVSEStopChargingReq.alarmcode[0] == 0 &&
  9391. ShmInternalComm->EVSEStopChargingReq.alarmcode[1] == 1 &&
  9392. ShmInternalComm->EVSEStopChargingReq.alarmcode[2] == 2 &&
  9393. ShmInternalComm->EVSEStopChargingReq.alarmcode[3] == 2 &&
  9394. ShmInternalComm->EVSEStopChargingReq.alarmcode[4] == 3 &&
  9395. ShmInternalComm->EVSEStopChargingReq.alarmcode[5] == 5)
  9396. {
  9397. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][CurrentDemandRes]CCS GFD trip => EVSE_EmergencyShutdown");
  9398. cur->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault;
  9399. }
  9400. else
  9401. {
  9402. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][CurrentDemandRes]EVSE_EmergencyShutdown");
  9403. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9404. }
  9405. //cur->ResponseCode = FAILED_ISO15118_2014;
  9406. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9407. //errn = -1;
  9408. }
  9409. else if (ShmInternalComm->ChargingPermission == FALSE)
  9410. {
  9411. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][CurrentDemandRes]Permission OFF");
  9412. //cur->ResponseCode = FAILED_ISO15118_2014;
  9413. cur->DC_EVSEStatus.EVSEIsolationStatus = (unsigned char)sys->IsolationStatus;
  9414. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  9415. //errn = -1;
  9416. }
  9417. else
  9418. {
  9419. //null
  9420. }
  9421. //Response to CP Error
  9422. #if CP_PROTECTION_MECHANISM == ENABLE
  9423. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9424. {
  9425. cur->ResponseCode = FAILED_ISO15118_2014;
  9426. cur->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9427. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9428. Update_V2G_Flow_Status(Other_Fault);
  9429. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9430. //CCS_SECC_CP_State_Error (023889)
  9431. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9432. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9433. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9434. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9435. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9436. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9437. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9438. sprintf((char*)buf_log_evcomm,
  9439. "[CurrentDemand]Emergency Stop by CP Error (%d, %.02f V)",
  9440. sys->CpState,
  9441. sys->CpVoltage);
  9442. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9443. }
  9444. #endif
  9445. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9446. #if PARAMETER_NORMAL_MODE == ENABLE
  9447. SHM_Read_iso1_CurrentDemandRes(&ccs_exi_doc_ISO1, ShmCcsData);
  9448. #else
  9449. Sudo_Parameter_iso1_CurrentDemandRes();
  9450. #endif
  9451. //STEP 4: ============ Encode and Send Response Message ===========
  9452. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  9453. {
  9454. errn = -1;
  9455. }
  9456. //STEP 5: ============ Update Flags ===========
  9457. return errn;
  9458. }
  9459. /*===========================================================================
  9460. FUNCTION: Proc_iso1_ChargingStatusRes
  9461. DESCRIPTION:
  9462. PRE-CONDITION:
  9463. INPUT:
  9464. OUTPUT:
  9465. GLOBAL VARIABLES:
  9466. =============================================================================*/
  9467. int Proc_iso1_ChargingStatusRes(int AcceptFd)
  9468. {
  9469. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9470. //if it is not the same, the packet should be ignored.
  9471. //STEP 1: ============ Initialize ============
  9472. //int i = 0;
  9473. int errn = 0;
  9474. bitstream_t v2g_tx_stream;
  9475. static struct ChargingStatusResponse_ISO15118_2014 *res;
  9476. static struct ChargingInfoData *sys;
  9477. size_t pos = 0;
  9478. v2g_tx_stream.pos = &pos;
  9479. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9480. v2g_tx_stream.data = V2GTP_Tx_buf;
  9481. res = &ShmCcsData->V2GMessage_ISO15118_2014.ChargingStatusResponse;
  9482. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9483. //Init
  9484. res->ResponseCode = OK_ISO15118_2014;
  9485. res->ReceiptRequired = FALSE; //optional
  9486. res->SAScheduleTupleID = 0;
  9487. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  9488. res->AC_EVSEStatus.NotificationMaxDelay = 0;
  9489. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9490. // iso1EVSENotificationType_None = 0,
  9491. // iso1EVSENotificationType_StopCharging = 1,
  9492. // iso1EVSENotificationType_ReNegotiation = 2
  9493. //[HEADER] Check Req SessionID
  9494. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  9495. {
  9496. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  9497. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  9498. errn = -1;
  9499. }
  9500. //Check for SequenceError
  9501. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9502. {
  9503. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  9504. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  9505. errn = -1;
  9506. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9507. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9508. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9509. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9510. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9511. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9512. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9513. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9514. }
  9515. //EVSE ID
  9516. memset(res->EVSEID, 0, sizeof(res->EVSEID));
  9517. //sprintf((char*)res->EVSEID, CCS_AC_EVSEID);
  9518. //[MeterInfo][0/5] init
  9519. //memset(res->MeterInfo.MeterID.characters, 0, sizeof(res->MeterInfo.MeterID.characters));
  9520. //memset(res->MeterInfo.SigMeterReading.bytes, 0, sizeof(res->MeterInfo.SigMeterReading.bytes));
  9521. //[MeterInfo][1/5] MeterID
  9522. //sprintf((char*)res->MeterInfo.MeterID , CCS_AC_METER_ID);
  9523. //[MeterInfo][2/5] SigMeterReading (optional)
  9524. //sprintf((char*)res->MeterInfo.SigMeterReading , CCS_AC_SIG_METER_READING);
  9525. //[MeterInfo][3/5] MeterStatus (optional)
  9526. res->MeterInfo.MeterStatus = 0;
  9527. //[MeterInfo][4/5] MeterReading (optional)
  9528. res->MeterInfo.MeterReading = 12345;
  9529. //[MeterInfo][5/5] TMeter (optional)
  9530. res->MeterInfo.TMeter = 1586243587; //Unix Time Stamp format
  9531. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9532. SAVE_PhysicalValueType_ISO15118_2014(&res->EVSEMaxCurrent, (int)(sys->AvailableChargingCurrent * 10), A_ISO15118_2014);
  9533. //Isolation Status (RCD)
  9534. if (sys->IsolationStatus == 0) //Isolation is invalid
  9535. {
  9536. res->AC_EVSEStatus.RCD = TRUE; //FALSE(no error), TRUE(error is detected)
  9537. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9538. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9539. sprintf((char*)buf_log_evcomm, "[Error][ChargingStatusRes]IsolationStatus = %d", sys->IsolationStatus);
  9540. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9541. Update_V2G_Flow_Status(Other_Fault);
  9542. errn = -1;
  9543. }
  9544. else if (sys->IsolationStatus == 1) //Isolation is valid
  9545. {
  9546. res->AC_EVSEStatus.RCD = FALSE; //FALSE(no error), TRUE(error is detected)
  9547. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  9548. }
  9549. else
  9550. {
  9551. res->AC_EVSEStatus.RCD = TRUE; //FALSE(no error), TRUE(error is detected)
  9552. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9553. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9554. sprintf((char*)buf_log_evcomm, "[Error][ChargingStatusRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  9555. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9556. Update_V2G_Flow_Status(Other_Fault);
  9557. errn = -1;
  9558. }
  9559. //Check for CSU command of "Stop by EVSE"
  9560. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9561. {
  9562. //res->ResponseCode = FAILED_ISO15118_2014;
  9563. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9564. //errn = -1;
  9565. }
  9566. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9567. {
  9568. //res->ResponseCode = FAILED_ISO15118_2014;
  9569. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9570. //errn = -1;
  9571. }
  9572. else if (ShmInternalComm->ChargingPermission == FALSE)
  9573. {
  9574. //res->ResponseCode = FAILED_ISO15118_2014;
  9575. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9576. //errn = -1;
  9577. }
  9578. //Response to CP Error
  9579. #if CP_PROTECTION_MECHANISM == ENABLE
  9580. if ((sys->CpState != 4) && (sys->CpState != 5)) //State C (6V), D (3V)
  9581. {
  9582. res->ResponseCode = FAILED_ISO15118_2014;
  9583. res->AC_EVSEStatus.EVSENotification = iso1EVSENotificationType_StopCharging;
  9584. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9585. Update_V2G_Flow_Status(Other_Fault);
  9586. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9587. //CCS_SECC_CP_State_Error (023889)
  9588. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9589. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9590. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9591. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  9592. ShmStatusCodeData->PresentStatusCode[0][4] = 8;
  9593. ShmStatusCodeData->PresentStatusCode[0][5] = 9;
  9594. CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  9595. sprintf((char*)buf_log_evcomm,
  9596. "[ChargingStatus]Emergency Stop by CP Error (%d, %.02f V)",
  9597. sys->CpState,
  9598. sys->CpVoltage);
  9599. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9600. }
  9601. #endif
  9602. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9603. #if PARAMETER_NORMAL_MODE == ENABLE
  9604. SHM_Read_iso1_ChargingStatusRes(&ccs_exi_doc_ISO1, ShmCcsData);
  9605. #else
  9606. Sudo_Parameter_iso1_ChargingStatusRes();
  9607. #endif
  9608. //STEP 4: ============ Encode and Send Response Message ===========
  9609. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  9610. {
  9611. errn = -1;
  9612. }
  9613. //STEP 5: ============ Update Flags ===========
  9614. return errn;
  9615. }
  9616. /*===========================================================================
  9617. FUNCTION: Proc_din_CurrentDemandReq
  9618. DESCRIPTION:
  9619. PRE-CONDITION:
  9620. INPUT:
  9621. OUTPUT:
  9622. GLOBAL VARIABLES:
  9623. =============================================================================*/
  9624. int Proc_din_CurrentDemandReq(int AcceptFd)
  9625. {
  9626. int errn = 0;
  9627. SAVE_SYS_LOG_MSG_EVCOMM("[V2G[RX]]CurrentDemandReq\n");
  9628. //Print the decoded XML Document
  9629. PRINT_XML_DOC_DIN_CurrentDemandReq(&ccs_exi_doc_DIN);
  9630. //Save into Share Memory
  9631. SHM_Save_din_CurrentDemandReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  9632. //Check for EV Error Code
  9633. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.CurrentDemandRequest.DC_EVStatus.EVErrorCode);
  9634. errn = Proc_din_CurrentDemandRes(AcceptFd);
  9635. if (errn == 0)
  9636. {
  9637. //Response is sent successfully.
  9638. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]CurrentDemandRes\n");
  9639. }
  9640. else
  9641. {
  9642. sprintf((char*)buf_log_evcomm,
  9643. "[Error]CurrentDemandRes: fail(%d,DEC)",
  9644. errn);
  9645. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9646. }
  9647. return errn;
  9648. }
  9649. /*===========================================================================
  9650. FUNCTION: Proc_iso1_CurrentDemandReq
  9651. DESCRIPTION:
  9652. PRE-CONDITION:
  9653. INPUT:
  9654. OUTPUT:
  9655. GLOBAL VARIABLES:
  9656. =============================================================================*/
  9657. int Proc_iso1_CurrentDemandReq(int AcceptFd)
  9658. {
  9659. int errn = 0;
  9660. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]CurrentDemandReq\n");
  9661. //Print the decoded XML Document
  9662. PRINT_XML_DOC_ISO1_CurrentDemandReq(&ccs_exi_doc_ISO1);
  9663. //Save into Share Memory
  9664. SHM_Save_iso1_CurrentDemandReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  9665. //Check for EV Error Code
  9666. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.CurrentDemandRequest.DC_EVStatus.EVErrorCode);
  9667. errn = Proc_iso1_CurrentDemandRes(AcceptFd);
  9668. if (errn == 0)
  9669. {
  9670. //Response is sent successfully.
  9671. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]CurrentDemandRes\n");
  9672. }
  9673. else
  9674. {
  9675. sprintf((char*)buf_log_evcomm,
  9676. "[Error]CurrentDemandRes: fail(%d,DEC)",
  9677. errn);
  9678. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9679. }
  9680. return errn;
  9681. }
  9682. /*===========================================================================
  9683. FUNCTION: Proc_iso1_ChargingStatusReq
  9684. DESCRIPTION:
  9685. PRE-CONDITION:
  9686. INPUT:
  9687. OUTPUT:
  9688. GLOBAL VARIABLES:
  9689. =============================================================================*/
  9690. int Proc_iso1_ChargingStatusReq(int AcceptFd)
  9691. {
  9692. int errn = 0;
  9693. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]Got ChargingStatusReq\n");
  9694. //Print the decoded XML Document
  9695. PRINT_XML_DOC_ISO1_ChargingStatusReq(&ccs_exi_doc_ISO1);
  9696. //Save into Share Memory
  9697. SHM_Save_iso1_ChargingStatusReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  9698. //Check for EV Error Code
  9699. //no content in ISO1
  9700. errn = Proc_iso1_ChargingStatusRes(AcceptFd);
  9701. if (errn == 0)
  9702. {
  9703. //Response is sent successfully.
  9704. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]ChargingStatusRes\n");
  9705. }
  9706. else
  9707. {
  9708. sprintf((char*)buf_log_evcomm,
  9709. "[Error]ChargingStatusRes: fail(%d,DEC)",
  9710. errn);
  9711. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9712. }
  9713. return errn;
  9714. }
  9715. /*===========================================================================
  9716. FUNCTION: Proc_din_PowerDeliveryStopRes
  9717. DESCRIPTION:
  9718. PRE-CONDITION:
  9719. INPUT:
  9720. OUTPUT:
  9721. GLOBAL VARIABLES:
  9722. =============================================================================*/
  9723. int Proc_din_PowerDeliveryStopRes(int AcceptFd)
  9724. {
  9725. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9726. //if it is not the same, the packet should be ignored.
  9727. //STEP 1: ============ Initialize ============
  9728. //int i = 0;
  9729. int errn = 0;
  9730. bitstream_t v2g_tx_stream;
  9731. struct dinPowerDeliveryResType *res;
  9732. struct ChargingInfoData *sys;
  9733. size_t pos = 0;
  9734. v2g_tx_stream.pos = &pos;
  9735. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9736. v2g_tx_stream.data = V2GTP_Tx_buf;
  9737. res = &ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryRes;
  9738. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9739. res->ResponseCode = OK_DIN70121;
  9740. //[HEADER] Check Req SessionID
  9741. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  9742. {
  9743. res->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  9744. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  9745. errn = -1;
  9746. }
  9747. //Check for SequenceError
  9748. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9749. {
  9750. res->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  9751. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  9752. errn = -1;
  9753. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9754. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9755. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9756. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9757. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9758. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9759. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9760. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9761. }
  9762. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9763. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9764. #if PARAMETER_NORMAL_MODE == ENABLE
  9765. ShmCcsData->V2GMessage_DIN70121.PowerDeliveryResponse.DC_EVSEStatus.EVSEStatusCode = EVSE_NotReady;
  9766. SHM_Read_din_PowerDeliveryRes(&ccs_exi_doc_DIN, ShmCcsData);
  9767. #else
  9768. Sudo_Parameter_din_PreChargeRes();
  9769. #endif
  9770. //EVSE Status Code
  9771. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  9772. //Check for CSU command of "Stop by EVSE"
  9773. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9774. {
  9775. //res->ResponseCode = FAILED_DIN70121;
  9776. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9777. }
  9778. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9779. {
  9780. //res->ResponseCode = FAILED_DIN70121;
  9781. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9782. }
  9783. else if (ShmInternalComm->ChargingPermission == FALSE)
  9784. {
  9785. //res->ResponseCode = FAILED_DIN70121;
  9786. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  9787. }
  9788. //STEP 4: ============ Encode and Send Response Message ===========
  9789. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  9790. {
  9791. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_PowerDeliveryStopRes][Error]Tx encoded msg error");
  9792. errn = -1;
  9793. }
  9794. //STEP 5: ============ Update Flags ===========
  9795. return errn;
  9796. }
  9797. /*===========================================================================
  9798. FUNCTION: Proc_iso1_PowerDeliveryStopRes
  9799. DESCRIPTION:
  9800. PRE-CONDITION:
  9801. INPUT:
  9802. OUTPUT:
  9803. GLOBAL VARIABLES:
  9804. =============================================================================*/
  9805. int Proc_iso1_PowerDeliveryStopRes(int AcceptFd)
  9806. {
  9807. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  9808. //if it is not the same, the packet should be ignored.
  9809. //STEP 1: ============ Initialize ============
  9810. //int i = 0;
  9811. int errn = 0;
  9812. bitstream_t v2g_tx_stream;
  9813. struct iso1PowerDeliveryResType *res;
  9814. struct ChargingInfoData *sys;
  9815. size_t pos = 0;
  9816. v2g_tx_stream.pos = &pos;
  9817. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  9818. v2g_tx_stream.data = V2GTP_Tx_buf;
  9819. res = &ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryRes;
  9820. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  9821. res->ResponseCode = OK_ISO15118_2014;
  9822. //[HEADER] Check Req SessionID
  9823. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  9824. {
  9825. res->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  9826. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  9827. errn = -1;
  9828. }
  9829. //Check for SequenceError
  9830. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  9831. {
  9832. res->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  9833. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  9834. errn = -1;
  9835. //Update_ShmStatusCode(); //[To-Do] to be implemented
  9836. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  9837. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  9838. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  9839. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  9840. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  9841. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  9842. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  9843. }
  9844. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  9845. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  9846. #if PARAMETER_NORMAL_MODE == ENABLE
  9847. ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryResponse.DC_EVSEStatus.DC_EVSEStatusCode = EVSE_NotReady;
  9848. SHM_Read_iso1_PowerDeliveryRes(&ccs_exi_doc_ISO1, ShmCcsData);
  9849. #else
  9850. Sudo_Parameter_iso1_PreChargeRes();
  9851. #endif
  9852. //EVSE Status Code
  9853. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  9854. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1 /*+++ 20200808, vern, Isolation Status should be valid during 2nd PowerDelivert ---*/
  9855. //Check for CSU command of "Stop by EVSE"
  9856. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  9857. {
  9858. //res->ResponseCode = FAILED_ISO15118_2014;
  9859. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; /*+++ 20200808, vern, Isolation Status should be valid during 2nd PowerDelivert ---*/
  9860. }
  9861. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  9862. {
  9863. //res->ResponseCode = FAILED_ISO15118_2014;
  9864. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  9865. }
  9866. else if (ShmInternalComm->ChargingPermission == FALSE)
  9867. {
  9868. //res->ResponseCode = FAILED_ISO15118_2014;
  9869. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready; /*+++ 20200808, vern, Isolation Status should be valid during 2nd PowerDelivert ---*/
  9870. }
  9871. //STEP 4: ============ Encode and Send Response Message ===========
  9872. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  9873. {
  9874. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_PowerDeliveryStopRes][Error]Tx encoded msg error");
  9875. errn = -1;
  9876. }
  9877. //STEP 5: ============ Update Flags ===========
  9878. return errn;
  9879. }
  9880. /*===========================================================================
  9881. FUNCTION: Proc_din_PowerDeliveryStopReq
  9882. DESCRIPTION:
  9883. PRE-CONDITION:
  9884. INPUT:
  9885. OUTPUT:
  9886. GLOBAL VARIABLES:
  9887. =============================================================================*/
  9888. int Proc_din_PowerDeliveryStopReq(int AcceptFd)
  9889. {
  9890. int errn = 0;
  9891. //Request CSU to STOP
  9892. //This should be reponsed as soon as possible once this message is received.
  9893. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9894. EVCOMM_SYS_INFO.EvBatterytargetVoltage = 0;
  9895. EVCOMM_SYS_INFO.EvBatterytargetCurrent = 0;
  9896. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PowerDeliveryReq (2nd)\n");
  9897. //Print the decoded XML Document
  9898. PRINT_XML_DOC_DIN_PowerDeliveryReq(&ccs_exi_doc_DIN);
  9899. //Save into Share Memory
  9900. SHM_Save_din_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  9901. //Check for EV Error Code
  9902. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  9903. //[To-Do] Sending response after the EVSE output voltage decreases to under 60V
  9904. usleep(1500000); //1.5 seconds
  9905. //sleep(1); //1 second
  9906. errn = Proc_din_PowerDeliveryStopRes(AcceptFd);
  9907. if (errn == 0)
  9908. {
  9909. //send response successfully.
  9910. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[DIN][V2G][TX]PowerDeliveryRes (2nd)\n");
  9911. }
  9912. else
  9913. {
  9914. sprintf((char*)buf_log_evcomm,
  9915. "[Error][SeccComm][Proc_din_PowerDeliveryStopReq]Proc_iso1_PowerDeliveryStopRes(): %d (DEC)",
  9916. errn);
  9917. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9918. }
  9919. return errn;
  9920. }
  9921. /*===========================================================================
  9922. FUNCTION: Proc_iso1_PowerDeliveryStopReq
  9923. DESCRIPTION:
  9924. PRE-CONDITION:
  9925. INPUT:
  9926. OUTPUT:
  9927. GLOBAL VARIABLES:
  9928. =============================================================================*/
  9929. int Proc_iso1_PowerDeliveryStopReq(int AcceptFd)
  9930. {
  9931. int errn = 0;
  9932. //Request CSU to STOP
  9933. //This should be reponsed as soon as possible once this message is received.
  9934. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  9935. EVCOMM_SYS_INFO.EvBatterytargetVoltage = 0;
  9936. EVCOMM_SYS_INFO.EvBatterytargetCurrent = 0;
  9937. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PowerDeliveryReq (2nd)\n");
  9938. //Print the decoded XML Document
  9939. PRINT_XML_DOC_ISO1_PowerDeliveryReq(&ccs_exi_doc_ISO1);
  9940. //Save into Share Memory
  9941. SHM_Save_iso1_PowerDeliveryReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  9942. //Check for EV Error Code
  9943. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.PowerDeliveryRequest.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode);
  9944. //[To-Do] Sending response after the EVSE output voltage decreases to under 60V
  9945. usleep(1500000); //1.5 seconds
  9946. //sleep(1); //1 second
  9947. errn = Proc_iso1_PowerDeliveryStopRes(AcceptFd);
  9948. if (errn == 0)
  9949. {
  9950. //send response successfully.
  9951. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]PowerDeliveryRes (2nd)");
  9952. }
  9953. else
  9954. {
  9955. sprintf((char*)buf_log_evcomm,
  9956. "[Error][SeccComm][Proc_iso1_PowerDeliveryStopReq]Proc_iso1_PowerDeliveryStopRes(): %d (DEC)",
  9957. errn);
  9958. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  9959. }
  9960. return errn;
  9961. }
  9962. /*===========================================================================
  9963. FUNCTION: SHM_Init_din_WeldingDetectionRes
  9964. DESCRIPTION:
  9965. PRE-CONDITION:
  9966. INPUT:
  9967. 1. shm_ccs
  9968. OUTPUT:
  9969. 1. shm_ccs
  9970. GLOBAL VARIABLES:
  9971. =============================================================================*/
  9972. void SHM_Init_din_WeldingDetectionRes(struct CcsData *shm_ccs)
  9973. {
  9974. struct WeldingDetectionResponse_DIN70121 *in;
  9975. in = &shm_ccs->V2GMessage_DIN70121.WeldingDetectionResponse;
  9976. //----- [BODY (1/3)] ResponseCode -----
  9977. in->ResponseCode = dinresponseCodeType_OK;
  9978. //----- [BODY (2/3)] EVSEPresentVoltage -----
  9979. short value = 0; int multiplier = 0; unsigned char unit = 0;
  9980. //value = 3820; multiplier = -1; unit = V_DIN70121; //382V, for test only.
  9981. value = 0; multiplier = 0; unit = V_DIN70121;
  9982. SHM_Save_dinPhysicalValueType(&in->EVSEPresentVoltage, value, multiplier, unit);
  9983. //----- [BODY (3/3)] DC_EVSEStatus -----
  9984. SHM_Init_dinDC_EVSEStatusType(&in->DC_EVSEStatus);
  9985. }
  9986. /*===========================================================================
  9987. FUNCTION: Sudo_Parameter_din_WeldingDetectionRes
  9988. DESCRIPTION:
  9989. PRE-CONDITION:
  9990. INPUT:
  9991. OUTPUT:
  9992. GLOBAL VARIABLES:
  9993. =============================================================================*/
  9994. void Sudo_Parameter_din_WeldingDetectionRes()
  9995. {
  9996. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  9997. init_dinWeldingDetectionResType(&ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes);
  9998. ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes_isUsed = 1u;
  9999. //----- [BODY (1/3)] ResponseCode -----
  10000. struct dinWeldingDetectionResType *res;
  10001. res = &ccs_exi_doc_DIN.V2G_Message.Body.WeldingDetectionRes;
  10002. res->ResponseCode = dinresponseCodeType_OK;
  10003. //----- [BODY (2/3)] EVSEPresentVoltage -----
  10004. res->EVSEPresentVoltage.Value = 3820;
  10005. res->EVSEPresentVoltage.Multiplier = -1;
  10006. res->EVSEPresentVoltage.Unit_isUsed = 1u;
  10007. res->EVSEPresentVoltage.Unit = dinunitSymbolType_V;
  10008. // dinunitSymbolType_h = 0,
  10009. // dinunitSymbolType_m = 1,
  10010. // dinunitSymbolType_s = 2,
  10011. // dinunitSymbolType_A = 3,
  10012. // dinunitSymbolType_Ah = 4,
  10013. // dinunitSymbolType_V = 5,
  10014. // dinunitSymbolType_VA = 6,
  10015. // dinunitSymbolType_W = 7,
  10016. // dinunitSymbolType_W_s = 8,
  10017. // dinunitSymbolType_Wh = 9
  10018. //----- [BODY (3/3)] DC_EVSEStatus -----
  10019. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  10020. res->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid;
  10021. // dinisolationLevelType_Invalid = 0,
  10022. // dinisolationLevelType_Valid = 1,
  10023. // dinisolationLevelType_Warning = 2,
  10024. // dinisolationLevelType_Fault = 3
  10025. res->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  10026. // dinDC_EVSEStatusCodeType_EVSE_NotReady = 0,
  10027. // dinDC_EVSEStatusCodeType_EVSE_Ready = 1,
  10028. // dinDC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  10029. // dinDC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  10030. // dinDC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  10031. // dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  10032. // dinDC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  10033. // dinDC_EVSEStatusCodeType_Reserved_8 = 7,
  10034. // dinDC_EVSEStatusCodeType_Reserved_9 = 8,
  10035. // dinDC_EVSEStatusCodeType_Reserved_A = 9,
  10036. // dinDC_EVSEStatusCodeType_Reserved_B = 10,
  10037. // dinDC_EVSEStatusCodeType_Reserved_C = 11
  10038. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  10039. res->DC_EVSEStatus.EVSENotification = dinEVSENotificationType_None;
  10040. // dinEVSENotificationType_None = 0,
  10041. // dinEVSENotificationType_StopCharging = 1,
  10042. // dinEVSENotificationType_ReNegotiation = 2
  10043. }
  10044. /*===========================================================================
  10045. FUNCTION: Sudo_Parameter_iso1_WeldingDetectionRes
  10046. DESCRIPTION:
  10047. PRE-CONDITION:
  10048. INPUT:
  10049. OUTPUT:
  10050. GLOBAL VARIABLES:
  10051. =============================================================================*/
  10052. void Sudo_Parameter_iso1_WeldingDetectionRes()
  10053. {
  10054. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  10055. init_iso1WeldingDetectionResType(&ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes);
  10056. ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes_isUsed = 1u;
  10057. //----- [BODY (1/3)] ResponseCode -----
  10058. struct iso1WeldingDetectionResType *res;
  10059. res = &ccs_exi_doc_ISO1.V2G_Message.Body.WeldingDetectionRes;
  10060. res->ResponseCode = iso1responseCodeType_OK;
  10061. //----- [BODY (2/3)] EVSEPresentVoltage -----
  10062. res->EVSEPresentVoltage.Value = 3820;
  10063. res->EVSEPresentVoltage.Multiplier = -1;
  10064. //res->EVSEPresentVoltage.Unit_isUsed = 1u;
  10065. res->EVSEPresentVoltage.Unit = iso1unitSymbolType_V;
  10066. //iso1unitSymbolType_h = 0,
  10067. //iso1unitSymbolType_m = 1,
  10068. //iso1unitSymbolType_s = 2,
  10069. //iso1unitSymbolType_A = 3,
  10070. //iso1unitSymbolType_V = 4,
  10071. //iso1unitSymbolType_W = 5,
  10072. //iso1unitSymbolType_Wh = 6
  10073. //----- [BODY (3/3)] DC_EVSEStatus -----
  10074. res->DC_EVSEStatus.EVSEIsolationStatus_isUsed = 1u;
  10075. res->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid;
  10076. //iso1isolationLevelType_Invalid = 0,
  10077. //iso1isolationLevelType_Valid = 1,
  10078. //iso1isolationLevelType_Warning = 2,
  10079. //iso1isolationLevelType_Fault = 3,
  10080. //iso1isolationLevelType_No_IMD = 4
  10081. res->DC_EVSEStatus.EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10082. //iso1DC_EVSEStatusCodeType_EVSE_NotReady = 0,
  10083. //iso1DC_EVSEStatusCodeType_EVSE_Ready = 1,
  10084. //iso1DC_EVSEStatusCodeType_EVSE_Shutdown = 2,
  10085. //iso1DC_EVSEStatusCodeType_EVSE_UtilityInterruptEvent = 3,
  10086. //iso1DC_EVSEStatusCodeType_EVSE_IsolationMonitoringActive = 4,
  10087. //iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown = 5,
  10088. //iso1DC_EVSEStatusCodeType_EVSE_Malfunction = 6,
  10089. //iso1DC_EVSEStatusCodeType_Reserved_8 = 7,
  10090. //iso1DC_EVSEStatusCodeType_Reserved_9 = 8,
  10091. //iso1DC_EVSEStatusCodeType_Reserved_A = 9,
  10092. //iso1DC_EVSEStatusCodeType_Reserved_B = 10,
  10093. //iso1DC_EVSEStatusCodeType_Reserved_C = 11
  10094. res->DC_EVSEStatus.NotificationMaxDelay = 0u;
  10095. res->DC_EVSEStatus.EVSENotification = iso1EVSENotificationType_None;
  10096. //iso1EVSENotificationType_None = 0,
  10097. //iso1EVSENotificationType_StopCharging = 1,
  10098. //iso1EVSENotificationType_ReNegotiation = 2
  10099. }
  10100. /*===========================================================================
  10101. FUNCTION: Proc_din_WeldingDetectionRes
  10102. DESCRIPTION:
  10103. PRE-CONDITION:
  10104. INPUT:
  10105. OUTPUT:
  10106. GLOBAL VARIABLES:
  10107. =============================================================================*/
  10108. int Proc_din_WeldingDetectionRes(int AcceptFd)
  10109. {
  10110. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10111. //if it is not the same, the packet should be ignored.
  10112. //STEP 1: ============ Initialize ============
  10113. //int i = 0;
  10114. int errn = 0;
  10115. bitstream_t v2g_tx_stream;
  10116. static struct WeldingDetectionResponse_DIN70121 *wel;
  10117. static struct ChargingInfoData *sys;
  10118. size_t pos = 0;
  10119. v2g_tx_stream.pos = &pos;
  10120. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10121. v2g_tx_stream.data = V2GTP_Tx_buf;
  10122. wel = &ShmCcsData->V2GMessage_DIN70121.WeldingDetectionResponse;
  10123. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10124. wel->ResponseCode = OK_DIN70121;
  10125. //[HEADER] Check Req SessionID
  10126. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  10127. {
  10128. wel->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  10129. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10130. errn = -1;
  10131. }
  10132. //Check for SequenceError
  10133. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10134. {
  10135. wel->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  10136. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10137. errn = -1;
  10138. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10139. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10140. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10141. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10142. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10143. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10144. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10145. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10146. }
  10147. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10148. SAVE_PhysicalValueType_DIN70121(&wel->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_DIN70121);
  10149. //EVSE Status Code
  10150. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Ready;
  10151. //Check for CSU command of "Stop by EVSE"
  10152. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10153. {
  10154. //wel->ResponseCode = FAILED_DIN70121;
  10155. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10156. }
  10157. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10158. {
  10159. //wel->ResponseCode = FAILED_DIN70121;
  10160. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10161. }
  10162. else if (ShmInternalComm->ChargingPermission == FALSE)
  10163. {
  10164. //wel->ResponseCode = FAILED_DIN70121;
  10165. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_Shutdown;
  10166. }
  10167. //Isolation Status
  10168. if (sys->IsolationStatus == GFD_Invalid) //0:invalid (on going)
  10169. {
  10170. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Invalid; //0
  10171. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10172. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10173. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_WeldingDetectionRes]IsolationStatus = %d", sys->IsolationStatus);
  10174. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10175. Update_V2G_Flow_Status(Other_Fault);
  10176. errn = -1;
  10177. }
  10178. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  10179. {
  10180. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Valid; //1
  10181. }
  10182. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  10183. {
  10184. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  10185. }
  10186. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  10187. {
  10188. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  10189. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10190. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10191. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_din_WeldingDetectionRes]GFD_Fault => Emergency Shutdown");
  10192. Update_V2G_Flow_Status(Other_Fault);
  10193. errn = -1;
  10194. }
  10195. else //GFD_No_IMD or other unexpected status
  10196. {
  10197. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Fault; //3
  10198. wel->DC_EVSEStatus.EVSEStatusCode = dinDC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10199. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10200. sprintf((char*)buf_log_evcomm, "[Error][Proc_din_WeldingDetectionRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  10201. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10202. Update_V2G_Flow_Status(Other_Fault);
  10203. errn = -1;
  10204. }
  10205. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10206. #if PARAMETER_NORMAL_MODE == ENABLE
  10207. SHM_Read_din_WeldingDetectionRes(&ccs_exi_doc_DIN, ShmCcsData);
  10208. #else
  10209. Sudo_Parameter_din_WeldingDetectionRes();
  10210. #endif
  10211. //STEP 4: ============ Encode and Send Response Message ===========
  10212. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  10213. {
  10214. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_din_WeldingDetectionRes][Error]Tx encoded msg error");
  10215. errn = -1;
  10216. }
  10217. //STEP 5: ============ Update Flags ===========
  10218. return errn;
  10219. }
  10220. /*===========================================================================
  10221. FUNCTION: Proc_iso1_WeldingDetectionRes
  10222. DESCRIPTION:
  10223. PRE-CONDITION:
  10224. INPUT:
  10225. OUTPUT:
  10226. GLOBAL VARIABLES:
  10227. =============================================================================*/
  10228. int Proc_iso1_WeldingDetectionRes(int AcceptFd)
  10229. {
  10230. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10231. //if it is not the same, the packet should be ignored.
  10232. //STEP 1: ============ Initialize ============
  10233. //int i = 0;
  10234. int errn = 0;
  10235. bitstream_t v2g_tx_stream;
  10236. static struct WeldingDetectionResponse_ISO15118_2014 *wel;
  10237. static struct ChargingInfoData *sys;
  10238. size_t pos = 0;
  10239. v2g_tx_stream.pos = &pos;
  10240. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10241. v2g_tx_stream.data = V2GTP_Tx_buf;
  10242. wel = &ShmCcsData->V2GMessage_ISO15118_2014.WeldingDetectionResponse;
  10243. sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10244. wel->ResponseCode = OK_ISO15118_2014;
  10245. //[HEADER] Check Req SessionID
  10246. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  10247. {
  10248. wel->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  10249. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10250. errn = -1;
  10251. }
  10252. //Check for SequenceError
  10253. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10254. {
  10255. wel->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10256. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10257. errn = -1;
  10258. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10259. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10260. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10261. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10262. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10263. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10264. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10265. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10266. }
  10267. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10268. SAVE_PhysicalValueType_ISO15118_2014(&wel->EVSEPresentVoltage, (int) (sys->PresentChargingVoltage * 10), V_ISO15118_2014);
  10269. //EVSE Status Code
  10270. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Ready;
  10271. //Check for CSU command of "Stop by EVSE"
  10272. if (sys->DC_EVSEStatus == EVSE_Shutdown)
  10273. {
  10274. //wel->ResponseCode = FAILED_ISO15118_2014;
  10275. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  10276. }
  10277. else if (sys->DC_EVSEStatus == EVSE_EmergencyShutdown)
  10278. {
  10279. //wel->ResponseCode = FAILED_ISO15118_2014;
  10280. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10281. }
  10282. else if (ShmInternalComm->ChargingPermission == FALSE)
  10283. {
  10284. //wel->ResponseCode = FAILED_ISO15118_2014;
  10285. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_Shutdown;
  10286. }
  10287. //Isolation Status
  10288. if (sys->IsolationStatus == GFD_Invalid) //0: invalid (on going)
  10289. {
  10290. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Invalid; //0
  10291. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10292. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10293. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_WeldingDetectionRes]IsolationStatus = %d", sys->IsolationStatus);
  10294. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10295. Update_V2G_Flow_Status(Other_Fault);
  10296. errn = -1;
  10297. }
  10298. else if (sys->IsolationStatus == GFD_Valid) //1: valid
  10299. {
  10300. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Valid; //1
  10301. }
  10302. else if (sys->IsolationStatus == GFD_Warning) //2: warning
  10303. {
  10304. wel->DC_EVSEStatus.EVSEIsolationStatus = dinisolationLevelType_Warning; //2
  10305. }
  10306. else if (sys->IsolationStatus == GFD_Fault) //3: fault
  10307. {
  10308. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  10309. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10310. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10311. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error][Proc_iso1_WeldingDetectionRes]GFD_Fault => EmergencyShutdown");
  10312. Update_V2G_Flow_Status(Other_Fault);
  10313. errn = -1;
  10314. }
  10315. else
  10316. {
  10317. wel->DC_EVSEStatus.EVSEIsolationStatus = iso1isolationLevelType_Fault; //3
  10318. wel->DC_EVSEStatus.DC_EVSEStatusCode = iso1DC_EVSEStatusCodeType_EVSE_EmergencyShutdown;
  10319. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  10320. sprintf((char*)buf_log_evcomm, "[Error][Proc_iso1_WeldingDetectionRes]IsolationStatus = %d(undefined)", sys->IsolationStatus);
  10321. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10322. Update_V2G_Flow_Status(Other_Fault);
  10323. errn = -1;
  10324. }
  10325. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10326. #if PARAMETER_NORMAL_MODE == ENABLE
  10327. SHM_Read_iso1_WeldingDetectionRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10328. #else
  10329. Sudo_Parameter_iso1_WeldingDetectionRes();
  10330. #endif
  10331. //STEP 4: ============ Encode and Send Response Message ===========
  10332. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10333. {
  10334. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Proc_iso1_WeldingDetectionRes][Error]Tx encoded msg error");
  10335. errn = -1;
  10336. }
  10337. //STEP 5: ============ Update Flags ===========
  10338. return errn;
  10339. }
  10340. /*===========================================================================
  10341. FUNCTION: Proc_din_WeldingDetectionReq
  10342. DESCRIPTION:
  10343. PRE-CONDITION:
  10344. INPUT:
  10345. OUTPUT:
  10346. GLOBAL VARIABLES:
  10347. =============================================================================*/
  10348. int Proc_din_WeldingDetectionReq(int AcceptFd)
  10349. {
  10350. int errn = 0;
  10351. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]WeldingDetectionReq\n");
  10352. //Print the decoded XML Document
  10353. PRINT_XML_DOC_DIN_WeldingDetectionReq(&ccs_exi_doc_DIN);
  10354. //Save into Share Memory
  10355. SHM_Save_din_WeldingDetectionReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  10356. //Check for EV Error Code
  10357. Check_EVErrorCode(ShmCcsData->V2GMessage_DIN70121.WeldingDetectionRequest.DC_EVStatus.EVErrorCode);
  10358. errn = Proc_din_WeldingDetectionRes(AcceptFd);
  10359. if (errn == 0)
  10360. {
  10361. //send response successfully.
  10362. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]WeldingDetectionRes\n");
  10363. }
  10364. else
  10365. {
  10366. sprintf((char*)buf_log_evcomm,
  10367. "[Error]Proc_din_WeldingDetectionRes(): %d (DEC)",
  10368. errn);
  10369. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10370. }
  10371. return errn;
  10372. }
  10373. /*===========================================================================
  10374. FUNCTION: Proc_iso1_WeldingDetectionReq
  10375. DESCRIPTION:
  10376. PRE-CONDITION:
  10377. INPUT:
  10378. OUTPUT:
  10379. GLOBAL VARIABLES:
  10380. =============================================================================*/
  10381. int Proc_iso1_WeldingDetectionReq(int AcceptFd)
  10382. {
  10383. int errn = 0;
  10384. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][RX]WeldingDetectionReq\n");
  10385. //Print the decoded XML Document
  10386. PRINT_XML_DOC_ISO1_WeldingDetectionReq(&ccs_exi_doc_ISO1);
  10387. //Save into Share Memory
  10388. SHM_Save_iso1_WeldingDetectionReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10389. //Check for EV Error Code
  10390. Check_EVErrorCode(ShmCcsData->V2GMessage_ISO15118_2014.WeldingDetectionRequest.DC_EVStatus.EVErrorCode);
  10391. errn = Proc_iso1_WeldingDetectionRes(AcceptFd);
  10392. if (errn == 0)
  10393. {
  10394. //send response successfully.
  10395. SAVE_SYS_LOG_MSG_EVCOMM("[V2G][TX]WeldingDetectionRes\n");
  10396. }
  10397. else
  10398. {
  10399. sprintf((char*)buf_log_evcomm,
  10400. "[Error]Proc_iso1_WeldingDetectionRes(): %d (DEC)",
  10401. errn);
  10402. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10403. }
  10404. return errn;
  10405. }
  10406. /*===========================================================================
  10407. FUNCTION: SHM_Init_din_SessionStopRes
  10408. DESCRIPTION:
  10409. PRE-CONDITION:
  10410. INPUT:
  10411. 1. shm_ccs
  10412. OUTPUT:
  10413. 1. shm_ccs
  10414. GLOBAL VARIABLES:
  10415. =============================================================================*/
  10416. void SHM_Init_din_SessionStopRes(struct CcsData *shm_ccs)
  10417. {
  10418. struct SessionStopResponse_DIN70121 *in;
  10419. in = &shm_ccs->V2GMessage_DIN70121.SessionStopResponse;
  10420. //----- [BODY (1/3)] ResponseCode -----
  10421. in->ResponseCode = dinresponseCodeType_OK;
  10422. }
  10423. /*===========================================================================
  10424. FUNCTION: Sudo_Parameter_din_SessionStopRes
  10425. DESCRIPTION:
  10426. PRE-CONDITION:
  10427. INPUT:
  10428. OUTPUT:
  10429. GLOBAL VARIABLES:
  10430. =============================================================================*/
  10431. void Sudo_Parameter_din_SessionStopRes()
  10432. {
  10433. init_dinBodyType(&ccs_exi_doc_DIN.V2G_Message.Body);
  10434. init_dinSessionStopResType(&ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes);
  10435. ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes_isUsed = 1u;
  10436. //----- [BODY (1/3)] ResponseCode -----
  10437. struct dinSessionStopResType *res;
  10438. res = &ccs_exi_doc_DIN.V2G_Message.Body.SessionStopRes;
  10439. res->ResponseCode = dinresponseCodeType_OK;
  10440. }
  10441. /*===========================================================================
  10442. FUNCTION: Sudo_Parameter_iso1_SessionStopRes
  10443. DESCRIPTION:
  10444. PRE-CONDITION:
  10445. INPUT:
  10446. OUTPUT:
  10447. GLOBAL VARIABLES:
  10448. =============================================================================*/
  10449. void Sudo_Parameter_iso1_SessionStopRes()
  10450. {
  10451. init_iso1BodyType(&ccs_exi_doc_ISO1.V2G_Message.Body);
  10452. init_iso1SessionStopResType(&ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes);
  10453. ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes_isUsed = 1u;
  10454. //----- [BODY (1/3)] ResponseCode -----
  10455. struct iso1SessionStopResType *res;
  10456. res = &ccs_exi_doc_ISO1.V2G_Message.Body.SessionStopRes;
  10457. res->ResponseCode = iso1responseCodeType_OK;
  10458. }
  10459. /*===========================================================================
  10460. FUNCTION: Proc_din_SessionStopRes
  10461. DESCRIPTION:
  10462. PRE-CONDITION:
  10463. INPUT:
  10464. OUTPUT:
  10465. GLOBAL VARIABLES:
  10466. =============================================================================*/
  10467. int Proc_din_SessionStopRes(int AcceptFd)
  10468. {
  10469. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10470. //if it is not the same, the packet should be ignored.
  10471. //STEP 1: ============ Initialize ============
  10472. //int i = 0;
  10473. int errn = 0;
  10474. bitstream_t v2g_tx_stream;
  10475. struct SessionStopResponse_DIN70121 *stp;
  10476. size_t pos = 0;
  10477. v2g_tx_stream.pos = &pos;
  10478. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10479. v2g_tx_stream.data = V2GTP_Tx_buf;
  10480. stp = &ShmCcsData->V2GMessage_DIN70121.SessionStopResponse;
  10481. stp->ResponseCode = OK_DIN70121;
  10482. //[HEADER] Check Req SessionID
  10483. if (Check_din_V2G_Rx_MSG_SessionID(&ccs_exi_doc_DIN) < 0)
  10484. {
  10485. stp->ResponseCode = dinresponseCodeType_FAILED_UnknownSession; //6
  10486. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10487. errn = -1;
  10488. }
  10489. //Check for SequenceError
  10490. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10491. {
  10492. stp->ResponseCode = dinresponseCodeType_FAILED_SequenceError; //5
  10493. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10494. errn = -1;
  10495. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10496. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10497. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10498. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10499. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10500. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10501. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10502. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10503. }
  10504. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10505. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10506. #if PARAMETER_NORMAL_MODE == ENABLE
  10507. SHM_Read_din_SessionStopRes(&ccs_exi_doc_DIN, ShmCcsData);
  10508. #else
  10509. Sudo_Parameter_din_SessionStopRes();
  10510. #endif
  10511. //STEP 4: ============ Encode and Send Response Message ===========
  10512. if (send_encoded_din_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_DIN) != 0)
  10513. {
  10514. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]SessionStopRes: fail");
  10515. errn = -1;
  10516. }
  10517. else
  10518. {
  10519. //send response successfully.
  10520. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]SessionStopRes");
  10521. }
  10522. //STEP 5: ============ Update Flags ===========
  10523. EVCOMM_SYS_INFO.ConnectorLocked = FALSE; //Indicating CSU that the Connector is unlocked.
  10524. //Once this is set, the CSU should
  10525. // =========== Annouce to CSU [To-Be Implemented]=============
  10526. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE; //This should be also added to EV Error events.
  10527. // =========== Re-initialized [To-Be Implemented]=============
  10528. //Keep 5% PWM for 2 seconds
  10529. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 2");
  10530. sleep(1);
  10531. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 1");
  10532. sleep(1);
  10533. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 0");
  10534. OutputCpPwmDuty(100);
  10535. //[To-Do] Reset All Share memory
  10536. //[To-Do] CCS Module enter "idle" mode and CSU should check for this state.
  10537. //system("reboot -f");
  10538. //sleep(5);
  10539. //system("reboot -f");
  10540. return errn;
  10541. }
  10542. /*===========================================================================
  10543. FUNCTION: Proc_iso1_SessionStopRes
  10544. DESCRIPTION:
  10545. PRE-CONDITION:
  10546. INPUT:
  10547. OUTPUT:
  10548. GLOBAL VARIABLES:
  10549. =============================================================================*/
  10550. int Proc_iso1_SessionStopRes(int AcceptFd)
  10551. {
  10552. //[Joseph, To-Do] Check SessionID of ServiceDiscoveryReq,
  10553. //if it is not the same, the packet should be ignored.
  10554. //STEP 1: ============ Initialize ============
  10555. //int i = 0;
  10556. int errn = 0;
  10557. bitstream_t v2g_tx_stream;
  10558. struct SessionStopResponse_ISO15118_2014 *stp;
  10559. //struct ChargingInfoData *sys;
  10560. size_t pos = 0;
  10561. v2g_tx_stream.pos = &pos;
  10562. v2g_tx_stream.size = V2GTP_MSG_TX_BUFFER_SIZE; //(64*1024) //65,536 = 65.5KB
  10563. v2g_tx_stream.data = V2GTP_Tx_buf;
  10564. stp = &ShmCcsData->V2GMessage_ISO15118_2014.SessionStopResponse;
  10565. //sys = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  10566. stp->ResponseCode = OK_ISO15118_2014;
  10567. //[HEADER] Check Req SessionID
  10568. if (Check_iso1_V2G_Rx_MSG_SessionID(&ccs_exi_doc_ISO1) < 0)
  10569. {
  10570. stp->ResponseCode = iso1responseCodeType_FAILED_UnknownSession; //6
  10571. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]unmatched SessionID => End_Process");
  10572. errn = -1;
  10573. }
  10574. //Check for SequenceError
  10575. if (EVCOMM_SYS_INFO.SequenceError == TRUE)
  10576. {
  10577. stp->ResponseCode = iso1responseCodeType_FAILED_SequenceError; //5
  10578. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[ERROR]SequenceError => End_Process");
  10579. errn = -1;
  10580. //Update_ShmStatusCode(); //[To-Do] to be implemented
  10581. //CCS_SECC_ResponseCode_FAILED_SequenceError (023758)
  10582. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  10583. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  10584. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  10585. ShmStatusCodeData->PresentStatusCode[0][3] = 7;
  10586. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  10587. ShmStatusCodeData->PresentStatusCode[0][5] = 8;
  10588. }
  10589. //STEP 2: ============ Modifiy Parameter of ShmCcsData ============
  10590. //STEP 3: ============ Save Parameters from ShmCcsData to EXI Engine Buffer ============
  10591. #if PARAMETER_NORMAL_MODE == ENABLE
  10592. SHM_Read_iso1_SessionStopRes(&ccs_exi_doc_ISO1, ShmCcsData);
  10593. #else
  10594. Sudo_Parameter_iso1_SessionStopRes();
  10595. #endif
  10596. //STEP 4: ============ Encode and Send Response Message ===========
  10597. if (send_encoded_iso1_V2GTP_Stream(AcceptFd, &v2g_tx_stream, &ccs_exi_doc_ISO1) != 0)
  10598. {
  10599. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]SessionStopRes: fail");
  10600. errn = -1;
  10601. }
  10602. else
  10603. {
  10604. //send response successfully.
  10605. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][TX]SessionStopRes");
  10606. }
  10607. //STEP 5: ============ Update Flags ===========
  10608. EVCOMM_SYS_INFO.ConnectorLocked = FALSE; //Indicating CSU that the Connector is unlocked.
  10609. //Once this is set, the CSU should
  10610. // =========== Annouce to CSU [To-Be Implemented]=============
  10611. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE; //This should be also added to EV Error events.
  10612. // =========== Re-initialized [To-Be Implemented]=============
  10613. //Keep 5% PWM for 2 seconds
  10614. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 2");
  10615. sleep(1);
  10616. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 1");
  10617. sleep(1);
  10618. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 5\% countdown: 0");
  10619. OutputCpPwmDuty(100);
  10620. //[To-Do] Reset All Share memory
  10621. //[To-Do] CCS Module enter "idle" mode and CSU should check for this state.
  10622. //system("reboot -f");
  10623. //sleep(5);
  10624. //system("reboot -f");
  10625. return errn;
  10626. }
  10627. /*===========================================================================
  10628. FUNCTION: Proc_din_SessionStopReq
  10629. DESCRIPTION:
  10630. PRE-CONDITION:
  10631. INPUT:
  10632. OUTPUT:
  10633. GLOBAL VARIABLES:
  10634. =============================================================================*/
  10635. int Proc_din_SessionStopReq(int AcceptFd)
  10636. {
  10637. int errn = 0;
  10638. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]SessionStopReq");
  10639. //Print the decoded XML Document
  10640. PRINT_XML_DOC_DIN_SessionStopReq(&ccs_exi_doc_DIN);
  10641. //Save into Share Memory
  10642. SHM_Save_din_SessionStopReq(ShmCcsData, &ccs_exi_doc_DIN, ShmSysConfigAndInfo);
  10643. errn = Proc_din_SessionStopRes(AcceptFd);
  10644. if (errn == 0)
  10645. {
  10646. //send response successfully.
  10647. }
  10648. else
  10649. {
  10650. sprintf((char*)buf_log_evcomm,
  10651. "[Error][SeccComm][Proc_din_SessionStopReq]Proc_iso1_SessionStopRes(): %d (DEC)",
  10652. errn);
  10653. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10654. }
  10655. return errn;
  10656. }
  10657. /*===========================================================================
  10658. FUNCTION: Proc_iso1_SessionStopReq
  10659. DESCRIPTION:
  10660. PRE-CONDITION:
  10661. INPUT:
  10662. OUTPUT:
  10663. GLOBAL VARIABLES:
  10664. =============================================================================*/
  10665. int Proc_iso1_SessionStopReq(int AcceptFd)
  10666. {
  10667. int errn = 0;
  10668. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]SessionStopReq");
  10669. //Print the decoded XML Document
  10670. PRINT_XML_DOC_ISO1_SessionStopReq(&ccs_exi_doc_ISO1);
  10671. //Save into Share Memory
  10672. SHM_Save_iso1_SessionStopReq(ShmCcsData, &ccs_exi_doc_ISO1, ShmSysConfigAndInfo);
  10673. errn = Proc_iso1_SessionStopRes(AcceptFd);
  10674. if (errn == 0)
  10675. {
  10676. //send response successfully.
  10677. }
  10678. else
  10679. {
  10680. sprintf((char*)buf_log_evcomm,
  10681. "[Error][SeccComm][Proc_iso1_SessionStopReq]Proc_iso1_SessionStopRes(): %d (DEC)",
  10682. errn);
  10683. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10684. }
  10685. return errn;
  10686. }
  10687. /*===========================================================================
  10688. FUNCTION: V2gMsg_Process_din
  10689. DESCRIPTION:
  10690. PRE-CONDITION:
  10691. INPUT:
  10692. 1. V2gFlowStatus
  10693. OUTPUT:
  10694. GLOBAL VARIABLES:
  10695. 1. V2gFlowStatus
  10696. =============================================================================*/
  10697. int V2gMsg_Process_din(int AcceptFd)
  10698. {
  10699. unsigned char req_is_responsed = FALSE;
  10700. while (req_is_responsed == FALSE)
  10701. {
  10702. //Check if it is in End_Process
  10703. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  10704. {
  10705. break;
  10706. }
  10707. switch(V2gFlowStatus)
  10708. {
  10709. //-------------------------------------------
  10710. case SupportedAppProtocolRequest:
  10711. {
  10712. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  10713. {
  10714. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  10715. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  10716. {
  10717. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10718. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  10719. }
  10720. else
  10721. {
  10722. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]supportedAppProtocolResReq: fail");
  10723. Update_V2G_Flow_Status(Other_Fault);
  10724. }
  10725. }
  10726. req_is_responsed = TRUE;
  10727. break;
  10728. }
  10729. case SupportedAppProtocolResponse:
  10730. {
  10731. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  10732. {
  10733. Update_V2G_Flow_Status(SessionSetupRequest);
  10734. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10735. }
  10736. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10737. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10738. {
  10739. sprintf((char*)buf_log_evcomm,
  10740. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10741. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10742. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10743. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10744. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10745. }
  10746. else
  10747. {
  10748. }
  10749. break;
  10750. }
  10751. //-------------------------------------------
  10752. case SessionSetupRequest: //19
  10753. {
  10754. if (Proc_din_SessionSetupReq(AcceptFd) == 0)
  10755. {
  10756. Update_V2G_Flow_Status(SessionSetupResponse);
  10757. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10758. }
  10759. else
  10760. {
  10761. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionSetupReqRes: fail");
  10762. Update_V2G_Flow_Status(Other_Fault);
  10763. }
  10764. req_is_responsed = TRUE;
  10765. break;
  10766. }
  10767. case SessionSetupResponse: //20
  10768. {
  10769. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  10770. {
  10771. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  10772. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10773. }
  10774. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10775. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10776. {
  10777. sprintf((char*)buf_log_evcomm,
  10778. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10779. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10780. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10781. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10782. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10783. }
  10784. else
  10785. {
  10786. }
  10787. break;
  10788. }
  10789. //-------------------------------------------
  10790. case ServiceDiscoveryRequest: //21
  10791. {
  10792. if (Proc_din_ServiceDiscoveryReq(AcceptFd) == 0)
  10793. {
  10794. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  10795. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10796. }
  10797. else
  10798. {
  10799. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceDiscoveryReqRes: fail");
  10800. Update_V2G_Flow_Status(Other_Fault);
  10801. }
  10802. req_is_responsed = TRUE;
  10803. break;
  10804. }
  10805. case ServiceDiscoveryResponse: //22
  10806. {
  10807. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  10808. {
  10809. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  10810. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10811. }
  10812. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10813. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10814. {
  10815. sprintf((char*)buf_log_evcomm, "[ERROR]SequenceError(%d) => Tx Res MSG", EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10816. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10817. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10818. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10819. }
  10820. else
  10821. {
  10822. }
  10823. break;
  10824. }
  10825. //-------------------------------------------
  10826. case ServiceAndPaymentSelectionRequest: //25
  10827. {
  10828. if (Proc_din_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  10829. {
  10830. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  10831. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10832. }
  10833. else
  10834. {
  10835. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceAndPaymentSelectionReqRes: fail");
  10836. Update_V2G_Flow_Status(Other_Fault);
  10837. }
  10838. req_is_responsed = TRUE;
  10839. break;
  10840. }
  10841. case ServiceAndPaymentSelectionResponse: //26
  10842. {
  10843. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  10844. {
  10845. Update_V2G_Flow_Status(AuthorizationRequest);
  10846. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10847. }
  10848. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10849. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10850. {
  10851. sprintf((char*)buf_log_evcomm,
  10852. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10853. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10854. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10855. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10856. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10857. }
  10858. else
  10859. {
  10860. }
  10861. break;
  10862. }
  10863. //-------------------------------------------
  10864. //case ContractAuthenticationReq:
  10865. case AuthorizationRequest: //29
  10866. {
  10867. if (Proc_din_ContractAuthenticationReq(AcceptFd) == 0)
  10868. {
  10869. Update_V2G_Flow_Status(AuthorizationResponse);
  10870. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10871. }
  10872. else
  10873. {
  10874. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  10875. Update_V2G_Flow_Status(Other_Fault);
  10876. }
  10877. req_is_responsed = TRUE;
  10878. break;
  10879. }
  10880. case AuthorizationResponse: //30
  10881. {
  10882. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  10883. {
  10884. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10885. if (Proc_din_ContractAuthenticationReq(AcceptFd) == 0)
  10886. {
  10887. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10888. }
  10889. else
  10890. {
  10891. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  10892. Update_V2G_Flow_Status(Other_Fault);
  10893. }
  10894. req_is_responsed = TRUE;
  10895. }
  10896. //Check for ChargeParameterDiscoveryReq
  10897. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  10898. {
  10899. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10900. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  10901. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  10902. ftime(&SeqStartTime);
  10903. #endif
  10904. }
  10905. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  10906. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  10907. {
  10908. sprintf((char*)buf_log_evcomm,
  10909. "[ERROR]SequenceError(%d) => Tx Res MSG",
  10910. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10911. EVCOMM_SYS_INFO.SequenceError = TRUE;
  10912. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  10913. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10914. }
  10915. else
  10916. {
  10917. }
  10918. break;
  10919. }
  10920. //-------------------------------------------
  10921. case ChargeParameterDiscoveryRequest: //35
  10922. {
  10923. if (Proc_din_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  10924. {
  10925. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  10926. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10927. }
  10928. else
  10929. {
  10930. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  10931. Update_V2G_Flow_Status(Other_Fault);
  10932. }
  10933. req_is_responsed = TRUE;
  10934. break;
  10935. }
  10936. case ChargeParameterDiscoveryResponse:
  10937. {
  10938. //STEP 1: Check for Process Timeout
  10939. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  10940. ftime(&SeqEndTime);
  10941. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  10942. {
  10943. sprintf((char*)buf_log_evcomm,
  10944. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  10945. DiffTimeb(SeqStartTime, SeqEndTime),
  10946. V2G_SECC_ChargingParameter_Performance_Time);
  10947. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  10948. Update_V2G_Flow_Status(Sequence_Timeout);
  10949. break;
  10950. }
  10951. #endif
  10952. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  10953. {
  10954. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10955. if (Proc_din_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  10956. {
  10957. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10958. }
  10959. else
  10960. {
  10961. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  10962. Update_V2G_Flow_Status(Other_Fault);
  10963. }
  10964. req_is_responsed = TRUE;
  10965. break;
  10966. }
  10967. //STEP 2: Check for CableCheckReq message
  10968. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  10969. {
  10970. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10971. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]CableCheckReqReq: isolated?");
  10972. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  10973. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  10974. Update_V2G_Flow_Status(CableCheckRequest);
  10975. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  10976. ftime(&SeqStartTime);
  10977. #endif
  10978. }
  10979. //STEP 3: Wait for PowerDeliveryReq Message
  10980. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  10981. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  10982. {
  10983. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  10984. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  10985. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  10986. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  10987. ftime(&SeqStartTime);
  10988. #endif
  10989. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  10990. {
  10991. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  10992. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  10993. }
  10994. else
  10995. {
  10996. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  10997. Update_V2G_Flow_Status(Other_Fault);
  10998. }
  10999. }
  11000. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11001. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11002. {
  11003. sprintf((char*)buf_log_evcomm,
  11004. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11005. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11006. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11007. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11008. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11009. }
  11010. else
  11011. {
  11012. }
  11013. break;
  11014. }
  11015. //-------------------------------------------
  11016. case CableCheckRequest: //37
  11017. {
  11018. //STEP 3: Execute Cable Check Process
  11019. if (Proc_din_CableCheckReq(AcceptFd) == 0)
  11020. {
  11021. Update_V2G_Flow_Status(CableCheckResponse);
  11022. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11023. }
  11024. else
  11025. {
  11026. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  11027. Update_V2G_Flow_Status(Other_Fault);
  11028. }
  11029. req_is_responsed = TRUE;
  11030. break;
  11031. }
  11032. case CableCheckResponse: //38
  11033. {
  11034. //STEP 1: Check for Process Timeout
  11035. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11036. ftime(&SeqEndTime);
  11037. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  11038. {
  11039. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CableCheck] end counting...");
  11040. sprintf((char*)buf_log_evcomm,
  11041. "CableCheck Timeout - (%.02lf of %d ms)\n",
  11042. DiffTimeb(SeqStartTime, SeqEndTime),
  11043. V2G_SECC_CableCheck_Performance_Time);
  11044. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11045. Update_V2G_Flow_Status(Sequence_Timeout);
  11046. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11047. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  11048. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11049. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11050. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11051. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  11052. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  11053. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  11054. break;
  11055. }
  11056. #endif
  11057. //STEP 2: Check for CableCheckReq message
  11058. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  11059. {
  11060. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11061. //STEP 3: Execute Cable Check Process
  11062. if (Proc_din_CableCheckReq(AcceptFd) == 0)
  11063. {
  11064. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11065. }
  11066. else
  11067. {
  11068. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  11069. Update_V2G_Flow_Status(Other_Fault);
  11070. }
  11071. req_is_responsed = TRUE;
  11072. }
  11073. //STEP 3: Check for PreChargeReq message
  11074. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  11075. {
  11076. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11077. Update_V2G_Flow_Status(PreChargeRequest);
  11078. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PreChargeReqReq: waiting for precharge voltage...");
  11079. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  11080. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  11081. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11082. ftime(&SeqStartTime);
  11083. #endif
  11084. }
  11085. //STEP 3: Wait for PowerDeliveryReq Message
  11086. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11087. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11088. {
  11089. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11090. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11091. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  11092. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11093. ftime(&SeqStartTime);
  11094. #endif
  11095. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  11096. {
  11097. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11098. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11099. }
  11100. else
  11101. {
  11102. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11103. Update_V2G_Flow_Status(Other_Fault);
  11104. }
  11105. }
  11106. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11107. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11108. {
  11109. sprintf((char*)buf_log_evcomm,
  11110. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11111. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11112. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11113. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11114. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11115. }
  11116. else
  11117. {
  11118. }
  11119. break;
  11120. }
  11121. //-------------------------------------------
  11122. case PreChargeRequest: //39
  11123. {
  11124. if (Proc_din_PreChargeReq(AcceptFd) == 0)
  11125. {
  11126. Update_V2G_Flow_Status(PreChargeResponse);
  11127. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11128. }
  11129. else
  11130. {
  11131. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  11132. Update_V2G_Flow_Status(Other_Fault);
  11133. }
  11134. req_is_responsed = TRUE;
  11135. break;
  11136. }
  11137. case PreChargeResponse: //40
  11138. {
  11139. //STEP 1: Check for Process Timeout
  11140. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11141. ftime(&SeqEndTime);
  11142. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  11143. {
  11144. sprintf((char*)buf_log_evcomm,
  11145. "Precharge Timeout - (%.02lf of %d ms)\n",
  11146. DiffTimeb(SeqStartTime, SeqEndTime),
  11147. V2G_SECC_PreCharge_Performance_Time);
  11148. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11149. Update_V2G_Flow_Status(Sequence_Timeout);
  11150. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11151. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  11152. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11153. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11154. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11155. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  11156. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  11157. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  11158. break;
  11159. }
  11160. #endif
  11161. //STEP 2: Check for PreChargeReq message
  11162. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  11163. {
  11164. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11165. if (Proc_din_PreChargeReq(AcceptFd) == 0)
  11166. {
  11167. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11168. }
  11169. else
  11170. {
  11171. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  11172. Update_V2G_Flow_Status(Other_Fault);
  11173. }
  11174. req_is_responsed = TRUE;
  11175. }
  11176. //STEP 3: Check for PowerDeliveryReq message
  11177. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11178. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11179. {
  11180. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11181. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  11182. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  11183. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11184. ftime(&SeqStartTime);
  11185. #endif
  11186. }
  11187. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11188. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11189. {
  11190. sprintf((char*)buf_log_evcomm,
  11191. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11192. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11193. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11194. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11195. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11196. }
  11197. else
  11198. {
  11199. }
  11200. break;
  11201. }
  11202. //-------------------------------------------
  11203. case PowerDeliveryRequestStart: //41
  11204. {
  11205. if (Proc_din_PowerDeliveryStartReq(AcceptFd) == 0)
  11206. {
  11207. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  11208. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11209. }
  11210. else
  11211. {
  11212. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStartReqRes: fail");
  11213. Update_V2G_Flow_Status(Other_Fault);
  11214. }
  11215. req_is_responsed = TRUE;
  11216. break;
  11217. }
  11218. case PowerDeliveryResponsetStart: //42
  11219. {
  11220. //STEP 1: Check for Process Timeout
  11221. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11222. if (ccs_exi_doc_DIN.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  11223. {
  11224. ftime(&SeqEndTime);
  11225. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  11226. {
  11227. sprintf((char*)buf_log_evcomm,
  11228. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  11229. DiffTimeb(SeqStartTime, SeqEndTime),
  11230. 2000);
  11231. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11232. Update_V2G_Flow_Status(Sequence_Timeout);
  11233. }
  11234. break;
  11235. }
  11236. #endif
  11237. //STEP 2: Wait for CurrentDemandReq Message
  11238. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  11239. {
  11240. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11241. Update_V2G_Flow_Status(CurrentDemandRequest);
  11242. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]CurrentDemandReqReq: energy transfering...");
  11243. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  11244. }
  11245. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11246. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11247. {
  11248. sprintf((char*)buf_log_evcomm,
  11249. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11250. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11251. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11252. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11253. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11254. }
  11255. else
  11256. {
  11257. }
  11258. break;
  11259. }
  11260. //-------------------------------------------
  11261. case CurrentDemandRequest: //45,
  11262. {
  11263. if (Proc_din_CurrentDemandReq(AcceptFd) == 0)
  11264. {
  11265. Update_V2G_Flow_Status(CurrentDemandResponse);
  11266. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11267. }
  11268. else
  11269. {
  11270. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  11271. Update_V2G_Flow_Status(Other_Fault);
  11272. }
  11273. req_is_responsed = TRUE;
  11274. break;
  11275. }
  11276. case CurrentDemandResponse: //46,
  11277. {
  11278. //STEP 1: Wait for CurrentDemandReq Message
  11279. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  11280. {
  11281. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11282. if (Proc_din_CurrentDemandReq(AcceptFd) == 0)
  11283. {
  11284. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11285. }
  11286. else
  11287. {
  11288. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  11289. Update_V2G_Flow_Status(Other_Fault);
  11290. }
  11291. req_is_responsed = TRUE;
  11292. break;
  11293. }
  11294. //STEP 2: Wait for PowerDeliveryReq Message
  11295. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11296. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11297. {
  11298. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11299. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11300. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  11301. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11302. ftime(&SeqStartTime);
  11303. #endif
  11304. }
  11305. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11306. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11307. {
  11308. sprintf((char*)buf_log_evcomm,
  11309. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11310. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11311. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11312. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11313. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11314. }
  11315. else
  11316. {
  11317. }
  11318. break;
  11319. }
  11320. //-------------------------------------------
  11321. case PowerDeliveryRequestStop: //49,
  11322. {
  11323. if (Proc_din_PowerDeliveryStopReq(AcceptFd) == 0)
  11324. {
  11325. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11326. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11327. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11328. ftime(&SeqStartTime);
  11329. #endif
  11330. }
  11331. else
  11332. {
  11333. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11334. Update_V2G_Flow_Status(Other_Fault);
  11335. }
  11336. req_is_responsed = TRUE;
  11337. break;
  11338. }
  11339. case PowerDeliveryResponseStop: //50,
  11340. {
  11341. //STEP 1: Check for Process Timeout
  11342. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11343. ftime(&SeqEndTime);
  11344. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  11345. {
  11346. sprintf((char*)buf_log_evcomm,
  11347. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  11348. DiffTimeb(SeqStartTime, SeqEndTime),
  11349. 2000);
  11350. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11351. Update_V2G_Flow_Status(Sequence_Timeout);
  11352. break;
  11353. }
  11354. #endif
  11355. //STEP 2: Check for WeldingDetectionReq Message
  11356. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  11357. {
  11358. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11359. Update_V2G_Flow_Status(WeldingDetectionRequest);
  11360. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]WeldingDetectionReq: ongoing...");
  11361. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  11362. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11363. ftime(&SeqStartTime);
  11364. #endif
  11365. }
  11366. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  11367. {
  11368. Update_V2G_Flow_Status(SessionStopRequest);
  11369. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11370. if (Proc_din_SessionStopReq(AcceptFd) == 0)
  11371. {
  11372. Update_V2G_Flow_Status(SessionStopResponse);
  11373. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11374. }
  11375. else
  11376. {
  11377. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  11378. Update_V2G_Flow_Status(Other_Fault);
  11379. }
  11380. break;
  11381. }
  11382. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11383. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11384. {
  11385. sprintf((char*)buf_log_evcomm,
  11386. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11387. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11388. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11389. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11390. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11391. }
  11392. else
  11393. {
  11394. }
  11395. break;
  11396. }
  11397. //-------------------------------------------
  11398. case WeldingDetectionRequest: //51,
  11399. {
  11400. if (Proc_din_WeldingDetectionReq(AcceptFd) == 0)
  11401. {
  11402. Update_V2G_Flow_Status(WeldingDetectionResponse);
  11403. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11404. }
  11405. else
  11406. {
  11407. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  11408. Update_V2G_Flow_Status(Other_Fault);
  11409. }
  11410. req_is_responsed = TRUE;
  11411. break;
  11412. }
  11413. case WeldingDetectionResponse: //52,
  11414. {
  11415. //STEP 1: Check for Process Timeout
  11416. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11417. ftime(&SeqEndTime);
  11418. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  11419. {
  11420. sprintf((char*)buf_log_evcomm,
  11421. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  11422. DiffTimeb(SeqStartTime, SeqEndTime),
  11423. V2G_SECC_WeldingDetection_Performance_Time);
  11424. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11425. Update_V2G_Flow_Status(Sequence_Timeout);
  11426. break;
  11427. }
  11428. #endif
  11429. //STEP 2: Check for WeldingDetectionReq Message
  11430. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  11431. {
  11432. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11433. if (Proc_din_WeldingDetectionReq(AcceptFd) == 0)
  11434. {
  11435. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11436. }
  11437. else
  11438. {
  11439. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  11440. Update_V2G_Flow_Status(Other_Fault);
  11441. }
  11442. req_is_responsed = TRUE;
  11443. }
  11444. //STEP 3: Check for SessionStopReq Message
  11445. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  11446. {
  11447. Update_V2G_Flow_Status(SessionStopRequest);
  11448. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11449. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  11450. }
  11451. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11452. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11453. {
  11454. sprintf((char*)buf_log_evcomm,
  11455. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11456. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11457. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11458. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11459. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11460. }
  11461. else
  11462. {
  11463. }
  11464. break;
  11465. }
  11466. //-------------------------------------------
  11467. case SessionStopRequest: //53,
  11468. {
  11469. if (Proc_din_SessionStopReq(AcceptFd) == 0)
  11470. {
  11471. Update_V2G_Flow_Status(SessionStopResponse);
  11472. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11473. }
  11474. else
  11475. {
  11476. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  11477. Update_V2G_Flow_Status(Other_Fault);
  11478. }
  11479. req_is_responsed = TRUE;
  11480. break;
  11481. }
  11482. case SessionStopResponse: //54,
  11483. {
  11484. break;
  11485. }
  11486. //-------------------------------------------
  11487. default:
  11488. {
  11489. break;
  11490. }
  11491. }
  11492. usleep(1000);
  11493. }
  11494. return 0;
  11495. }
  11496. /*===========================================================================
  11497. FUNCTION: V2gMsg_Process_iso1_DC
  11498. DESCRIPTION:
  11499. PRE-CONDITION:
  11500. INPUT:
  11501. 1. V2gFlowStatus
  11502. OUTPUT:
  11503. GLOBAL VARIABLES:
  11504. 1. V2gFlowStatus
  11505. =============================================================================*/
  11506. int V2gMsg_Process_iso1_DC(int AcceptFd)
  11507. {
  11508. unsigned char req_is_responsed = FALSE;
  11509. while (req_is_responsed == FALSE)
  11510. {
  11511. //Check if it is in End_Process
  11512. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  11513. {
  11514. break;
  11515. }
  11516. switch(V2gFlowStatus)
  11517. {
  11518. //-------------------------------------------
  11519. case SupportedAppProtocolRequest:
  11520. {
  11521. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  11522. {
  11523. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  11524. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  11525. {
  11526. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11527. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  11528. }
  11529. else
  11530. {
  11531. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]supportedAppProtocolResReq: fail");
  11532. Update_V2G_Flow_Status(Other_Fault);
  11533. }
  11534. }
  11535. req_is_responsed = TRUE;
  11536. break;
  11537. }
  11538. case SupportedAppProtocolResponse:
  11539. {
  11540. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  11541. {
  11542. Update_V2G_Flow_Status(SessionSetupRequest);
  11543. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11544. }
  11545. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11546. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11547. {
  11548. sprintf((char*)buf_log_evcomm,
  11549. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11550. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11551. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11552. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11553. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11554. }
  11555. else
  11556. {
  11557. }
  11558. break;
  11559. }
  11560. //-------------------------------------------
  11561. case SessionSetupRequest: //19
  11562. {
  11563. if (Proc_iso1_SessionSetupReq(AcceptFd) == 0)
  11564. {
  11565. Update_V2G_Flow_Status(SessionSetupResponse);
  11566. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11567. }
  11568. else
  11569. {
  11570. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionSetupReqRes: fail");
  11571. Update_V2G_Flow_Status(Other_Fault);
  11572. }
  11573. req_is_responsed = TRUE;
  11574. break;
  11575. }
  11576. case SessionSetupResponse: //20
  11577. {
  11578. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  11579. {
  11580. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  11581. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11582. }
  11583. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11584. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11585. {
  11586. sprintf((char*)buf_log_evcomm,
  11587. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11588. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11589. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11590. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11591. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11592. }
  11593. else
  11594. {
  11595. }
  11596. break;
  11597. }
  11598. //-------------------------------------------
  11599. case ServiceDiscoveryRequest: //21
  11600. {
  11601. if (Proc_iso1_ServiceDiscoveryReq(AcceptFd) == 0)
  11602. {
  11603. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  11604. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11605. }
  11606. else
  11607. {
  11608. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceDiscoveryReqRes: fail");
  11609. Update_V2G_Flow_Status(Other_Fault);
  11610. }
  11611. req_is_responsed = TRUE;
  11612. break;
  11613. }
  11614. case ServiceDiscoveryResponse: //22
  11615. {
  11616. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  11617. {
  11618. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  11619. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11620. }
  11621. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11622. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11623. {
  11624. sprintf((char*)buf_log_evcomm,
  11625. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11626. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11627. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11628. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11629. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11630. }
  11631. else
  11632. {
  11633. }
  11634. break;
  11635. }
  11636. //-------------------------------------------
  11637. case ServiceAndPaymentSelectionRequest: //25
  11638. {
  11639. if (Proc_iso1_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  11640. {
  11641. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  11642. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11643. }
  11644. else
  11645. {
  11646. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceAndPaymentSelectionReqRes: fail");
  11647. Update_V2G_Flow_Status(Other_Fault);
  11648. }
  11649. req_is_responsed = TRUE;
  11650. break;
  11651. }
  11652. case ServiceAndPaymentSelectionResponse: //26
  11653. {
  11654. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11655. {
  11656. Update_V2G_Flow_Status(AuthorizationRequest);
  11657. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11658. }
  11659. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11660. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11661. {
  11662. sprintf((char*)buf_log_evcomm,
  11663. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11664. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11665. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11666. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11667. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11668. }
  11669. else
  11670. {
  11671. }
  11672. break;
  11673. }
  11674. //-------------------------------------------
  11675. //case ContractAuthenticationReq:
  11676. case AuthorizationRequest: //29
  11677. {
  11678. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  11679. {
  11680. Update_V2G_Flow_Status(AuthorizationResponse);
  11681. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11682. }
  11683. else
  11684. {
  11685. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  11686. Update_V2G_Flow_Status(Other_Fault);
  11687. }
  11688. req_is_responsed = TRUE;
  11689. break;
  11690. }
  11691. case AuthorizationResponse: //30
  11692. {
  11693. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  11694. {
  11695. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11696. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  11697. {
  11698. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11699. }
  11700. else
  11701. {
  11702. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  11703. Update_V2G_Flow_Status(Other_Fault);
  11704. }
  11705. req_is_responsed = TRUE;
  11706. }
  11707. //Check for ChargeParameterDiscoveryReq
  11708. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  11709. {
  11710. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11711. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  11712. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]ChargeParameterDiscoveryReq: CSU Permission?");
  11713. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11714. ftime(&SeqStartTime);
  11715. #endif
  11716. }
  11717. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11718. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11719. {
  11720. sprintf((char*)buf_log_evcomm,
  11721. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11722. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11723. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11724. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11725. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11726. }
  11727. else
  11728. {
  11729. }
  11730. break;
  11731. }
  11732. //-------------------------------------------
  11733. case ChargeParameterDiscoveryRequest: //35
  11734. {
  11735. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  11736. {
  11737. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  11738. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11739. }
  11740. else
  11741. {
  11742. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  11743. Update_V2G_Flow_Status(Other_Fault);
  11744. }
  11745. req_is_responsed = TRUE;
  11746. break;
  11747. }
  11748. case ChargeParameterDiscoveryResponse:
  11749. {
  11750. //STEP 1: Check for Process Timeout
  11751. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11752. ftime(&SeqEndTime);
  11753. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  11754. {
  11755. sprintf((char*)buf_log_evcomm,
  11756. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  11757. DiffTimeb(SeqStartTime, SeqEndTime),
  11758. V2G_SECC_ChargingParameter_Performance_Time);
  11759. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11760. Update_V2G_Flow_Status(Sequence_Timeout);
  11761. break;
  11762. }
  11763. #endif
  11764. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  11765. {
  11766. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11767. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  11768. {
  11769. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11770. }
  11771. else
  11772. {
  11773. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  11774. Update_V2G_Flow_Status(Other_Fault);
  11775. }
  11776. req_is_responsed = TRUE;
  11777. }
  11778. //STEP 2: Check for CableCheckReq message
  11779. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  11780. {
  11781. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11782. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]CableCheckReqReq: isolated?");
  11783. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  11784. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  11785. Update_V2G_Flow_Status(CableCheckRequest);
  11786. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11787. ftime(&SeqStartTime);
  11788. #endif
  11789. }
  11790. //STEP 3: Wait for PowerDeliveryReq Message
  11791. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11792. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11793. {
  11794. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11795. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11796. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  11797. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11798. ftime(&SeqStartTime);
  11799. #endif
  11800. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  11801. {
  11802. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11803. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11804. }
  11805. else
  11806. {
  11807. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11808. Update_V2G_Flow_Status(Other_Fault);
  11809. }
  11810. break;
  11811. }
  11812. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11813. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11814. {
  11815. sprintf((char*)buf_log_evcomm,
  11816. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11817. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11818. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11819. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11820. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11821. }
  11822. else
  11823. {
  11824. }
  11825. break;
  11826. }
  11827. //-------------------------------------------
  11828. case CableCheckRequest: //37
  11829. {
  11830. //STEP 3: Execute Cable Check Process
  11831. if (Proc_iso1_CableCheckReq(AcceptFd) == 0)
  11832. {
  11833. Update_V2G_Flow_Status(CableCheckResponse);
  11834. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11835. }
  11836. else
  11837. {
  11838. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  11839. Update_V2G_Flow_Status(Other_Fault);
  11840. }
  11841. req_is_responsed = TRUE;
  11842. break;
  11843. }
  11844. case CableCheckResponse: //38
  11845. {
  11846. //STEP 1: Check for Process Timeout
  11847. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11848. ftime(&SeqEndTime);
  11849. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  11850. {
  11851. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CableCheck] end counting...");
  11852. sprintf((char*)buf_log_evcomm,
  11853. "CableCheck Timeout - (%.02lf of %d ms)\n",
  11854. DiffTimeb(SeqStartTime, SeqEndTime),
  11855. V2G_SECC_CableCheck_Performance_Time);
  11856. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11857. Update_V2G_Flow_Status(Sequence_Timeout);
  11858. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11859. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  11860. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11861. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11862. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11863. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  11864. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  11865. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  11866. break;
  11867. }
  11868. #endif
  11869. //STEP 2: Check for CableCheckReq message
  11870. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  11871. {
  11872. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11873. //STEP 3: Execute Cable Check Process
  11874. if (Proc_iso1_CableCheckReq(AcceptFd) == 0)
  11875. {
  11876. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11877. }
  11878. else
  11879. {
  11880. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  11881. Update_V2G_Flow_Status(Other_Fault);
  11882. }
  11883. req_is_responsed = TRUE;
  11884. }
  11885. //STEP 3: Check for PreChargeReq message
  11886. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  11887. {
  11888. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11889. Update_V2G_Flow_Status(PreChargeRequest);
  11890. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PreChargeReqReq: waiting for precharge voltage...");
  11891. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  11892. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  11893. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11894. ftime(&SeqStartTime);
  11895. #endif
  11896. }
  11897. //STEP 3: Wait for PowerDeliveryReq Message
  11898. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11899. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11900. {
  11901. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  11902. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11903. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  11904. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11905. ftime(&SeqStartTime);
  11906. #endif
  11907. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  11908. {
  11909. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  11910. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11911. }
  11912. else
  11913. {
  11914. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  11915. Update_V2G_Flow_Status(Other_Fault);
  11916. }
  11917. }
  11918. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  11919. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  11920. {
  11921. sprintf((char*)buf_log_evcomm,
  11922. "[ERROR]SequenceError(%d) => Tx Res MSG",
  11923. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11924. EVCOMM_SYS_INFO.SequenceError = TRUE;
  11925. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  11926. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11927. }
  11928. else
  11929. {
  11930. }
  11931. break;
  11932. }
  11933. //-------------------------------------------
  11934. case PreChargeRequest: //39
  11935. {
  11936. if (Proc_iso1_PreChargeReq(AcceptFd) == 0)
  11937. {
  11938. Update_V2G_Flow_Status(PreChargeResponse);
  11939. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11940. }
  11941. else
  11942. {
  11943. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  11944. Update_V2G_Flow_Status(Other_Fault);
  11945. }
  11946. req_is_responsed = TRUE;
  11947. break;
  11948. }
  11949. case PreChargeResponse: //40
  11950. {
  11951. //STEP 1: Check for Process Timeout
  11952. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11953. ftime(&SeqEndTime);
  11954. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  11955. {
  11956. sprintf((char*)buf_log_evcomm,
  11957. "Precharge Timeout - (%.02lf of %d ms)\n",
  11958. DiffTimeb(SeqStartTime, SeqEndTime),
  11959. V2G_SECC_PreCharge_Performance_Time);
  11960. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  11961. Update_V2G_Flow_Status(Sequence_Timeout);
  11962. //Update_ShmStatusCode(); //[To-Do] to be implemented
  11963. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  11964. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  11965. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  11966. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  11967. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  11968. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  11969. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  11970. break;
  11971. }
  11972. #endif
  11973. //STEP 2: Check for PreChargeReq message
  11974. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  11975. {
  11976. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11977. if (Proc_iso1_PreChargeReq(AcceptFd) == 0)
  11978. {
  11979. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  11980. }
  11981. else
  11982. {
  11983. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  11984. Update_V2G_Flow_Status(Other_Fault);
  11985. }
  11986. req_is_responsed = TRUE;
  11987. }
  11988. //STEP 3: Check for PowerDeliveryReq message
  11989. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  11990. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  11991. {
  11992. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  11993. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  11994. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  11995. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  11996. ftime(&SeqStartTime);
  11997. #endif
  11998. }
  11999. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12000. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12001. {
  12002. sprintf((char*)buf_log_evcomm,
  12003. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12004. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12005. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12006. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12007. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12008. }
  12009. else
  12010. {
  12011. }
  12012. break;
  12013. }
  12014. //-------------------------------------------
  12015. case PowerDeliveryRequestStart: //41
  12016. {
  12017. if (Proc_iso1_PowerDeliveryStartReq(AcceptFd) == 0)
  12018. {
  12019. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  12020. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12021. }
  12022. else
  12023. {
  12024. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStartReqRes: fail");
  12025. Update_V2G_Flow_Status(Other_Fault);
  12026. }
  12027. req_is_responsed = TRUE;
  12028. break;
  12029. }
  12030. case PowerDeliveryResponsetStart: //42
  12031. {
  12032. //STEP 1: Check for Process Timeout
  12033. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12034. if (ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  12035. {
  12036. ftime(&SeqEndTime);
  12037. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  12038. {
  12039. sprintf((char*)buf_log_evcomm,
  12040. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  12041. DiffTimeb(SeqStartTime, SeqEndTime),
  12042. 2000);
  12043. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12044. Update_V2G_Flow_Status(Sequence_Timeout);
  12045. }
  12046. break;
  12047. }
  12048. #endif
  12049. //STEP 2: Wait for CurrentDemandReq Message
  12050. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  12051. {
  12052. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12053. Update_V2G_Flow_Status(CurrentDemandRequest);
  12054. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]CurrentDemandReqReq: energy transfering...");
  12055. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  12056. }
  12057. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12058. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12059. {
  12060. sprintf((char*)buf_log_evcomm,
  12061. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12062. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12063. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12064. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12065. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12066. }
  12067. else
  12068. {
  12069. }
  12070. break;
  12071. }
  12072. //-------------------------------------------
  12073. case CurrentDemandRequest: //45,
  12074. {
  12075. if (Proc_iso1_CurrentDemandReq(AcceptFd) == 0)
  12076. {
  12077. Update_V2G_Flow_Status(CurrentDemandResponse);
  12078. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12079. }
  12080. else
  12081. {
  12082. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  12083. Update_V2G_Flow_Status(Other_Fault);
  12084. }
  12085. req_is_responsed = TRUE;
  12086. break;
  12087. }
  12088. case CurrentDemandResponse: //46,
  12089. {
  12090. //STEP 1: Wait for CurrentDemandReq Message
  12091. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  12092. {
  12093. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12094. if (Proc_iso1_CurrentDemandReq(AcceptFd) == 0)
  12095. {
  12096. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12097. }
  12098. else
  12099. {
  12100. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  12101. Update_V2G_Flow_Status(Other_Fault);
  12102. }
  12103. req_is_responsed = TRUE;
  12104. }
  12105. //STEP 2: Wait for PowerDeliveryReq Message
  12106. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12107. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12108. {
  12109. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  12110. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12111. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  12112. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12113. ftime(&SeqStartTime);
  12114. #endif
  12115. }
  12116. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12117. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12118. {
  12119. sprintf((char*)buf_log_evcomm,
  12120. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12121. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12122. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12123. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12124. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12125. }
  12126. else
  12127. {
  12128. }
  12129. break;
  12130. }
  12131. //-------------------------------------------
  12132. case PowerDeliveryRequestStop: //49,
  12133. {
  12134. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12135. {
  12136. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12137. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12138. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12139. ftime(&SeqStartTime);
  12140. #endif
  12141. }
  12142. else
  12143. {
  12144. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  12145. Update_V2G_Flow_Status(Other_Fault);
  12146. }
  12147. req_is_responsed = TRUE;
  12148. break;
  12149. }
  12150. case PowerDeliveryResponseStop: //50,
  12151. {
  12152. //STEP 1: Check for Process Timeout
  12153. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12154. ftime(&SeqEndTime);
  12155. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  12156. {
  12157. sprintf((char*)buf_log_evcomm,
  12158. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12159. DiffTimeb(SeqStartTime, SeqEndTime),
  12160. 2000);
  12161. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12162. Update_V2G_Flow_Status(Sequence_Timeout);
  12163. break;
  12164. }
  12165. #endif
  12166. //STEP 2: Check for WeldingDetectionReq Message
  12167. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  12168. {
  12169. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12170. Update_V2G_Flow_Status(WeldingDetectionRequest);
  12171. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]WeldingDetectionReq: ongoing...");
  12172. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  12173. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12174. ftime(&SeqStartTime);
  12175. #endif
  12176. }
  12177. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12178. {
  12179. Update_V2G_Flow_Status(SessionStopRequest);
  12180. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12181. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  12182. {
  12183. Update_V2G_Flow_Status(SessionStopResponse);
  12184. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12185. }
  12186. else
  12187. {
  12188. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  12189. Update_V2G_Flow_Status(Other_Fault);
  12190. }
  12191. }
  12192. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12193. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12194. {
  12195. sprintf((char*)buf_log_evcomm,
  12196. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12197. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12198. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12199. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12200. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12201. }
  12202. else
  12203. {
  12204. }
  12205. break;
  12206. }
  12207. //-------------------------------------------
  12208. case WeldingDetectionRequest: //51,
  12209. {
  12210. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  12211. {
  12212. Update_V2G_Flow_Status(WeldingDetectionResponse);
  12213. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12214. }
  12215. else
  12216. {
  12217. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  12218. Update_V2G_Flow_Status(Other_Fault);
  12219. }
  12220. req_is_responsed = TRUE;
  12221. break;
  12222. }
  12223. case WeldingDetectionResponse: //52,
  12224. {
  12225. //STEP 1: Check for Process Timeout
  12226. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12227. ftime(&SeqEndTime);
  12228. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  12229. {
  12230. sprintf((char*)buf_log_evcomm,
  12231. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12232. DiffTimeb(SeqStartTime, SeqEndTime),
  12233. V2G_SECC_WeldingDetection_Performance_Time);
  12234. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12235. Update_V2G_Flow_Status(Sequence_Timeout);
  12236. break;
  12237. }
  12238. #endif
  12239. //STEP 2: Check for WeldingDetectionReq Message
  12240. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  12241. {
  12242. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12243. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  12244. {
  12245. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12246. }
  12247. else
  12248. {
  12249. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  12250. Update_V2G_Flow_Status(Other_Fault);
  12251. }
  12252. req_is_responsed = TRUE;
  12253. }
  12254. //STEP 3: Check for SessionStopReq Message
  12255. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12256. {
  12257. Update_V2G_Flow_Status(SessionStopRequest);
  12258. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12259. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  12260. }
  12261. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12262. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12263. {
  12264. sprintf((char*)buf_log_evcomm,
  12265. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12266. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12267. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12268. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12269. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12270. }
  12271. else
  12272. {
  12273. }
  12274. break;
  12275. }
  12276. //-------------------------------------------
  12277. case SessionStopRequest: //53,
  12278. {
  12279. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  12280. {
  12281. Update_V2G_Flow_Status(SessionStopResponse);
  12282. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12283. }
  12284. else
  12285. {
  12286. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  12287. Update_V2G_Flow_Status(Other_Fault);
  12288. }
  12289. req_is_responsed = TRUE;
  12290. break;
  12291. }
  12292. case SessionStopResponse: //54,
  12293. {
  12294. break;
  12295. }
  12296. //-------------------------------------------
  12297. default:
  12298. {
  12299. break;
  12300. }
  12301. }
  12302. usleep(1000);
  12303. }
  12304. return 0;
  12305. }
  12306. /*===========================================================================
  12307. FUNCTION: V2gMsg_Process_iso1_AC
  12308. DESCRIPTION:
  12309. PRE-CONDITION:
  12310. INPUT:
  12311. 1. V2gFlowStatus
  12312. OUTPUT:
  12313. GLOBAL VARIABLES:
  12314. 1. V2gFlowStatus
  12315. =============================================================================*/
  12316. int V2gMsg_Process_iso1_AC(int AcceptFd)
  12317. {
  12318. unsigned char req_is_responsed = FALSE;
  12319. while (req_is_responsed == FALSE)
  12320. {
  12321. //Check if it is in End_Process
  12322. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  12323. {
  12324. break;
  12325. }
  12326. switch(V2gFlowStatus)
  12327. {
  12328. //-------------------------------------------
  12329. case SupportedAppProtocolRequest: //17
  12330. {
  12331. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  12332. {
  12333. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  12334. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  12335. {
  12336. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12337. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  12338. }
  12339. else
  12340. {
  12341. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]supportedAppProtocolResReq: fail");
  12342. Update_V2G_Flow_Status(Other_Fault);
  12343. }
  12344. }
  12345. req_is_responsed = TRUE;
  12346. break;
  12347. }
  12348. case SupportedAppProtocolResponse: //18
  12349. {
  12350. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  12351. {
  12352. Update_V2G_Flow_Status(SessionSetupRequest);
  12353. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12354. }
  12355. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12356. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12357. {
  12358. sprintf((char*)buf_log_evcomm,
  12359. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12360. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12361. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12362. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12363. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12364. }
  12365. else
  12366. {
  12367. }
  12368. break;
  12369. }
  12370. //-------------------------------------------
  12371. case SessionSetupRequest: //19
  12372. {
  12373. if (Proc_iso1_SessionSetupReq(AcceptFd) == 0)
  12374. {
  12375. Update_V2G_Flow_Status(SessionSetupResponse);
  12376. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12377. }
  12378. else
  12379. {
  12380. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionSetupReqRes: fail");
  12381. Update_V2G_Flow_Status(Other_Fault);
  12382. }
  12383. req_is_responsed = TRUE;
  12384. break;
  12385. }
  12386. case SessionSetupResponse: //20
  12387. {
  12388. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  12389. {
  12390. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  12391. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12392. }
  12393. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12394. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12395. {
  12396. sprintf((char*)buf_log_evcomm,
  12397. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12398. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12399. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12400. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12401. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12402. }
  12403. else
  12404. {
  12405. }
  12406. break;
  12407. }
  12408. //-------------------------------------------
  12409. case ServiceDiscoveryRequest: //21
  12410. {
  12411. if (Proc_iso1_ServiceDiscoveryReq(AcceptFd) == 0)
  12412. {
  12413. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  12414. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12415. }
  12416. else
  12417. {
  12418. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceDiscoveryReqRes: fail");
  12419. Update_V2G_Flow_Status(Other_Fault);
  12420. }
  12421. req_is_responsed = TRUE;
  12422. break;
  12423. }
  12424. case ServiceDiscoveryResponse: //22
  12425. {
  12426. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  12427. {
  12428. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  12429. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12430. }
  12431. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12432. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12433. {
  12434. sprintf((char*)buf_log_evcomm,
  12435. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12436. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12437. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12438. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12439. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12440. }
  12441. else
  12442. {
  12443. }
  12444. break;
  12445. }
  12446. //-------------------------------------------
  12447. case ServiceAndPaymentSelectionRequest: //25
  12448. {
  12449. if (Proc_iso1_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  12450. {
  12451. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  12452. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12453. }
  12454. else
  12455. {
  12456. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceAndPaymentSelectionReqRes: fail");
  12457. Update_V2G_Flow_Status(Other_Fault);
  12458. }
  12459. req_is_responsed = TRUE;
  12460. break;
  12461. }
  12462. case ServiceAndPaymentSelectionResponse://26
  12463. {
  12464. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  12465. {
  12466. Update_V2G_Flow_Status(AuthorizationRequest);
  12467. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12468. }
  12469. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12470. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12471. {
  12472. sprintf((char*)buf_log_evcomm,
  12473. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12474. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12475. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12476. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12477. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12478. }
  12479. else
  12480. {
  12481. }
  12482. break;
  12483. }
  12484. //-------------------------------------------
  12485. //case ContractAuthenticationReq:
  12486. case AuthorizationRequest: //29
  12487. {
  12488. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  12489. {
  12490. Update_V2G_Flow_Status(AuthorizationResponse);
  12491. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12492. }
  12493. else
  12494. {
  12495. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail\n");
  12496. Update_V2G_Flow_Status(Other_Fault);
  12497. }
  12498. req_is_responsed = TRUE;
  12499. break;
  12500. }
  12501. case AuthorizationResponse: //30
  12502. {
  12503. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  12504. {
  12505. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12506. if (Proc_iso1_AuthenticationReq(AcceptFd) == 0)
  12507. {
  12508. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12509. }
  12510. else
  12511. {
  12512. SAVE_SYS_LOG_MSG_EVCOMM("[Error]AuthorizationReqRes: fail\n");
  12513. Update_V2G_Flow_Status(Other_Fault);
  12514. }
  12515. req_is_responsed = TRUE;
  12516. }
  12517. //Check for ChargeParameterDiscoveryReq
  12518. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  12519. {
  12520. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12521. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  12522. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12523. ftime(&SeqStartTime);
  12524. #endif
  12525. }
  12526. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12527. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12528. {
  12529. sprintf((char*)buf_log_evcomm,
  12530. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12531. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12532. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12533. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12534. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12535. }
  12536. else
  12537. {}
  12538. break;
  12539. }
  12540. //-------------------------------------------
  12541. case ChargeParameterDiscoveryRequest: //35
  12542. {
  12543. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  12544. {
  12545. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  12546. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12547. }
  12548. else
  12549. {
  12550. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  12551. Update_V2G_Flow_Status(Other_Fault);
  12552. }
  12553. req_is_responsed = TRUE;
  12554. break;
  12555. }
  12556. case ChargeParameterDiscoveryResponse: //36
  12557. {
  12558. //STEP 1: Check for Process Timeout
  12559. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12560. ftime(&SeqEndTime);
  12561. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  12562. {
  12563. sprintf((char*)buf_log_evcomm,
  12564. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  12565. DiffTimeb(SeqStartTime, SeqEndTime),
  12566. V2G_SECC_ChargingParameter_Performance_Time);
  12567. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12568. Update_V2G_Flow_Status(Sequence_Timeout);
  12569. break;
  12570. }
  12571. #endif
  12572. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  12573. {
  12574. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12575. if (Proc_iso1_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  12576. {
  12577. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12578. }
  12579. else
  12580. {
  12581. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  12582. Update_V2G_Flow_Status(Other_Fault);
  12583. }
  12584. req_is_responsed = TRUE;
  12585. }
  12586. //STEP 3: Wait for PowerDeliveryReq Message
  12587. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12588. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12589. {
  12590. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  12591. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12592. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  12593. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12594. ftime(&SeqStartTime);
  12595. #endif
  12596. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12597. {
  12598. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12599. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12600. }
  12601. else
  12602. {
  12603. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  12604. Update_V2G_Flow_Status(Other_Fault);
  12605. }
  12606. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12607. ftime(&SeqStartTime);
  12608. #endif
  12609. }
  12610. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12611. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12612. {
  12613. sprintf((char*)buf_log_evcomm,
  12614. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12615. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12616. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12617. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12618. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12619. }
  12620. else
  12621. {
  12622. }
  12623. break;
  12624. }
  12625. //-------------------------------------------
  12626. case PowerDeliveryRequestStart: //41
  12627. {
  12628. if (Proc_iso1_PowerDeliveryStartReq(AcceptFd) == 0)
  12629. {
  12630. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  12631. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12632. }
  12633. else
  12634. {
  12635. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStartReqRes: fail");
  12636. Update_V2G_Flow_Status(Other_Fault);
  12637. }
  12638. req_is_responsed = TRUE;
  12639. break;
  12640. }
  12641. case PowerDeliveryResponsetStart: //42
  12642. {
  12643. //STEP 1: Check for Process Timeout
  12644. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12645. if (ccs_exi_doc_ISO1.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  12646. {
  12647. ftime(&SeqEndTime);
  12648. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  12649. {
  12650. sprintf((char*)buf_log_evcomm,
  12651. "Wait for ChargingStatusReq Timeout - (%.02lf of %d ms)\n",
  12652. DiffTimeb(SeqStartTime, SeqEndTime),
  12653. 2000);
  12654. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12655. Update_V2G_Flow_Status(Sequence_Timeout);
  12656. }
  12657. break;
  12658. }
  12659. #endif
  12660. //STEP 2: Wait for ChargingStatusReq Message
  12661. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargingStatusRequest)
  12662. {
  12663. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12664. Update_V2G_Flow_Status(ChargingStatusRequest);
  12665. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]ChargingStatusReq: energy transfering...");
  12666. ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargingStatus_Timer_Start);
  12667. }
  12668. else
  12669. {
  12670. }
  12671. break;
  12672. }
  12673. //-------------------------------------------
  12674. case ChargingStatusRequest: //43
  12675. {
  12676. if (Proc_iso1_ChargingStatusReq(AcceptFd) == 0)
  12677. {
  12678. Update_V2G_Flow_Status(ChargingStatusResponse);
  12679. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12680. }
  12681. else
  12682. {
  12683. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargingStatusRes: fail");
  12684. Update_V2G_Flow_Status(Other_Fault);
  12685. }
  12686. req_is_responsed = TRUE;
  12687. break;
  12688. }
  12689. case ChargingStatusResponse: //44
  12690. {
  12691. //STEP 1: Wait for ChargingStatusReq Message
  12692. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargingStatusRequest)
  12693. {
  12694. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12695. if (Proc_iso1_ChargingStatusReq(AcceptFd) == 0)
  12696. {
  12697. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12698. }
  12699. else
  12700. {
  12701. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargingStatusRes: fail");
  12702. Update_V2G_Flow_Status(Other_Fault);
  12703. }
  12704. req_is_responsed = TRUE;
  12705. }
  12706. //STEP 2: Wait for PowerDeliveryReq Message
  12707. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  12708. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  12709. {
  12710. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  12711. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12712. ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargingStatus_Timer_End);
  12713. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12714. ftime(&SeqStartTime);
  12715. #endif
  12716. }
  12717. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12718. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12719. {
  12720. sprintf((char*)buf_log_evcomm,
  12721. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12722. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12723. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12724. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12725. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12726. }
  12727. else
  12728. {
  12729. }
  12730. break;
  12731. }
  12732. //-------------------------------------------
  12733. case PowerDeliveryRequestStop: //49
  12734. {
  12735. if (Proc_iso1_PowerDeliveryStopReq(AcceptFd) == 0)
  12736. {
  12737. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  12738. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12739. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12740. ftime(&SeqStartTime);
  12741. #endif
  12742. }
  12743. else
  12744. {
  12745. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  12746. Update_V2G_Flow_Status(Other_Fault);
  12747. }
  12748. req_is_responsed = TRUE;
  12749. break;
  12750. }
  12751. case PowerDeliveryResponseStop: //50
  12752. {
  12753. //STEP 1: Check for Process Timeout
  12754. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  12755. ftime(&SeqEndTime);
  12756. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  12757. {
  12758. sprintf((char*)buf_log_evcomm,
  12759. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  12760. DiffTimeb(SeqStartTime, SeqEndTime),
  12761. 2000);
  12762. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  12763. Update_V2G_Flow_Status(Sequence_Timeout);
  12764. break;
  12765. }
  12766. #endif
  12767. //STEP 3: Check for SessionStopReq Message
  12768. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  12769. {
  12770. Update_V2G_Flow_Status(SessionStopRequest);
  12771. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12772. }
  12773. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12774. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12775. {
  12776. sprintf((char*)buf_log_evcomm,
  12777. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12778. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12779. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12780. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12781. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12782. }
  12783. else
  12784. {
  12785. }
  12786. break;
  12787. }
  12788. //-------------------------------------------
  12789. case SessionStopRequest: //53
  12790. {
  12791. if (Proc_iso1_SessionStopReq(AcceptFd) == 0)
  12792. {
  12793. Update_V2G_Flow_Status(SessionStopResponse);
  12794. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12795. }
  12796. else
  12797. {
  12798. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  12799. Update_V2G_Flow_Status(Other_Fault);
  12800. }
  12801. req_is_responsed = TRUE;
  12802. break;
  12803. }
  12804. case SessionStopResponse: //54
  12805. {
  12806. break;
  12807. }
  12808. //-------------------------------------------
  12809. default:
  12810. {
  12811. break;
  12812. }
  12813. }
  12814. usleep(1000);
  12815. }
  12816. return 0;
  12817. }
  12818. /*===========================================================================
  12819. FUNCTION: V2gMsg_Process_iso1
  12820. DESCRIPTION:
  12821. 1. EnergyTransferMode:
  12822. AC_single_phase_core = 0,
  12823. AC_three_phase_core = 1,
  12824. DC_core = 2,
  12825. DC_extended = 3,
  12826. DC_combo_core = 4,
  12827. DC_unique = 5
  12828. iso1EnergyTransferModeType_AC_single_phase_core = 0,
  12829. iso1EnergyTransferModeType_AC_three_phase_core = 1,
  12830. iso1EnergyTransferModeType_DC_core = 2,
  12831. iso1EnergyTransferModeType_DC_extended = 3,
  12832. iso1EnergyTransferModeType_DC_combo_core = 4,
  12833. iso1EnergyTransferModeType_DC_unique = 5
  12834. PRE-CONDITION:
  12835. INPUT:
  12836. 1. V2gFlowStatus
  12837. OUTPUT:
  12838. GLOBAL VARIABLES:
  12839. 1. V2gFlowStatus
  12840. =============================================================================*/
  12841. int V2gMsg_Process_iso1(int AcceptFd, unsigned char EnergyTransferMode)
  12842. {
  12843. switch (EnergyTransferMode)
  12844. {
  12845. case DC_extended:
  12846. {
  12847. //SAVE_SYS_LOG_MSG_EVCOMM("EnergyTransferMode: DC_extended\n");
  12848. V2gMsg_Process_iso1_DC(AcceptFd);
  12849. break;
  12850. }
  12851. case AC_single_phase_core:
  12852. case AC_three_phase_core:
  12853. {
  12854. //SAVE_SYS_LOG_MSG_EVCOMM("EnergyTransferMode: AC_single_phase_core or AC_three_phase_core\n");
  12855. V2gMsg_Process_iso1_AC(AcceptFd);
  12856. break;
  12857. }
  12858. default:
  12859. {
  12860. SAVE_SYS_LOG_MSG_EVCOMM("[Warning]Unexpected EnergyTransferMode(%d)\n", EnergyTransferMode);
  12861. break;
  12862. }
  12863. }
  12864. return 0;
  12865. }
  12866. /*===========================================================================
  12867. FUNCTION: V2gMsg_Process_iso2_DC
  12868. DESCRIPTION:
  12869. PRE-CONDITION:
  12870. INPUT:
  12871. 1. V2gFlowStatus
  12872. OUTPUT:
  12873. GLOBAL VARIABLES:
  12874. 1. V2gFlowStatus
  12875. =============================================================================*/
  12876. int V2gMsg_Process_iso2_DC(int AcceptFd)
  12877. {
  12878. unsigned char req_is_responsed = FALSE;
  12879. while (req_is_responsed == FALSE)
  12880. {
  12881. //Check if it is in End_Process
  12882. if (EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  12883. {
  12884. break;
  12885. }
  12886. switch(V2gFlowStatus)
  12887. {
  12888. //-------------------------------------------
  12889. case SupportedAppProtocolRequest:
  12890. {
  12891. if (ccs_handshake.supportedAppProtocolReq_isUsed == 1u)
  12892. {
  12893. ccs_handshake.supportedAppProtocolReq_isUsed = 0;
  12894. if (Proc_supportedAppProtocolReq(AcceptFd) == 0) //0: no error
  12895. {
  12896. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12897. Update_V2G_Flow_Status(SupportedAppProtocolResponse);
  12898. }
  12899. else
  12900. {
  12901. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]supportedAppProtocolResReq: fail");
  12902. Update_V2G_Flow_Status(Other_Fault);
  12903. }
  12904. }
  12905. req_is_responsed = TRUE;
  12906. break;
  12907. }
  12908. case SupportedAppProtocolResponse:
  12909. {
  12910. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionSetupRequest)
  12911. {
  12912. Update_V2G_Flow_Status(SessionSetupRequest);
  12913. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12914. }
  12915. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12916. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12917. {
  12918. sprintf((char*)buf_log_evcomm,
  12919. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12920. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12921. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12922. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12923. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12924. }
  12925. else
  12926. {
  12927. }
  12928. break;
  12929. }
  12930. //-------------------------------------------
  12931. case SessionSetupRequest: //19
  12932. {
  12933. if (Proc_iso2_SessionSetupReq(AcceptFd) == 0)
  12934. {
  12935. Update_V2G_Flow_Status(SessionSetupResponse);
  12936. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12937. }
  12938. else
  12939. {
  12940. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionSetupReqRes: fail");
  12941. Update_V2G_Flow_Status(Other_Fault);
  12942. }
  12943. req_is_responsed = TRUE;
  12944. break;
  12945. }
  12946. case SessionSetupResponse: //20
  12947. {
  12948. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceDiscoveryRequest)
  12949. {
  12950. Update_V2G_Flow_Status(ServiceDiscoveryRequest);
  12951. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12952. }
  12953. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12954. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12955. {
  12956. sprintf((char*)buf_log_evcomm,
  12957. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12958. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12959. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12960. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12961. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12962. }
  12963. else
  12964. {
  12965. }
  12966. break;
  12967. }
  12968. #if 0
  12969. //-------------------------------------------
  12970. case ServiceDiscoveryRequest: //21
  12971. {
  12972. if (Proc_iso2_ServiceDiscoveryReq(AcceptFd) == 0)
  12973. {
  12974. Update_V2G_Flow_Status(ServiceDiscoveryResponse);
  12975. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  12976. }
  12977. else
  12978. {
  12979. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceDiscoveryReqRes: fail");
  12980. Update_V2G_Flow_Status(Other_Fault);
  12981. }
  12982. req_is_responsed = TRUE;
  12983. break;
  12984. }
  12985. case ServiceDiscoveryResponse: //22
  12986. {
  12987. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ServiceAndPaymentSelectionRequest)
  12988. {
  12989. Update_V2G_Flow_Status(ServiceAndPaymentSelectionRequest);
  12990. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  12991. }
  12992. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  12993. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  12994. {
  12995. sprintf((char*)buf_log_evcomm,
  12996. "[ERROR]SequenceError(%d) => Tx Res MSG",
  12997. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  12998. EVCOMM_SYS_INFO.SequenceError = TRUE;
  12999. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13000. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13001. }
  13002. else
  13003. {
  13004. break;
  13005. }
  13006. }
  13007. //-------------------------------------------
  13008. case ServiceAndPaymentSelectionRequest: //25
  13009. {
  13010. if (Proc_iso2_ServiceAndPaymentSelectionReq(AcceptFd) == 0)
  13011. {
  13012. Update_V2G_Flow_Status(ServiceAndPaymentSelectionResponse);
  13013. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13014. }
  13015. else
  13016. {
  13017. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ServiceAndPaymentSelectionReqRes: fail");
  13018. Update_V2G_Flow_Status(Other_Fault);
  13019. }
  13020. req_is_responsed = TRUE;
  13021. break;
  13022. }
  13023. case ServiceAndPaymentSelectionResponse: //26
  13024. {
  13025. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  13026. {
  13027. Update_V2G_Flow_Status(AuthorizationRequest);
  13028. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13029. }
  13030. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13031. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13032. {
  13033. sprintf((char*)buf_log_evcomm,
  13034. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13035. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13036. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13037. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13038. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13039. }
  13040. else
  13041. {
  13042. break;
  13043. }
  13044. }
  13045. //-------------------------------------------
  13046. //case ContractAuthenticationReq:
  13047. case AuthorizationRequest: //29
  13048. {
  13049. if (Proc_iso2_AuthenticationReq(AcceptFd) == 0)
  13050. {
  13051. Update_V2G_Flow_Status(AuthorizationResponse);
  13052. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13053. }
  13054. else
  13055. {
  13056. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  13057. Update_V2G_Flow_Status(Other_Fault);
  13058. }
  13059. req_is_responsed = TRUE;
  13060. break;
  13061. }
  13062. case AuthorizationResponse: //30
  13063. {
  13064. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == AuthorizationRequest)
  13065. {
  13066. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13067. if (Proc_iso2_AuthenticationReq(AcceptFd) == 0)
  13068. {
  13069. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13070. }
  13071. else
  13072. {
  13073. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]AuthorizationReqRes: fail");
  13074. Update_V2G_Flow_Status(Other_Fault);
  13075. }
  13076. req_is_responsed = TRUE;
  13077. break;
  13078. }
  13079. //Check for ChargeParameterDiscoveryReq
  13080. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  13081. {
  13082. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13083. Update_V2G_Flow_Status(ChargeParameterDiscoveryRequest);
  13084. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]ChargeParameterDiscoveryReq: CSU Permission?");
  13085. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13086. ftime(&SeqStartTime);
  13087. #endif
  13088. }
  13089. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13090. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13091. {
  13092. sprintf((char*)buf_log_evcomm,
  13093. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13094. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13095. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13096. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13097. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13098. }
  13099. else
  13100. {
  13101. break;
  13102. }
  13103. }
  13104. //-------------------------------------------
  13105. case ChargeParameterDiscoveryRequest: //35
  13106. {
  13107. if (Proc_iso2_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  13108. {
  13109. Update_V2G_Flow_Status(ChargeParameterDiscoveryResponse);
  13110. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13111. }
  13112. else
  13113. {
  13114. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  13115. Update_V2G_Flow_Status(Other_Fault);
  13116. }
  13117. req_is_responsed = TRUE;
  13118. break;
  13119. }
  13120. case ChargeParameterDiscoveryResponse:
  13121. {
  13122. //STEP 1: Check for Process Timeout
  13123. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13124. ftime(&SeqEndTime);
  13125. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_ChargingParameter_Performance_Time) //60 seconds
  13126. {
  13127. sprintf((char*)buf_log_evcomm,
  13128. "ChargingParameter Timeout - (%.02lf of %d ms)\n",
  13129. DiffTimeb(SeqStartTime, SeqEndTime),
  13130. V2G_SECC_ChargingParameter_Performance_Time);
  13131. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13132. Update_V2G_Flow_Status(Sequence_Timeout);
  13133. break;
  13134. }
  13135. #endif
  13136. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == ChargeParameterDiscoveryRequest)
  13137. {
  13138. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13139. if (Proc_iso2_ChargeParameterDiscoveryReq(AcceptFd) == 0)
  13140. {
  13141. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13142. }
  13143. else
  13144. {
  13145. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]ChargeParameterDiscoveryReqRes: fail");
  13146. Update_V2G_Flow_Status(Other_Fault);
  13147. }
  13148. req_is_responsed = TRUE;
  13149. break;
  13150. }
  13151. //STEP 2: Check for CableCheckReq message
  13152. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  13153. {
  13154. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13155. Update_V2G_Flow_Status(CableCheckRequest);
  13156. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]CableCheckReqReq: isolated?");
  13157. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_Start);
  13158. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  13159. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13160. ftime(&SeqStartTime);
  13161. #endif
  13162. }
  13163. //STEP 3: Wait for PowerDeliveryReq Message
  13164. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13165. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13166. {
  13167. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13168. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13169. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  13170. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13171. ftime(&SeqStartTime);
  13172. #endif
  13173. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  13174. {
  13175. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13176. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13177. }
  13178. else
  13179. {
  13180. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  13181. Update_V2G_Flow_Status(Other_Fault);
  13182. }
  13183. break;
  13184. }
  13185. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13186. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13187. {
  13188. sprintf((char*)buf_log_evcomm,
  13189. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13190. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13191. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13192. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13193. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13194. }
  13195. else
  13196. {
  13197. break;
  13198. }
  13199. }
  13200. //-------------------------------------------
  13201. case CableCheckRequest: //37
  13202. {
  13203. //STEP 3: Execute Cable Check Process
  13204. if (Proc_iso2_CableCheckReq(AcceptFd) == 0)
  13205. {
  13206. Update_V2G_Flow_Status(CableCheckResponse);
  13207. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13208. }
  13209. else
  13210. {
  13211. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  13212. Update_V2G_Flow_Status(Other_Fault);
  13213. }
  13214. req_is_responsed = TRUE;
  13215. break;
  13216. }
  13217. case CableCheckResponse: //38
  13218. {
  13219. //STEP 1: Check for Process Timeout
  13220. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13221. ftime(&SeqEndTime);
  13222. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_CableCheck_Performance_Time) //38 seconds
  13223. {
  13224. //SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[CableCheck] end counting...");
  13225. sprintf((char*)buf_log_evcomm,
  13226. "CableCheck Timeout - (%.02lf of %d ms)\n",
  13227. DiffTimeb(SeqStartTime, SeqEndTime),
  13228. V2G_SECC_CableCheck_Performance_Time);
  13229. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13230. Update_V2G_Flow_Status(Sequence_Timeout);
  13231. //Update_ShmStatusCode(); //[To-Do] to be implemented
  13232. //CCS_SECC_TIMEOUT_V2G_CableCheck_Performance_Time (023847)
  13233. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13234. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13235. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13236. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  13237. ShmStatusCodeData->PresentStatusCode[0][4] = 4;
  13238. ShmStatusCodeData->PresentStatusCode[0][5] = 7;
  13239. break;
  13240. }
  13241. #endif
  13242. //STEP 2: Check for CableCheckReq message
  13243. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CableCheckRequest)
  13244. {
  13245. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13246. //STEP 3: Execute Cable Check Process
  13247. if (Proc_iso2_CableCheckReq(AcceptFd) == 0)
  13248. {
  13249. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13250. }
  13251. else
  13252. {
  13253. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CableCheckReqRes: fail");
  13254. Update_V2G_Flow_Status(Other_Fault);
  13255. }
  13256. req_is_responsed = TRUE;
  13257. break;
  13258. }
  13259. //STEP 3: Check for PreChargeReq message
  13260. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  13261. {
  13262. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13263. Update_V2G_Flow_Status(PreChargeRequest);
  13264. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]PreChargeReqReq: waiting for precharge voltage...");
  13265. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CableCheck_Timer_End);
  13266. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_Start);
  13267. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13268. ftime(&SeqStartTime);
  13269. #endif
  13270. }
  13271. //STEP 3: Wait for PowerDeliveryReq Message
  13272. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13273. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13274. {
  13275. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13276. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13277. //ftime(&EVCOMM_SYS_INFO.V2G_SECC_ChargeParameterDiscovery_Timer_End);
  13278. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13279. ftime(&SeqStartTime);
  13280. #endif
  13281. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  13282. {
  13283. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13284. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13285. }
  13286. else
  13287. {
  13288. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  13289. Update_V2G_Flow_Status(Other_Fault);
  13290. }
  13291. break;
  13292. }
  13293. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13294. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13295. {
  13296. sprintf((char*)buf_log_evcomm,
  13297. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13298. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13299. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13300. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13301. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13302. }
  13303. else
  13304. {
  13305. break;
  13306. }
  13307. }
  13308. //-------------------------------------------
  13309. case PreChargeRequest: //39
  13310. {
  13311. if (Proc_iso2_PreChargeReq(AcceptFd) == 0)
  13312. {
  13313. Update_V2G_Flow_Status(PreChargeResponse);
  13314. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13315. }
  13316. else
  13317. {
  13318. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  13319. Update_V2G_Flow_Status(Other_Fault);
  13320. }
  13321. req_is_responsed = TRUE;
  13322. break;
  13323. }
  13324. case PreChargeResponse: //40
  13325. {
  13326. //STEP 1: Check for Process Timeout
  13327. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13328. ftime(&SeqEndTime);
  13329. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_PreCharge_Performance_Time) //5 seconds
  13330. {
  13331. sprintf((char*)buf_log_evcomm,
  13332. "Precharge Timeout - (%.02lf of %d ms)\n",
  13333. DiffTimeb(SeqStartTime, SeqEndTime),
  13334. V2G_SECC_PreCharge_Performance_Time);
  13335. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13336. Update_V2G_Flow_Status(Sequence_Timeout);
  13337. //Update_ShmStatusCode(); //[To-Do] to be implemented
  13338. //CCS_SECC_TIMEOUT_V2G_PreCharge_Performace_Time (023850)
  13339. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  13340. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  13341. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  13342. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  13343. ShmStatusCodeData->PresentStatusCode[0][4] = 5;
  13344. ShmStatusCodeData->PresentStatusCode[0][5] = 0;
  13345. break;
  13346. }
  13347. #endif
  13348. //STEP 2: Check for PreChargeReq message
  13349. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == PreChargeRequest)
  13350. {
  13351. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13352. if (Proc_iso2_PreChargeReq(AcceptFd) == 0)
  13353. {
  13354. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13355. }
  13356. else
  13357. {
  13358. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PreChargeReqRes: fail");
  13359. Update_V2G_Flow_Status(Other_Fault);
  13360. }
  13361. req_is_responsed = TRUE;
  13362. break;
  13363. }
  13364. //STEP 3: Check for PowerDeliveryReq message
  13365. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13366. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13367. {
  13368. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13369. Update_V2G_Flow_Status(PowerDeliveryRequestStart);
  13370. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Precharge_Timer_End);
  13371. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13372. ftime(&SeqStartTime);
  13373. #endif
  13374. }
  13375. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13376. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13377. {
  13378. sprintf((char*)buf_log_evcomm,
  13379. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13380. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13381. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13382. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13383. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13384. }
  13385. else
  13386. {
  13387. break;
  13388. }
  13389. }
  13390. //-------------------------------------------
  13391. case PowerDeliveryRequestStart: //41
  13392. {
  13393. if (Proc_iso2_PowerDeliveryStartReq(AcceptFd) == 0)
  13394. {
  13395. Update_V2G_Flow_Status(PowerDeliveryResponsetStart);
  13396. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13397. }
  13398. else
  13399. {
  13400. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStartReqRes: fail");
  13401. Update_V2G_Flow_Status(Other_Fault);
  13402. }
  13403. req_is_responsed = TRUE;
  13404. break;
  13405. }
  13406. case PowerDeliveryResponsetStart: //42
  13407. {
  13408. //STEP 1: Check for Process Timeout
  13409. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13410. if (ccs_exi_doc_ISO2.V2G_Message.Body.PowerDeliveryReq_isUsed == 1u)
  13411. {
  13412. ftime(&SeqEndTime);
  13413. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //5 seconds
  13414. {
  13415. sprintf((char*)buf_log_evcomm,
  13416. "Wait for CurrentDemandReq Timeout - (%.02lf of %d ms)\n",
  13417. DiffTimeb(SeqStartTime, SeqEndTime),
  13418. 2000);
  13419. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13420. Update_V2G_Flow_Status(Sequence_Timeout);
  13421. }
  13422. break;
  13423. }
  13424. #endif
  13425. //STEP 2: Wait for CurrentDemandReq Message
  13426. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  13427. {
  13428. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13429. Update_V2G_Flow_Status(CurrentDemandRequest);
  13430. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]CurrentDemandReqReq: energy transfering...");
  13431. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_Start);
  13432. }
  13433. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13434. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13435. {
  13436. sprintf((char*)buf_log_evcomm,
  13437. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13438. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13439. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13440. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13441. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13442. }
  13443. else
  13444. {
  13445. break;
  13446. }
  13447. }
  13448. //-------------------------------------------
  13449. case CurrentDemandRequest: //45,
  13450. {
  13451. if (Proc_iso2_CurrentDemandReq(AcceptFd) == 0)
  13452. {
  13453. Update_V2G_Flow_Status(CurrentDemandResponse);
  13454. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13455. }
  13456. else
  13457. {
  13458. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  13459. Update_V2G_Flow_Status(Other_Fault);
  13460. }
  13461. req_is_responsed = TRUE;
  13462. break;
  13463. }
  13464. case CurrentDemandResponse: //46,
  13465. {
  13466. //STEP 1: Wait for CurrentDemandReq Message
  13467. if (EVCOMM_SYS_INFO.V2G_Rx_Msg == CurrentDemandRequest)
  13468. {
  13469. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13470. if (Proc_iso2_CurrentDemandReq(AcceptFd) == 0)
  13471. {
  13472. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13473. }
  13474. else
  13475. {
  13476. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]CurrentDemandReqRes: fail");
  13477. Update_V2G_Flow_Status(Other_Fault);
  13478. }
  13479. req_is_responsed = TRUE;
  13480. break;
  13481. }
  13482. //STEP 2: Wait for PowerDeliveryReq Message
  13483. else if((EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStop) ||
  13484. (EVCOMM_SYS_INFO.V2G_Rx_Msg == PowerDeliveryRequestStart))
  13485. {
  13486. Update_V2G_Flow_Status(PowerDeliveryRequestStop);
  13487. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13488. ftime(&EVCOMM_SYS_INFO.V2G_SECC_CurrentDemand_Timer_End);
  13489. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13490. ftime(&SeqStartTime);
  13491. #endif
  13492. }
  13493. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13494. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13495. {
  13496. sprintf((char*)buf_log_evcomm,
  13497. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13498. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13499. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13500. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13501. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13502. }
  13503. else
  13504. {
  13505. break;
  13506. }
  13507. }
  13508. //-------------------------------------------
  13509. case PowerDeliveryRequestStop: //49,
  13510. {
  13511. if (Proc_iso2_PowerDeliveryStopReq(AcceptFd) == 0)
  13512. {
  13513. Update_V2G_Flow_Status(PowerDeliveryResponseStop);
  13514. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13515. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13516. ftime(&SeqStartTime);
  13517. #endif
  13518. }
  13519. else
  13520. {
  13521. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]PowerDeliveryStopReqRes: fail");
  13522. Update_V2G_Flow_Status(Other_Fault);
  13523. }
  13524. req_is_responsed = TRUE;
  13525. break;
  13526. }
  13527. case PowerDeliveryResponseStop: //50,
  13528. {
  13529. //STEP 1: Check for Process Timeout
  13530. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13531. ftime(&SeqEndTime);
  13532. if(DiffTimeb(SeqStartTime, SeqEndTime) > 2000) //2 seconds
  13533. {
  13534. sprintf((char*)buf_log_evcomm,
  13535. "Wait for WeldingDetectionReq or SessionStopReq Timeout - (%.02lf of %d ms)\n",
  13536. DiffTimeb(SeqStartTime, SeqEndTime),
  13537. 2000);
  13538. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13539. Update_V2G_Flow_Status(Sequence_Timeout);
  13540. break;
  13541. }
  13542. #endif
  13543. //STEP 2: Check for WeldingDetectionReq Message
  13544. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  13545. {
  13546. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13547. Update_V2G_Flow_Status(WeldingDetectionRequest);
  13548. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[V2G][RX]WeldingDetectionReq: ongoing...");
  13549. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_Start);
  13550. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13551. ftime(&SeqStartTime);
  13552. #endif
  13553. }
  13554. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  13555. {
  13556. Update_V2G_Flow_Status(SessionStopRequest);
  13557. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13558. if (Proc_iso2_SessionStopReq(AcceptFd) == 0)
  13559. {
  13560. Update_V2G_Flow_Status(SessionStopResponse);
  13561. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13562. }
  13563. else
  13564. {
  13565. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  13566. Update_V2G_Flow_Status(Other_Fault);
  13567. }
  13568. break;
  13569. }
  13570. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13571. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13572. {
  13573. sprintf((char*)buf_log_evcomm,
  13574. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13575. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13576. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13577. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13578. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13579. }
  13580. else
  13581. {
  13582. break;
  13583. }
  13584. }
  13585. //-------------------------------------------
  13586. case WeldingDetectionRequest: //51,
  13587. {
  13588. if (Proc_iso2_WeldingDetectionReq(AcceptFd) == 0)
  13589. {
  13590. Update_V2G_Flow_Status(WeldingDetectionResponse);
  13591. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13592. }
  13593. else
  13594. {
  13595. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  13596. Update_V2G_Flow_Status(Other_Fault);
  13597. }
  13598. req_is_responsed = TRUE;
  13599. break;
  13600. }
  13601. case WeldingDetectionResponse: //52,
  13602. {
  13603. //STEP 1: Check for Process Timeout
  13604. #if V2G_SECC_TIMEOUT_PROTECTION == ENABLE
  13605. ftime(&SeqEndTime);
  13606. if(DiffTimeb(SeqStartTime, SeqEndTime) > V2G_SECC_WeldingDetection_Performance_Time) //20 seconds
  13607. {
  13608. sprintf((char*)buf_log_evcomm,
  13609. "Wait for SessionStopReq Timeout - (%.02lf of %d ms)\n",
  13610. DiffTimeb(SeqStartTime, SeqEndTime),
  13611. V2G_SECC_WeldingDetection_Performance_Time);
  13612. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13613. Update_V2G_Flow_Status(Sequence_Timeout);
  13614. break;
  13615. }
  13616. #endif
  13617. //STEP 2: Check for WeldingDetectionReq Message
  13618. if(EVCOMM_SYS_INFO.V2G_Rx_Msg == WeldingDetectionRequest)
  13619. {
  13620. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13621. if (Proc_iso1_WeldingDetectionReq(AcceptFd) == 0)
  13622. {
  13623. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13624. }
  13625. else
  13626. {
  13627. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]WeldingDetectionReqRes: fail");
  13628. Update_V2G_Flow_Status(Other_Fault);
  13629. }
  13630. req_is_responsed = TRUE;
  13631. break;
  13632. }
  13633. //STEP 3: Check for SessionStopReq Message
  13634. else if(EVCOMM_SYS_INFO.V2G_Rx_Msg == SessionStopRequest)
  13635. {
  13636. Update_V2G_Flow_Status(SessionStopRequest);
  13637. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13638. ftime(&EVCOMM_SYS_INFO.V2G_SECC_WeldingDetection_Timer_End);
  13639. }
  13640. else if (EVCOMM_SYS_INFO.V2G_Rx_Msg >= SupportedAppProtocolRequest &&
  13641. EVCOMM_SYS_INFO.V2G_Rx_Msg <= SessionStopRequest)
  13642. {
  13643. sprintf((char*)buf_log_evcomm,
  13644. "[ERROR]SequenceError(%d) => Tx Res MSG",
  13645. EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13646. EVCOMM_SYS_INFO.SequenceError = TRUE;
  13647. Update_V2G_Flow_Status(EVCOMM_SYS_INFO.V2G_Rx_Msg);
  13648. EVCOMM_SYS_INFO.V2G_Rx_Msg = 0;
  13649. }
  13650. else
  13651. {
  13652. break;
  13653. }
  13654. }
  13655. //-------------------------------------------
  13656. case SessionStopRequest: //53,
  13657. {
  13658. if (Proc_iso2_SessionStopReq(AcceptFd) == 0)
  13659. {
  13660. Update_V2G_Flow_Status(SessionStopResponse);
  13661. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  13662. }
  13663. else
  13664. {
  13665. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[Error]SessionStopReqRes: fail");
  13666. Update_V2G_Flow_Status(Other_Fault);
  13667. }
  13668. req_is_responsed = TRUE;
  13669. //break;
  13670. }
  13671. case SessionStopResponse: //54,
  13672. {
  13673. break;
  13674. }
  13675. #endif
  13676. //-------------------------------------------
  13677. default:
  13678. {
  13679. break;
  13680. }
  13681. }
  13682. usleep(1000);
  13683. }
  13684. return 0;
  13685. }
  13686. /*===========================================================================
  13687. FUNCTION: V2gMsg_Process_iso2_AC
  13688. DESCRIPTION:
  13689. PRE-CONDITION:
  13690. INPUT:
  13691. 1. V2gFlowStatus
  13692. OUTPUT:
  13693. GLOBAL VARIABLES:
  13694. 1. V2gFlowStatus
  13695. =============================================================================*/
  13696. int V2gMsg_Process_iso2_AC(int AcceptFd)
  13697. {
  13698. return 0;
  13699. }
  13700. /*===========================================================================
  13701. FUNCTION: V2gMsg_Process_iso2
  13702. DESCRIPTION:
  13703. PRE-CONDITION:
  13704. INPUT:
  13705. 1. V2gFlowStatus
  13706. OUTPUT:
  13707. GLOBAL VARIABLES:
  13708. 1. V2gFlowStatus
  13709. =============================================================================*/
  13710. int V2gMsg_Process_iso2(int AcceptFd, unsigned char EnergyTransferMode)
  13711. {
  13712. switch (EnergyTransferMode)
  13713. {
  13714. case DC_extended:
  13715. {
  13716. V2gMsg_Process_iso2_DC(AcceptFd);
  13717. break;
  13718. }
  13719. case AC_single_phase_core:
  13720. case AC_three_phase_core:
  13721. {
  13722. V2gMsg_Process_iso2_AC(AcceptFd);
  13723. break;
  13724. }
  13725. default:
  13726. {
  13727. sprintf((char*)buf_log_evcomm,
  13728. "[ISO2][Warning]Unexpected EnergyTransferMode(%d)",
  13729. EnergyTransferMode);
  13730. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13731. break;
  13732. }
  13733. }
  13734. return 0;
  13735. }
  13736. /*===========================================================================
  13737. FUNCTION: V2gMsg_Process
  13738. DESCRIPTION:
  13739. PRE-CONDITION:
  13740. INPUT:
  13741. OUTPUT:
  13742. GLOBAL VARIABLES:
  13743. =============================================================================*/
  13744. int V2gMsg_Process(int AcceptFd)
  13745. {
  13746. int errn = 0;
  13747. switch (ShmCcsData->CommProtocol)
  13748. {
  13749. case V2GT_MSG_PROTOCOL_DIN70121: //0
  13750. {
  13751. V2gMsg_Process_din(AcceptFd);
  13752. break;
  13753. }
  13754. case V2GT_MSG_PROTOCOL_ISO15118_2014: //1
  13755. {
  13756. V2gMsg_Process_iso1(AcceptFd, ShmCcsData->EnergyTransferMode);
  13757. break;
  13758. }
  13759. case V2GT_MSG_PROTOCOL_ISO15118_2018: //2
  13760. {
  13761. V2gMsg_Process_iso2(AcceptFd, ShmCcsData->EnergyTransferMode);
  13762. break;
  13763. }
  13764. default:
  13765. {
  13766. SAVE_SYS_LOG_MSG_EVCOMM("[Warning]Unexpected CommProtocol(%d)\n", ShmCcsData->CommProtocol);
  13767. break;
  13768. }
  13769. }
  13770. return errn;
  13771. }
  13772. /*===========================================================================
  13773. FUNCTION: V2gMsg_Rx
  13774. DESCRIPTION:
  13775. PRE-CONDITION:
  13776. INPUT:
  13777. OUTPUT:
  13778. GLOBAL VARIABLES:
  13779. =============================================================================*/
  13780. int V2gMsg_Rx(int AcceptFd)
  13781. {
  13782. int errn = 0;
  13783. unsigned int packet_size = 0;
  13784. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  13785. packet_size = recv(AcceptFd, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, 0);
  13786. //[CAUTION] Everytime recv() is called, it will take a default time to wait for TCP packets.
  13787. //The more time you call recv(), the more time you will waste here.
  13788. //Here it is suggested that response immediatedly once you receive any packets.
  13789. //For configuring the Rx waiting time, please use setsockopt().
  13790. if(packet_size > 0) //[Joseph] If there is no data, ignore. (TBD)
  13791. {
  13792. //DEBUG_PRINTF_EVCOMM_DETAIL("\n\n Got TCP V2GTP Message: size = %d Bytes\n", packet_size);
  13793. errn = V2gMsgDecoder(V2gtpMsgRxBuf, packet_size, V2gFlowStatus);
  13794. if (errn < 0)
  13795. {
  13796. sprintf((char*)buf_log_evcomm, "[ERROR]V2gMsgDecoder (%d)", errn);
  13797. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13798. }
  13799. }
  13800. return errn;
  13801. }
  13802. /*===========================================================================
  13803. FUNCTION: V2gComm
  13804. DESCRIPTION:
  13805. PRE-CONDITION:
  13806. 1. TCP socket is connected.
  13807. INPUT:
  13808. 1. AcceptFd //TCP Connection ID
  13809. 2. V2gtpMsgRxBuf[] //V2GTP Messages (Header + Payload)
  13810. 3. V2GTP_MSG_RX_BUFFER_SIZE //64*1024 = 65,536 = 65.5K (Bytes)
  13811. OUTPUT:
  13812. GLOBAL VARIABLES:
  13813. 1. V2gtpMsgRxBuf[]
  13814. =============================================================================*/
  13815. int V2gComm(int AcceptFd)
  13816. {
  13817. int errn = 0;
  13818. if (V2gMsg_Rx(AcceptFd) < 0)
  13819. {
  13820. Update_V2G_Flow_Status(Other_Fault);
  13821. errn = -1;
  13822. }
  13823. //following are the response message handling according to status flag
  13824. if (V2gMsg_Process(AcceptFd) < 0)
  13825. {
  13826. errn = -1;
  13827. }
  13828. //Error Check
  13829. //V2G_Error_Monitor();
  13830. return errn;
  13831. }
  13832. /*===========================================================================
  13833. FUNCTION: SdpUdpConnected
  13834. DESCRIPTION:
  13835. PRE-CONDITION:
  13836. INPUT:
  13837. OUTPUT:
  13838. GLOBAL VARIABLES:
  13839. =============================================================================*/
  13840. int SdpUdpConnected()
  13841. {
  13842. int packet_size,Rtn;
  13843. struct sockaddr_in6 ServerAddr,ClientAddr;
  13844. struct V2gtpHeader *header;
  13845. unsigned char *payload;
  13846. if(UdpSock <= 0)
  13847. {
  13848. if ((UdpSock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0)
  13849. {
  13850. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "SdpUdpConnected: Fail to open UdpSock");
  13851. return 0;
  13852. }
  13853. memset(&ServerAddr,0, sizeof(struct sockaddr_in));
  13854. ServerAddr.sin6_family = AF_INET6;
  13855. ServerAddr.sin6_addr = in6addr_any;
  13856. ServerAddr.sin6_port = htons(SdpUdpServerPort);
  13857. if(bind(UdpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) <0)
  13858. {
  13859. sprintf((char*)buf_log_evcomm,
  13860. "SdpUdpConnected: Fail to bind UdpSock(%d)",
  13861. UdpSock);
  13862. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13863. close(UdpSock);
  13864. UdpSock = -1;
  13865. return 0;
  13866. }
  13867. sprintf((char*)buf_log_evcomm, "[UdpSock]opend:%d", UdpSock);
  13868. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13869. sprintf((char*)buf_log_evcomm, "[SDP]Req from EVCC: waiting...(%d)", UdpSock);
  13870. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13871. }
  13872. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  13873. memset(&ClientAddr, 0, sizeof(struct sockaddr_in));
  13874. Rtn = sizeof(struct sockaddr_in6);
  13875. packet_size = recvfrom(UdpSock, V2gtpMsgRxBuf, V2GTP_MSG_RX_BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *)&ClientAddr, (socklen_t *)&Rtn);
  13876. if(packet_size > 0)
  13877. {
  13878. header = (struct V2gtpHeader *) V2gtpMsgRxBuf;
  13879. payload = V2gtpMsgRxBuf+sizeof(struct V2gtpHeader);
  13880. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  13881. {
  13882. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n Got UDP packet_size = %d (Bytes)\n", packet_size);
  13883. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***********************************\n");
  13884. DEBUG_PRINTF_EVCOMM_DETAIL("***** Received SDP Packet *****\n");
  13885. DEBUG_PRINTF_EVCOMM_DETAIL("***********************************\n");
  13886. DEBUG_PRINTF_EVCOMM_DETAIL("ClientAddress=");
  13887. for(Rtn = 0; Rtn < 16; Rtn += 2)
  13888. {
  13889. DEBUG_PRINTF_EVCOMM_DETAIL("%02x%02x:",ClientAddr.sin6_addr.s6_addr[Rtn],ClientAddr.sin6_addr.s6_addr[Rtn+1]);
  13890. }
  13891. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  13892. DEBUG_PRINTF_EVCOMM_DETAIL("ClientPort=%d\n",ClientAddr.sin6_port);
  13893. DEBUG_PRINTF_EVCOMM_DETAIL("ProtocolVersion=%d\n",header->ProtocolVersion);
  13894. DEBUG_PRINTF_EVCOMM_DETAIL("InverseProtocolVersion=0x%x\n",header->InverseProtocolVersion);
  13895. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadType=0x%x\n",htons(header->PayloadType));
  13896. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadLength=0x%x\n",htonl(header->PayloadLength));
  13897. DEBUG_PRINTF_EVCOMM_DETAIL("htons(header->PayloadType)=0x%x\n",htons(header->PayloadType));
  13898. }
  13899. #endif
  13900. if( (header->ProtocolVersion == 0x01) &&
  13901. (header->InverseProtocolVersion == 0xFE) &&
  13902. (htons(header->PayloadType) == V2GTP_PAYLOAD_TYPE_SDP_REQUEST))
  13903. {
  13904. sprintf((char*)buf_log_evcomm, "[SDP][RX]Req from EVCC: GOT(%d)", UdpSock);
  13905. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13906. DEBUG_PRINTF_EVCOMM_DETAIL("Security=0x%x\n", *(payload + 0));
  13907. DEBUG_PRINTF_EVCOMM_DETAIL("TransportProtocol=0x%x\n", *(payload + 1));
  13908. header->PayloadType = htons(V2GTP_PAYLOAD_TYPE_SDP_RESPONSE);
  13909. header->PayloadLength = htonl(20); //Fixed Length=20
  13910. memset(payload, 0, 20);
  13911. // MAC address[0:2] + FFFE + MAC address[3:5]
  13912. payload[0] = (IPV6_LINK_LOCAL_PREFIX>>8) & 0xFF;
  13913. payload[1] = IPV6_LINK_LOCAL_PREFIX & 0xFF;
  13914. payload[8 ]= CsuMac[0];
  13915. payload[8] ^= 0x02;// bit 1 should complemented.
  13916. payload[9] = CsuMac[1];
  13917. payload[10] = CsuMac[2];
  13918. payload[11] = 0xFF;
  13919. payload[12] = 0xFE;
  13920. payload[13] = CsuMac[3];
  13921. payload[14] = CsuMac[4];
  13922. payload[15] = CsuMac[5];
  13923. //TCP port
  13924. payload[16] = (EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active>>8) & 0xFF;
  13925. payload[17] = EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active & 0xFF;
  13926. payload[18] = SDP_PAYLOAD_SECURITY_NONE; //Security
  13927. payload[19] = SDP_PAYLOAD_TRANS_PROTOCOL_TCP; //Transport protocol
  13928. //[To-Do] Setup the TCP in advance to receive the coming TCP handshke messages after SDP response.
  13929. Rtn = sendto(UdpSock, V2gtpMsgRxBuf, sizeof(struct V2gtpHeader) + htonl(header->PayloadLength), 0, (struct sockaddr *)&ClientAddr, sizeof(struct sockaddr_in6));
  13930. sprintf((char*)buf_log_evcomm, "[SDP][TX]Res from SECC");
  13931. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13932. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  13933. {
  13934. DEBUG_PRINTF_EVCOMM_DETAIL("\n\n***** Response SDP Packet *****\n");
  13935. DEBUG_PRINTF_EVCOMM_DETAIL("Send size=%d\n",Rtn);
  13936. DEBUG_PRINTF_EVCOMM_DETAIL("Destination Address=");
  13937. for(Rtn = 0; Rtn < 16; Rtn++)
  13938. {
  13939. DEBUG_PRINTF_EVCOMM_DETAIL("%02x, ", ClientAddr.sin6_addr.s6_addr[Rtn]);
  13940. }
  13941. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  13942. DEBUG_PRINTF_EVCOMM_DETAIL("Destination Port=%d\n", ClientAddr.sin6_port);
  13943. DEBUG_PRINTF_EVCOMM_DETAIL("ProtocolVersion=%d\n", header->ProtocolVersion);
  13944. DEBUG_PRINTF_EVCOMM_DETAIL("InverseProtocolVersion=0x%x\n", header->InverseProtocolVersion);
  13945. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadType=0x%x\n", htons(header->PayloadType));
  13946. DEBUG_PRINTF_EVCOMM_DETAIL("PayloadLength=0x%x\n", htonl(header->PayloadLength));
  13947. DEBUG_PRINTF_EVCOMM_DETAIL("SECC Ipv6 Address=");
  13948. for(Rtn = 0; Rtn < 16; Rtn++)
  13949. {
  13950. DEBUG_PRINTF_EVCOMM_DETAIL("%02x:",payload[Rtn]);
  13951. }
  13952. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  13953. DEBUG_PRINTF_EVCOMM_DETAIL("SECC Port=%d\n", (payload[16]<<8 | payload[17]));
  13954. DEBUG_PRINTF_EVCOMM_DETAIL("Security=0x%x\n", payload[19]);
  13955. DEBUG_PRINTF_EVCOMM_DETAIL("TransportProtocol=0x%x\n", payload[20]);
  13956. }
  13957. #endif
  13958. if(Rtn > 0)
  13959. {
  13960. return 1;
  13961. }
  13962. }
  13963. }
  13964. return 0;
  13965. }
  13966. /*===========================================================================
  13967. FUNCTION: V2gTcpConnected
  13968. DESCRIPTION:
  13969. PRE-CONDITION:
  13970. INPUT:
  13971. OUTPUT:
  13972. GLOBAL VARIABLES:
  13973. =============================================================================*/
  13974. int V2gTcpConnected()
  13975. {
  13976. int Rtn,AcceptFd;
  13977. struct sockaddr_in6 ServerAddr,ClientAddr;
  13978. if(TcpSock <= 0)
  13979. {
  13980. if ((TcpSock = socket(PF_INET6, SOCK_STREAM, 0)) < 0)
  13981. {
  13982. sprintf((char*)buf_log_evcomm,
  13983. "V2gTcpConnected: Fail to open TcpSock (%s)",
  13984. strerror(errno));
  13985. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  13986. usleep(100000); //100ms
  13987. return 0;
  13988. }
  13989. fcntl(TcpSock, F_SETFL, O_NONBLOCK); //set to O_NONBLOCK
  13990. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]socket set: DONE");
  13991. memset(&ServerAddr,0, sizeof(struct sockaddr_in));
  13992. ServerAddr.sin6_family = PF_INET6;
  13993. ServerAddr.sin6_addr = in6addr_any;
  13994. ServerAddr.sin6_port = htons(EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  13995. //ServerAddr.sin6_port = htons(SdpTcpServerPort + (rand() % 10) + 1);
  13996. //printf("SdpTcpServerPort = %d(DEC)\n", htons(ServerAddr.sin6_port));
  13997. if(bind(TcpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) < 0)
  13998. {
  13999. sprintf((char*)buf_log_evcomm,
  14000. "V2gTcpConnected: Fail to bind TcpSock (%s), SdpTcpServerPort = %d",
  14001. strerror(errno),
  14002. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active
  14003. );
  14004. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14005. //Change to another TCP port
  14006. /*
  14007. memset(&ServerAddr, 0, sizeof(struct sockaddr_in));
  14008. ServerAddr.sin6_family = PF_INET6;
  14009. ServerAddr.sin6_addr = in6addr_any;
  14010. //ServerAddr.sin6_port = htons(SdpTcpServerPort + (rand() % 1000) + 1);
  14011. ServerAddr.sin6_port = htons(EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  14012. */
  14013. if(bind(TcpSock, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in6)) < 0)
  14014. {
  14015. sprintf((char*)buf_log_evcomm,
  14016. "V2gTcpConnected: Fail to bind TcpSock (%s), SdpTcpServerPort = %d",
  14017. strerror(errno),
  14018. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active
  14019. );
  14020. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14021. usleep(100000); //100ms
  14022. close(TcpSock);
  14023. TcpSock = -1;
  14024. return 0;
  14025. }
  14026. }
  14027. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]blid: DONE");
  14028. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]listen: START");
  14029. if(listen(TcpSock, 1) == -1) //only accept one connection
  14030. {
  14031. sprintf((char*)buf_log_evcomm,
  14032. "V2gTcpConnected: Fail to listen TcpSock (%s)",
  14033. strerror(errno));
  14034. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14035. usleep(100000); //100ms
  14036. close(TcpSock);
  14037. TcpSock = -1;
  14038. return 0;
  14039. }
  14040. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]listen: DONE");
  14041. sprintf((char*)buf_log_evcomm, "[TCP]TcpSock: opened(%d), port=%d", TcpSock, htons(ServerAddr.sin6_port));
  14042. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14043. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]accept: START");
  14044. }
  14045. Rtn = sizeof(struct sockaddr_in6);
  14046. if((AcceptFd = accept(TcpSock, (struct sockaddr *)&ClientAddr, (socklen_t *)&Rtn)) == -1)
  14047. {
  14048. static BOOL tmp = 0;
  14049. if (tmp == 0)
  14050. {
  14051. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[TCP]Wait TCP connection...");
  14052. tmp = 1;
  14053. }
  14054. else
  14055. {
  14056. //DEBUG_PRINTF_EVCOMM_DETAIL(".");
  14057. }
  14058. return 0;
  14059. }
  14060. SAVE_SYS_LOG_MSG_EVCOMM("%s", "[TCP]accept: DONE\n");
  14061. #if (DEBUG_PRINTF_EVCOMM_DETAIL_SHOW == ENABLE)
  14062. {
  14063. DEBUG_PRINTF_EVCOMM_DETAIL("\n\nAccept one TCP connection:\n");
  14064. DEBUG_PRINTF_EVCOMM_DETAIL("AcceptFd=%d\n",AcceptFd);
  14065. DEBUG_PRINTF_EVCOMM_DETAIL("ClientAddress=");
  14066. for(Rtn = 0; Rtn < 16; Rtn += 2)
  14067. {
  14068. DEBUG_PRINTF_EVCOMM_DETAIL("%02x%02x:", ClientAddr.sin6_addr.s6_addr[Rtn], ClientAddr.sin6_addr.s6_addr[Rtn+1]);
  14069. }
  14070. DEBUG_PRINTF_EVCOMM_DETAIL("\n");
  14071. DEBUG_PRINTF_EVCOMM_DETAIL("ClientPort=%d\n", ClientAddr.sin6_port);
  14072. }
  14073. #endif
  14074. return AcceptFd;
  14075. }
  14076. /*===========================================================================
  14077. FUNCTION: End_Process
  14078. DESCRIPTION:
  14079. PRE-CONDITION:
  14080. 1. <CAUTION> This function could only be used in SeccComm fork2.
  14081. INPUT:
  14082. OUTPUT:
  14083. GLOBAL VARIABLES:
  14084. =============================================================================*/
  14085. int End_Process()
  14086. {
  14087. if(EVCOMM_SYS_INFO.End_Process_inused == TRUE)
  14088. {
  14089. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "End_Process has been triggered by another event.");
  14090. return -1;
  14091. }
  14092. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Entering...");
  14093. //STEP 1: Ask CSU to Stop
  14094. EVCOMM_SYS_INFO.End_Process_inused = TRUE;
  14095. CSUCOMMDC_TASK_FLAG.Send_EVStopReq = TRUE;
  14096. EVCOMM_SYS_INFO.ConnectorLocked = FALSE;
  14097. ShmInternalComm->ChargingPermission = FALSE;
  14098. //Step 2: Close sockets
  14099. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Close sockets...");
  14100. if(RawSock > 0)
  14101. {
  14102. close(RawSock);
  14103. }
  14104. if(UdpSock > 0)
  14105. {
  14106. close(UdpSock);
  14107. }
  14108. if(TcpSock > 0)
  14109. {
  14110. close(TcpSock);
  14111. close(TcpAcceptFd);
  14112. }
  14113. RawSock = UdpSock = TcpSock = TcpAcceptFd = -1;
  14114. //STEP 3: Switch to State E
  14115. //SwitchCpStateE(ENABLE);
  14116. //STEP 4: Close tcpdump
  14117. Sniffer_Tcpdump(DISABLE);
  14118. //STEP 5: Keep 100% PWM for 5 seconds
  14119. OutputCpPwmDuty(100);
  14120. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 5");
  14121. sleep(1);
  14122. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 4");
  14123. sleep(1);
  14124. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 3");
  14125. sleep(1);
  14126. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 2");
  14127. sleep(1);
  14128. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 1");
  14129. sleep(1);
  14130. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "PWM 100\% countdown: 0");
  14131. AttenProfileCnt = 0;
  14132. init_appHandEXIDocument(&ccs_handshake);
  14133. // Qca7kPowerReset(); //reset QCA7000 /* +++ 20200808, vern, should disconnected PLC connection after session stop ---*/
  14134. #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
  14135. {
  14136. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "[End_Process]1st sync...");
  14137. system("sync");
  14138. }
  14139. #endif
  14140. //STEP 4: Switch to State E
  14141. //Keep State E for 5 seconds
  14142. #if 0
  14143. SwitchCpStateE(ENABLE); //Set PWM Duty as 0 and set State as E (0V)
  14144. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 5");
  14145. sleep(1);
  14146. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 4");
  14147. sleep(1);
  14148. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 3");
  14149. sleep(1);
  14150. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 2");
  14151. sleep(1);
  14152. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 1");
  14153. sleep(1);
  14154. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "State E countdown: 0");
  14155. #endif
  14156. //Reset Memory
  14157. unsigned char SlaveAddress_backup;
  14158. unsigned int matched_backup;
  14159. //unsigned char state_backup;
  14160. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "Soft reset (closing SeccComm)...");
  14161. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "---------------------------------------------");
  14162. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "-- EVCOMM: END --");
  14163. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "---------------------------------------------\n");
  14164. #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
  14165. {
  14166. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "2nd sync...");
  14167. system("sync");
  14168. }
  14169. #endif
  14170. system("sleep 1");
  14171. //Backup CsuComm flags
  14172. SlaveAddress_backup = ShmInternalComm->SlaveAddress;
  14173. matched_backup = CSUCOMMDC_TASK_FLAG.matched;
  14174. //state_backup = Check_V2G_Flow_Status();
  14175. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  14176. memset(V2gtpMsgTxBuf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  14177. memset(&ccs_handshake, 0, sizeof(struct appHandEXIDocument));
  14178. memset(&ccs_exi_doc_DIN, 0, sizeof(struct dinEXIDocument));
  14179. memset(V2GTP_Tx_buf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  14180. memset(buf_log_evcomm, 0, sizeof(buf_log_evcomm));
  14181. memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
  14182. memset(ShmInternalComm, 0, sizeof(struct InternalComm));
  14183. memset(ShmCcsData, 0, sizeof(struct CcsData));
  14184. //Resume CsuComm flags
  14185. ShmInternalComm->SlaveAddress = SlaveAddress_backup;
  14186. CSUCOMMDC_TASK_FLAG.matched = matched_backup;
  14187. Sniffer_Candump(DISABLE);
  14188. Sniffer_Candump(ENABLE);
  14189. //memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo)); //EVCOMM_SYS_INFO.End_Process_inused = FALSE;
  14190. //EVCOMM_SYS_INFO.End_Process_inused = TRUE;
  14191. //Update_V2G_Flow_Status(state_backup);
  14192. //CP_Detection_Pid = 0;
  14193. //PP_Detection_Pid = 0;
  14194. //Error_Monitor_Pid = 0;
  14195. //system("cd /root;./reset_soft.sh");
  14196. system("pkill Module_CCS");
  14197. while(1)
  14198. {
  14199. //wait for CSU confirm
  14200. usleep(1000);
  14201. }
  14202. }
  14203. /*===========================================================================
  14204. FUNCTION: Parameters_Init
  14205. DESCRIPTION:
  14206. PRE-CONDITION:
  14207. INPUT:
  14208. OUTPUT:
  14209. GLOBAL VARIABLES:
  14210. =============================================================================*/
  14211. int Parameters_Init()
  14212. {
  14213. //Step 0: Generate random number
  14214. unsigned int value_random;
  14215. struct timeb time_seed;
  14216. ftime(&time_seed);
  14217. srand(time_seed.millitm);
  14218. //Step 1: Init SDP TCP Port
  14219. value_random = rand();
  14220. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active = (unsigned short)(SdpTcpServerPort + (value_random % 10000) + 1);
  14221. sprintf((char*)buf_log_evcomm,
  14222. "[Init]TCP Port:OK(%d)",
  14223. EVCOMM_SYS_INFO.SDP_TCP_Server_Port_active);
  14224. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14225. //Step 2: Init SessionID
  14226. value_random = rand();
  14227. memcpy(&EVCOMM_SYS_INFO.SessionID[0], &value_random, 4);
  14228. value_random = rand();
  14229. memcpy(&EVCOMM_SYS_INFO.SessionID[4], &value_random, 4);
  14230. sprintf((char*)buf_log_evcomm,
  14231. "[Init]SessionID:OK(%02X%02X%02X%02X%02X%02X%02X%02X)",
  14232. EVCOMM_SYS_INFO.SessionID[0],
  14233. EVCOMM_SYS_INFO.SessionID[1],
  14234. EVCOMM_SYS_INFO.SessionID[2],
  14235. EVCOMM_SYS_INFO.SessionID[3],
  14236. EVCOMM_SYS_INFO.SessionID[4],
  14237. EVCOMM_SYS_INFO.SessionID[5],
  14238. EVCOMM_SYS_INFO.SessionID[6],
  14239. EVCOMM_SYS_INFO.SessionID[7]);
  14240. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14241. return 0;
  14242. }
  14243. /*===========================================================================
  14244. FUNCTION: AC share memory synchronize
  14245. DESCRIPTION:
  14246. PRE-CONDITION:
  14247. INPUT:
  14248. OUTPUT:
  14249. GLOBAL VARIABLES:
  14250. =============================================================================*/
  14251. int SyncAcShreaMemory()
  14252. {
  14253. #if (CCS_ENERGY_TRANSFER_MODE == MODE_AC_THREE_PHASE_CORE)
  14254. pid_t pid;
  14255. pid = fork();
  14256. if(pid == 0)
  14257. {
  14258. for(;;)
  14259. {
  14260. if(!EVCOMM_SYS_INFO.End_Process_inused)
  14261. {
  14262. for(uint8_t gun_index=0;gun_index<1;gun_index++)
  14263. {
  14264. //========================================
  14265. // CSU -> CCS setting
  14266. //========================================
  14267. // Permission
  14268. if(ShmInternalComm->ChargingPermission != ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission)
  14269. {
  14270. DEBUG_INFO("AC permission: %d -> %d\n", ShmInternalComm->ChargingPermission, ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission);
  14271. ShmInternalComm->ChargingPermission_new = ShmCharger->gun_info[gun_index].acCcsInfo.ChargingPermission;
  14272. ShmInternalComm->ChargingPermission_pre = ShmInternalComm->ChargingPermission;
  14273. ShmInternalComm->ChargingPermission = ShmInternalComm->ChargingPermission_new;
  14274. }
  14275. // CP
  14276. ShmInternalComm->AC_CpPositiveVoltage = ShmCharger->gun_info[gun_index].acCcsInfo.CpPositiveVoltage;
  14277. if(ShmInternalComm->AC_CpPresentState != ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState)
  14278. {
  14279. DEBUG_INFO("CP state: %d -> %d\n", ShmInternalComm->AC_CpPresentState, ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState);
  14280. ShmInternalComm->AC_CpPresentState = ShmCharger->gun_info[gun_index].acCcsInfo.CpPresentState;
  14281. }
  14282. //========================================
  14283. // CCS -> CSU check
  14284. //========================================
  14285. // V2G message flow status
  14286. if(ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus != Check_V2G_Flow_Status())
  14287. {
  14288. //DEBUG_INFO("PresentMsgFlowStatus: %d -> %d\n", ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus, Check_V2G_Flow_Status());
  14289. ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus = Check_V2G_Flow_Status();
  14290. switch(ShmCharger->gun_info[gun_index].acCcsInfo.PresentMsgFlowStatus)
  14291. {
  14292. case PowerDeliveryRequestStart ... ChargingStatusResponse:
  14293. ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = HLC_START_MODE;
  14294. break;
  14295. case CM_SLAC_PARM_REQ ... PreChargeResponse:
  14296. ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = HLC_STANDBY_MODE;
  14297. break;
  14298. default:
  14299. ShmCharger->gun_info[gun_index].acCcsInfo.EVChargeProgress = HLC_STOP_MODE;
  14300. break;
  14301. }
  14302. }
  14303. }
  14304. }
  14305. usleep(1000);
  14306. }
  14307. }
  14308. #endif
  14309. return 0;
  14310. }
  14311. /*===========================================================================
  14312. FUNCTION: main
  14313. DESCRIPTION:
  14314. PRE-CONDITION:
  14315. INPUT:
  14316. OUTPUT:
  14317. GLOBAL VARIABLES:
  14318. =============================================================================*/
  14319. int main(int argc, char *argv[])
  14320. {
  14321. //unsigned char Rtn;
  14322. Qca7kPowerReset();
  14323. //Initialization
  14324. ShareMemory_Init();
  14325. memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
  14326. if(RawSock > 0)
  14327. {
  14328. close(RawSock);
  14329. }
  14330. if(UdpSock > 0)
  14331. {
  14332. close(UdpSock);
  14333. }
  14334. if(TcpSock > 0)
  14335. {
  14336. close(TcpSock);
  14337. }
  14338. RawSock = UdpSock = TcpSock = -1;
  14339. Update_V2G_Flow_Status(IDLE);
  14340. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "---------------------------------------------");
  14341. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "-- EVCOMM: START --");
  14342. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", "---------------------------------------------");
  14343. //Init V2G TCP/IPv6 packets buffer
  14344. memset(V2gtpMsgRxBuf, 0, V2GTP_MSG_RX_BUFFER_SIZE);
  14345. memset(V2gtpMsgTxBuf, 0, V2GTP_MSG_TX_BUFFER_SIZE);
  14346. //Release State E Control
  14347. SwitchCpStateE(DISABLE);
  14348. OutputCpPwmDuty(100);
  14349. //start to detect CP pilot state
  14350. CP_Detection_Pid = 0;
  14351. CP_Detection(); //fork1
  14352. SAVE_SYS_LOG_MSG_EVCOMM("[fork1]CP Detection: ON\n");
  14353. //start to detect errors
  14354. Error_Monitor(); //fork2
  14355. SAVE_SYS_LOG_MSG_EVCOMM("[fork2]Error Monitor: ON\n");
  14356. //start to detect PP
  14357. PP_Detection_Pid = 0;
  14358. #if (PP_PROTECTION_MECHANISM == ENABLE)
  14359. PP_Detection();
  14360. SAVE_SYS_LOG_MSG_EVCOMM("[fork3]PP Detection: ON\n");
  14361. #else
  14362. SAVE_SYS_LOG_MSG_EVCOMM("[fork3]PP Detection: OFF\n");
  14363. #endif
  14364. //Init communication parameters
  14365. GetEthMac((uint8_t*)QcaInterface, CsuMac);
  14366. AttenProfileCnt = 0;
  14367. init_appHandEXIDocument(&ccs_handshake);
  14368. //Init Energy transfer mode
  14369. //[To-Do] Parsing Model Name
  14370. ShmCcsData->EnergyTransferMode = CCS_ENERGY_TRANSFER_MODE;
  14371. //struct ChargingInfoData *ccs;
  14372. //ccs = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[0];
  14373. Parameters_Init();
  14374. Sniffer_Tcpdump(ENABLE);
  14375. #if (TCPDUMP_PACKETS_SNIFFER_SWITCH == ENABLE)
  14376. sleep(1); //wait for tcpdump getting ready
  14377. #endif
  14378. SyncAcShreaMemory();
  14379. SAVE_SYS_LOG_MSG_EVCOMM("Initialize OK.\n");
  14380. while(1)
  14381. {
  14382. //DEBUG_PRINTF_EVCOMM_DETAIL("\nV2gFlowStatus = %d\n", V2gFlowStatus);
  14383. //if((ShmInternalComm->ChargingPermission == 0x01) && (CheckConnectorPlugIn() == 1))
  14384. //if((CheckConnectorPlugIn() == TRUE) && (ShmInternalComm->ChargingPermission == TRUE))
  14385. //if(ShmInternalComm->ChargingPermission == 0x01)
  14386. //if(CheckConnectorPlugIn() == TRUE)
  14387. if (EVCOMM_SYS_INFO.End_Process_inused == FALSE)
  14388. {
  14389. if(V2gFlowStatus < SLACC_SDP_UDP_Connection)
  14390. {
  14391. SlacComm();
  14392. }
  14393. else if(V2gFlowStatus == SLACC_SDP_UDP_Connection)
  14394. {
  14395. if(SdpUdpConnected() == 1)
  14396. {
  14397. Update_V2G_Flow_Status(SLACC_SDP_TCP_Connection);
  14398. continue;
  14399. }
  14400. SlacComm(); //TC_SECC_VTB_CmSlacMatch_004
  14401. ftime(&SeqEndTime);
  14402. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_join)
  14403. {
  14404. sprintf((char*)buf_log_evcomm,
  14405. "Wait SLACC_SDP_UDP_Connection Timeout - TT_match_join (%.02lf of %d ms)\n",
  14406. DiffTimeb(SeqStartTime, SeqEndTime),
  14407. TT_match_join);
  14408. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14409. Update_V2G_Flow_Status(Sequence_Timeout);
  14410. //Update_ShmStatusCode(); //[To-Do] to be implemented
  14411. //CCS_SECC_TIMEOUT_SLACC_SDP_UDP_TT_match_join (023823)
  14412. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  14413. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  14414. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  14415. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  14416. ShmStatusCodeData->PresentStatusCode[0][4] = 2;
  14417. ShmStatusCodeData->PresentStatusCode[0][5] = 3;
  14418. //CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  14419. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  14420. }
  14421. }
  14422. else if(V2gFlowStatus == SLACC_SDP_TCP_Connection)
  14423. {
  14424. if((TcpAcceptFd = V2gTcpConnected()) > 0)
  14425. {
  14426. Update_V2G_Flow_Status(SupportedAppProtocolRequest);
  14427. ftime(&EVCOMM_SYS_INFO.V2G_SECC_Sequence_Timer_Start);
  14428. continue;
  14429. }
  14430. SlacComm();
  14431. ftime(&SeqEndTime);
  14432. if(DiffTimeb(SeqStartTime, SeqEndTime) > TT_match_join)
  14433. {
  14434. sprintf((char*)buf_log_evcomm,
  14435. "Wait SLACC_SDP_TCP_Connection Timeout - TT_match_join (%.02lf / %d ms)",
  14436. DiffTimeb(SeqStartTime, SeqEndTime),
  14437. TT_match_join);
  14438. SAVE_SYS_LOG_MSG_EVCOMM("%s\n", buf_log_evcomm);
  14439. Update_V2G_Flow_Status(Sequence_Timeout);
  14440. //Update_ShmStatusCode(); //[To-Do] to be implemented
  14441. //CCS_SECC_TIMEOUT_SLACC_SDP_TCP_TT_match_join (023824)
  14442. ShmStatusCodeData->PresentStatusCode[0][0] = 0;
  14443. ShmStatusCodeData->PresentStatusCode[0][1] = 2;
  14444. ShmStatusCodeData->PresentStatusCode[0][2] = 3;
  14445. ShmStatusCodeData->PresentStatusCode[0][3] = 8;
  14446. ShmStatusCodeData->PresentStatusCode[0][4] = 2;
  14447. ShmStatusCodeData->PresentStatusCode[0][5] = 4;
  14448. //CSUCOMMDC_TASK_FLAG.EV_Stop_Type_Emergency = TRUE;
  14449. Proc_EVStopRes(ShmInternalComm->FD_CAN_Socket);
  14450. }
  14451. }
  14452. else if(V2gFlowStatus <= SessionStopResponse)
  14453. {
  14454. if (V2gComm(TcpAcceptFd) < 0)
  14455. {
  14456. //error occours
  14457. }
  14458. }
  14459. else if (V2gFlowStatus >= Performance_Timeout)
  14460. {
  14461. //End_Process
  14462. }
  14463. else
  14464. {
  14465. //null
  14466. }
  14467. }
  14468. usleep(1000);
  14469. } //while
  14470. }//main while